comparison src/event/quic/ngx_event_quic_streams.c @ 8827:fe919fd63b0b quic

QUIC: client certificate validation with OCSP.
author Sergey Kandaurov <pluknet@nginx.com>
date Wed, 04 Aug 2021 15:49:18 +0300
parents 4009f120cad4
children a9f6540e61da
comparison
equal deleted inserted replaced
8826:c35b255d80dc 8827:fe919fd63b0b
13 #define NGX_QUIC_STREAM_GONE (void *) -1 13 #define NGX_QUIC_STREAM_GONE (void *) -1
14 14
15 15
16 static ngx_quic_stream_t *ngx_quic_create_client_stream(ngx_connection_t *c, 16 static ngx_quic_stream_t *ngx_quic_create_client_stream(ngx_connection_t *c,
17 uint64_t id); 17 uint64_t id);
18 static ngx_int_t ngx_quic_init_stream(ngx_quic_stream_t *qs);
18 static ngx_quic_stream_t *ngx_quic_create_stream(ngx_connection_t *c, 19 static ngx_quic_stream_t *ngx_quic_create_stream(ngx_connection_t *c,
19 uint64_t id); 20 uint64_t id);
21 static void ngx_quic_empty_handler(ngx_event_t *ev);
20 static ssize_t ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf, 22 static ssize_t ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf,
21 size_t size); 23 size_t size);
22 static ssize_t ngx_quic_stream_send(ngx_connection_t *c, u_char *buf, 24 static ssize_t ngx_quic_stream_send(ngx_connection_t *c, u_char *buf,
23 size_t size); 25 size_t size);
24 static ngx_chain_t *ngx_quic_stream_send_chain(ngx_connection_t *c, 26 static ngx_chain_t *ngx_quic_stream_send_chain(ngx_connection_t *c,
144 146
145 147
146 ngx_int_t 148 ngx_int_t
147 ngx_quic_close_streams(ngx_connection_t *c, ngx_quic_connection_t *qc) 149 ngx_quic_close_streams(ngx_connection_t *c, ngx_quic_connection_t *qc)
148 { 150 {
151 ngx_pool_t *pool;
152 ngx_queue_t *q;
149 ngx_event_t *rev, *wev; 153 ngx_event_t *rev, *wev;
150 ngx_rbtree_t *tree; 154 ngx_rbtree_t *tree;
151 ngx_rbtree_node_t *node; 155 ngx_rbtree_node_t *node;
152 ngx_quic_stream_t *qs; 156 ngx_quic_stream_t *qs;
153 157
154 #if (NGX_DEBUG) 158 #if (NGX_DEBUG)
155 ngx_uint_t ns; 159 ngx_uint_t ns;
156 #endif 160 #endif
161
162 while (!ngx_queue_empty(&qc->streams.uninitialized)) {
163 q = ngx_queue_head(&qc->streams.uninitialized);
164 ngx_queue_remove(q);
165
166 qs = ngx_queue_data(q, ngx_quic_stream_t, queue);
167 pool = qs->connection->pool;
168
169 ngx_close_connection(qs->connection);
170 ngx_destroy_pool(pool);
171 }
157 172
158 tree = &qc->streams.tree; 173 tree = &qc->streams.tree;
159 174
160 if (tree->root == tree->sentinel) { 175 if (tree->root == tree->sentinel) {
161 return NGX_OK; 176 return NGX_OK;
308 qs = ngx_quic_create_stream(c, min_id); 323 qs = ngx_quic_create_stream(c, min_id);
309 if (qs == NULL) { 324 if (qs == NULL) {
310 return NULL; 325 return NULL;
311 } 326 }
312 327
313 qs->connection->listening->handler(qs->connection); 328 if (ngx_quic_init_stream(qs) != NGX_OK) {
329 return NULL;
330 }
314 331
315 if (qc->shutdown) { 332 if (qc->shutdown) {
316 return NGX_QUIC_STREAM_GONE; 333 return NGX_QUIC_STREAM_GONE;
317 } 334 }
318 } 335 }
319 336
320 return ngx_quic_create_stream(c, id); 337 return ngx_quic_create_stream(c, id);
338 }
339
340
341 static ngx_int_t
342 ngx_quic_init_stream(ngx_quic_stream_t *qs)
343 {
344 ngx_connection_t *c;
345 ngx_quic_connection_t *qc;
346
347 qc = ngx_quic_get_connection(qs->parent);
348
349 c = qs->connection;
350
351 if (!qc->streams.initialized) {
352 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
353 "quic postpone stream init");
354
355 ngx_queue_insert_tail(&qc->streams.uninitialized, &qs->queue);
356 return NGX_OK;
357 }
358
359 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic init stream");
360
361 c->listening->handler(c);
362
363 return NGX_OK;
364 }
365
366
367 void
368 ngx_quic_init_streams(ngx_connection_t *c)
369 {
370 ngx_queue_t *q;
371 ngx_quic_stream_t *qs;
372 ngx_quic_connection_t *qc;
373
374 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, "quic init streams");
375
376 qc = ngx_quic_get_connection(c);
377
378 while (!ngx_queue_empty(&qc->streams.uninitialized)) {
379 q = ngx_queue_head(&qc->streams.uninitialized);
380 ngx_queue_remove(q);
381
382 qs = ngx_queue_data(q, ngx_quic_stream_t, queue);
383
384 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, qs->connection->log, 0,
385 "quic init postponed stream");
386
387 qs->connection->listening->handler(qs->connection);
388 }
389
390 qc->streams.initialized = 1;
321 } 391 }
322 392
323 393
324 static ngx_quic_stream_t * 394 static ngx_quic_stream_t *
325 ngx_quic_create_stream(ngx_connection_t *c, uint64_t id) 395 ngx_quic_create_stream(ngx_connection_t *c, uint64_t id)
385 sc->send_chain = ngx_quic_stream_send_chain; 455 sc->send_chain = ngx_quic_stream_send_chain;
386 456
387 sc->read->log = log; 457 sc->read->log = log;
388 sc->write->log = log; 458 sc->write->log = log;
389 459
460 sc->read->handler = ngx_quic_empty_handler;
461 sc->write->handler = ngx_quic_empty_handler;
462
390 log->connection = sc->number; 463 log->connection = sc->number;
391 464
392 if ((id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0 465 if ((id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0
393 || (id & NGX_QUIC_STREAM_SERVER_INITIATED)) 466 || (id & NGX_QUIC_STREAM_SERVER_INITIATED))
394 { 467 {
427 cln->data = sc; 500 cln->data = sc;
428 501
429 ngx_rbtree_insert(&qc->streams.tree, &qs->node); 502 ngx_rbtree_insert(&qc->streams.tree, &qs->node);
430 503
431 return qs; 504 return qs;
505 }
506
507
508 static void
509 ngx_quic_empty_handler(ngx_event_t *ev)
510 {
432 } 511 }
433 512
434 513
435 static ssize_t 514 static ssize_t
436 ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf, size_t size) 515 ngx_quic_stream_recv(ngx_connection_t *c, u_char *buf, size_t size)
830 909
831 if (ngx_quic_order_bufs(c, &qs->in, frame->data, f->offset) != NGX_OK) { 910 if (ngx_quic_order_bufs(c, &qs->in, frame->data, f->offset) != NGX_OK) {
832 goto cleanup; 911 goto cleanup;
833 } 912 }
834 913
835 sc->listening->handler(sc); 914 return ngx_quic_init_stream(qs);
836
837 return NGX_OK;
838 } 915 }
839 916
840 sc = qs->connection; 917 sc = qs->connection;
841 918
842 rev = sc->read; 919 rev = sc->read;
984 return NGX_OK; 1061 return NGX_OK;
985 } 1062 }
986 1063
987 limit = qs->recv_max_data; 1064 limit = qs->recv_max_data;
988 1065
989 qs->connection->listening->handler(qs->connection); 1066 if (ngx_quic_init_stream(qs) != NGX_OK) {
1067 return NGX_ERROR;
1068 }
990 1069
991 } else { 1070 } else {
992 limit = qs->recv_max_data; 1071 limit = qs->recv_max_data;
993 } 1072 }
994 1073
1041 1120
1042 if (f->limit > qs->send_max_data) { 1121 if (f->limit > qs->send_max_data) {
1043 qs->send_max_data = f->limit; 1122 qs->send_max_data = f->limit;
1044 } 1123 }
1045 1124
1046 qs->connection->listening->handler(qs->connection); 1125 return ngx_quic_init_stream(qs);
1047
1048 return NGX_OK;
1049 } 1126 }
1050 1127
1051 if (f->limit <= qs->send_max_data) { 1128 if (f->limit <= qs->send_max_data) {
1052 return NGX_OK; 1129 return NGX_OK;
1053 } 1130 }
1115 1192
1116 if (ngx_quic_update_flow(sc, qs->final_size) != NGX_OK) { 1193 if (ngx_quic_update_flow(sc, qs->final_size) != NGX_OK) {
1117 goto cleanup; 1194 goto cleanup;
1118 } 1195 }
1119 1196
1120 sc->listening->handler(sc); 1197 return ngx_quic_init_stream(qs);
1121
1122 return NGX_OK;
1123 } 1198 }
1124 1199
1125 sc = qs->connection; 1200 sc = qs->connection;
1126 1201
1127 rev = sc->read; 1202 rev = sc->read;
1200 1275
1201 wev = sc->write; 1276 wev = sc->write;
1202 wev->error = 1; 1277 wev->error = 1;
1203 wev->ready = 1; 1278 wev->ready = 1;
1204 1279
1205 sc->listening->handler(sc); 1280 return ngx_quic_init_stream(qs);
1206
1207 return NGX_OK;
1208 } 1281 }
1209 1282
1210 wev = qs->connection->write; 1283 wev = qs->connection->write;
1211 wev->error = 1; 1284 wev->error = 1;
1212 wev->ready = 1; 1285 wev->ready = 1;