]> git.kaiwu.me - nginx.git/commitdiff
QUIC: simplified quic connection dispatching.
authorVladimir Homutov <vl@nginx.com>
Fri, 2 Apr 2021 08:31:37 +0000 (11:31 +0300)
committerVladimir Homutov <vl@nginx.com>
Fri, 2 Apr 2021 08:31:37 +0000 (11:31 +0300)
Currently listener contains rbtree with multiple nodes for single QUIC
connection: each corresponding to specific server id.  Each udp node points
to same ngx_connection_t, which points to QUIC connection via c->udp field.

Thus when an event handler is called, it only gets ngx_connection_t with
c->udp pointing to QUIC connection.  This makes it hard to obtain actual
node which was used to dispatch packet (it requires to repeat DCID lookup).

Additionally, ngx_quic_connection_t->udp field is only needed to keep a
pointer in c->udp. The node is not added into the tree and does not carry
useful information.

src/event/ngx_event_udp.c
src/event/quic/ngx_event_quic.c
src/event/quic/ngx_event_quic.h

index ca70e3bd67c8872387a7044d2751fc23a34cc27f..95895571d974ed1a22875d46e3d9a95d8f4496b6 100644 (file)
@@ -684,6 +684,13 @@ ngx_lookup_udp_connection(ngx_listening_t *ls, ngx_str_t *key,
         }
 
         if (rc == 0) {
+
+#if (NGX_QUIC)
+            if (ls->quic && c->udp != udp) {
+                c->udp = udp;
+            }
+#endif
+
             return c;
         }
 
index 77f0eeda89dce071b497e37283a161fcf27f79e2..d07c3ed49492a19dfaef67f991847862e832dd64 100644 (file)
@@ -112,8 +112,6 @@ typedef struct {
 
 
 typedef struct {
-    ngx_udp_connection_t              udp;
-
     uint32_t                          version;
     ngx_str_t                         scid;  /* initial client ID */
     ngx_str_t                         dcid;  /* server (our own) ID */
@@ -198,6 +196,7 @@ typedef struct {
 
 typedef struct {
     ngx_udp_connection_t              udp;
+    ngx_quic_connection_t            *quic;
     ngx_queue_t                       queue;
     uint64_t                          seqnum;
     size_t                            len;
@@ -342,7 +341,7 @@ static ngx_int_t ngx_quic_handle_retire_connection_id_frame(ngx_connection_t *c,
 static ngx_int_t ngx_quic_issue_server_ids(ngx_connection_t *c);
 static void ngx_quic_clear_temp_server_ids(ngx_connection_t *c);
 static ngx_quic_server_id_t *ngx_quic_insert_server_id(ngx_connection_t *c,
-    ngx_str_t *id);
+    ngx_quic_connection_t *qc, ngx_str_t *id);
 static ngx_quic_client_id_t *ngx_quic_alloc_client_id(ngx_connection_t *c,
     ngx_quic_connection_t *qc);
 static ngx_quic_server_id_t *ngx_quic_alloc_server_id(ngx_connection_t *c,
@@ -1096,6 +1095,7 @@ ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf,
 {
     ngx_uint_t              i;
     ngx_quic_tp_t          *ctp;
+    ngx_quic_server_id_t   *sid;
     ngx_quic_client_id_t   *cid;
     ngx_quic_connection_t  *qc;
 
@@ -1247,18 +1247,19 @@ ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf,
         return NULL;
     }
 
-    c->udp = &qc->udp;
-
-    if (ngx_quic_insert_server_id(c, &qc->odcid) == NULL) {
+    if (ngx_quic_insert_server_id(c, qc, &qc->odcid) == NULL) {
         return NULL;
     }
 
     qc->server_seqnum = 0;
 
-    if (ngx_quic_insert_server_id(c, &qc->dcid) == NULL) {
+    sid = ngx_quic_insert_server_id(c, qc, &qc->dcid);
+    if (sid == NULL) {
         return NULL;
     }
 
+    c->udp = &sid->udp;
+
     qc->validated = pkt->validated;
 
     return qc;
@@ -4777,7 +4778,7 @@ ngx_quic_issue_server_ids(ngx_connection_t *c)
         dcid.len = NGX_QUIC_SERVER_CID_LEN;
         dcid.data = id;
 
-        sid = ngx_quic_insert_server_id(c, &dcid);
+        sid = ngx_quic_insert_server_id(c, qc, &dcid);
         if (sid == NULL) {
             return NGX_ERROR;
         }
@@ -4840,19 +4841,19 @@ ngx_quic_clear_temp_server_ids(ngx_connection_t *c)
 
 
 static ngx_quic_server_id_t *
-ngx_quic_insert_server_id(ngx_connection_t *c, ngx_str_t *id)
+ngx_quic_insert_server_id(ngx_connection_t *c, ngx_quic_connection_t *qc,
+    ngx_str_t *id)
 {
-    ngx_str_t               dcid;
-    ngx_quic_server_id_t   *sid;
-    ngx_quic_connection_t  *qc;
-
-    qc = ngx_quic_get_connection(c);
+    ngx_str_t              dcid;
+    ngx_quic_server_id_t  *sid;
 
     sid = ngx_quic_alloc_server_id(c, qc);
     if (sid == NULL) {
         return NULL;
     }
 
+    sid->quic = qc;
+
     sid->seqnum = qc->server_seqnum;
 
     if (qc->server_seqnum != NGX_QUIC_UNSET_PN) {
index 0a38d911cf7bcb325bf339e2a45b1aeb60aefaf2..865e5f08c44a0d1c6728e56499f8f84a6e018c9c 100644 (file)
@@ -64,7 +64,8 @@
 
 #define NGX_QUIC_BUFFER_SIZE                 4096
 
-#define ngx_quic_get_connection(c)           ((ngx_quic_connection_t *)(c)->udp)
+#define ngx_quic_get_connection(c)                                            \
+    (((c)->udp) ? (((ngx_quic_server_id_t *)((c)->udp))->quic) : NULL)
 
 
 typedef struct {