comparison src/event/ngx_event_quic.c @ 8415:125cbfa77013 quic

Renamed max_packet_size to max_udp_payload_size, from draft-28. No functional changes.
author Sergey Kandaurov <pluknet@nginx.com>
date Fri, 29 May 2020 12:56:08 +0300
parents f27fdf86275d
children 6633f17044eb
comparison
equal deleted inserted replaced
8414:49a98760afd2 8415:125cbfa77013
413 && qc->ctp.max_idle_timeout < qc->tp.max_idle_timeout) 413 && qc->ctp.max_idle_timeout < qc->tp.max_idle_timeout)
414 { 414 {
415 qc->tp.max_idle_timeout = qc->ctp.max_idle_timeout; 415 qc->tp.max_idle_timeout = qc->ctp.max_idle_timeout;
416 } 416 }
417 417
418 if (qc->ctp.max_packet_size < NGX_QUIC_MIN_INITIAL_SIZE 418 if (qc->ctp.max_udp_payload_size < NGX_QUIC_MIN_INITIAL_SIZE
419 || qc->ctp.max_packet_size > NGX_QUIC_DEFAULT_MAX_PACKET_SIZE) 419 || qc->ctp.max_udp_payload_size > NGX_QUIC_MAX_UDP_PAYLOAD_SIZE)
420 { 420 {
421 qc->error = NGX_QUIC_ERR_TRANSPORT_PARAMETER_ERROR; 421 qc->error = NGX_QUIC_ERR_TRANSPORT_PARAMETER_ERROR;
422 qc->error_reason = "invalid maximum packet size"; 422 qc->error_reason = "invalid maximum packet size";
423 423
424 ngx_log_error(NGX_LOG_INFO, c->log, 0, 424 ngx_log_error(NGX_LOG_INFO, c->log, 0,
432 432
433 /* 433 /*
434 * we need to fit at least 1 frame into a packet, thus account head/tail; 434 * we need to fit at least 1 frame into a packet, thus account head/tail;
435 * 17 = 1 + 8x2 is max header for CRYPTO frame, with 1 byte for frame type 435 * 17 = 1 + 8x2 is max header for CRYPTO frame, with 1 byte for frame type
436 */ 436 */
437 limit = qc->ctp.max_packet_size - NGX_QUIC_MAX_LONG_HEADER - 17 437 limit = qc->ctp.max_udp_payload_size - NGX_QUIC_MAX_LONG_HEADER - 17
438 - EVP_GCM_TLS_TAG_LEN; 438 - EVP_GCM_TLS_TAG_LEN;
439 439
440 fs = &qc->crypto[level]; 440 fs = &qc->crypto[level];
441 441
442 p = (u_char *) data; 442 p = (u_char *) data;
553 ngx_uint_t i; 553 ngx_uint_t i;
554 ngx_quic_tp_t *ctp; 554 ngx_quic_tp_t *ctp;
555 ngx_quic_secrets_t *keys; 555 ngx_quic_secrets_t *keys;
556 ngx_quic_send_ctx_t *ctx; 556 ngx_quic_send_ctx_t *ctx;
557 ngx_quic_connection_t *qc; 557 ngx_quic_connection_t *qc;
558 static u_char buf[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 558 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
559 559
560 if (ngx_buf_size(pkt->raw) < NGX_QUIC_MIN_INITIAL_SIZE) { 560 if (ngx_buf_size(pkt->raw) < NGX_QUIC_MIN_INITIAL_SIZE) {
561 ngx_log_error(NGX_LOG_INFO, c->log, 0, 561 ngx_log_error(NGX_LOG_INFO, c->log, 0,
562 "quic UDP datagram is too small for initial packet"); 562 "quic UDP datagram is too small for initial packet");
563 return NGX_ERROR; 563 return NGX_ERROR;
623 qc->ssl = ssl; 623 qc->ssl = ssl;
624 qc->tp = *tp; 624 qc->tp = *tp;
625 qc->streams.handler = handler; 625 qc->streams.handler = handler;
626 626
627 ctp = &qc->ctp; 627 ctp = &qc->ctp;
628 ctp->max_packet_size = NGX_QUIC_DEFAULT_MAX_PACKET_SIZE; 628 ctp->max_udp_payload_size = NGX_QUIC_MAX_UDP_PAYLOAD_SIZE;
629 ctp->ack_delay_exponent = NGX_QUIC_DEFAULT_ACK_DELAY_EXPONENT; 629 ctp->ack_delay_exponent = NGX_QUIC_DEFAULT_ACK_DELAY_EXPONENT;
630 ctp->max_ack_delay = NGX_QUIC_DEFAULT_MAX_ACK_DELAY; 630 ctp->max_ack_delay = NGX_QUIC_DEFAULT_MAX_ACK_DELAY;
631 631
632 qc->streams.recv_max_data = qc->tp.initial_max_data; 632 qc->streams.recv_max_data = qc->tp.initial_max_data;
633 633
634 qc->congestion.window = ngx_min(10 * qc->tp.max_packet_size, 634 qc->congestion.window = ngx_min(10 * qc->tp.max_udp_payload_size,
635 ngx_max(2 * qc->tp.max_packet_size, 14720)); 635 ngx_max(2 * qc->tp.max_udp_payload_size,
636 14720));
636 qc->congestion.ssthresh = NGX_MAX_SIZE_T_VALUE; 637 qc->congestion.ssthresh = NGX_MAX_SIZE_T_VALUE;
637 qc->congestion.recovery_start = ngx_current_msec; 638 qc->congestion.recovery_start = ngx_current_msec;
638 639
639 if (ngx_quic_new_dcid(c, &pkt->dcid) != NGX_OK) { 640 if (ngx_quic_new_dcid(c, &pkt->dcid) != NGX_OK) {
640 return NGX_ERROR; 641 return NGX_ERROR;
1079 { 1080 {
1080 ssize_t n; 1081 ssize_t n;
1081 ngx_buf_t b; 1082 ngx_buf_t b;
1082 ngx_connection_t *c; 1083 ngx_connection_t *c;
1083 ngx_quic_connection_t *qc; 1084 ngx_quic_connection_t *qc;
1084 static u_char buf[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 1085 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
1085 1086
1086 ngx_memzero(&b, sizeof(ngx_buf_t)); 1087 ngx_memzero(&b, sizeof(ngx_buf_t));
1087 b.start = buf; 1088 b.start = buf;
1088 b.end = buf + sizeof(buf); 1089 b.end = buf + sizeof(buf);
1089 b.pos = b.last = b.start; 1090 b.pos = b.last = b.start;
1444 { 1445 {
1445 ngx_int_t rc; 1446 ngx_int_t rc;
1446 ngx_quic_secrets_t *keys; 1447 ngx_quic_secrets_t *keys;
1447 ngx_quic_send_ctx_t *ctx; 1448 ngx_quic_send_ctx_t *ctx;
1448 ngx_quic_connection_t *qc; 1449 ngx_quic_connection_t *qc;
1449 static u_char buf[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 1450 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
1450 1451
1451 c->log->action = "retrying quic connection"; 1452 c->log->action = "retrying quic connection";
1452 1453
1453 if (ngx_buf_size(pkt->raw) < NGX_QUIC_MIN_INITIAL_SIZE) { 1454 if (ngx_buf_size(pkt->raw) < NGX_QUIC_MIN_INITIAL_SIZE) {
1454 ngx_log_error(NGX_LOG_INFO, c->log, 0, 1455 ngx_log_error(NGX_LOG_INFO, c->log, 0,
1532 { 1533 {
1533 ngx_int_t rc; 1534 ngx_int_t rc;
1534 ngx_ssl_conn_t *ssl_conn; 1535 ngx_ssl_conn_t *ssl_conn;
1535 ngx_quic_secrets_t *keys; 1536 ngx_quic_secrets_t *keys;
1536 ngx_quic_send_ctx_t *ctx; 1537 ngx_quic_send_ctx_t *ctx;
1537 static u_char buf[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 1538 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
1538 1539
1539 c->log->action = "processing initial quic packet"; 1540 c->log->action = "processing initial quic packet";
1540 1541
1541 ssl_conn = c->ssl->connection; 1542 ssl_conn = c->ssl->connection;
1542 1543
1571 { 1572 {
1572 ngx_int_t rc; 1573 ngx_int_t rc;
1573 ngx_quic_secrets_t *keys; 1574 ngx_quic_secrets_t *keys;
1574 ngx_quic_send_ctx_t *ctx; 1575 ngx_quic_send_ctx_t *ctx;
1575 ngx_quic_connection_t *qc; 1576 ngx_quic_connection_t *qc;
1576 static u_char buf[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 1577 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
1577 1578
1578 c->log->action = "processing handshake quic packet"; 1579 c->log->action = "processing handshake quic packet";
1579 1580
1580 qc = c->quic; 1581 qc = c->quic;
1581 1582
1628 { 1629 {
1629 ngx_int_t rc; 1630 ngx_int_t rc;
1630 ngx_quic_secrets_t *keys; 1631 ngx_quic_secrets_t *keys;
1631 ngx_quic_send_ctx_t *ctx; 1632 ngx_quic_send_ctx_t *ctx;
1632 ngx_quic_connection_t *qc; 1633 ngx_quic_connection_t *qc;
1633 static u_char buf[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 1634 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
1634 1635
1635 c->log->action = "processing early data quic packet"; 1636 c->log->action = "processing early data quic packet";
1636 1637
1637 qc = c->quic; 1638 qc = c->quic;
1638 1639
1708 { 1709 {
1709 ngx_int_t rc; 1710 ngx_int_t rc;
1710 ngx_quic_secrets_t *keys, *next, tmp; 1711 ngx_quic_secrets_t *keys, *next, tmp;
1711 ngx_quic_send_ctx_t *ctx; 1712 ngx_quic_send_ctx_t *ctx;
1712 ngx_quic_connection_t *qc; 1713 ngx_quic_connection_t *qc;
1713 static u_char buf[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 1714 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
1714 1715
1715 c->log->action = "processing application data quic packet"; 1716 c->log->action = "processing application data quic packet";
1716 1717
1717 qc = c->quic; 1718 qc = c->quic;
1718 1719
2961 /* process group of frames that fits into packet */ 2962 /* process group of frames that fits into packet */
2962 f = ngx_queue_data(q, ngx_quic_frame_t, queue); 2963 f = ngx_queue_data(q, ngx_quic_frame_t, queue);
2963 2964
2964 n = ngx_quic_create_frame(NULL, f); 2965 n = ngx_quic_create_frame(NULL, f);
2965 2966
2966 if (len && hlen + len + n > qc->ctp.max_packet_size) { 2967 if (len && hlen + len + n > qc->ctp.max_udp_payload_size) {
2967 break; 2968 break;
2968 } 2969 }
2969 2970
2970 if (f->need_ack) { 2971 if (f->need_ack) {
2971 need_ack = 1; 2972 need_ack = 1;
3060 ngx_quic_header_t pkt; 3061 ngx_quic_header_t pkt;
3061 ngx_quic_secrets_t *keys; 3062 ngx_quic_secrets_t *keys;
3062 ngx_quic_send_ctx_t *ctx; 3063 ngx_quic_send_ctx_t *ctx;
3063 ngx_quic_connection_t *qc; 3064 ngx_quic_connection_t *qc;
3064 static ngx_str_t initial_token = ngx_null_string; 3065 static ngx_str_t initial_token = ngx_null_string;
3065 static u_char src[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 3066 static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
3066 static u_char dst[NGX_QUIC_DEFAULT_MAX_PACKET_SIZE]; 3067 static u_char dst[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE];
3067 3068
3068 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, 3069 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0,
3069 "quic ngx_quic_send_frames"); 3070 "quic ngx_quic_send_frames");
3070 3071
3071 ssl_conn = c->ssl ? c->ssl->connection : NULL; 3072 ssl_conn = c->ssl ? c->ssl->connection : NULL;
3630 3631
3631 /* 3632 /*
3632 * we need to fit at least 1 frame into a packet, thus account head/tail; 3633 * we need to fit at least 1 frame into a packet, thus account head/tail;
3633 * 25 = 1 + 8x3 is max header for STREAM frame, with 1 byte for frame type 3634 * 25 = 1 + 8x3 is max header for STREAM frame, with 1 byte for frame type
3634 */ 3635 */
3635 limit = qc->ctp.max_packet_size - NGX_QUIC_MAX_SHORT_HEADER - 25 3636 limit = qc->ctp.max_udp_payload_size - NGX_QUIC_MAX_SHORT_HEADER - 25
3636 - EVP_GCM_TLS_TAG_LEN; 3637 - EVP_GCM_TLS_TAG_LEN;
3637 3638
3638 len = size; 3639 len = size;
3639 sent = c->sent; 3640 sent = c->sent;
3640 unacked = sent - qs->acked; 3641 unacked = sent - qs->acked;
3910 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 3911 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
3911 "quic congestion slow start win:%uz, ss:%uz, if:%uz", 3912 "quic congestion slow start win:%uz, ss:%uz, if:%uz",
3912 cg->window, cg->ssthresh, cg->in_flight); 3913 cg->window, cg->ssthresh, cg->in_flight);
3913 3914
3914 } else { 3915 } else {
3915 cg->window += qc->tp.max_packet_size * n / cg->window; 3916 cg->window += qc->tp.max_udp_payload_size * n / cg->window;
3916 3917
3917 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 3918 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,
3918 "quic congestion avoidance win:%uz, ss:%uz, if:%uz", 3919 "quic congestion avoidance win:%uz, ss:%uz, if:%uz",
3919 cg->window, cg->ssthresh, cg->in_flight); 3920 cg->window, cg->ssthresh, cg->in_flight);
3920 } 3921 }
3946 } 3947 }
3947 3948
3948 cg->recovery_start = ngx_current_msec; 3949 cg->recovery_start = ngx_current_msec;
3949 cg->window /= 2; 3950 cg->window /= 2;
3950 3951
3951 if (cg->window < qc->tp.max_packet_size * 2) { 3952 if (cg->window < qc->tp.max_udp_payload_size * 2) {
3952 cg->window = qc->tp.max_packet_size * 2; 3953 cg->window = qc->tp.max_udp_payload_size * 2;
3953 } 3954 }
3954 3955
3955 cg->ssthresh = cg->window; 3956 cg->ssthresh = cg->window;
3956 3957
3957 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, 3958 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0,