Mercurial > hg > nginx
annotate src/event/quic/ngx_event_quic_output.c @ 9250:55a5a40dccde
Reordered checks for Content-Length and Transfer-Encoding.
This ensures that r->headers_in.content_length_n is not set when both
Content-Length and Transfer-Encoding headers are present, making it slightly
safer to use complex processing for 400 (Bad Request) errors.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 27 Apr 2024 18:16:27 +0300 |
parents | ce1ff81e9b92 |
children |
rev | line source |
---|---|
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
2 /* |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
3 * Copyright (C) Nginx, Inc. |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
4 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
5 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
6 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
7 #include <ngx_config.h> |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
8 #include <ngx_core.h> |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
9 #include <ngx_event.h> |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
10 #include <ngx_event_quic_connection.h> |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
11 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
12 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
13 #define NGX_QUIC_MAX_UDP_SEGMENT_BUF 65487 /* 65K - IPv6 header */ |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
14 #define NGX_QUIC_MAX_SEGMENTS 64 /* UDP_MAX_SEGMENTS */ |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
15 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
16 #define NGX_QUIC_RETRY_TOKEN_LIFETIME 3 /* seconds */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
17 #define NGX_QUIC_NEW_TOKEN_LIFETIME 600 /* seconds */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
18 #define NGX_QUIC_RETRY_BUFFER_SIZE 256 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
19 /* 1 flags + 4 version + 3 x (1 + 20) s/o/dcid + itag + token(64) */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
20 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
21 /* |
8797
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8763
diff
changeset
|
22 * RFC 9000, 10.3. Stateless Reset |
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8763
diff
changeset
|
23 * |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
24 * Endpoints MUST discard packets that are too small to be valid QUIC |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
25 * packets. With the set of AEAD functions defined in [QUIC-TLS], |
8797
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8763
diff
changeset
|
26 * short header packets that are smaller than 21 bytes are never valid. |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
27 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
28 #define NGX_QUIC_MIN_PKT_LEN 21 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
29 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
30 #define NGX_QUIC_MIN_SR_PACKET 43 /* 5 rand + 16 srt + 22 padding */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
31 #define NGX_QUIC_MAX_SR_PACKET 1200 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
32 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
33 #define NGX_QUIC_CC_MIN_INTERVAL 1000 /* 1s */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
34 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
35 #define NGX_QUIC_SOCKET_RETRY_DELAY 10 /* ms, for NGX_AGAIN on write */ |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
36 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
37 |
9184
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
38 #define ngx_quic_log_packet(log, pkt) \ |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
39 ngx_log_debug6(NGX_LOG_DEBUG_EVENT, log, 0, \ |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
40 "quic packet tx %s bytes:%ui need_ack:%d" \ |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
41 " number:%L encoded nl:%d trunc:0x%xD", \ |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
42 ngx_quic_level_name((pkt)->level), (pkt)->payload.len, \ |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
43 (pkt)->need_ack, (pkt)->number, (pkt)->num_len, \ |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
44 (pkt)->trunc); |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
45 |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
46 |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
47 static ngx_int_t ngx_quic_create_datagrams(ngx_connection_t *c); |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
48 static void ngx_quic_commit_send(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
49 static void ngx_quic_revert_send(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
50 uint64_t pnum); |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
51 #if ((NGX_HAVE_UDP_SEGMENT) && (NGX_HAVE_MSGHDR_MSG_CONTROL)) |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
52 static ngx_uint_t ngx_quic_allow_segmentation(ngx_connection_t *c); |
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
53 static ngx_int_t ngx_quic_create_segments(ngx_connection_t *c); |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
54 static ssize_t ngx_quic_send_segments(ngx_connection_t *c, u_char *buf, |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
55 size_t len, struct sockaddr *sockaddr, socklen_t socklen, size_t segment); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
56 #endif |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
57 static ssize_t ngx_quic_output_packet(ngx_connection_t *c, |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
58 ngx_quic_send_ctx_t *ctx, u_char *data, size_t max, size_t min); |
8892
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
59 static void ngx_quic_init_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
60 ngx_quic_header_t *pkt, ngx_quic_path_t *path); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
61 static ngx_uint_t ngx_quic_get_padding_level(ngx_connection_t *c); |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
62 static ssize_t ngx_quic_send(ngx_connection_t *c, u_char *buf, size_t len, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
63 struct sockaddr *sockaddr, socklen_t socklen); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
64 static void ngx_quic_set_packet_number(ngx_quic_header_t *pkt, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
65 ngx_quic_send_ctx_t *ctx); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
66 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
67 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
68 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
69 ngx_quic_output(ngx_connection_t *c) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
70 { |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
71 size_t in_flight; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
72 ngx_int_t rc; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
73 ngx_quic_congestion_t *cg; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
74 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
75 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
76 c->log->action = "sending frames"; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
77 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
78 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
79 cg = &qc->congestion; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
80 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
81 in_flight = cg->in_flight; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
82 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
83 #if ((NGX_HAVE_UDP_SEGMENT) && (NGX_HAVE_MSGHDR_MSG_CONTROL)) |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
84 if (ngx_quic_allow_segmentation(c)) { |
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
85 rc = ngx_quic_create_segments(c); |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
86 } else |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
87 #endif |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
88 { |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
89 rc = ngx_quic_create_datagrams(c); |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
90 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
91 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
92 if (rc != NGX_OK) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
93 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
94 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
95 |
9001
868e1b76c956
QUIC: do not arm loss detection timer if nothing was sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9000
diff
changeset
|
96 if (in_flight == cg->in_flight || qc->closing) { |
868e1b76c956
QUIC: do not arm loss detection timer if nothing was sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9000
diff
changeset
|
97 /* no ack-eliciting data was sent or we are done */ |
868e1b76c956
QUIC: do not arm loss detection timer if nothing was sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9000
diff
changeset
|
98 return NGX_OK; |
868e1b76c956
QUIC: do not arm loss detection timer if nothing was sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9000
diff
changeset
|
99 } |
868e1b76c956
QUIC: do not arm loss detection timer if nothing was sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9000
diff
changeset
|
100 |
868e1b76c956
QUIC: do not arm loss detection timer if nothing was sent.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9000
diff
changeset
|
101 if (!qc->send_timer_set) { |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
102 qc->send_timer_set = 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
103 ngx_add_timer(c->read, qc->tp.max_idle_timeout); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
104 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
105 |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
106 ngx_quic_set_lost_timer(c); |
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
107 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
108 return NGX_OK; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
109 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
110 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
111 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
112 static ngx_int_t |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
113 ngx_quic_create_datagrams(ngx_connection_t *c) |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
114 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
115 size_t len, min; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
116 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
117 u_char *p; |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
118 uint64_t preserved_pnum[NGX_QUIC_SEND_CTX_LAST]; |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
119 ngx_uint_t i, pad; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
120 ngx_quic_path_t *path; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
121 ngx_quic_send_ctx_t *ctx; |
8823
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8822
diff
changeset
|
122 ngx_quic_congestion_t *cg; |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
123 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
124 static u_char dst[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
125 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
126 qc = ngx_quic_get_connection(c); |
8823
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8822
diff
changeset
|
127 cg = &qc->congestion; |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
128 path = qc->path; |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
129 |
8823
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8822
diff
changeset
|
130 while (cg->in_flight < cg->window) { |
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8822
diff
changeset
|
131 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
132 p = dst; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
133 |
9147
58afcd72446f
QUIC: path MTU discovery.
Roman Arutyunyan <arut@nginx.com>
parents:
9146
diff
changeset
|
134 len = ngx_quic_path_limit(c, path, path->mtu); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
135 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
136 pad = ngx_quic_get_padding_level(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
137 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
138 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
139 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
140 ctx = &qc->send_ctx[i]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
141 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
142 preserved_pnum[i] = ctx->pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
143 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
144 if (ngx_quic_generate_ack(c, ctx) != NGX_OK) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
145 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
146 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
147 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
148 min = (i == pad && p - dst < NGX_QUIC_MIN_INITIAL_SIZE) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
149 ? NGX_QUIC_MIN_INITIAL_SIZE - (p - dst) : 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
150 |
8891
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8823
diff
changeset
|
151 if (min > len) { |
9000
cd8018bc81a5
QUIC: fixed padding of initial packets in case of limited path.
Vladimir Homutov <vl@nginx.com>
parents:
8994
diff
changeset
|
152 /* padding can't be applied - avoid sending the packet */ |
cd8018bc81a5
QUIC: fixed padding of initial packets in case of limited path.
Vladimir Homutov <vl@nginx.com>
parents:
8994
diff
changeset
|
153 |
9006
5f78174d1ac1
QUIC: fixed output context restoring.
Vladimir Homutov <vl@nginx.com>
parents:
9001
diff
changeset
|
154 while (i-- > 0) { |
9000
cd8018bc81a5
QUIC: fixed padding of initial packets in case of limited path.
Vladimir Homutov <vl@nginx.com>
parents:
8994
diff
changeset
|
155 ctx = &qc->send_ctx[i]; |
cd8018bc81a5
QUIC: fixed padding of initial packets in case of limited path.
Vladimir Homutov <vl@nginx.com>
parents:
8994
diff
changeset
|
156 ngx_quic_revert_send(c, ctx, preserved_pnum[i]); |
cd8018bc81a5
QUIC: fixed padding of initial packets in case of limited path.
Vladimir Homutov <vl@nginx.com>
parents:
8994
diff
changeset
|
157 } |
cd8018bc81a5
QUIC: fixed padding of initial packets in case of limited path.
Vladimir Homutov <vl@nginx.com>
parents:
8994
diff
changeset
|
158 |
cd8018bc81a5
QUIC: fixed padding of initial packets in case of limited path.
Vladimir Homutov <vl@nginx.com>
parents:
8994
diff
changeset
|
159 return NGX_OK; |
8891
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8823
diff
changeset
|
160 } |
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8823
diff
changeset
|
161 |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
162 n = ngx_quic_output_packet(c, ctx, p, len, min); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
163 if (n == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
164 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
165 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
166 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
167 p += n; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
168 len -= n; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
169 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
170 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
171 len = p - dst; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
172 if (len == 0) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
173 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
174 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
175 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
176 n = ngx_quic_send(c, dst, len, path->sockaddr, path->socklen); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
177 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
178 if (n == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
179 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
180 } |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
181 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
182 if (n == NGX_AGAIN) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
183 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
184 ngx_quic_revert_send(c, &qc->send_ctx[i], preserved_pnum[i]); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
185 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
186 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
187 ngx_add_timer(&qc->push, NGX_QUIC_SOCKET_RETRY_DELAY); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
188 break; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
189 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
190 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
191 for (i = 0; i < NGX_QUIC_SEND_CTX_LAST; i++) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
192 ngx_quic_commit_send(c, &qc->send_ctx[i]); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
193 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
194 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
195 path->sent += len; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
196 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
197 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
198 return NGX_OK; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
199 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
200 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
201 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
202 static void |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
203 ngx_quic_commit_send(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx) |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
204 { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
205 ngx_queue_t *q; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
206 ngx_quic_frame_t *f; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
207 ngx_quic_congestion_t *cg; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
208 ngx_quic_connection_t *qc; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
209 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
210 qc = ngx_quic_get_connection(c); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
211 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
212 cg = &qc->congestion; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
213 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
214 while (!ngx_queue_empty(&ctx->sending)) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
215 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
216 q = ngx_queue_head(&ctx->sending); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
217 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
218 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
219 ngx_queue_remove(q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
220 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
221 if (f->pkt_need_ack && !qc->closing) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
222 ngx_queue_insert_tail(&ctx->sent, q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
223 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
224 cg->in_flight += f->plen; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
225 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
226 } else { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
227 ngx_quic_free_frame(c, f); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
228 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
229 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
230 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
231 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
232 "quic congestion send if:%uz", cg->in_flight); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
233 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
234 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
235 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
236 static void |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
237 ngx_quic_revert_send(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
238 uint64_t pnum) |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
239 { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
240 ngx_queue_t *q; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
241 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
242 while (!ngx_queue_empty(&ctx->sending)) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
243 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
244 q = ngx_queue_last(&ctx->sending); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
245 ngx_queue_remove(q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
246 ngx_queue_insert_head(&ctx->frames, q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
247 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
248 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
249 ctx->pnum = pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
250 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
251 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
252 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
253 #if ((NGX_HAVE_UDP_SEGMENT) && (NGX_HAVE_MSGHDR_MSG_CONTROL)) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
254 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
255 static ngx_uint_t |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
256 ngx_quic_allow_segmentation(ngx_connection_t *c) |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
257 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
258 size_t bytes, len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
259 ngx_queue_t *q; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
260 ngx_quic_frame_t *f; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
261 ngx_quic_send_ctx_t *ctx; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
262 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
263 |
8815
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8811
diff
changeset
|
264 qc = ngx_quic_get_connection(c); |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8811
diff
changeset
|
265 |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8811
diff
changeset
|
266 if (!qc->conf->gso_enabled) { |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8811
diff
changeset
|
267 return 0; |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8811
diff
changeset
|
268 } |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8811
diff
changeset
|
269 |
9144
bba136612fe4
QUIC: removed path->limited flag.
Roman Arutyunyan <arut@nginx.com>
parents:
9143
diff
changeset
|
270 if (!qc->path->validated) { |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
271 /* don't even try to be faster on non-validated paths */ |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
272 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
273 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
274 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
275 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_initial); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
276 if (!ngx_queue_empty(&ctx->frames)) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
277 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
278 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
279 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
280 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_handshake); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
281 if (!ngx_queue_empty(&ctx->frames)) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
282 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
283 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
284 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
285 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
286 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
287 bytes = 0; |
9147
58afcd72446f
QUIC: path MTU discovery.
Roman Arutyunyan <arut@nginx.com>
parents:
9146
diff
changeset
|
288 len = ngx_min(qc->path->mtu, NGX_QUIC_MAX_UDP_SEGMENT_BUF); |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
289 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
290 for (q = ngx_queue_head(&ctx->frames); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
291 q != ngx_queue_sentinel(&ctx->frames); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
292 q = ngx_queue_next(q)) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
293 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
294 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
295 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
296 bytes += f->len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
297 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
298 if (bytes > len * 3) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
299 /* require at least ~3 full packets to batch */ |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
300 return 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
301 } |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
302 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
303 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
304 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
305 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
306 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
307 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
308 static ngx_int_t |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
309 ngx_quic_create_segments(ngx_connection_t *c) |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
310 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
311 size_t len, segsize; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
312 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
313 u_char *p, *end; |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
314 uint64_t preserved_pnum; |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
315 ngx_uint_t nseg; |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
316 ngx_quic_path_t *path; |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
317 ngx_quic_send_ctx_t *ctx; |
8823
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8822
diff
changeset
|
318 ngx_quic_congestion_t *cg; |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
319 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
320 static u_char dst[NGX_QUIC_MAX_UDP_SEGMENT_BUF]; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
321 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
322 qc = ngx_quic_get_connection(c); |
8823
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8822
diff
changeset
|
323 cg = &qc->congestion; |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
324 path = qc->path; |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
325 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
326 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
327 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
328 if (ngx_quic_generate_ack(c, ctx) != NGX_OK) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
329 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
330 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
331 |
9147
58afcd72446f
QUIC: path MTU discovery.
Roman Arutyunyan <arut@nginx.com>
parents:
9146
diff
changeset
|
332 segsize = ngx_min(path->mtu, NGX_QUIC_MAX_UDP_SEGMENT_BUF); |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
333 p = dst; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
334 end = dst + sizeof(dst); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
335 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
336 nseg = 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
337 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
338 preserved_pnum = ctx->pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
339 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
340 for ( ;; ) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
341 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
342 len = ngx_min(segsize, (size_t) (end - p)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
343 |
9140
e9a003d40485
QUIC: fixed congesion control in GSO mode.
Roman Arutyunyan <arut@nginx.com>
parents:
9139
diff
changeset
|
344 if (len && cg->in_flight + (p - dst) < cg->window) { |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
345 |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
346 n = ngx_quic_output_packet(c, ctx, p, len, len); |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
347 if (n == NGX_ERROR) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
348 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
349 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
350 |
8899
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8894
diff
changeset
|
351 if (n) { |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8894
diff
changeset
|
352 p += n; |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8894
diff
changeset
|
353 nseg++; |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8894
diff
changeset
|
354 } |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
355 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
356 } else { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
357 n = 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
358 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
359 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
360 if (p == dst) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
361 break; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
362 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
363 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
364 if (n == 0 || nseg == NGX_QUIC_MAX_SEGMENTS) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
365 n = ngx_quic_send_segments(c, dst, p - dst, path->sockaddr, |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
366 path->socklen, segsize); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
367 if (n == NGX_ERROR) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
368 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
369 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
370 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
371 if (n == NGX_AGAIN) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
372 ngx_quic_revert_send(c, ctx, preserved_pnum); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
373 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
374 ngx_add_timer(&qc->push, NGX_QUIC_SOCKET_RETRY_DELAY); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
375 break; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
376 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
377 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
378 ngx_quic_commit_send(c, ctx); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
379 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
380 path->sent += n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
381 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
382 p = dst; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
383 nseg = 0; |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
384 preserved_pnum = ctx->pnum; |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
385 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
386 } |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
387 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
388 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
389 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
390 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
391 |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
392 static ssize_t |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
393 ngx_quic_send_segments(ngx_connection_t *c, u_char *buf, size_t len, |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
394 struct sockaddr *sockaddr, socklen_t socklen, size_t segment) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
395 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
396 size_t clen; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
397 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
398 uint16_t *valp; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
399 struct iovec iov; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
400 struct msghdr msg; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
401 struct cmsghdr *cmsg; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
402 |
8976 | 403 #if (NGX_HAVE_ADDRINFO_CMSG) |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
404 char msg_control[CMSG_SPACE(sizeof(uint16_t)) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
405 + CMSG_SPACE(sizeof(ngx_addrinfo_t))]; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
406 #else |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
407 char msg_control[CMSG_SPACE(sizeof(uint16_t))]; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
408 #endif |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
409 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
410 ngx_memzero(&msg, sizeof(struct msghdr)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
411 ngx_memzero(msg_control, sizeof(msg_control)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
412 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
413 iov.iov_len = len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
414 iov.iov_base = buf; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
415 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
416 msg.msg_iov = &iov; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
417 msg.msg_iovlen = 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
418 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
419 msg.msg_name = sockaddr; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
420 msg.msg_namelen = socklen; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
421 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
422 msg.msg_control = msg_control; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
423 msg.msg_controllen = sizeof(msg_control); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
424 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
425 cmsg = CMSG_FIRSTHDR(&msg); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
426 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
427 cmsg->cmsg_level = SOL_UDP; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
428 cmsg->cmsg_type = UDP_SEGMENT; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
429 cmsg->cmsg_len = CMSG_LEN(sizeof(uint16_t)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
430 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
431 clen = CMSG_SPACE(sizeof(uint16_t)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
432 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
433 valp = (void *) CMSG_DATA(cmsg); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
434 *valp = segment; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
435 |
8976 | 436 #if (NGX_HAVE_ADDRINFO_CMSG) |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
437 if (c->listening && c->listening->wildcard && c->local_sockaddr) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
438 cmsg = CMSG_NXTHDR(&msg, cmsg); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
439 clen += ngx_set_srcaddr_cmsg(cmsg, c->local_sockaddr); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
440 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
441 #endif |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
442 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
443 msg.msg_controllen = clen; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
444 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
445 n = ngx_sendmsg(c, &msg, 0); |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
446 if (n < 0) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
447 return n; |
8811
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
448 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
449 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
450 c->sent += n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
451 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
452 return n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
453 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
454 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
455 #endif |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
456 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
457 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8808
diff
changeset
|
458 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
459 static ngx_uint_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
460 ngx_quic_get_padding_level(ngx_connection_t *c) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
461 { |
9009
e5f16d886c97
QUIC: optimized datagram expansion with half-RTT tickets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9006
diff
changeset
|
462 ngx_uint_t i; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
463 ngx_queue_t *q; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
464 ngx_quic_frame_t *f; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
465 ngx_quic_send_ctx_t *ctx; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
466 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
467 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
468 /* |
8797
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8763
diff
changeset
|
469 * RFC 9000, 14.1. Initial Datagram Size |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
470 * |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
471 * Similarly, a server MUST expand the payload of all UDP datagrams |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
472 * carrying ack-eliciting Initial packets to at least the smallest |
8797
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8763
diff
changeset
|
473 * allowed maximum datagram size of 1200 bytes. |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
474 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
475 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
476 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
477 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_initial); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
478 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
479 for (q = ngx_queue_head(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
480 q != ngx_queue_sentinel(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
481 q = ngx_queue_next(q)) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
482 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
483 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
484 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
485 if (f->need_ack) { |
9009
e5f16d886c97
QUIC: optimized datagram expansion with half-RTT tickets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9006
diff
changeset
|
486 for (i = 0; i + 1 < NGX_QUIC_SEND_CTX_LAST; i++) { |
e5f16d886c97
QUIC: optimized datagram expansion with half-RTT tickets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9006
diff
changeset
|
487 ctx = &qc->send_ctx[i + 1]; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
488 |
9009
e5f16d886c97
QUIC: optimized datagram expansion with half-RTT tickets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9006
diff
changeset
|
489 if (ngx_queue_empty(&ctx->frames)) { |
e5f16d886c97
QUIC: optimized datagram expansion with half-RTT tickets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9006
diff
changeset
|
490 break; |
e5f16d886c97
QUIC: optimized datagram expansion with half-RTT tickets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9006
diff
changeset
|
491 } |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
492 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
493 |
9009
e5f16d886c97
QUIC: optimized datagram expansion with half-RTT tickets.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9006
diff
changeset
|
494 return i; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
495 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
496 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
497 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
498 return NGX_QUIC_SEND_CTX_LAST; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
499 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
500 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
501 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
502 static ssize_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
503 ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
504 u_char *data, size_t max, size_t min) |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
505 { |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
506 size_t len, pad, min_payload, max_payload; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
507 u_char *p; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
508 ssize_t flen; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
509 ngx_str_t res; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
510 ngx_int_t rc; |
9145
93aee926d27f
QUIC: removed explicit packet padding for certain frames.
Roman Arutyunyan <arut@nginx.com>
parents:
9144
diff
changeset
|
511 ngx_uint_t nframes; |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
512 ngx_msec_t now; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
513 ngx_queue_t *q; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
514 ngx_quic_frame_t *f; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
515 ngx_quic_header_t pkt; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
516 ngx_quic_connection_t *qc; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
517 static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
518 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
519 if (ngx_queue_empty(&ctx->frames)) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
520 return 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
521 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
522 |
8945
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
523 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
524 "quic output %s packet max:%uz min:%uz", |
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8941
diff
changeset
|
525 ngx_quic_level_name(ctx->level), max, min); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
526 |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
527 qc = ngx_quic_get_connection(c); |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
528 |
9169
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
529 if (!ngx_quic_keys_available(qc->keys, ctx->level, 1)) { |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
530 ngx_log_error(NGX_LOG_ALERT, c->log, 0, "quic %s write keys discarded", |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
531 ngx_quic_level_name(ctx->level)); |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
532 |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
533 while (!ngx_queue_empty(&ctx->frames)) { |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
534 q = ngx_queue_head(&ctx->frames); |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
535 ngx_queue_remove(q); |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
536 |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
537 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
538 ngx_quic_free_frame(c, f); |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
539 } |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
540 |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
541 return 0; |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
542 } |
60c4e8d3151f
QUIC: added safety belt to prevent using discarded keys.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9147
diff
changeset
|
543 |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
544 ngx_quic_init_packet(c, ctx, &pkt, qc->path); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
545 |
8894
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
546 min_payload = ngx_quic_payload_size(&pkt, min); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
547 max_payload = ngx_quic_payload_size(&pkt, max); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
548 |
8894
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
549 /* RFC 9001, 5.4.2. Header Protection Sample */ |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
550 pad = 4 - pkt.num_len; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
551 min_payload = ngx_max(min_payload, pad); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
552 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
553 if (min_payload > max_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
554 return 0; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
555 } |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
556 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
557 now = ngx_current_msec; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
558 nframes = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
559 p = src; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
560 len = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
561 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
562 for (q = ngx_queue_head(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
563 q != ngx_queue_sentinel(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
564 q = ngx_queue_next(q)) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
565 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
566 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
567 |
8894
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
568 if (len >= max_payload) { |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
569 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
570 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
571 |
8894
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
572 if (len + f->len > max_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
573 rc = ngx_quic_split_frame(c, f, max_payload - len); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
574 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
575 if (rc == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
576 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
577 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
578 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
579 if (rc == NGX_DECLINED) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
580 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
581 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
582 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
583 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
584 if (f->need_ack) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
585 pkt.need_ack = 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
586 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
587 |
9184
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
588 f->pnum = ctx->pnum; |
9193
ce1ff81e9b92
QUIC: ngx_quic_frame_t time fields cleanup.
Roman Arutyunyan <arut@nginx.com>
parents:
9192
diff
changeset
|
589 f->send_time = now; |
9184
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
590 f->plen = 0; |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
591 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
592 ngx_quic_log_frame(c->log, f, 1); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
593 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
594 flen = ngx_quic_create_frame(p, f); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
595 if (flen == -1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
596 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
597 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
598 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
599 len += flen; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
600 p += flen; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
601 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
602 nframes++; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
603 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
604 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
605 if (nframes == 0) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
606 return 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
607 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
608 |
8894
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
609 if (len < min_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
610 ngx_memset(p, NGX_QUIC_FT_PADDING, min_payload - len); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
611 len = min_payload; |
9075
12b756caaf16
QUIC: fixed indentation.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9072
diff
changeset
|
612 } |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
613 |
8894
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
614 pkt.payload.data = src; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
615 pkt.payload.len = len; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
616 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
617 res.data = data; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
618 |
9184
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
619 ngx_quic_log_packet(c->log, &pkt); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
620 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
621 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
622 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
623 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
624 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
625 ctx->pnum++; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
626 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
627 if (pkt.need_ack) { |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
628 q = ngx_queue_head(&ctx->frames); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
629 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
630 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
631 f->plen = res.len; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
632 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
633 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
634 while (nframes--) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
635 q = ngx_queue_head(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
636 f = ngx_queue_data(q, ngx_quic_frame_t, queue); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
637 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
638 f->pkt_need_ack = pkt.need_ack; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
639 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
640 ngx_queue_remove(q); |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
641 ngx_queue_insert_tail(&ctx->sending, q); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
642 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
643 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
644 return res.len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
645 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
646 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
647 |
8892
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
648 static void |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
649 ngx_quic_init_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
650 ngx_quic_header_t *pkt, ngx_quic_path_t *path) |
8892
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
651 { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
652 ngx_quic_connection_t *qc; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
653 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
654 qc = ngx_quic_get_connection(c); |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
655 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
656 ngx_memzero(pkt, sizeof(ngx_quic_header_t)); |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
657 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
658 pkt->flags = NGX_QUIC_PKT_FIXED_BIT; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
659 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
660 if (ctx->level == ssl_encryption_initial) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
661 pkt->flags |= NGX_QUIC_PKT_LONG | NGX_QUIC_PKT_INITIAL; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
662 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
663 } else if (ctx->level == ssl_encryption_handshake) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
664 pkt->flags |= NGX_QUIC_PKT_LONG | NGX_QUIC_PKT_HANDSHAKE; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
665 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
666 } else { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
667 if (qc->key_phase) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
668 pkt->flags |= NGX_QUIC_PKT_KPHASE; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
669 } |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
670 } |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
671 |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
672 pkt->dcid.data = path->cid->id; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
673 pkt->dcid.len = path->cid->len; |
8892
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
674 |
8985
da24a78720eb
QUIC: fixed handling of initial source connection id.
Vladimir Homutov <vl@nginx.com>
parents:
8980
diff
changeset
|
675 pkt->scid = qc->tp.initial_scid; |
8892
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
676 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
677 pkt->version = qc->version; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
678 pkt->log = c->log; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
679 pkt->level = ctx->level; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
680 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
681 pkt->keys = qc->keys; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
682 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
683 ngx_quic_set_packet_number(pkt, ctx); |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
684 } |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
685 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8891
diff
changeset
|
686 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
687 static ssize_t |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
688 ngx_quic_send(ngx_connection_t *c, u_char *buf, size_t len, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
689 struct sockaddr *sockaddr, socklen_t socklen) |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
690 { |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
691 ssize_t n; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
692 struct iovec iov; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
693 struct msghdr msg; |
8976 | 694 #if (NGX_HAVE_ADDRINFO_CMSG) |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
695 struct cmsghdr *cmsg; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
696 char msg_control[CMSG_SPACE(sizeof(ngx_addrinfo_t))]; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
697 #endif |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
698 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
699 ngx_memzero(&msg, sizeof(struct msghdr)); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
700 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
701 iov.iov_len = len; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
702 iov.iov_base = buf; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
703 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
704 msg.msg_iov = &iov; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
705 msg.msg_iovlen = 1; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
706 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
707 msg.msg_name = sockaddr; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
708 msg.msg_namelen = socklen; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
709 |
8976 | 710 #if (NGX_HAVE_ADDRINFO_CMSG) |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
711 if (c->listening && c->listening->wildcard && c->local_sockaddr) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
712 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
713 msg.msg_control = msg_control; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
714 msg.msg_controllen = sizeof(msg_control); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
715 ngx_memzero(msg_control, sizeof(msg_control)); |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
716 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
717 cmsg = CMSG_FIRSTHDR(&msg); |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
718 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
719 msg.msg_controllen = ngx_set_srcaddr_cmsg(cmsg, c->local_sockaddr); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
720 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
721 #endif |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
722 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
723 n = ngx_sendmsg(c, &msg, 0); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
724 if (n < 0) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
725 return n; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
726 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
727 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
728 c->sent += n; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
729 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
730 return n; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
731 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
732 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
733 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
734 static void |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
735 ngx_quic_set_packet_number(ngx_quic_header_t *pkt, ngx_quic_send_ctx_t *ctx) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
736 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
737 uint64_t delta; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
738 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
739 delta = ctx->pnum - ctx->largest_ack; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
740 pkt->number = ctx->pnum; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
741 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
742 if (delta <= 0x7F) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
743 pkt->num_len = 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
744 pkt->trunc = ctx->pnum & 0xff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
745 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
746 } else if (delta <= 0x7FFF) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
747 pkt->num_len = 2; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
748 pkt->flags |= 0x1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
749 pkt->trunc = ctx->pnum & 0xffff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
750 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
751 } else if (delta <= 0x7FFFFF) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
752 pkt->num_len = 3; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
753 pkt->flags |= 0x2; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
754 pkt->trunc = ctx->pnum & 0xffffff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
755 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
756 } else { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
757 pkt->num_len = 4; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
758 pkt->flags |= 0x3; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
759 pkt->trunc = ctx->pnum & 0xffffffff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
760 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
761 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
762 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
763 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
764 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
765 ngx_quic_negotiate_version(ngx_connection_t *c, ngx_quic_header_t *inpkt) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
766 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
767 size_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
768 ngx_quic_header_t pkt; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
769 static u_char buf[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
770 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
771 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
772 "sending version negotiation packet"); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
773 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
774 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
775 pkt.flags = NGX_QUIC_PKT_LONG | NGX_QUIC_PKT_FIXED_BIT; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
776 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
777 pkt.scid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
778 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
779 len = ngx_quic_create_version_negotiation(&pkt, buf); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
780 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
781 #ifdef NGX_QUIC_DEBUG_PACKETS |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
782 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
783 "quic vnego packet to send len:%uz %*xs", len, len, buf); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
784 #endif |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
785 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
786 (void) ngx_quic_send(c, buf, len, c->sockaddr, c->socklen); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
787 |
8973
e5509ff0dfd2
QUIC: avoid logging error in case of version negotiation.
Vladimir Homutov <vl@nginx.com>
parents:
8971
diff
changeset
|
788 return NGX_DONE; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
789 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
790 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
791 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
792 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
793 ngx_quic_send_stateless_reset(ngx_connection_t *c, ngx_quic_conf_t *conf, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
794 ngx_quic_header_t *pkt) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
795 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
796 u_char *token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
797 size_t len, max; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
798 uint16_t rndbytes; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
799 u_char buf[NGX_QUIC_MAX_SR_PACKET]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
800 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
801 ngx_log_debug0(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
802 "quic handle stateless reset output"); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
803 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
804 if (pkt->len <= NGX_QUIC_MIN_PKT_LEN) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
805 return NGX_DECLINED; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
806 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
807 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
808 if (pkt->len <= NGX_QUIC_MIN_SR_PACKET) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
809 len = pkt->len - 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
810 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
811 } else { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
812 max = ngx_min(NGX_QUIC_MAX_SR_PACKET, pkt->len * 3); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
813 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
814 if (RAND_bytes((u_char *) &rndbytes, sizeof(rndbytes)) != 1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
815 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
816 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
817 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
818 len = (rndbytes % (max - NGX_QUIC_MIN_SR_PACKET + 1)) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
819 + NGX_QUIC_MIN_SR_PACKET; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
820 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
821 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
822 if (RAND_bytes(buf, len - NGX_QUIC_SR_TOKEN_LEN) != 1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
823 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
824 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
825 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
826 buf[0] &= ~NGX_QUIC_PKT_LONG; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
827 buf[0] |= NGX_QUIC_PKT_FIXED_BIT; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
828 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
829 token = &buf[len - NGX_QUIC_SR_TOKEN_LEN]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
830 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
831 if (ngx_quic_new_sr_token(c, &pkt->dcid, conf->sr_token_key, token) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
832 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
833 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
834 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
835 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
836 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
837 (void) ngx_quic_send(c, buf, len, c->sockaddr, c->socklen); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
838 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
839 return NGX_DECLINED; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
840 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
841 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
842 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
843 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
844 ngx_quic_send_cc(ngx_connection_t *c) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
845 { |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
846 ngx_quic_frame_t *frame; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
847 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
848 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
849 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
850 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
851 if (qc->draining) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
852 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
853 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
854 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
855 if (qc->closing |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
856 && ngx_current_msec - qc->last_cc < NGX_QUIC_CC_MIN_INTERVAL) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
857 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
858 /* dot not send CC too often */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
859 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
860 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
861 |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
862 frame = ngx_quic_alloc_frame(c); |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
863 if (frame == NULL) { |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
864 return NGX_ERROR; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
865 } |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
866 |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
867 frame->level = qc->error_level; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
868 frame->type = qc->error_app ? NGX_QUIC_FT_CONNECTION_CLOSE_APP |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
869 : NGX_QUIC_FT_CONNECTION_CLOSE; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
870 frame->u.close.error_code = qc->error; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
871 frame->u.close.frame_type = qc->error_ftype; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
872 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
873 if (qc->error_reason) { |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
874 frame->u.close.reason.len = ngx_strlen(qc->error_reason); |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
875 frame->u.close.reason.data = (u_char *) qc->error_reason; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
876 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
877 |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
878 frame->ignore_congestion = 1; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
879 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
880 qc->last_cc = ngx_current_msec; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
881 |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
882 return ngx_quic_frame_sendto(c, frame, 0, qc->path); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
883 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
884 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
885 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
886 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
887 ngx_quic_send_early_cc(ngx_connection_t *c, ngx_quic_header_t *inpkt, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
888 ngx_uint_t err, const char *reason) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
889 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
890 ssize_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
891 ngx_str_t res; |
9025
e50f77a2d0b0
QUIC: removed ngx_quic_keys_new().
Vladimir Homutov <vl@nginx.com>
parents:
9024
diff
changeset
|
892 ngx_quic_keys_t keys; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
893 ngx_quic_frame_t frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
894 ngx_quic_header_t pkt; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
895 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
896 static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
897 static u_char dst[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
898 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
899 ngx_memzero(&frame, sizeof(ngx_quic_frame_t)); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
900 ngx_memzero(&pkt, sizeof(ngx_quic_header_t)); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
901 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
902 frame.level = inpkt->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
903 frame.type = NGX_QUIC_FT_CONNECTION_CLOSE; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
904 frame.u.close.error_code = err; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
905 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
906 frame.u.close.reason.data = (u_char *) reason; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
907 frame.u.close.reason.len = ngx_strlen(reason); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
908 |
9184
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
909 ngx_quic_log_frame(c->log, &frame, 1); |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
910 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
911 len = ngx_quic_create_frame(NULL, &frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
912 if (len > NGX_QUIC_MAX_UDP_PAYLOAD_SIZE) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
913 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
914 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
915 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
916 len = ngx_quic_create_frame(src, &frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
917 if (len == -1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
918 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
919 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
920 |
9025
e50f77a2d0b0
QUIC: removed ngx_quic_keys_new().
Vladimir Homutov <vl@nginx.com>
parents:
9024
diff
changeset
|
921 ngx_memzero(&keys, sizeof(ngx_quic_keys_t)); |
e50f77a2d0b0
QUIC: removed ngx_quic_keys_new().
Vladimir Homutov <vl@nginx.com>
parents:
9024
diff
changeset
|
922 |
e50f77a2d0b0
QUIC: removed ngx_quic_keys_new().
Vladimir Homutov <vl@nginx.com>
parents:
9024
diff
changeset
|
923 pkt.keys = &keys; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
924 |
9024
f2925c80401c
QUIC: avoided pool usage in ngx_quic_protection.c.
Vladimir Homutov <vl@nginx.com>
parents:
9009
diff
changeset
|
925 if (ngx_quic_keys_set_initial_secret(pkt.keys, &inpkt->dcid, c->log) |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
926 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
927 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
928 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
929 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
930 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
931 pkt.flags = NGX_QUIC_PKT_FIXED_BIT | NGX_QUIC_PKT_LONG |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
932 | NGX_QUIC_PKT_INITIAL; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
933 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
934 pkt.num_len = 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
935 /* |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
936 * pkt.num = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
937 * pkt.trunc = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
938 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
939 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
940 pkt.version = inpkt->version; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
941 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
942 pkt.level = inpkt->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
943 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
944 pkt.scid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
945 pkt.payload.data = src; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
946 pkt.payload.len = len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
947 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
948 res.data = dst; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
949 |
9184
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
950 ngx_quic_log_packet(c->log, &pkt); |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
951 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
952 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) { |
9172
4ccb0d973206
QUIC: reusing crypto contexts for packet protection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9169
diff
changeset
|
953 ngx_quic_keys_cleanup(pkt.keys); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
954 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
955 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
956 |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
957 if (ngx_quic_send(c, res.data, res.len, c->sockaddr, c->socklen) < 0) { |
9172
4ccb0d973206
QUIC: reusing crypto contexts for packet protection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9169
diff
changeset
|
958 ngx_quic_keys_cleanup(pkt.keys); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
959 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
960 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
961 |
9172
4ccb0d973206
QUIC: reusing crypto contexts for packet protection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9169
diff
changeset
|
962 ngx_quic_keys_cleanup(pkt.keys); |
4ccb0d973206
QUIC: reusing crypto contexts for packet protection.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9169
diff
changeset
|
963 |
8994
e00295b76395
QUIC: revised ngx_quic_handle_datagram() error codes.
Vladimir Homutov <vl@nginx.com>
parents:
8985
diff
changeset
|
964 return NGX_DONE; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
965 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
966 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
967 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
968 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
969 ngx_quic_send_retry(ngx_connection_t *c, ngx_quic_conf_t *conf, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
970 ngx_quic_header_t *inpkt) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
971 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
972 time_t expires; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
973 ssize_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
974 ngx_str_t res, token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
975 ngx_quic_header_t pkt; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
976 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
977 u_char buf[NGX_QUIC_RETRY_BUFFER_SIZE]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
978 u_char dcid[NGX_QUIC_SERVER_CID_LEN]; |
9026
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
979 u_char tbuf[NGX_QUIC_TOKEN_BUF_SIZE]; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
980 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
981 expires = ngx_time() + NGX_QUIC_RETRY_TOKEN_LIFETIME; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
982 |
9026
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
983 token.data = tbuf; |
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
984 token.len = NGX_QUIC_TOKEN_BUF_SIZE; |
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
985 |
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
986 if (ngx_quic_new_token(c->log, c->sockaddr, c->socklen, conf->av_token_key, |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
987 &token, &inpkt->dcid, expires, 1) |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
988 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
989 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
990 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
991 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
992 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
993 ngx_memzero(&pkt, sizeof(ngx_quic_header_t)); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
994 pkt.flags = NGX_QUIC_PKT_FIXED_BIT | NGX_QUIC_PKT_LONG | NGX_QUIC_PKT_RETRY; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
995 pkt.version = inpkt->version; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
996 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
997 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
998 pkt.odcid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
999 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1000 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1001 /* TODO: generate routable dcid */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1002 if (RAND_bytes(dcid, NGX_QUIC_SERVER_CID_LEN) != 1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1003 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1004 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1005 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1006 pkt.scid.len = NGX_QUIC_SERVER_CID_LEN; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1007 pkt.scid.data = dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1008 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1009 pkt.token = token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1010 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1011 res.data = buf; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1012 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1013 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1014 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1015 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1016 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1017 #ifdef NGX_QUIC_DEBUG_PACKETS |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1018 ngx_log_debug2(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1019 "quic packet to send len:%uz %xV", res.len, &res); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1020 #endif |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1021 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1022 len = ngx_quic_send(c, res.data, res.len, c->sockaddr, c->socklen); |
8822
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8815
diff
changeset
|
1023 if (len < 0) { |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1024 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1025 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1026 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1027 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1028 "quic retry packet sent to %xV", &pkt.dcid); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1029 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1030 /* |
8797
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8763
diff
changeset
|
1031 * RFC 9000, 17.2.5.1. Sending a Retry Packet |
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8763
diff
changeset
|
1032 * |
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8763
diff
changeset
|
1033 * A server MUST NOT send more than one Retry |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1034 * packet in response to a single UDP datagram. |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1035 * NGX_DONE will stop quic_input() from processing further |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1036 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1037 return NGX_DONE; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1038 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1039 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1040 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1041 ngx_int_t |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1042 ngx_quic_send_new_token(ngx_connection_t *c, ngx_quic_path_t *path) |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1043 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1044 time_t expires; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1045 ngx_str_t token; |
9072
def8e398d7c5
QUIC: fixed broken token in NEW_TOKEN (ticket #2446).
Roman Arutyunyan <arut@nginx.com>
parents:
9026
diff
changeset
|
1046 ngx_chain_t *out; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1047 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1048 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1049 |
9026
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
1050 u_char tbuf[NGX_QUIC_TOKEN_BUF_SIZE]; |
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
1051 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1052 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1053 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1054 expires = ngx_time() + NGX_QUIC_NEW_TOKEN_LIFETIME; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1055 |
9026
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
1056 token.data = tbuf; |
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
1057 token.len = NGX_QUIC_TOKEN_BUF_SIZE; |
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
1058 |
3550b00d9dc8
QUIC: avoided pool usage in token calculation.
Vladimir Homutov <vl@nginx.com>
parents:
9025
diff
changeset
|
1059 if (ngx_quic_new_token(c->log, path->sockaddr, path->socklen, |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1060 qc->conf->av_token_key, &token, NULL, expires, 0) |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1061 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1062 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1063 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1064 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1065 |
9072
def8e398d7c5
QUIC: fixed broken token in NEW_TOKEN (ticket #2446).
Roman Arutyunyan <arut@nginx.com>
parents:
9026
diff
changeset
|
1066 out = ngx_quic_copy_buffer(c, token.data, token.len); |
def8e398d7c5
QUIC: fixed broken token in NEW_TOKEN (ticket #2446).
Roman Arutyunyan <arut@nginx.com>
parents:
9026
diff
changeset
|
1067 if (out == NGX_CHAIN_ERROR) { |
def8e398d7c5
QUIC: fixed broken token in NEW_TOKEN (ticket #2446).
Roman Arutyunyan <arut@nginx.com>
parents:
9026
diff
changeset
|
1068 return NGX_ERROR; |
def8e398d7c5
QUIC: fixed broken token in NEW_TOKEN (ticket #2446).
Roman Arutyunyan <arut@nginx.com>
parents:
9026
diff
changeset
|
1069 } |
def8e398d7c5
QUIC: fixed broken token in NEW_TOKEN (ticket #2446).
Roman Arutyunyan <arut@nginx.com>
parents:
9026
diff
changeset
|
1070 |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1071 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1072 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1073 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1074 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1075 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1076 frame->level = ssl_encryption_application; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1077 frame->type = NGX_QUIC_FT_NEW_TOKEN; |
9072
def8e398d7c5
QUIC: fixed broken token in NEW_TOKEN (ticket #2446).
Roman Arutyunyan <arut@nginx.com>
parents:
9026
diff
changeset
|
1078 frame->data = out; |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1079 frame->u.token.length = token.len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1080 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1081 ngx_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1082 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1083 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1084 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1085 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1086 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1087 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1088 ngx_quic_send_ack(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1089 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1090 size_t len, left; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1091 uint64_t ack_delay; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1092 ngx_buf_t *b; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1093 ngx_uint_t i; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1094 ngx_chain_t *cl, **ll; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1095 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1096 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1097 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1098 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1099 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1100 ack_delay = ngx_current_msec - ctx->largest_received; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1101 ack_delay *= 1000; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1102 ack_delay >>= qc->tp.ack_delay_exponent; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1103 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1104 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1105 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1106 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1107 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1108 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1109 ll = &frame->data; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1110 b = NULL; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1111 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1112 for (i = 0; i < ctx->nranges; i++) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1113 len = ngx_quic_create_ack_range(NULL, ctx->ranges[i].gap, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1114 ctx->ranges[i].range); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1115 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1116 left = b ? b->end - b->last : 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1117 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1118 if (left < len) { |
8948
19e063e955bf
QUIC: renamed buffer-related functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8945
diff
changeset
|
1119 cl = ngx_quic_alloc_chain(c); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1120 if (cl == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1121 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1122 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1123 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1124 *ll = cl; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1125 ll = &cl->next; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1126 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1127 b = cl->buf; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1128 left = b->end - b->last; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1129 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1130 if (left < len) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1131 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1132 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1133 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1134 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1135 b->last += ngx_quic_create_ack_range(b->last, ctx->ranges[i].gap, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1136 ctx->ranges[i].range); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1137 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1138 frame->u.ack.ranges_length += len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1139 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1140 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1141 *ll = NULL; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1142 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1143 frame->level = ctx->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1144 frame->type = NGX_QUIC_FT_ACK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1145 frame->u.ack.largest = ctx->largest_range; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1146 frame->u.ack.delay = ack_delay; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1147 frame->u.ack.range_count = ctx->nranges; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1148 frame->u.ack.first_range = ctx->first_range; |
9139
d7dec2970161
QUIC: always add ACK frame to the queue head.
Roman Arutyunyan <arut@nginx.com>
parents:
9093
diff
changeset
|
1149 frame->len = ngx_quic_create_frame(NULL, frame); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1150 |
9139
d7dec2970161
QUIC: always add ACK frame to the queue head.
Roman Arutyunyan <arut@nginx.com>
parents:
9093
diff
changeset
|
1151 ngx_queue_insert_head(&ctx->frames, &frame->queue); |
8751
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1152 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1153 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1154 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1155 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1156 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1157 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1158 ngx_quic_send_ack_range(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1159 uint64_t smallest, uint64_t largest) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1160 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1161 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1162 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1163 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1164 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1165 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1166 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1167 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1168 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1169 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1170 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1171 frame->level = ctx->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1172 frame->type = NGX_QUIC_FT_ACK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1173 frame->u.ack.largest = largest; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1174 frame->u.ack.delay = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1175 frame->u.ack.range_count = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1176 frame->u.ack.first_range = largest - smallest; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1177 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1178 ngx_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1179 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1180 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1181 } |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1182 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1183 |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1184 ngx_int_t |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1185 ngx_quic_frame_sendto(ngx_connection_t *c, ngx_quic_frame_t *frame, |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1186 size_t min, ngx_quic_path_t *path) |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1187 { |
9190
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1188 size_t max, max_payload, min_payload, pad; |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1189 ssize_t len, sent; |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1190 ngx_str_t res; |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1191 ngx_msec_t now; |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1192 ngx_quic_header_t pkt; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1193 ngx_quic_send_ctx_t *ctx; |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1194 ngx_quic_congestion_t *cg; |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1195 ngx_quic_connection_t *qc; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1196 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1197 static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1198 static u_char dst[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1199 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1200 qc = ngx_quic_get_connection(c); |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1201 cg = &qc->congestion; |
9093
9ae24a9ba763
QUIC: fixed encryption level in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9092
diff
changeset
|
1202 ctx = ngx_quic_get_send_ctx(qc, frame->level); |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1203 |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1204 now = ngx_current_msec; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1205 |
9190
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1206 max = ngx_quic_path_limit(c, path, path->mtu); |
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1207 |
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1208 ngx_log_debug3(NGX_LOG_DEBUG_EVENT, c->log, 0, |
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1209 "quic sendto %s packet max:%uz min:%uz", |
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1210 ngx_quic_level_name(ctx->level), max, min); |
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1211 |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1212 if (cg->in_flight >= cg->window && !frame->ignore_congestion) { |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1213 ngx_quic_free_frame(c, frame); |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1214 return NGX_AGAIN; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1215 } |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1216 |
8971
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8948
diff
changeset
|
1217 ngx_quic_init_packet(c, ctx, &pkt, path); |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1218 |
9190
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1219 min_payload = ngx_quic_payload_size(&pkt, min); |
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1220 max_payload = ngx_quic_payload_size(&pkt, max); |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1221 |
9190
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1222 /* RFC 9001, 5.4.2. Header Protection Sample */ |
8894
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
1223 pad = 4 - pkt.num_len; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
1224 min_payload = ngx_max(min_payload, pad); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
1225 |
9190
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1226 if (min_payload > max_payload) { |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1227 ngx_quic_free_frame(c, frame); |
9190
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1228 return NGX_AGAIN; |
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1229 } |
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1230 |
9184
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
1231 #if (NGX_DEBUG) |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
1232 frame->pnum = pkt.number; |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
1233 #endif |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
1234 |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
1235 ngx_quic_log_frame(c->log, frame, 1); |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
1236 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1237 len = ngx_quic_create_frame(NULL, frame); |
9190
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1238 if ((size_t) len > max_payload) { |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1239 ngx_quic_free_frame(c, frame); |
9190
3a67dd34b6cc
QUIC: fixed anti-amplification with explicit send.
Roman Arutyunyan <arut@nginx.com>
parents:
9189
diff
changeset
|
1240 return NGX_AGAIN; |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1241 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1242 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1243 len = ngx_quic_create_frame(src, frame); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1244 if (len == -1) { |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1245 ngx_quic_free_frame(c, frame); |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1246 return NGX_ERROR; |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1247 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1248 |
8894
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
1249 if (len < (ssize_t) min_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
1250 ngx_memset(src + len, NGX_QUIC_FT_PADDING, min_payload - len); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8892
diff
changeset
|
1251 len = min_payload; |
9075
12b756caaf16
QUIC: fixed indentation.
Sergey Kandaurov <pluknet@nginx.com>
parents:
9072
diff
changeset
|
1252 } |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1253 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1254 pkt.payload.data = src; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1255 pkt.payload.len = len; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1256 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1257 res.data = dst; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1258 |
9184
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
1259 ngx_quic_log_packet(c->log, &pkt); |
7ec761f0365f
QUIC: improved packet and frames debug tracing.
Vladimir Khomutov <vl@wbsrv.ru>
parents:
9172
diff
changeset
|
1260 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1261 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) { |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1262 ngx_quic_free_frame(c, frame); |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1263 return NGX_ERROR; |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1264 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1265 |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1266 frame->pnum = ctx->pnum; |
9193
ce1ff81e9b92
QUIC: ngx_quic_frame_t time fields cleanup.
Roman Arutyunyan <arut@nginx.com>
parents:
9192
diff
changeset
|
1267 frame->send_time = now; |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1268 frame->plen = res.len; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1269 |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1270 ctx->pnum++; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1271 |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1272 sent = ngx_quic_send(c, res.data, res.len, path->sockaddr, path->socklen); |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1273 if (sent < 0) { |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1274 ngx_quic_free_frame(c, frame); |
9146
f3412ec3b6d1
QUIC: allowed ngx_quic_frame_sendto() to return NGX_AGAIN.
Roman Arutyunyan <arut@nginx.com>
parents:
9145
diff
changeset
|
1275 return sent; |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1276 } |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1277 |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1278 path->sent += sent; |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1279 |
9192
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1280 if (frame->need_ack && !qc->closing) { |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1281 ngx_queue_insert_tail(&ctx->sent, &frame->queue); |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1282 |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1283 cg->in_flight += frame->plen; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1284 |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1285 } else { |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1286 ngx_quic_free_frame(c, frame); |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1287 return NGX_OK; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1288 } |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1289 |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1290 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, c->log, 0, |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1291 "quic congestion send if:%uz", cg->in_flight); |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1292 |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1293 if (!qc->send_timer_set) { |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1294 qc->send_timer_set = 1; |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1295 ngx_add_timer(c->read, qc->tp.max_idle_timeout); |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1296 } |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1297 |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1298 ngx_quic_set_lost_timer(c); |
efcdaa66df2e
QUIC: congestion control in ngx_quic_frame_sendto().
Roman Arutyunyan <arut@nginx.com>
parents:
9190
diff
changeset
|
1299 |
8932
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8916
diff
changeset
|
1300 return NGX_OK; |
8763
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8751
diff
changeset
|
1301 } |
8941
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1302 |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1303 |
9189
fcec773dd249
QUIC: avoid partial expansion of PATH_CHALLENGE/PATH_RESPONSE.
Roman Arutyunyan <arut@nginx.com>
parents:
9184
diff
changeset
|
1304 size_t |
8941
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1305 ngx_quic_path_limit(ngx_connection_t *c, ngx_quic_path_t *path, size_t size) |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1306 { |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1307 off_t max; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1308 |
9144
bba136612fe4
QUIC: removed path->limited flag.
Roman Arutyunyan <arut@nginx.com>
parents:
9143
diff
changeset
|
1309 if (!path->validated) { |
8941
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1310 max = path->received * 3; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1311 max = (path->sent >= max) ? 0 : max - path->sent; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1312 |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1313 if ((off_t) size > max) { |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1314 return max; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1315 } |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1316 } |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1317 |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1318 return size; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8940
diff
changeset
|
1319 } |