# HG changeset patch # User Vladimir Homutov # Date 1617352297 -10800 # Node ID 9ce6d80df113812c42e96a8c8b9027f8ffb65b56 # Parent c61fcdc1b8e3333653868b4ac545b487484c75bb QUIC: simplified quic connection dispatching. 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. diff --git a/src/event/ngx_event_udp.c b/src/event/ngx_event_udp.c --- a/src/event/ngx_event_udp.c +++ b/src/event/ngx_event_udp.c @@ -684,6 +684,13 @@ ngx_lookup_udp_connection(ngx_listening_ } if (rc == 0) { + +#if (NGX_QUIC) + if (ls->quic && c->udp != udp) { + c->udp = udp; + } +#endif + return c; } diff --git a/src/event/quic/ngx_event_quic.c b/src/event/quic/ngx_event_quic.c --- a/src/event/quic/ngx_event_quic.c +++ b/src/event/quic/ngx_event_quic.c @@ -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_ 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 { 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 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 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_conne 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) { diff --git a/src/event/quic/ngx_event_quic.h b/src/event/quic/ngx_event_quic.h --- a/src/event/quic/ngx_event_quic.h +++ b/src/event/quic/ngx_event_quic.h @@ -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 {