Mercurial > hg > nginx-quic
annotate src/event/quic/ngx_event_quic_output.c @ 8816:7ea585a6ed0f quic
QUIC: set to standard TLS codepoint after draft versions removal.
This is to ease transition with oldish BoringSSL versions,
the default for SSL_set_quic_use_legacy_codepoint() has been
flipped in BoringSSL a1d3bfb64fd7ef2cb178b5b515522ffd75d7b8c5.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 26 Jan 2022 14:15:40 +0300 |
parents | d8865baab732 |
children | da24a78720eb |
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 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
107 if (in_flight != cg->in_flight && !qc->send_timer_set && !qc->closing) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
108 qc->send_timer_set = 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
109 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
|
110 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
111 |
8758
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8730
diff
changeset
|
112 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
|
113 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
114 return NGX_OK; |
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 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
117 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
118 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
|
119 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
|
120 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
121 size_t len, min; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
122 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
123 u_char *p; |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
124 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
|
125 ngx_uint_t i, pad; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
126 ngx_quic_path_t *path; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
127 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
|
128 ngx_quic_congestion_t *cg; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
129 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
130 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
|
131 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
132 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
|
133 cg = &qc->congestion; |
8797
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
134 path = qc->path; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
135 |
8548
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8547
diff
changeset
|
136 while (cg->in_flight < cg->window) { |
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8547
diff
changeset
|
137 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
138 p = dst; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
139 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
140 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
|
141 NGX_QUIC_MAX_UDP_PAYLOAD_SIZE); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
142 |
8730
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
143 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
|
144 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
145 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
|
146 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
147 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
|
148 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
149 ctx = &qc->send_ctx[i]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
150 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
151 preserved_pnum[i] = ctx->pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
152 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
153 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
|
154 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
155 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
156 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
157 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
|
158 ? 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
|
159 |
8680
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8548
diff
changeset
|
160 if (min > len) { |
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8548
diff
changeset
|
161 continue; |
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8548
diff
changeset
|
162 } |
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8548
diff
changeset
|
163 |
8758
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8730
diff
changeset
|
164 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
|
165 if (n == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
166 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
167 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
168 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
169 p += n; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
170 len -= n; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
171 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
172 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
173 len = p - dst; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
174 if (len == 0) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
175 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
176 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
177 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
178 n = ngx_quic_send(c, dst, len, path->sockaddr, path->socklen); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
179 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
180 if (n == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
181 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
182 } |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
183 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
184 if (n == NGX_AGAIN) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
185 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
|
186 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
|
187 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
188 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
189 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
|
190 break; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
191 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
192 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
193 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
|
194 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
|
195 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
196 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
197 path->sent += len; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
198 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
199 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
200 return NGX_OK; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
201 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
202 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
203 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
204 static void |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
205 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
|
206 { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
207 ngx_queue_t *q; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
208 ngx_quic_frame_t *f; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
209 ngx_quic_congestion_t *cg; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
210 ngx_quic_connection_t *qc; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
211 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
212 qc = ngx_quic_get_connection(c); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
213 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
214 cg = &qc->congestion; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
215 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
216 while (!ngx_queue_empty(&ctx->sending)) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
217 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
218 q = ngx_queue_head(&ctx->sending); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
219 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
|
220 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
221 ngx_queue_remove(q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
222 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
223 if (f->pkt_need_ack && !qc->closing) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
224 ngx_queue_insert_tail(&ctx->sent, q); |
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->in_flight += f->plen; |
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 } else { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
229 ngx_quic_free_frame(c, f); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
230 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
231 } |
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_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
|
234 "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
|
235 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
236 |
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 static void |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
239 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
|
240 uint64_t pnum) |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
241 { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
242 ngx_queue_t *q; |
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 while (!ngx_queue_empty(&ctx->sending)) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
245 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
246 q = ngx_queue_last(&ctx->sending); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
247 ngx_queue_remove(q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
248 ngx_queue_insert_head(&ctx->frames, q); |
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 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
251 ctx->pnum = pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
252 } |
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 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
255 #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
|
256 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
257 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
|
258 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
|
259 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
260 size_t bytes, len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
261 ngx_queue_t *q; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
262 ngx_quic_frame_t *f; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
263 ngx_quic_send_ctx_t *ctx; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
264 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
265 |
8540
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
266 qc = ngx_quic_get_connection(c); |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
267 |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
268 if (!qc->conf->gso_enabled) { |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
269 return 0; |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
270 } |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
271 |
8797
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
272 if (qc->path->limited) { |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
273 /* 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
|
274 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
275 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
276 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
277 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
|
278 if (!ngx_queue_empty(&ctx->frames)) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
279 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
280 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
281 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
282 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
|
283 if (!ngx_queue_empty(&ctx->frames)) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
284 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
285 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
286 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
287 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
|
288 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
289 bytes = 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
290 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
291 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
|
292 NGX_QUIC_MAX_UDP_SEGMENT_BUF); |
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 for (q = ngx_queue_head(&ctx->frames); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
295 q != ngx_queue_sentinel(&ctx->frames); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
296 q = ngx_queue_next(q)) |
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 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
|
299 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
300 bytes += f->len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
301 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
302 if (bytes > len * 3) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
303 /* require at least ~3 full packets to batch */ |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
304 return 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
305 } |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
306 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
307 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
308 return 0; |
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 |
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 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
|
313 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
|
314 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
315 size_t len, segsize; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
316 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
317 u_char *p, *end; |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
318 uint64_t preserved_pnum; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
319 ngx_uint_t nseg; |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
320 ngx_quic_path_t *path; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
321 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
|
322 ngx_quic_congestion_t *cg; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
323 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
324 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
|
325 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
326 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
|
327 cg = &qc->congestion; |
8797
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
328 path = qc->path; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
329 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
330 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
|
331 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
332 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
|
333 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
334 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
335 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
336 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
|
337 NGX_QUIC_MAX_UDP_SEGMENT_BUF); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
338 p = dst; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
339 end = dst + sizeof(dst); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
340 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
341 nseg = 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
342 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
343 preserved_pnum = ctx->pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
344 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
345 for ( ;; ) { |
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 len = ngx_min(segsize, (size_t) (end - p)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
348 |
8548
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8547
diff
changeset
|
349 if (len && cg->in_flight < cg->window) { |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
350 |
8758
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8730
diff
changeset
|
351 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
|
352 if (n == NGX_ERROR) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
353 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
354 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
355 |
8688
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8683
diff
changeset
|
356 if (n) { |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8683
diff
changeset
|
357 p += n; |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8683
diff
changeset
|
358 nseg++; |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8683
diff
changeset
|
359 } |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
360 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
361 } else { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
362 n = 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
363 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
364 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
365 if (p == dst) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
366 break; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
367 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
368 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
369 if (n == 0 || nseg == NGX_QUIC_MAX_SEGMENTS) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
370 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
|
371 path->socklen, segsize); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
372 if (n == NGX_ERROR) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
373 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
374 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
375 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
376 if (n == NGX_AGAIN) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
377 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
|
378 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
379 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
|
380 break; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
381 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
382 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
383 ngx_quic_commit_send(c, ctx); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
384 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
385 path->sent += n; |
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 p = dst; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
388 nseg = 0; |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
389 preserved_pnum = ctx->pnum; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
390 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
391 } |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
392 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
393 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
394 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
395 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
396 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
397 static ssize_t |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
398 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
|
399 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
|
400 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
401 size_t clen; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
402 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
403 uint16_t *valp; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
404 struct iovec iov; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
405 struct msghdr msg; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
406 struct cmsghdr *cmsg; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
407 |
8802 | 408 #if (NGX_HAVE_ADDRINFO_CMSG) |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
409 char msg_control[CMSG_SPACE(sizeof(uint16_t)) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
410 + CMSG_SPACE(sizeof(ngx_addrinfo_t))]; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
411 #else |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
412 char msg_control[CMSG_SPACE(sizeof(uint16_t))]; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
413 #endif |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
414 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
415 ngx_memzero(&msg, sizeof(struct msghdr)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
416 ngx_memzero(msg_control, sizeof(msg_control)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
417 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
418 iov.iov_len = len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
419 iov.iov_base = buf; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
420 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
421 msg.msg_iov = &iov; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
422 msg.msg_iovlen = 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
423 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
424 msg.msg_name = sockaddr; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
425 msg.msg_namelen = socklen; |
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 msg.msg_control = msg_control; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
428 msg.msg_controllen = 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 cmsg = CMSG_FIRSTHDR(&msg); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
431 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
432 cmsg->cmsg_level = SOL_UDP; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
433 cmsg->cmsg_type = UDP_SEGMENT; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
434 cmsg->cmsg_len = CMSG_LEN(sizeof(uint16_t)); |
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 clen = CMSG_SPACE(sizeof(uint16_t)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
437 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
438 valp = (void *) CMSG_DATA(cmsg); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
439 *valp = segment; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
440 |
8802 | 441 #if (NGX_HAVE_ADDRINFO_CMSG) |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
442 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
|
443 cmsg = CMSG_NXTHDR(&msg, cmsg); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
444 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
|
445 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
446 #endif |
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 msg.msg_controllen = clen; |
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 n = ngx_sendmsg(c, &msg, 0); |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
451 if (n < 0) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
452 return n; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
453 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
454 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
455 c->sent += n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
456 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
457 return n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
458 } |
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 #endif |
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 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
463 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
464 static ngx_uint_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
465 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
|
466 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
467 ngx_queue_t *q; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
468 ngx_quic_frame_t *f; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
469 ngx_quic_send_ctx_t *ctx; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
470 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
471 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
472 /* |
8498
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8423
diff
changeset
|
473 * 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
|
474 * |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
475 * 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
|
476 * 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
|
477 * 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
|
478 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
479 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
480 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
481 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
|
482 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
483 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
|
484 q != ngx_queue_sentinel(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
485 q = ngx_queue_next(q)) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
486 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
487 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
|
488 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
489 if (f->need_ack) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
490 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_handshake); |
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 if (ngx_queue_empty(&ctx->frames)) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
493 return 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
494 } |
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 return 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
497 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
498 } |
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 return NGX_QUIC_SEND_CTX_LAST; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
503 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
504 static ssize_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
505 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
|
506 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
|
507 { |
8797
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
508 size_t len, pad, min_payload, max_payload; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
509 u_char *p; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
510 ssize_t flen; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
511 ngx_str_t res; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
512 ngx_int_t rc; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
513 ngx_uint_t nframes, expand; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
514 ngx_msec_t now; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
515 ngx_queue_t *q; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
516 ngx_quic_frame_t *f; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
517 ngx_quic_header_t pkt; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
518 ngx_quic_connection_t *qc; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
519 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
|
520 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
521 if (ngx_queue_empty(&ctx->frames)) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
522 return 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
523 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
524 |
8758
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8730
diff
changeset
|
525 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
|
526 "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
|
527 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
|
528 |
8797
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
529 qc = ngx_quic_get_connection(c); |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
530 |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
531 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
|
532 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
533 min_payload = ngx_quic_payload_size(&pkt, min); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
534 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
|
535 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
536 /* RFC 9001, 5.4.2. Header Protection Sample */ |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
537 pad = 4 - pkt.num_len; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
538 min_payload = ngx_max(min_payload, pad); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
539 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
540 if (min_payload > max_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
541 return 0; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
542 } |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
543 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
544 now = ngx_current_msec; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
545 nframes = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
546 p = src; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
547 len = 0; |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
548 expand = 0; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
549 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
550 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
|
551 q != ngx_queue_sentinel(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
552 q = ngx_queue_next(q)) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
553 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
554 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
|
555 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
556 if (!expand && (f->type == NGX_QUIC_FT_PATH_RESPONSE |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
557 || f->type == NGX_QUIC_FT_PATH_CHALLENGE)) |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
558 { |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
559 /* |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
560 * RFC 9000, 8.2.1. Initiating Path Validation |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
561 * |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
562 * An endpoint MUST expand datagrams that contain a |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
563 * PATH_CHALLENGE frame to at least the smallest allowed |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
564 * maximum datagram size of 1200 bytes... |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
565 * |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
566 * (same applies to PATH_RESPONSE frames) |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
567 */ |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
568 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
569 if (max < 1200) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
570 /* expanded packet will not fit */ |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
571 break; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
572 } |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
573 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
574 if (min < 1200) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
575 min = 1200; |
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 min_payload = ngx_quic_payload_size(&pkt, min); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
578 } |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
579 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
580 expand = 1; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
581 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
582 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
583 if (len >= max_payload) { |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
584 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
585 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
586 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
587 if (len + f->len > max_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
588 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
|
589 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
590 if (rc == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
591 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
592 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
593 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
594 if (rc == NGX_DECLINED) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
595 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
596 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
597 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
598 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
599 if (f->need_ack) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
600 pkt.need_ack = 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
601 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
602 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
603 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
|
604 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
605 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
|
606 if (flen == -1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
607 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
610 len += flen; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
611 p += flen; |
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 f->pnum = ctx->pnum; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
614 f->first = now; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
615 f->last = now; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
616 f->plen = 0; |
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 nframes++; |
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 if (f->flush) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
621 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
622 } |
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 if (nframes == 0) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
626 return 0; |
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 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
629 if (len < min_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
630 ngx_memset(p, NGX_QUIC_FT_PADDING, min_payload - len); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
631 len = min_payload; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
632 } |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
633 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
634 pkt.payload.data = src; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
635 pkt.payload.len = len; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
636 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
637 res.data = data; |
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 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
|
640 "quic packet tx %s bytes:%ui" |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
641 " 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
|
642 ngx_quic_level_name(ctx->level), pkt.payload.len, |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
643 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
|
644 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
645 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
|
646 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
647 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
648 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
649 ctx->pnum++; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
650 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
651 if (pkt.need_ack) { |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
652 q = ngx_queue_head(&ctx->frames); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
653 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
|
654 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
655 f->plen = res.len; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
656 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
657 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
658 while (nframes--) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
659 q = ngx_queue_head(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
660 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
|
661 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
662 f->pkt_need_ack = pkt.need_ack; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
663 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
664 ngx_queue_remove(q); |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
665 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
|
666 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
667 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
668 return res.len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
669 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
670 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
671 |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
672 static void |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
673 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
|
674 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
|
675 { |
8758
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8730
diff
changeset
|
676 ngx_quic_socket_t *qsock; |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
677 ngx_quic_connection_t *qc; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
678 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
679 qc = ngx_quic_get_connection(c); |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
680 |
8797
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
681 qsock = ngx_quic_get_socket(c); |
8758
e72db9162180
QUIC: got rid of excessive "qsock" argument in ngx_quic_output.c.
Vladimir Homutov <vl@nginx.com>
parents:
8730
diff
changeset
|
682 |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
683 ngx_memzero(pkt, sizeof(ngx_quic_header_t)); |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
684 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
685 pkt->flags = NGX_QUIC_PKT_FIXED_BIT; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
686 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
687 if (ctx->level == ssl_encryption_initial) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
688 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
|
689 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
690 } else if (ctx->level == ssl_encryption_handshake) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
691 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
|
692 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
693 } else { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
694 if (qc->key_phase) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
695 pkt->flags |= NGX_QUIC_PKT_KPHASE; |
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 } |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
698 |
8797
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
699 pkt->dcid.data = path->cid->id; |
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
700 pkt->dcid.len = path->cid->len; |
8681
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 pkt->scid.data = qsock->sid.id; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
703 pkt->scid.len = qsock->sid.len; |
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 pkt->version = qc->version; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
706 pkt->log = c->log; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
707 pkt->level = ctx->level; |
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 pkt->keys = qc->keys; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
710 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
711 ngx_quic_set_packet_number(pkt, ctx); |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
712 } |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
713 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
714 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
715 static ssize_t |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
716 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
|
717 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
|
718 { |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
719 ssize_t n; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
720 struct iovec iov; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
721 struct msghdr msg; |
8802 | 722 #if (NGX_HAVE_ADDRINFO_CMSG) |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
723 struct cmsghdr *cmsg; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
724 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
|
725 #endif |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
726 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
727 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
|
728 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
729 iov.iov_len = len; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
730 iov.iov_base = buf; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
731 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
732 msg.msg_iov = &iov; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
733 msg.msg_iovlen = 1; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
734 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
735 msg.msg_name = sockaddr; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
736 msg.msg_namelen = socklen; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
737 |
8802 | 738 #if (NGX_HAVE_ADDRINFO_CMSG) |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
739 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
|
740 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
741 msg.msg_control = msg_control; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
742 msg.msg_controllen = sizeof(msg_control); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
743 ngx_memzero(msg_control, sizeof(msg_control)); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
744 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
745 cmsg = CMSG_FIRSTHDR(&msg); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
746 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
747 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
|
748 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
749 #endif |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
750 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
751 n = ngx_sendmsg(c, &msg, 0); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
752 if (n < 0) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
753 return n; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
754 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
755 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
756 c->sent += n; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
757 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
758 return n; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
759 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
760 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
761 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
762 static void |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
763 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
|
764 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
765 uint64_t delta; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
766 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
767 delta = ctx->pnum - ctx->largest_ack; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
768 pkt->number = ctx->pnum; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
769 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
770 if (delta <= 0x7F) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
771 pkt->num_len = 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
772 pkt->trunc = ctx->pnum & 0xff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
773 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
774 } else if (delta <= 0x7FFF) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
775 pkt->num_len = 2; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
776 pkt->flags |= 0x1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
777 pkt->trunc = ctx->pnum & 0xffff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
778 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
779 } else if (delta <= 0x7FFFFF) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
780 pkt->num_len = 3; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
781 pkt->flags |= 0x2; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
782 pkt->trunc = ctx->pnum & 0xffffff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
783 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
784 } else { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
785 pkt->num_len = 4; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
786 pkt->flags |= 0x3; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
787 pkt->trunc = ctx->pnum & 0xffffffff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
788 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
789 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
790 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
791 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
792 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
793 ngx_quic_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
|
794 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
795 size_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
796 ngx_quic_header_t pkt; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
797 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
|
798 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
799 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
|
800 "sending version negotiation packet"); |
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 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
803 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
|
804 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
805 pkt.scid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
806 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
807 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
|
808 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
809 #ifdef NGX_QUIC_DEBUG_PACKETS |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
810 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
|
811 "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
|
812 #endif |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
813 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
814 (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
|
815 |
8799
e5509ff0dfd2
QUIC: avoid logging error in case of version negotiation.
Vladimir Homutov <vl@nginx.com>
parents:
8797
diff
changeset
|
816 return NGX_DONE; |
8411
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 |
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 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
821 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
|
822 ngx_quic_header_t *pkt) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
823 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
824 u_char *token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
825 size_t len, max; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
826 uint16_t rndbytes; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
827 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
|
828 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
829 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
|
830 "quic handle stateless reset output"); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
831 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
832 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
|
833 return NGX_DECLINED; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
836 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
|
837 len = pkt->len - 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
838 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
839 } else { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
840 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
|
841 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
842 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
|
843 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
844 } |
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 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
|
847 + NGX_QUIC_MIN_SR_PACKET; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
848 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
849 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
850 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
|
851 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
854 buf[0] &= ~NGX_QUIC_PKT_LONG; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
855 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
|
856 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
857 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
|
858 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
859 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
|
860 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
861 { |
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 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
865 (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
|
866 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
867 return NGX_DECLINED; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
868 } |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
871 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
872 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
|
873 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
874 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
875 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
876 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
877 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
878 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
879 if (qc->draining) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
880 return NGX_OK; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
883 if (qc->closing |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
884 && 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
|
885 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
886 /* dot not send CC too often */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
887 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
888 } |
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 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
891 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
892 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
895 frame->level = qc->error_level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
896 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
|
897 : NGX_QUIC_FT_CONNECTION_CLOSE; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
898 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
|
899 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
|
900 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
901 if (qc->error_reason) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
902 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
|
903 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
|
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 ngx_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
907 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
908 qc->last_cc = ngx_current_msec; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
909 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
910 return ngx_quic_output(c); |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
913 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
914 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
915 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
|
916 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
|
917 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
918 ssize_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
919 ngx_str_t res; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
920 ngx_quic_frame_t frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
921 ngx_quic_header_t pkt; |
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 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
|
924 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
|
925 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
926 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
|
927 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
|
928 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
929 frame.level = inpkt->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
930 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
|
931 frame.u.close.error_code = err; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
932 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
933 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
|
934 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
|
935 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
936 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
|
937 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
|
938 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
939 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
940 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
941 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
|
942 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
943 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
|
944 if (len == -1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
945 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
946 } |
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 pkt.keys = ngx_quic_keys_new(c->pool); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
949 if (pkt.keys == NULL) { |
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 |
8815
d8865baab732
QUIC: removed draft versions support.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8802
diff
changeset
|
953 if (ngx_quic_keys_set_initial_secret(c->pool, pkt.keys, &inpkt->dcid) |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
954 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
955 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
956 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
957 } |
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 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
|
960 | NGX_QUIC_PKT_INITIAL; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
961 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
962 pkt.num_len = 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
963 /* |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
964 * pkt.num = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
965 * pkt.trunc = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
966 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
967 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
968 pkt.version = inpkt->version; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
969 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
970 pkt.level = inpkt->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
971 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
972 pkt.scid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
973 pkt.payload.data = src; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
974 pkt.payload.len = len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
975 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
976 res.data = dst; |
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 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
|
979 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
980 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
981 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
982 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
|
983 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
984 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
985 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
986 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
987 } |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
990 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
991 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
|
992 ngx_quic_header_t *inpkt) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
993 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
994 time_t expires; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
995 ssize_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
996 ngx_str_t res, token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
997 ngx_quic_header_t pkt; |
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 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
|
1000 u_char dcid[NGX_QUIC_SERVER_CID_LEN]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1001 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1002 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
|
1003 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1004 if (ngx_quic_new_token(c, c->sockaddr, c->socklen, conf->av_token_key, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1005 &token, &inpkt->dcid, expires, 1) |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1006 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1007 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1008 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1011 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
|
1012 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
|
1013 pkt.version = inpkt->version; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1014 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1015 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1016 pkt.odcid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1017 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1018 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1019 /* TODO: generate routable dcid */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1020 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
|
1021 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1024 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
|
1025 pkt.scid.data = dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1026 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1027 pkt.token = token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1028 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1029 res.data = buf; |
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 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
|
1032 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1035 #ifdef NGX_QUIC_DEBUG_PACKETS |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1036 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
|
1037 "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
|
1038 #endif |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1039 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1040 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
|
1041 if (len < 0) { |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1042 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1045 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
|
1046 "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
|
1047 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1048 /* |
8498
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8423
diff
changeset
|
1049 * RFC 9000, 17.2.5.1. Sending a Retry Packet |
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8423
diff
changeset
|
1050 * |
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8423
diff
changeset
|
1051 * 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
|
1052 * 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
|
1053 * 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
|
1054 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1055 return NGX_DONE; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1056 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1057 |
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 ngx_int_t |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1060 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
|
1061 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1062 time_t expires; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1063 ngx_str_t token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1064 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1065 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1066 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1067 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1068 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1069 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
|
1070 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1071 if (ngx_quic_new_token(c, path->sockaddr, path->socklen, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1072 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
|
1073 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1074 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1075 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1078 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1079 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1080 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1081 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1082 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1083 frame->level = ssl_encryption_application; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1084 frame->type = NGX_QUIC_FT_NEW_TOKEN; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1085 frame->u.token.length = token.len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1086 frame->u.token.data = token.data; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1087 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1088 ngx_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1089 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1090 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1091 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1092 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1093 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1094 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1095 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
|
1096 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1097 size_t len, left; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1098 uint64_t ack_delay; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1099 ngx_buf_t *b; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1100 ngx_uint_t i; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1101 ngx_chain_t *cl, **ll; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1102 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1103 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1104 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1105 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1106 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1107 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
|
1108 ack_delay *= 1000; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1109 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
|
1110 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1111 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1112 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1113 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1114 } |
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 ll = &frame->data; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1117 b = NULL; |
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 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
|
1120 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
|
1121 ctx->ranges[i].range); |
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 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
|
1124 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1125 if (left < len) { |
8761
19e063e955bf
QUIC: renamed buffer-related functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8758
diff
changeset
|
1126 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
|
1127 if (cl == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1128 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1129 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1130 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1131 *ll = cl; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1132 ll = &cl->next; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1133 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1134 b = cl->buf; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1135 left = b->end - b->last; |
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 if (left < len) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1138 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1139 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1140 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1141 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1142 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
|
1143 ctx->ranges[i].range); |
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 frame->u.ack.ranges_length += len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1146 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1147 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1148 *ll = NULL; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1149 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1150 frame->level = ctx->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1151 frame->type = NGX_QUIC_FT_ACK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1152 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
|
1153 frame->u.ack.delay = ack_delay; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1154 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
|
1155 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
|
1156 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1157 ngx_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1158 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1159 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1160 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1161 |
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 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1164 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
|
1165 uint64_t smallest, uint64_t largest) |
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 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1168 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1169 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1170 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1171 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1172 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1173 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1174 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1177 frame->level = ctx->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1178 frame->type = NGX_QUIC_FT_ACK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1179 frame->u.ack.largest = largest; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1180 frame->u.ack.delay = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1181 frame->u.ack.range_count = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1182 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
|
1183 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1184 ngx_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1185 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1186 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1187 } |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1188 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1189 |
8721
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1190 ngx_int_t |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1191 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
|
1192 size_t min, ngx_quic_path_t *path) |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1193 { |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1194 size_t min_payload, pad; |
8721
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1195 ssize_t len, sent; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1196 ngx_str_t res; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1197 ngx_quic_header_t pkt; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1198 ngx_quic_send_ctx_t *ctx; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1199 ngx_quic_connection_t *qc; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1200 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1201 static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1202 static u_char dst[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1203 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1204 qc = ngx_quic_get_connection(c); |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
1205 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1206 |
8797
1e2f4e9c8195
QUIC: reworked migration handling.
Vladimir Homutov <vl@nginx.com>
parents:
8761
diff
changeset
|
1207 ngx_quic_init_packet(c, ctx, &pkt, path); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1208 |
8730
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1209 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
|
1210 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1211 min_payload = min ? ngx_quic_payload_size(&pkt, min) : 0; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1212 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1213 pad = 4 - pkt.num_len; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1214 min_payload = ngx_max(min_payload, pad); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1215 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1216 len = ngx_quic_create_frame(NULL, frame); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1217 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
|
1218 return NGX_ERROR; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1219 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1220 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1221 ngx_quic_log_frame(c->log, frame, 1); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1222 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1223 len = ngx_quic_create_frame(src, frame); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1224 if (len == -1) { |
8721
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1225 return NGX_ERROR; |
8423
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 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1228 if (len < (ssize_t) min_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1229 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
|
1230 len = min_payload; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1231 } |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1232 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1233 pkt.payload.data = src; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1234 pkt.payload.len = len; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1235 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1236 res.data = dst; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1237 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1238 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
|
1239 return NGX_ERROR; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1240 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1241 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1242 ctx->pnum++; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1243 |
8721
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1244 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
|
1245 if (sent < 0) { |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1246 return NGX_ERROR; |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1247 } |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1248 |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1249 path->sent += sent; |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1250 |
501f28679d56
QUIC: refactored ngx_quic_frame_sendto() function.
Vladimir Homutov <vl@nginx.com>
parents:
8705
diff
changeset
|
1251 return NGX_OK; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1252 } |
8730
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1253 |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1254 |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1255 static size_t |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1256 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
|
1257 { |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1258 off_t max; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1259 |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1260 if (path->limited) { |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1261 max = path->received * 3; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1262 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
|
1263 |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1264 if ((off_t) size > max) { |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1265 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
|
1266 "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
|
1267 return max; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1268 } |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1269 } |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1270 |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1271 return size; |
0433e69f5425
QUIC: added path limiting function ngx_quic_path_limit().
Roman Arutyunyan <arut@nginx.com>
parents:
8729
diff
changeset
|
1272 } |