comparison src/event/quic/ngx_event_quic.c @ 8913:40445fc7c403 quic

QUIC: fixed migration during NAT rebinding. The RFC 9000 allows a packet from known CID arrive from unknown path: These requirements regarding connection ID reuse apply only to the sending of packets, as unintentional changes in path without a change in connection ID are possible. For example, after a period of network inactivity, NAT rebinding might cause packets to be sent on a new path when the client resumes sending. Before the patch, such packets were rejected with an error in the ngx_quic_check_migration() function. Removing the check makes the separate function excessive - remaining checks are early migration check and "disable_active_migration" check. The latter is a transport parameter sent to client and it should not be used by server. The server should send "disable_active_migration" "if the endpoint does not support active connection migration" (18.2). The support status depends on nginx configuration: to have migration working with multiple workers, you need bpf helper, available on recent Linux systems. The patch does not set "disable_active_migration" automatically and leaves it for the administrator. By default, active migration is enabled. RFC 900 says that it is ok to migrate if the peer violates "disable_active_migration" flag requirements: If the peer violates this requirement, the endpoint MUST either drop the incoming packets on that path without generating a Stateless Reset OR proceed with path validation and allow the peer to migrate. Generating a Stateless Reset or closing the connection would allow third parties in the network to cause connections to close by spoofing or otherwise manipulating observed traffic. So, nginx adheres to the second option and proceeds to path validation. Note: The ngtcp2 may be used for testing both active migration and NAT rebinding: ngtcp2/client --change-local-addr=200ms --delay-stream=500ms <ip> <port> <url> ngtcp2/client --change-local-addr=200ms --delay-stream=500ms --nat-rebinding \ <ip> <port> <url>
author Vladimir Homutov <vl@nginx.com>
date Mon, 29 Nov 2021 11:51:14 +0300
parents 50d73bf20e73
children d6ef13c5fd8e
comparison
equal deleted inserted replaced
8912:50d73bf20e73 8913:40445fc7c403
810 ngx_log_error(NGX_LOG_INFO, c->log, 0, 810 ngx_log_error(NGX_LOG_INFO, c->log, 0,
811 "quic unsupported version: 0x%xD", pkt->version); 811 "quic unsupported version: 0x%xD", pkt->version);
812 return NGX_DECLINED; 812 return NGX_DECLINED;
813 } 813 }
814 814
815 rc = ngx_quic_check_migration(c, pkt);
816 if (rc != NGX_OK) {
817 return rc;
818 }
819
820 if (pkt->level != ssl_encryption_application) { 815 if (pkt->level != ssl_encryption_application) {
821 816
822 if (pkt->version != qc->version) { 817 if (pkt->version != qc->version) {
823 ngx_log_error(NGX_LOG_INFO, c->log, 0, 818 ngx_log_error(NGX_LOG_INFO, c->log, 0,
824 "quic version mismatch: 0x%xD", pkt->version); 819 "quic version mismatch: 0x%xD", pkt->version);
825 return NGX_DECLINED; 820 return NGX_DECLINED;
821 }
822
823 if (pkt->first) {
824 if (ngx_quic_find_path(c, c->udp->dgram->sockaddr,
825 c->udp->dgram->socklen)
826 == NULL)
827 {
828 /* packet comes from unknown path, possibly migration */
829 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
830 "quic too early migration attempt");
831 return NGX_DECLINED;
832 }
826 } 833 }
827 834
828 if (ngx_quic_check_csid(qc, pkt) != NGX_OK) { 835 if (ngx_quic_check_csid(qc, pkt) != NGX_OK) {
829 return NGX_DECLINED; 836 return NGX_DECLINED;
830 } 837 }