comparison src/event/quic/ngx_event_quic.c @ 8385:9ce6d80df113 quic

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.
author Vladimir Homutov <vl@nginx.com>
date Fri, 02 Apr 2021 11:31:37 +0300
parents c61fcdc1b8e3
children 714e9af983de
comparison
equal deleted inserted replaced
8384:c61fcdc1b8e3 8385:9ce6d80df113
110 ngx_uint_t send_ack; 110 ngx_uint_t send_ack;
111 } ngx_quic_send_ctx_t; 111 } ngx_quic_send_ctx_t;
112 112
113 113
114 typedef struct { 114 typedef struct {
115 ngx_udp_connection_t udp;
116
117 uint32_t version; 115 uint32_t version;
118 ngx_str_t scid; /* initial client ID */ 116 ngx_str_t scid; /* initial client ID */
119 ngx_str_t dcid; /* server (our own) ID */ 117 ngx_str_t dcid; /* server (our own) ID */
120 ngx_str_t odcid; /* original server ID */ 118 ngx_str_t odcid; /* original server ID */
121 119
196 } ngx_quic_client_id_t; 194 } ngx_quic_client_id_t;
197 195
198 196
199 typedef struct { 197 typedef struct {
200 ngx_udp_connection_t udp; 198 ngx_udp_connection_t udp;
199 ngx_quic_connection_t *quic;
201 ngx_queue_t queue; 200 ngx_queue_t queue;
202 uint64_t seqnum; 201 uint64_t seqnum;
203 size_t len; 202 size_t len;
204 u_char id[NGX_QUIC_CID_LEN_MAX]; 203 u_char id[NGX_QUIC_CID_LEN_MAX];
205 } ngx_quic_server_id_t; 204 } ngx_quic_server_id_t;
340 static ngx_int_t ngx_quic_handle_retire_connection_id_frame(ngx_connection_t *c, 339 static ngx_int_t ngx_quic_handle_retire_connection_id_frame(ngx_connection_t *c,
341 ngx_quic_header_t *pkt, ngx_quic_retire_cid_frame_t *f); 340 ngx_quic_header_t *pkt, ngx_quic_retire_cid_frame_t *f);
342 static ngx_int_t ngx_quic_issue_server_ids(ngx_connection_t *c); 341 static ngx_int_t ngx_quic_issue_server_ids(ngx_connection_t *c);
343 static void ngx_quic_clear_temp_server_ids(ngx_connection_t *c); 342 static void ngx_quic_clear_temp_server_ids(ngx_connection_t *c);
344 static ngx_quic_server_id_t *ngx_quic_insert_server_id(ngx_connection_t *c, 343 static ngx_quic_server_id_t *ngx_quic_insert_server_id(ngx_connection_t *c,
345 ngx_str_t *id); 344 ngx_quic_connection_t *qc, ngx_str_t *id);
346 static ngx_quic_client_id_t *ngx_quic_alloc_client_id(ngx_connection_t *c, 345 static ngx_quic_client_id_t *ngx_quic_alloc_client_id(ngx_connection_t *c,
347 ngx_quic_connection_t *qc); 346 ngx_quic_connection_t *qc);
348 static ngx_quic_server_id_t *ngx_quic_alloc_server_id(ngx_connection_t *c, 347 static ngx_quic_server_id_t *ngx_quic_alloc_server_id(ngx_connection_t *c,
349 ngx_quic_connection_t *qc); 348 ngx_quic_connection_t *qc);
350 349
1094 ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf, 1093 ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf,
1095 ngx_quic_header_t *pkt) 1094 ngx_quic_header_t *pkt)
1096 { 1095 {
1097 ngx_uint_t i; 1096 ngx_uint_t i;
1098 ngx_quic_tp_t *ctp; 1097 ngx_quic_tp_t *ctp;
1098 ngx_quic_server_id_t *sid;
1099 ngx_quic_client_id_t *cid; 1099 ngx_quic_client_id_t *cid;
1100 ngx_quic_connection_t *qc; 1100 ngx_quic_connection_t *qc;
1101 1101
1102 qc = ngx_pcalloc(c->pool, sizeof(ngx_quic_connection_t)); 1102 qc = ngx_pcalloc(c->pool, sizeof(ngx_quic_connection_t));
1103 if (qc == NULL) { 1103 if (qc == NULL) {
1245 != NGX_OK) 1245 != NGX_OK)
1246 { 1246 {
1247 return NULL; 1247 return NULL;
1248 } 1248 }
1249 1249
1250 c->udp = &qc->udp; 1250 if (ngx_quic_insert_server_id(c, qc, &qc->odcid) == NULL) {
1251
1252 if (ngx_quic_insert_server_id(c, &qc->odcid) == NULL) {
1253 return NULL; 1251 return NULL;
1254 } 1252 }
1255 1253
1256 qc->server_seqnum = 0; 1254 qc->server_seqnum = 0;
1257 1255
1258 if (ngx_quic_insert_server_id(c, &qc->dcid) == NULL) { 1256 sid = ngx_quic_insert_server_id(c, qc, &qc->dcid);
1257 if (sid == NULL) {
1259 return NULL; 1258 return NULL;
1260 } 1259 }
1260
1261 c->udp = &sid->udp;
1261 1262
1262 qc->validated = pkt->validated; 1263 qc->validated = pkt->validated;
1263 1264
1264 return qc; 1265 return qc;
1265 } 1266 }
4775 } 4776 }
4776 4777
4777 dcid.len = NGX_QUIC_SERVER_CID_LEN; 4778 dcid.len = NGX_QUIC_SERVER_CID_LEN;
4778 dcid.data = id; 4779 dcid.data = id;
4779 4780
4780 sid = ngx_quic_insert_server_id(c, &dcid); 4781 sid = ngx_quic_insert_server_id(c, qc, &dcid);
4781 if (sid == NULL) { 4782 if (sid == NULL) {
4782 return NGX_ERROR; 4783 return NGX_ERROR;
4783 } 4784 }
4784 4785
4785 frame = ngx_quic_alloc_frame(c); 4786 frame = ngx_quic_alloc_frame(c);
4838 } 4839 }
4839 } 4840 }
4840 4841
4841 4842
4842 static ngx_quic_server_id_t * 4843 static ngx_quic_server_id_t *
4843 ngx_quic_insert_server_id(ngx_connection_t *c, ngx_str_t *id) 4844 ngx_quic_insert_server_id(ngx_connection_t *c, ngx_quic_connection_t *qc,
4844 { 4845 ngx_str_t *id)
4845 ngx_str_t dcid; 4846 {
4846 ngx_quic_server_id_t *sid; 4847 ngx_str_t dcid;
4847 ngx_quic_connection_t *qc; 4848 ngx_quic_server_id_t *sid;
4848
4849 qc = ngx_quic_get_connection(c);
4850 4849
4851 sid = ngx_quic_alloc_server_id(c, qc); 4850 sid = ngx_quic_alloc_server_id(c, qc);
4852 if (sid == NULL) { 4851 if (sid == NULL) {
4853 return NULL; 4852 return NULL;
4854 } 4853 }
4854
4855 sid->quic = qc;
4855 4856
4856 sid->seqnum = qc->server_seqnum; 4857 sid->seqnum = qc->server_seqnum;
4857 4858
4858 if (qc->server_seqnum != NGX_QUIC_UNSET_PN) { 4859 if (qc->server_seqnum != NGX_QUIC_UNSET_PN) {
4859 qc->server_seqnum++; 4860 qc->server_seqnum++;