# HG changeset patch # User Vladimir Homutov # Date 1638175749 -10800 # Node ID 50d73bf20e73e6394ad0207c0f4cf254d4667048 # Parent b09f055daa4e60bc251aae76ae4565738f29765f 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. 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 @@ -358,7 +358,7 @@ ngx_quic_process_stateless_reset(ngx_con qc = ngx_quic_get_connection(c); /* A stateless reset uses an entire UDP datagram */ - if (pkt->raw->start != pkt->data) { + if (!pkt->first) { return NGX_DECLINED; } @@ -666,7 +666,7 @@ static ngx_int_t ngx_quic_input(ngx_connection_t *c, ngx_buf_t *b, ngx_quic_conf_t *conf) { size_t size; - u_char *p; + u_char *p, *start; ngx_int_t rc; ngx_uint_t good; ngx_quic_header_t pkt; @@ -676,7 +676,7 @@ ngx_quic_input(ngx_connection_t *c, ngx_ size = b->last - b->pos; - p = b->pos; + p = start = b->pos; while (p < b->last) { @@ -685,6 +685,7 @@ ngx_quic_input(ngx_connection_t *c, ngx_ pkt.data = p; pkt.len = b->last - p; pkt.log = c->log; + pkt.first = (p == start) ? 1 : 0; pkt.flags = p[0]; pkt.raw->pos++; @@ -979,8 +980,10 @@ ngx_quic_process_payload(ngx_connection_ pkt->decrypted = 1; - if (ngx_quic_update_paths(c, pkt) != NGX_OK) { - return NGX_ERROR; + if (pkt->first) { + if (ngx_quic_update_paths(c, pkt) != NGX_OK) { + return NGX_ERROR; + } } if (c->ssl == NULL) { diff --git a/src/event/quic/ngx_event_quic_migration.c b/src/event/quic/ngx_event_quic_migration.c --- a/src/event/quic/ngx_event_quic_migration.c +++ b/src/event/quic/ngx_event_quic_migration.c @@ -388,12 +388,7 @@ ngx_quic_update_paths(ngx_connection_t * update: - if (pkt->raw->start == pkt->data) { - len = pkt->raw->last - pkt->raw->start; - - } else { - len = 0; - } + len = pkt->raw->last - pkt->raw->start; /* TODO: this may be too late in some cases; * for example, if error happens during decrypt(), we cannot diff --git a/src/event/quic/ngx_event_quic_transport.h b/src/event/quic/ngx_event_quic_transport.h --- a/src/event/quic/ngx_event_quic_transport.h +++ b/src/event/quic/ngx_event_quic_transport.h @@ -334,6 +334,7 @@ typedef struct { unsigned decrypted:1; unsigned validated:1; unsigned retried:1; + unsigned first:1; } ngx_quic_header_t;