diff src/event/ngx_event_quic_transport.c @ 8624:340cd26158fb quic

QUIC: preparatory changes for multiple QUIC versions support. A negotiated version is decoupled from NGX_QUIC_VERSION and, if supported, now stored in c->quic->version after packets processing. It is then used to create long header packets. Otherwise, the list of supported versions (which may be many now) is sent in the Version Negotiation packet. All packets in the connection are expected to have the same version. Incoming packets with mismatched version are now rejected.
author Sergey Kandaurov <pluknet@nginx.com>
date Tue, 10 Nov 2020 00:20:44 +0300
parents 867c189f875d
children 4416b7ab0a27
line wrap: on
line diff
--- a/src/event/ngx_event_quic_transport.c
+++ b/src/event/ngx_event_quic_transport.c
@@ -72,6 +72,7 @@ static ngx_int_t ngx_quic_parse_short_he
     size_t dcid_len);
 static ngx_int_t ngx_quic_parse_initial_header(ngx_quic_header_t *pkt);
 static ngx_int_t ngx_quic_parse_handshake_header(ngx_quic_header_t *pkt);
+static ngx_int_t ngx_quic_supported_version(uint32_t version);
 
 static ngx_int_t ngx_quic_frame_allowed(ngx_quic_header_t *pkt,
     ngx_uint_t frame_type);
@@ -268,7 +269,7 @@ ngx_quic_parse_packet(ngx_quic_header_t 
         return NGX_DECLINED;
     }
 
-    if (pkt->version != NGX_QUIC_VERSION) {
+    if (!ngx_quic_supported_version(pkt->version)) {
         return NGX_ABORT;
     }
 
@@ -430,7 +431,7 @@ ngx_quic_create_long_header(ngx_quic_hea
 
     *p++ = pkt->flags;
 
-    p = ngx_quic_write_uint32(p, NGX_QUIC_VERSION);
+    p = ngx_quic_write_uint32(p, pkt->version);
 
     *p++ = pkt->dcid.len;
     p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len);
@@ -517,7 +518,7 @@ ngx_quic_create_retry_itag(ngx_quic_head
 
     *p++ = 0xff;
 
-    p = ngx_quic_write_uint32(p, NGX_QUIC_VERSION);
+    p = ngx_quic_write_uint32(p, pkt->version);
 
     *p++ = pkt->dcid.len;
     p = ngx_cpymem(p, pkt->dcid.data, pkt->dcid.len);
@@ -651,6 +652,21 @@ ngx_quic_parse_handshake_header(ngx_quic
 }
 
 
+static ngx_int_t
+ngx_quic_supported_version(uint32_t version)
+{
+    ngx_uint_t  i;
+
+    for (i = 0; i < NGX_QUIC_NVERSIONS; i++) {
+        if (ngx_quic_versions[i] == version) {
+            return 1;
+        }
+    }
+
+    return 0;
+}
+
+
 #define ngx_quic_stream_bit_off(val)  (((val) & 0x04) ? 1 : 0)
 #define ngx_quic_stream_bit_len(val)  (((val) & 0x02) ? 1 : 0)
 #define ngx_quic_stream_bit_fin(val)  (((val) & 0x01) ? 1 : 0)