Mercurial > hg > nginx
diff src/event/quic/ngx_event_quic_output.c @ 8971:1e2f4e9c8195 quic
QUIC: reworked migration handling.
The quic connection now holds active, backup and probe paths instead
of sockets. The number of migration paths is now limited and cannot
be inflated by a bad client or an attacker.
The client id is now associated with path rather than socket. This allows
to simplify processing of output and connection ids handling.
New migration abandons any previously started migrations. This allows to
free consumed client ids and request new for use in future migrations and
make progress in case when connection id limit is hit during migration.
A path now can be revalidated without losing its state.
The patch also fixes various issues with NAT rebinding case handling:
- paths are now validated (previously, there was no validation
and paths were left in limited state)
- attempt to reuse id on different path is now again verified
(this was broken in 40445fc7c403)
- former path is now validated in case of apparent migration
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Wed, 19 Jan 2022 22:39:24 +0300 |
parents | 19e063e955bf |
children | e5509ff0dfd2 |
line wrap: on
line diff
--- a/src/event/quic/ngx_event_quic_output.c +++ b/src/event/quic/ngx_event_quic_output.c @@ -51,7 +51,7 @@ static ssize_t ngx_quic_send_segments(ng static ssize_t ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, u_char *data, size_t max, size_t min); static void ngx_quic_init_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, - ngx_quic_header_t *pkt); + ngx_quic_header_t *pkt, ngx_quic_path_t *path); static ngx_uint_t ngx_quic_get_padding_level(ngx_connection_t *c); static ssize_t ngx_quic_send(ngx_connection_t *c, u_char *buf, size_t len, struct sockaddr *sockaddr, socklen_t socklen); @@ -131,7 +131,7 @@ ngx_quic_create_datagrams(ngx_connection qc = ngx_quic_get_connection(c); cg = &qc->congestion; - path = qc->socket->path; + path = qc->path; while (cg->in_flight < cg->window) { @@ -269,7 +269,7 @@ ngx_quic_allow_segmentation(ngx_connecti return 0; } - if (qc->socket->path->limited) { + if (qc->path->limited) { /* don't even try to be faster on non-validated paths */ return 0; } @@ -325,7 +325,7 @@ ngx_quic_create_segments(ngx_connection_ qc = ngx_quic_get_connection(c); cg = &qc->congestion; - path = qc->socket->path; + path = qc->path; ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application); @@ -505,17 +505,18 @@ static ssize_t ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, u_char *data, size_t max, size_t min) { - size_t len, pad, min_payload, max_payload; - u_char *p; - ssize_t flen; - ngx_str_t res; - ngx_int_t rc; - ngx_uint_t nframes, expand; - ngx_msec_t now; - ngx_queue_t *q; - ngx_quic_frame_t *f; - ngx_quic_header_t pkt; - static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; + size_t len, pad, min_payload, max_payload; + u_char *p; + ssize_t flen; + ngx_str_t res; + ngx_int_t rc; + ngx_uint_t nframes, expand; + ngx_msec_t now; + ngx_queue_t *q; + ngx_quic_frame_t *f; + ngx_quic_header_t pkt; + ngx_quic_connection_t *qc; + static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; if (ngx_queue_empty(&ctx->frames)) { return 0; @@ -525,7 +526,9 @@ ngx_quic_output_packet(ngx_connection_t "quic output %s packet max:%uz min:%uz", ngx_quic_level_name(ctx->level), max, min); - ngx_quic_init_packet(c, ctx, &pkt); + qc = ngx_quic_get_connection(c); + + ngx_quic_init_packet(c, ctx, &pkt, qc->path); min_payload = ngx_quic_payload_size(&pkt, min); max_payload = ngx_quic_payload_size(&pkt, max); @@ -668,14 +671,14 @@ ngx_quic_output_packet(ngx_connection_t static void ngx_quic_init_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, - ngx_quic_header_t *pkt) + ngx_quic_header_t *pkt, ngx_quic_path_t *path) { ngx_quic_socket_t *qsock; ngx_quic_connection_t *qc; qc = ngx_quic_get_connection(c); - qsock = qc->socket; + qsock = ngx_quic_get_socket(c); ngx_memzero(pkt, sizeof(ngx_quic_header_t)); @@ -693,8 +696,8 @@ ngx_quic_init_packet(ngx_connection_t *c } } - pkt->dcid.data = qsock->cid->id; - pkt->dcid.len = qsock->cid->len; + pkt->dcid.data = path->cid->id; + pkt->dcid.len = path->cid->len; pkt->scid.data = qsock->sid.id; pkt->scid.len = qsock->sid.len; @@ -1202,7 +1205,7 @@ ngx_quic_frame_sendto(ngx_connection_t * qc = ngx_quic_get_connection(c); ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application); - ngx_quic_init_packet(c, ctx, &pkt); + ngx_quic_init_packet(c, ctx, &pkt, path); min = ngx_quic_path_limit(c, path, min);