Latest update - 9147

This commit is contained in:
2023-08-16 02:05:57 +09:00
parent 1ee9716461
commit 5a04d278c2
14 changed files with 388 additions and 219 deletions
+5
View File
@@ -1583,6 +1583,10 @@ ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
}
#endif
if (err == NGX_EMSGSIZE && c->log_error == NGX_ERROR_IGNORE_EMSGSIZE) {
return 0;
}
if (err == 0
|| err == NGX_ECONNRESET
#if (NGX_WIN32)
@@ -1600,6 +1604,7 @@ ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
{
switch (c->log_error) {
case NGX_ERROR_IGNORE_EMSGSIZE:
case NGX_ERROR_IGNORE_EINVAL:
case NGX_ERROR_IGNORE_ECONNRESET:
case NGX_ERROR_INFO:
+2 -1
View File
@@ -97,7 +97,8 @@ typedef enum {
NGX_ERROR_ERR,
NGX_ERROR_INFO,
NGX_ERROR_IGNORE_ECONNRESET,
NGX_ERROR_IGNORE_EINVAL
NGX_ERROR_IGNORE_EINVAL,
NGX_ERROR_IGNORE_EMSGSIZE
} ngx_connection_log_error_e;
+2 -8
View File
@@ -149,11 +149,6 @@ ngx_quic_apply_transport_params(ngx_connection_t *c, ngx_quic_tp_t *ctp)
ngx_log_error(NGX_LOG_INFO, c->log, 0,
"quic maximum packet size is invalid");
return NGX_ERROR;
} else if (ctp->max_udp_payload_size > ngx_quic_max_udp_payload(c)) {
ctp->max_udp_payload_size = ngx_quic_max_udp_payload(c);
ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic client maximum packet size truncated");
}
if (ctp->active_connection_id_limit < 2) {
@@ -286,7 +281,7 @@ ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf,
qc->path_validation.log = c->log;
qc->path_validation.data = c;
qc->path_validation.handler = ngx_quic_path_validation_handler;
qc->path_validation.handler = ngx_quic_path_handler;
qc->conf = conf;
@@ -297,7 +292,7 @@ ngx_quic_new_connection(ngx_connection_t *c, ngx_quic_conf_t *conf,
ctp = &qc->ctp;
/* defaults to be used before actual client parameters are received */
ctp->max_udp_payload_size = ngx_quic_max_udp_payload(c);
ctp->max_udp_payload_size = NGX_QUIC_MAX_UDP_PAYLOAD_SIZE;
ctp->ack_delay_exponent = NGX_QUIC_DEFAULT_ACK_DELAY_EXPONENT;
ctp->max_ack_delay = NGX_QUIC_DEFAULT_MAX_ACK_DELAY;
ctp->active_connection_id_limit = 2;
@@ -1013,7 +1008,6 @@ ngx_quic_handle_payload(ngx_connection_t *c, ngx_quic_header_t *pkt)
if (!qc->path->validated) {
qc->path->validated = 1;
qc->path->limited = 0;
ngx_quic_path_dbg(c, "in handshake", qc->path);
ngx_post_event(&qc->push, &ngx_posted_events);
}
+25 -56
View File
@@ -229,6 +229,12 @@ ngx_quic_handle_ack_frame_range(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx,
qc = ngx_quic_get_connection(c);
if (ctx->level == ssl_encryption_application) {
if (ngx_quic_handle_path_mtu(c, qc->path, min, max) != NGX_OK) {
return NGX_ERROR;
}
}
st->max_pn = NGX_TIMER_INFINITE;
found = 0;
@@ -548,6 +554,7 @@ ngx_quic_persistent_congestion(ngx_connection_t *c)
void
ngx_quic_resend_frames(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx)
{
uint64_t pnum;
ngx_queue_t *q;
ngx_quic_frame_t *f, *start;
ngx_quic_stream_t *qs;
@@ -556,6 +563,7 @@ ngx_quic_resend_frames(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx)
qc = ngx_quic_get_connection(c);
q = ngx_queue_head(&ctx->sent);
start = ngx_queue_data(q, ngx_quic_frame_t, queue);
pnum = start->pnum;
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic resend packet pnum:%uL", start->pnum);
@@ -565,7 +573,7 @@ ngx_quic_resend_frames(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx)
do {
f = ngx_queue_data(q, ngx_quic_frame_t, queue);
if (f->pnum != start->pnum) {
if (f->pnum != pnum) {
break;
}
@@ -818,9 +826,9 @@ ngx_quic_pto_handler(ngx_event_t *ev)
{
ngx_uint_t i;
ngx_msec_t now;
ngx_queue_t *q, *next;
ngx_queue_t *q;
ngx_connection_t *c;
ngx_quic_frame_t *f;
ngx_quic_frame_t *f, frame;
ngx_quic_send_ctx_t *ctx;
ngx_quic_connection_t *qc;
@@ -838,7 +846,7 @@ ngx_quic_pto_handler(ngx_event_t *ev)
continue;
}
q = ngx_queue_head(&ctx->sent);
q = ngx_queue_last(&ctx->sent);
f = ngx_queue_data(q, ngx_quic_frame_t, queue);
if (f->pnum <= ctx->largest_ack
@@ -857,63 +865,23 @@ ngx_quic_pto_handler(ngx_event_t *ev)
"quic pto %s pto_count:%ui",
ngx_quic_level_name(ctx->level), qc->pto_count);
for (q = ngx_queue_head(&ctx->frames);
q != ngx_queue_sentinel(&ctx->frames);
/* void */)
ngx_memzero(&frame, sizeof(ngx_quic_frame_t));
frame.level = ctx->level;
frame.type = NGX_QUIC_FT_PING;
if (ngx_quic_frame_sendto(c, &frame, 0, qc->path) != NGX_OK
|| ngx_quic_frame_sendto(c, &frame, 0, qc->path) != NGX_OK)
{
next = ngx_queue_next(q);
f = ngx_queue_data(q, ngx_quic_frame_t, queue);
if (f->type == NGX_QUIC_FT_PING) {
ngx_queue_remove(q);
ngx_quic_free_frame(c, f);
ngx_quic_close_connection(c, NGX_ERROR);
return;
}
q = next;
}
for (q = ngx_queue_head(&ctx->sent);
q != ngx_queue_sentinel(&ctx->sent);
/* void */)
{
next = ngx_queue_next(q);
f = ngx_queue_data(q, ngx_quic_frame_t, queue);
if (f->type == NGX_QUIC_FT_PING) {
ngx_quic_congestion_lost(c, f);
ngx_queue_remove(q);
ngx_quic_free_frame(c, f);
}
q = next;
}
/* enforce 2 udp datagrams */
f = ngx_quic_alloc_frame(c);
if (f == NULL) {
break;
}
f->level = ctx->level;
f->type = NGX_QUIC_FT_PING;
f->flush = 1;
ngx_quic_queue_frame(qc, f);
f = ngx_quic_alloc_frame(c);
if (f == NULL) {
break;
}
f->level = ctx->level;
f->type = NGX_QUIC_FT_PING;
ngx_quic_queue_frame(qc, f);
}
qc->pto_count++;
ngx_quic_set_lost_timer(c);
ngx_quic_connstate_dbg(c);
}
@@ -1171,7 +1139,8 @@ ngx_quic_generate_ack(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx)
delay = ngx_current_msec - ctx->ack_delay_start;
qc = ngx_quic_get_connection(c);
if (ctx->send_ack < NGX_QUIC_MAX_ACK_GAP
if (ngx_queue_empty(&ctx->frames)
&& ctx->send_ack < NGX_QUIC_MAX_ACK_GAP
&& delay < qc->tp.max_ack_delay)
{
if (!qc->push.timer_set && !qc->closing) {
+14 -3
View File
@@ -66,6 +66,14 @@ typedef struct ngx_quic_keys_s ngx_quic_keys_t;
#define ngx_quic_get_socket(c) ((ngx_quic_socket_t *)((c)->udp))
typedef enum {
NGX_QUIC_PATH_IDLE = 0,
NGX_QUIC_PATH_VALIDATING,
NGX_QUIC_PATH_WAITING,
NGX_QUIC_PATH_MTUD
} ngx_quic_path_state_e;
struct ngx_quic_client_id_s {
ngx_queue_t queue;
uint64_t seqnum;
@@ -89,19 +97,22 @@ struct ngx_quic_path_s {
ngx_sockaddr_t sa;
socklen_t socklen;
ngx_quic_client_id_t *cid;
ngx_quic_path_state_e state;
ngx_msec_t expires;
ngx_uint_t tries;
ngx_uint_t tag;
size_t mtu;
size_t mtud;
size_t max_mtu;
off_t sent;
off_t received;
u_char challenge1[8];
u_char challenge2[8];
uint64_t seqnum;
uint64_t mtu_pnum[NGX_QUIC_PATH_RETRIES];
ngx_str_t addr_text;
u_char text[NGX_SOCKADDR_STRLEN];
unsigned validated:1;
unsigned validating:1;
unsigned limited:1;
ngx_uint_t validated; /* unsigned validated:1; */
};
+284 -43
View File
@@ -10,6 +10,10 @@
#include <ngx_event_quic_connection.h>
#define NGX_QUIC_PATH_MTU_DELAY 100
#define NGX_QUIC_PATH_MTU_PRECISION 16
static void ngx_quic_set_connection_path(ngx_connection_t *c,
ngx_quic_path_t *path);
static ngx_int_t ngx_quic_validate_path(ngx_connection_t *c,
@@ -17,7 +21,15 @@ static ngx_int_t ngx_quic_validate_path(ngx_connection_t *c,
static ngx_int_t ngx_quic_send_path_challenge(ngx_connection_t *c,
ngx_quic_path_t *path);
static void ngx_quic_set_path_timer(ngx_connection_t *c);
static ngx_int_t ngx_quic_expire_path_validation(ngx_connection_t *c,
ngx_quic_path_t *path);
static ngx_int_t ngx_quic_expire_path_mtu_delay(ngx_connection_t *c,
ngx_quic_path_t *path);
static ngx_int_t ngx_quic_expire_path_mtu_discovery(ngx_connection_t *c,
ngx_quic_path_t *path);
static ngx_quic_path_t *ngx_quic_get_path(ngx_connection_t *c, ngx_uint_t tag);
static ngx_int_t ngx_quic_send_path_mtu_probe(ngx_connection_t *c,
ngx_quic_path_t *path);
ngx_int_t
@@ -46,7 +58,7 @@ ngx_quic_handle_path_challenge_frame(ngx_connection_t *c,
* An endpoint MUST expand datagrams that contain a PATH_RESPONSE frame
* to at least the smallest allowed maximum datagram size of 1200 bytes.
*/
if (ngx_quic_frame_sendto(c, &frame, 1200, pkt->path) != NGX_OK) {
if (ngx_quic_frame_sendto(c, &frame, 1200, pkt->path) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -97,7 +109,7 @@ ngx_quic_handle_path_response_frame(ngx_connection_t *c,
{
path = ngx_queue_data(q, ngx_quic_path_t, queue);
if (!path->validating) {
if (path->state != NGX_QUIC_PATH_VALIDATING) {
continue;
}
@@ -136,6 +148,9 @@ valid:
{
/* address did not change */
rst = 0;
path->mtu = prev->mtu;
path->max_mtu = prev->max_mtu;
}
}
@@ -167,10 +182,8 @@ valid:
ngx_quic_path_dbg(c, "is validated", path);
path->validated = 1;
path->validating = 0;
path->limited = 0;
ngx_quic_set_path_timer(c);
ngx_quic_discover_path_mtu(c, path);
return NGX_OK;
}
@@ -208,8 +221,6 @@ ngx_quic_new_path(ngx_connection_t *c,
path->cid = cid;
cid->used = 1;
path->limited = 1;
path->seqnum = qc->path_seqnum++;
path->sockaddr = &path->sa.sockaddr;
@@ -220,6 +231,8 @@ ngx_quic_new_path(ngx_connection_t *c,
path->addr_text.len = ngx_sock_ntop(sockaddr, socklen, path->text,
NGX_SOCKADDR_STRLEN, 1);
path->mtu = NGX_QUIC_MIN_INITIAL_SIZE;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic path seq:%uL created addr:%V",
path->seqnum, &path->addr_text);
@@ -467,7 +480,7 @@ ngx_quic_handle_migration(ngx_connection_t *c, ngx_quic_header_t *pkt)
ngx_quic_set_connection_path(c, next);
if (!next->validated && !next->validating) {
if (!next->validated && next->state != NGX_QUIC_PATH_VALIDATING) {
if (ngx_quic_validate_path(c, next) != NGX_OK) {
return NGX_ERROR;
}
@@ -495,7 +508,6 @@ ngx_quic_validate_path(ngx_connection_t *c, ngx_quic_path_t *path)
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic initiated validation of path seq:%uL", path->seqnum);
path->validating = 1;
path->tries = 0;
if (RAND_bytes(path->challenge1, 8) != 1) {
@@ -514,6 +526,7 @@ ngx_quic_validate_path(ngx_connection_t *c, ngx_quic_path_t *path)
pto = ngx_max(ngx_quic_pto(c, ctx), 1000);
path->expires = ngx_current_msec + pto;
path->state = NGX_QUIC_PATH_VALIDATING;
ngx_quic_set_path_timer(c);
@@ -547,13 +560,13 @@ ngx_quic_send_path_challenge(ngx_connection_t *c, ngx_quic_path_t *path)
*/
/* same applies to PATH_RESPONSE frames */
if (ngx_quic_frame_sendto(c, &frame, 1200, path) != NGX_OK) {
if (ngx_quic_frame_sendto(c, &frame, 1200, path) == NGX_ERROR) {
return NGX_ERROR;
}
ngx_memcpy(frame.u.path_challenge.data, path->challenge2, 8);
if (ngx_quic_frame_sendto(c, &frame, 1200, path) != NGX_OK) {
if (ngx_quic_frame_sendto(c, &frame, 1200, path) == NGX_ERROR) {
return NGX_ERROR;
}
@@ -561,6 +574,42 @@ ngx_quic_send_path_challenge(ngx_connection_t *c, ngx_quic_path_t *path)
}
void
ngx_quic_discover_path_mtu(ngx_connection_t *c, ngx_quic_path_t *path)
{
ngx_quic_connection_t *qc;
qc = ngx_quic_get_connection(c);
if (path->max_mtu) {
if (path->max_mtu - path->mtu <= NGX_QUIC_PATH_MTU_PRECISION) {
path->state = NGX_QUIC_PATH_IDLE;
ngx_quic_set_path_timer(c);
return;
}
path->mtud = (path->mtu + path->max_mtu) / 2;
} else {
path->mtud = path->mtu * 2;
if (path->mtud >= qc->ctp.max_udp_payload_size) {
path->mtud = qc->ctp.max_udp_payload_size;
path->max_mtu = qc->ctp.max_udp_payload_size;
}
}
path->state = NGX_QUIC_PATH_WAITING;
path->expires = ngx_current_msec + NGX_QUIC_PATH_MTU_DELAY;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic path seq:%uL schedule mtu:%uz",
path->seqnum, path->mtud);
ngx_quic_set_path_timer(c);
}
static void
ngx_quic_set_path_timer(ngx_connection_t *c)
{
@@ -581,7 +630,7 @@ ngx_quic_set_path_timer(ngx_connection_t *c)
{
path = ngx_queue_data(q, ngx_quic_path_t, queue);
if (!path->validating) {
if (path->state == NGX_QUIC_PATH_IDLE) {
continue;
}
@@ -603,22 +652,18 @@ ngx_quic_set_path_timer(ngx_connection_t *c)
void
ngx_quic_path_validation_handler(ngx_event_t *ev)
ngx_quic_path_handler(ngx_event_t *ev)
{
ngx_msec_t now;
ngx_queue_t *q;
ngx_msec_int_t left, next, pto;
ngx_quic_path_t *path, *bkp;
ngx_msec_int_t left;
ngx_quic_path_t *path;
ngx_connection_t *c;
ngx_quic_send_ctx_t *ctx;
ngx_quic_connection_t *qc;
c = ev->data;
qc = ngx_quic_get_connection(c);
ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application);
next = -1;
now = ngx_current_msec;
q = ngx_queue_head(&qc->paths);
@@ -628,44 +673,79 @@ ngx_quic_path_validation_handler(ngx_event_t *ev)
path = ngx_queue_data(q, ngx_quic_path_t, queue);
q = ngx_queue_next(q);
if (!path->validating) {
if (path->state == NGX_QUIC_PATH_IDLE) {
continue;
}
left = path->expires - now;
if (left > 0) {
if (next == -1 || left < next) {
next = left;
}
continue;
}
switch (path->state) {
case NGX_QUIC_PATH_VALIDATING:
if (ngx_quic_expire_path_validation(c, path) != NGX_OK) {
goto failed;
}
break;
case NGX_QUIC_PATH_WAITING:
if (ngx_quic_expire_path_mtu_delay(c, path) != NGX_OK) {
goto failed;
}
break;
case NGX_QUIC_PATH_MTUD:
if (ngx_quic_expire_path_mtu_discovery(c, path) != NGX_OK) {
goto failed;
}
break;
default:
break;
}
}
ngx_quic_set_path_timer(c);
return;
failed:
ngx_quic_close_connection(c, NGX_ERROR);
}
static ngx_int_t
ngx_quic_expire_path_validation(ngx_connection_t *c, ngx_quic_path_t *path)
{
ngx_msec_int_t pto;
ngx_quic_path_t *bkp;
ngx_quic_send_ctx_t *ctx;
ngx_quic_connection_t *qc;
qc = ngx_quic_get_connection(c);
ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application);
if (++path->tries < NGX_QUIC_PATH_RETRIES) {
pto = ngx_max(ngx_quic_pto(c, ctx), 1000) << path->tries;
path->expires = ngx_current_msec + pto;
if (next == -1 || pto < next) {
next = pto;
}
/* retransmit */
(void) ngx_quic_send_path_challenge(c, path);
continue;
return NGX_OK;
}
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, ev->log, 0,
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic path seq:%uL validation failed", path->seqnum);
/* found expired path */
path->validated = 0;
path->validating = 0;
path->limited = 1;
/* RFC 9000, 9.3.2. On-Path Address Spoofing
@@ -683,8 +763,7 @@ ngx_quic_path_validation_handler(ngx_event_t *ev)
if (bkp == NULL) {
qc->error = NGX_QUIC_ERR_NO_VIABLE_PATH;
qc->error_reason = "no viable path";
ngx_quic_close_connection(c, NGX_ERROR);
return;
return NGX_ERROR;
}
qc->path = bkp;
@@ -699,13 +778,175 @@ ngx_quic_path_validation_handler(ngx_event_t *ev)
ngx_quic_path_dbg(c, "is active", qc->path);
}
if (ngx_quic_free_path(c, path) != NGX_OK) {
ngx_quic_close_connection(c, NGX_ERROR);
return;
}
return ngx_quic_free_path(c, path);
}
static ngx_int_t
ngx_quic_expire_path_mtu_delay(ngx_connection_t *c, ngx_quic_path_t *path)
{
ngx_int_t rc;
ngx_uint_t i;
ngx_msec_t pto;
ngx_quic_send_ctx_t *ctx;
ngx_quic_connection_t *qc;
qc = ngx_quic_get_connection(c);
ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application);
path->tries = 0;
for ( ;; ) {
for (i = 0; i < NGX_QUIC_PATH_RETRIES; i++) {
path->mtu_pnum[i] = NGX_QUIC_UNSET_PN;
}
if (next != -1) {
ngx_add_timer(&qc->path_validation, next);
rc = ngx_quic_send_path_mtu_probe(c, path);
if (rc == NGX_ERROR) {
return NGX_ERROR;
}
if (rc == NGX_OK) {
pto = ngx_quic_pto(c, ctx);
path->expires = ngx_current_msec + pto;
path->state = NGX_QUIC_PATH_MTUD;
return NGX_OK;
}
/* rc == NGX_DECLINED */
path->max_mtu = path->mtud;
if (path->max_mtu - path->mtu <= NGX_QUIC_PATH_MTU_PRECISION) {
path->state = NGX_QUIC_PATH_IDLE;
return NGX_OK;
}
path->mtud = (path->mtu + path->max_mtu) / 2;
}
}
static ngx_int_t
ngx_quic_expire_path_mtu_discovery(ngx_connection_t *c, ngx_quic_path_t *path)
{
ngx_int_t rc;
ngx_msec_int_t pto;
ngx_quic_send_ctx_t *ctx;
ngx_quic_connection_t *qc;
qc = ngx_quic_get_connection(c);
ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application);
if (++path->tries < NGX_QUIC_PATH_RETRIES) {
rc = ngx_quic_send_path_mtu_probe(c, path);
if (rc == NGX_ERROR) {
return NGX_ERROR;
}
if (rc == NGX_OK) {
pto = ngx_quic_pto(c, ctx) << path->tries;
path->expires = ngx_current_msec + pto;
return NGX_OK;
}
/* rc == NGX_DECLINED */
}
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic path seq:%uL expired mtu:%uz",
path->seqnum, path->mtud);
path->max_mtu = path->mtud;
ngx_quic_discover_path_mtu(c, path);
return NGX_OK;
}
static ngx_int_t
ngx_quic_send_path_mtu_probe(ngx_connection_t *c, ngx_quic_path_t *path)
{
ngx_int_t rc;
ngx_uint_t log_error;
ngx_quic_frame_t frame;
ngx_quic_send_ctx_t *ctx;
ngx_quic_connection_t *qc;
ngx_memzero(&frame, sizeof(ngx_quic_frame_t));
frame.level = ssl_encryption_application;
frame.type = NGX_QUIC_FT_PING;
qc = ngx_quic_get_connection(c);
ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application);
path->mtu_pnum[path->tries] = ctx->pnum;
ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic path seq:%uL send probe "
"mtu:%uz pnum:%uL tries:%ui",
path->seqnum, path->mtud, ctx->pnum, path->tries);
log_error = c->log_error;
c->log_error = NGX_ERROR_IGNORE_EMSGSIZE;
rc = ngx_quic_frame_sendto(c, &frame, path->mtud, path);
c->log_error = log_error;
if (rc == NGX_ERROR) {
if (c->write->error) {
c->write->error = 0;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic path seq:%uL rejected mtu:%uz",
path->seqnum, path->mtud);
return NGX_DECLINED;
}
return NGX_ERROR;
}
return NGX_OK;
}
ngx_int_t
ngx_quic_handle_path_mtu(ngx_connection_t *c, ngx_quic_path_t *path,
uint64_t min, uint64_t max)
{
uint64_t pnum;
ngx_uint_t i;
if (path->state != NGX_QUIC_PATH_MTUD) {
return NGX_OK;
}
for (i = 0; i < NGX_QUIC_PATH_RETRIES; i++) {
pnum = path->mtu_pnum[i];
if (pnum == NGX_QUIC_UNSET_PN) {
break;
}
if (pnum < min || pnum > max) {
continue;
}
path->mtu = path->mtud;
ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0,
"quic path seq:%uL ack mtu:%uz",
path->seqnum, path->mtu);
ngx_quic_discover_path_mtu(c, path);
break;
}
return NGX_OK;
}
+7 -4
View File
@@ -19,10 +19,9 @@
#define ngx_quic_path_dbg(c, msg, path) \
ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0, \
"quic path seq:%uL %s sent:%O recvd:%O state:%s%s%s", \
"quic path seq:%uL %s tx:%O rx:%O valid:%ui st:%d mtu:%uz",\
path->seqnum, msg, path->sent, path->received, \
path->limited ? "L" : "", path->validated ? "V": "N", \
path->validating ? "R": "");
path->validated, path->state, path->mtu);
ngx_int_t ngx_quic_handle_path_challenge_frame(ngx_connection_t *c,
ngx_quic_header_t *pkt, ngx_quic_path_challenge_frame_t *f);
@@ -37,6 +36,10 @@ ngx_int_t ngx_quic_set_path(ngx_connection_t *c, ngx_quic_header_t *pkt);
ngx_int_t ngx_quic_handle_migration(ngx_connection_t *c,
ngx_quic_header_t *pkt);
void ngx_quic_path_validation_handler(ngx_event_t *ev);
void ngx_quic_path_handler(ngx_event_t *ev);
void ngx_quic_discover_path_mtu(ngx_connection_t *c, ngx_quic_path_t *path);
ngx_int_t ngx_quic_handle_path_mtu(ngx_connection_t *c,
ngx_quic_path_t *path, uint64_t min, uint64_t max);
#endif /* _NGX_EVENT_QUIC_MIGRATION_H_INCLUDED_ */
+10 -65
View File
@@ -10,9 +10,6 @@
#include <ngx_event_quic_connection.h>
#define NGX_QUIC_MAX_UDP_PAYLOAD_OUT 1252
#define NGX_QUIC_MAX_UDP_PAYLOAD_OUT6 1232
#define NGX_QUIC_MAX_UDP_SEGMENT_BUF 65487 /* 65K - IPv6 header */
#define NGX_QUIC_MAX_SEGMENTS 64 /* UDP_MAX_SEGMENTS */
@@ -61,21 +58,6 @@ static size_t ngx_quic_path_limit(ngx_connection_t *c, ngx_quic_path_t *path,
size_t size);
size_t
ngx_quic_max_udp_payload(ngx_connection_t *c)
{
/* TODO: path MTU discovery */
#if (NGX_HAVE_INET6)
if (c->sockaddr->sa_family == AF_INET6) {
return NGX_QUIC_MAX_UDP_PAYLOAD_OUT6;
}
#endif
return NGX_QUIC_MAX_UDP_PAYLOAD_OUT;
}
ngx_int_t
ngx_quic_output(ngx_connection_t *c)
{
@@ -142,10 +124,7 @@ ngx_quic_create_datagrams(ngx_connection_t *c)
p = dst;
len = ngx_min(qc->ctp.max_udp_payload_size,
NGX_QUIC_MAX_UDP_PAYLOAD_SIZE);
len = ngx_quic_path_limit(c, path, len);
len = ngx_quic_path_limit(c, path, path->mtu);
pad = ngx_quic_get_padding_level(c);
@@ -281,7 +260,7 @@ ngx_quic_allow_segmentation(ngx_connection_t *c)
return 0;
}
if (qc->path->limited) {
if (!qc->path->validated) {
/* don't even try to be faster on non-validated paths */
return 0;
}
@@ -299,9 +278,7 @@ ngx_quic_allow_segmentation(ngx_connection_t *c)
ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application);
bytes = 0;
len = ngx_min(qc->ctp.max_udp_payload_size,
NGX_QUIC_MAX_UDP_SEGMENT_BUF);
len = ngx_min(qc->path->mtu, NGX_QUIC_MAX_UDP_SEGMENT_BUF);
for (q = ngx_queue_head(&ctx->frames);
q != ngx_queue_sentinel(&ctx->frames);
@@ -345,8 +322,7 @@ ngx_quic_create_segments(ngx_connection_t *c)
return NGX_ERROR;
}
segsize = ngx_min(qc->ctp.max_udp_payload_size,
NGX_QUIC_MAX_UDP_SEGMENT_BUF);
segsize = ngx_min(path->mtu, NGX_QUIC_MAX_UDP_SEGMENT_BUF);
p = dst;
end = dst + sizeof(dst);
@@ -358,7 +334,7 @@ ngx_quic_create_segments(ngx_connection_t *c)
len = ngx_min(segsize, (size_t) (end - p));
if (len && cg->in_flight < cg->window) {
if (len && cg->in_flight + (p - dst) < cg->window) {
n = ngx_quic_output_packet(c, ctx, p, len, len);
if (n == NGX_ERROR) {
@@ -525,7 +501,7 @@ ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx,
ssize_t flen;
ngx_str_t res;
ngx_int_t rc;
ngx_uint_t nframes, expand;
ngx_uint_t nframes;
ngx_msec_t now;
ngx_queue_t *q;
ngx_quic_frame_t *f;
@@ -560,7 +536,6 @@ ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx,
nframes = 0;
p = src;
len = 0;
expand = 0;
for (q = ngx_queue_head(&ctx->frames);
q != ngx_queue_sentinel(&ctx->frames);
@@ -568,33 +543,6 @@ ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx,
{
f = ngx_queue_data(q, ngx_quic_frame_t, queue);
if (!expand && (f->type == NGX_QUIC_FT_PATH_RESPONSE
|| f->type == NGX_QUIC_FT_PATH_CHALLENGE))
{
/*
* RFC 9000, 8.2.1. Initiating Path Validation
*
* An endpoint MUST expand datagrams that contain a
* PATH_CHALLENGE frame to at least the smallest allowed
* maximum datagram size of 1200 bytes...
*
* (same applies to PATH_RESPONSE frames)
*/
if (max < 1200) {
/* expanded packet will not fit */
break;
}
if (min < 1200) {
min = 1200;
min_payload = ngx_quic_payload_size(&pkt, min);
}
expand = 1;
}
if (len >= max_payload) {
break;
}
@@ -631,10 +579,6 @@ ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx,
f->plen = 0;
nframes++;
if (f->flush) {
break;
}
}
if (nframes == 0) {
@@ -1174,8 +1118,9 @@ ngx_quic_send_ack(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx)
frame->u.ack.delay = ack_delay;
frame->u.ack.range_count = ctx->nranges;
frame->u.ack.first_range = ctx->first_range;
frame->len = ngx_quic_create_frame(NULL, frame);
ngx_quic_queue_frame(qc, frame);
ngx_queue_insert_head(&ctx->frames, &frame->queue);
return NGX_OK;
}
@@ -1264,7 +1209,7 @@ ngx_quic_frame_sendto(ngx_connection_t *c, ngx_quic_frame_t *frame,
sent = ngx_quic_send(c, res.data, res.len, path->sockaddr, path->socklen);
if (sent < 0) {
return NGX_ERROR;
return sent;
}
path->sent += sent;
@@ -1278,7 +1223,7 @@ ngx_quic_path_limit(ngx_connection_t *c, ngx_quic_path_t *path, size_t size)
{
off_t max;
if (path->limited) {
if (!path->validated) {
max = path->received * 3;
max = (path->sent >= max) ? 0 : max - path->sent;
-2
View File
@@ -12,8 +12,6 @@
#include <ngx_core.h>
size_t ngx_quic_max_udp_payload(ngx_connection_t *c);
ngx_int_t ngx_quic_output(ngx_connection_t *c);
ngx_int_t ngx_quic_negotiate_version(ngx_connection_t *c,
-1
View File
@@ -82,7 +82,6 @@ ngx_quic_open_sockets(ngx_connection_t *c, ngx_quic_connection_t *qc,
if (pkt->validated) {
qc->path->validated = 1;
qc->path->limited = 0;
}
ngx_quic_path_dbg(c, "set active", qc->path);
+2
View File
@@ -494,6 +494,8 @@ ngx_quic_crypto_input(ngx_connection_t *c, ngx_chain_t *data)
*/
ngx_quic_discard_ctx(c, ssl_encryption_handshake);
ngx_quic_discover_path_mtu(c, qc->path);
/* start accepting clients on negotiated number of server ids */
if (ngx_quic_create_sockets(c) != NGX_OK) {
return NGX_ERROR;
@@ -271,7 +271,6 @@ struct ngx_quic_frame_s {
ssize_t len;
unsigned need_ack:1;
unsigned pkt_need_ack:1;
unsigned flush:1;
ngx_chain_t *data;
union {
+1
View File
@@ -54,6 +54,7 @@ typedef int ngx_err_t;
#define NGX_ENOMOREFILES 0
#define NGX_ELOOP ELOOP
#define NGX_EBADF EBADF
#define NGX_EMSGSIZE EMSGSIZE
#if (NGX_HAVE_OPENAT)
#define NGX_EMLINK EMLINK
+1
View File
@@ -57,6 +57,7 @@ typedef DWORD ngx_err_t;
#define NGX_EILSEQ ERROR_NO_UNICODE_TRANSLATION
#define NGX_ELOOP 0
#define NGX_EBADF WSAEBADF
#define NGX_EMSGSIZE WSAEMSGSIZE
#define NGX_EALREADY WSAEALREADY
#define NGX_EINVAL WSAEINVAL