comparison src/event/quic/ngx_event_quic.c @ 8701:50d73bf20e73 quic

QUIC: refactored multiple QUIC packets handling. Single UDP datagram may contain multiple QUIC datagrams. In order to facilitate handling of such cases, 'first' flag in the ngx_quic_header_t structure is introduced.
author Vladimir Homutov <vl@nginx.com>
date Mon, 29 Nov 2021 11:49:09 +0300
parents d041b8d6ab0b
children 40445fc7c403
comparison
equal deleted inserted replaced
8700:b09f055daa4e 8701:50d73bf20e73
356 ngx_quic_connection_t *qc; 356 ngx_quic_connection_t *qc;
357 357
358 qc = ngx_quic_get_connection(c); 358 qc = ngx_quic_get_connection(c);
359 359
360 /* A stateless reset uses an entire UDP datagram */ 360 /* A stateless reset uses an entire UDP datagram */
361 if (pkt->raw->start != pkt->data) { 361 if (!pkt->first) {
362 return NGX_DECLINED; 362 return NGX_DECLINED;
363 } 363 }
364 364
365 tail = pkt->raw->last - NGX_QUIC_SR_TOKEN_LEN; 365 tail = pkt->raw->last - NGX_QUIC_SR_TOKEN_LEN;
366 366
664 664
665 static ngx_int_t 665 static ngx_int_t
666 ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b, ngx_quic_conf_t *conf) 666 ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b, ngx_quic_conf_t *conf)
667 { 667 {
668 size_t size; 668 size_t size;
669 u_char *p; 669 u_char *p, *start;
670 ngx_int_t rc; 670 ngx_int_t rc;
671 ngx_uint_t good; 671 ngx_uint_t good;
672 ngx_quic_header_t pkt; 672 ngx_quic_header_t pkt;
673 ngx_quic_connection_t *qc; 673 ngx_quic_connection_t *qc;
674 674
675 good = 0; 675 good = 0;
676 676
677 size = b->last - b->pos; 677 size = b->last - b->pos;
678 678
679 p = b->pos; 679 p = start = b->pos;
680 680
681 while (p < b->last) { 681 while (p < b->last) {
682 682
683 ngx_memzero(&pkt, sizeof(ngx_quic_header_t)); 683 ngx_memzero(&pkt, sizeof(ngx_quic_header_t));
684 pkt.raw = b; 684 pkt.raw = b;
685 pkt.data = p; 685 pkt.data = p;
686 pkt.len = b->last - p; 686 pkt.len = b->last - p;
687 pkt.log = c->log; 687 pkt.log = c->log;
688 pkt.first = (p == start) ? 1 : 0;
688 pkt.flags = p[0]; 689 pkt.flags = p[0];
689 pkt.raw->pos++; 690 pkt.raw->pos++;
690 691
691 rc = ngx_quic_process_packet(c, conf, &pkt); 692 rc = ngx_quic_process_packet(c, conf, &pkt);
692 693
977 return rc; 978 return rc;
978 } 979 }
979 980
980 pkt->decrypted = 1; 981 pkt->decrypted = 1;
981 982
982 if (ngx_quic_update_paths(c, pkt) != NGX_OK) { 983 if (pkt->first) {
983 return NGX_ERROR; 984 if (ngx_quic_update_paths(c, pkt) != NGX_OK) {
985 return NGX_ERROR;
986 }
984 } 987 }
985 988
986 if (c->ssl == NULL) { 989 if (c->ssl == NULL) {
987 if (ngx_quic_init_connection(c) != NGX_OK) { 990 if (ngx_quic_init_connection(c) != NGX_OK) {
988 return NGX_ERROR; 991 return NGX_ERROR;