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