Mercurial > hg > nginx-quic
annotate src/event/quic/ngx_event_quic_output.c @ 8717:e06283038ec8 quic
QUIC: clear SSL_OP_ENABLE_MIDDLEBOX_COMPAT on SSL context switch.
The SSL_OP_ENABLE_MIDDLEBOX_COMPAT option is provided by QuicTLS and enabled
by default in the newly created SSL contexts. SSL_set_quic_method() is used
to clear it, which is required for SSL handshake to work on QUIC connections.
Switching context in the ngx_http_ssl_servername() SNI callback overrides SSL
options from the new SSL context. This results in the option set again.
Fix is to explicitly clear it when switching to another SSL context.
Initially reported here (in Russian):
http://mailman.nginx.org/pipermail/nginx-ru/2021-November/063989.html
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Tue, 07 Dec 2021 15:49:51 +0300 |
parents | ff473a6f656c |
children | 501f28679d56 |
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 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
41 static ngx_int_t ngx_quic_socket_output(ngx_connection_t *c, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
42 ngx_quic_socket_t *qsock); |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
43 static ngx_int_t ngx_quic_create_datagrams(ngx_connection_t *c, |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
44 ngx_quic_socket_t *qsock); |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
45 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
|
46 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
|
47 uint64_t pnum); |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
48 #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
|
49 static ngx_uint_t ngx_quic_allow_segmentation(ngx_connection_t *c, |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
50 ngx_quic_socket_t *qsock); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
51 static ngx_int_t ngx_quic_create_segments(ngx_connection_t *c, |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
52 ngx_quic_socket_t *qsock); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
53 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
|
54 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
|
55 #endif |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
56 static ssize_t ngx_quic_output_packet(ngx_connection_t *c, |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
57 ngx_quic_send_ctx_t *ctx, u_char *data, size_t max, size_t min, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
58 ngx_quic_socket_t *qsock); |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
59 static void ngx_quic_init_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
60 ngx_quic_socket_t *qsock, ngx_quic_header_t *pkt); |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
61 static ngx_uint_t ngx_quic_get_padding_level(ngx_connection_t *c); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
62 static ssize_t ngx_quic_send(ngx_connection_t *c, u_char *buf, size_t len, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
63 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
|
64 static void ngx_quic_set_packet_number(ngx_quic_header_t *pkt, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
65 ngx_quic_send_ctx_t *ctx); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
66 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
67 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
68 size_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
69 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
|
70 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
71 /* TODO: path MTU discovery */ |
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 #if (NGX_HAVE_INET6) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
74 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
|
75 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
|
76 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
77 #endif |
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 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
|
80 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
81 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
82 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
83 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
84 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
|
85 { |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
86 ngx_quic_connection_t *qc; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
87 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
88 qc = ngx_quic_get_connection(c); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
89 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
90 if (ngx_quic_socket_output(c, qc->socket) != NGX_OK) { |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
91 return NGX_ERROR; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
92 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
93 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
94 ngx_quic_set_lost_timer(c); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
95 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
96 return NGX_OK; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
97 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
98 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
99 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
100 static ngx_int_t |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
101 ngx_quic_socket_output(ngx_connection_t *c, ngx_quic_socket_t *qsock) |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
102 { |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
103 size_t in_flight; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
104 ngx_int_t rc; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
105 ngx_quic_congestion_t *cg; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
106 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
107 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
108 c->log->action = "sending frames"; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
109 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
110 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
111 cg = &qc->congestion; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
112 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
113 in_flight = cg->in_flight; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
114 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
115 #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
|
116 if (ngx_quic_allow_segmentation(c, qsock)) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
117 rc = ngx_quic_create_segments(c, qsock); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
118 } else |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
119 #endif |
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 rc = ngx_quic_create_datagrams(c, qsock); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
122 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
123 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
124 if (rc != NGX_OK) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
125 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
126 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
127 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
128 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
|
129 qc->send_timer_set = 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
130 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
|
131 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
132 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
133 return NGX_OK; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
134 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
135 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
136 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
137 static ngx_int_t |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
138 ngx_quic_create_datagrams(ngx_connection_t *c, ngx_quic_socket_t *qsock) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
139 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
140 off_t max; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
141 size_t len, min; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
142 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
143 u_char *p; |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
144 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
|
145 ngx_uint_t i, pad; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
146 ngx_quic_path_t *path; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
147 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
|
148 ngx_quic_congestion_t *cg; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
149 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
150 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
|
151 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
152 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
|
153 cg = &qc->congestion; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
154 path = qsock->path; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
155 |
8548
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8547
diff
changeset
|
156 while (cg->in_flight < cg->window) { |
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8547
diff
changeset
|
157 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
158 p = dst; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
159 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
160 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
|
161 NGX_QUIC_MAX_UDP_PAYLOAD_SIZE); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
162 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
163 if (path->state != NGX_QUIC_PATH_VALIDATED) { |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
164 max = path->received * 3; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
165 max = (path->sent >= max) ? 0 : max - path->sent; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
166 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
167 len = ngx_min(len, (size_t) max); |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
170 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
|
171 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
172 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
|
173 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
174 ctx = &qc->send_ctx[i]; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
175 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
176 preserved_pnum[i] = ctx->pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
177 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
178 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
|
179 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
180 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
181 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
182 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
|
183 ? 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
|
184 |
8680
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8548
diff
changeset
|
185 if (min > len) { |
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8548
diff
changeset
|
186 continue; |
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8548
diff
changeset
|
187 } |
c5155a0cb12f
QUIC: fixed processing of minimum packet size.
Vladimir Homutov <vl@nginx.com>
parents:
8548
diff
changeset
|
188 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
189 n = ngx_quic_output_packet(c, ctx, p, len, min, qsock); |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
190 if (n == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
191 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
192 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
193 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
194 p += n; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
195 len -= n; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
196 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
197 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
198 len = p - dst; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
199 if (len == 0) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
200 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
201 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
202 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
203 n = ngx_quic_send(c, dst, len, path->sockaddr, path->socklen); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
204 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
205 if (n == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
206 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
207 } |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
208 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
209 if (n == NGX_AGAIN) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
210 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
|
211 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
|
212 } |
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 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
|
215 break; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
216 } |
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 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
|
219 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
|
220 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
221 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
222 path->sent += len; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
223 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
224 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
225 return NGX_OK; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
226 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
227 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
228 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
229 static void |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
230 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
|
231 { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
232 ngx_queue_t *q; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
233 ngx_quic_frame_t *f; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
234 ngx_quic_congestion_t *cg; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
235 ngx_quic_connection_t *qc; |
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 qc = ngx_quic_get_connection(c); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
238 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
239 cg = &qc->congestion; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
240 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
241 while (!ngx_queue_empty(&ctx->sending)) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
242 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
243 q = ngx_queue_head(&ctx->sending); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
244 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
|
245 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
246 ngx_queue_remove(q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
247 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
248 if (f->pkt_need_ack && !qc->closing) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
249 ngx_queue_insert_tail(&ctx->sent, q); |
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 cg->in_flight += f->plen; |
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 } else { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
254 ngx_quic_free_frame(c, f); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
255 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
256 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
257 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
258 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
|
259 "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
|
260 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
261 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
262 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
263 static void |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
264 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
|
265 uint64_t pnum) |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
266 { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
267 ngx_queue_t *q; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
268 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
269 while (!ngx_queue_empty(&ctx->sending)) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
270 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
271 q = ngx_queue_last(&ctx->sending); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
272 ngx_queue_remove(q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
273 ngx_queue_insert_head(&ctx->frames, q); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
274 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
275 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
276 ctx->pnum = pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
277 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
278 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
279 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
280 #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
|
281 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
282 static ngx_uint_t |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
283 ngx_quic_allow_segmentation(ngx_connection_t *c, ngx_quic_socket_t *qsock) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
284 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
285 size_t bytes, len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
286 ngx_queue_t *q; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
287 ngx_quic_frame_t *f; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
288 ngx_quic_send_ctx_t *ctx; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
289 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
290 |
8540
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
291 qc = ngx_quic_get_connection(c); |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
292 |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
293 if (!qc->conf->gso_enabled) { |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
294 return 0; |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
295 } |
8ab0d609af09
QUIC: the "quic_gso" directive.
Vladimir Homutov <vl@nginx.com>
parents:
8512
diff
changeset
|
296 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
297 if (qsock->path->state != NGX_QUIC_PATH_VALIDATED) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
298 /* 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
|
299 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
300 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
301 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
302 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
|
303 if (!ngx_queue_empty(&ctx->frames)) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
304 return 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
305 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
306 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
307 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
|
308 if (!ngx_queue_empty(&ctx->frames)) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
309 return 0; |
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 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
|
313 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
314 bytes = 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
315 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
316 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
|
317 NGX_QUIC_MAX_UDP_SEGMENT_BUF); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
318 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
319 for (q = ngx_queue_head(&ctx->frames); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
320 q != ngx_queue_sentinel(&ctx->frames); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
321 q = ngx_queue_next(q)) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
322 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
323 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
|
324 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
325 bytes += f->len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
326 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
327 if (bytes > len * 3) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
328 /* require at least ~3 full packets to batch */ |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
329 return 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
330 } |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
331 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
332 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
333 return 0; |
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 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
337 static ngx_int_t |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
338 ngx_quic_create_segments(ngx_connection_t *c, ngx_quic_socket_t *qsock) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
339 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
340 size_t len, segsize; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
341 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
342 u_char *p, *end; |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
343 uint64_t preserved_pnum; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
344 ngx_uint_t nseg; |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
345 ngx_quic_path_t *path; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
346 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
|
347 ngx_quic_congestion_t *cg; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
348 ngx_quic_connection_t *qc; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
349 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
|
350 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
351 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
|
352 cg = &qc->congestion; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
353 path = qsock->path; |
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 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
|
356 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
357 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
|
358 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
359 } |
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 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
|
362 NGX_QUIC_MAX_UDP_SEGMENT_BUF); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
363 p = dst; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
364 end = dst + sizeof(dst); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
365 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
366 nseg = 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
367 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
368 preserved_pnum = ctx->pnum; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
369 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
370 for ( ;; ) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
371 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
372 len = ngx_min(segsize, (size_t) (end - p)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
373 |
8548
f3331deed357
QUIC: limit in-flight bytes by congestion window.
Roman Arutyunyan <arut@nginx.com>
parents:
8547
diff
changeset
|
374 if (len && cg->in_flight < cg->window) { |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
375 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
376 n = ngx_quic_output_packet(c, ctx, p, len, len, qsock); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
377 if (n == NGX_ERROR) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
378 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
379 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
380 |
8688
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8683
diff
changeset
|
381 if (n) { |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8683
diff
changeset
|
382 p += n; |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8683
diff
changeset
|
383 nseg++; |
25b87b392ce0
QUIC: fixed GSO packets count.
Vladimir Homutov <vl@nginx.com>
parents:
8683
diff
changeset
|
384 } |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
385 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
386 } else { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
387 n = 0; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
388 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
389 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
390 if (p == dst) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
391 break; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
392 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
393 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
394 if (n == 0 || nseg == NGX_QUIC_MAX_SEGMENTS) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
395 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
|
396 path->socklen, segsize); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
397 if (n == NGX_ERROR) { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
398 return NGX_ERROR; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
399 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
400 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
401 if (n == NGX_AGAIN) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
402 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
|
403 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
404 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
|
405 break; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
406 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
407 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
408 ngx_quic_commit_send(c, ctx); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
409 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
410 path->sent += n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
411 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
412 p = dst; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
413 nseg = 0; |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
414 preserved_pnum = ctx->pnum; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
415 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
416 } |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
417 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
418 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
419 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
420 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
421 |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
422 static ssize_t |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
423 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
|
424 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
|
425 { |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
426 size_t clen; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
427 ssize_t n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
428 uint16_t *valp; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
429 struct iovec iov; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
430 struct msghdr msg; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
431 struct cmsghdr *cmsg; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
432 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
433 #if defined(NGX_HAVE_ADDRINFO_CMSG) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
434 char msg_control[CMSG_SPACE(sizeof(uint16_t)) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
435 + CMSG_SPACE(sizeof(ngx_addrinfo_t))]; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
436 #else |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
437 char msg_control[CMSG_SPACE(sizeof(uint16_t))]; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
438 #endif |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
439 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
440 ngx_memzero(&msg, sizeof(struct msghdr)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
441 ngx_memzero(msg_control, sizeof(msg_control)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
442 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
443 iov.iov_len = len; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
444 iov.iov_base = buf; |
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 msg.msg_iov = &iov; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
447 msg.msg_iovlen = 1; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
448 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
449 msg.msg_name = sockaddr; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
450 msg.msg_namelen = socklen; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
451 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
452 msg.msg_control = msg_control; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
453 msg.msg_controllen = sizeof(msg_control); |
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 cmsg = CMSG_FIRSTHDR(&msg); |
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 cmsg->cmsg_level = SOL_UDP; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
458 cmsg->cmsg_type = UDP_SEGMENT; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
459 cmsg->cmsg_len = CMSG_LEN(sizeof(uint16_t)); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
460 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
461 clen = CMSG_SPACE(sizeof(uint16_t)); |
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 valp = (void *) CMSG_DATA(cmsg); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
464 *valp = segment; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
465 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
466 #if defined(NGX_HAVE_ADDRINFO_CMSG) |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
467 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
|
468 cmsg = CMSG_NXTHDR(&msg, cmsg); |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
469 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
|
470 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
471 #endif |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
472 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
473 msg.msg_controllen = clen; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
474 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
475 n = ngx_sendmsg(c, &msg, 0); |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
476 if (n < 0) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
477 return n; |
8512
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
478 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
479 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
480 c->sent += n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
481 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
482 return n; |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
483 } |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
484 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
485 #endif |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
486 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
487 |
bb5152ed045b
QUIC: added support for segmentation offloading.
Vladimir Homutov <vl@nginx.com>
parents:
8509
diff
changeset
|
488 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
489 static ngx_uint_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
490 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
|
491 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
492 ngx_queue_t *q; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
493 ngx_quic_frame_t *f; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
494 ngx_quic_send_ctx_t *ctx; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
495 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
496 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
497 /* |
8498
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8423
diff
changeset
|
498 * 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
|
499 * |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
500 * 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
|
501 * 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
|
502 * 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
|
503 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
504 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
505 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
506 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
|
507 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
508 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
|
509 q != ngx_queue_sentinel(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
510 q = ngx_queue_next(q)) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
511 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
512 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
|
513 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
514 if (f->need_ack) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
515 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
|
516 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
517 if (ngx_queue_empty(&ctx->frames)) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
518 return 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
519 } |
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 return 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
522 } |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
525 return NGX_QUIC_SEND_CTX_LAST; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
526 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
527 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
528 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
529 static ssize_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
530 ngx_quic_output_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
531 u_char *data, size_t max, size_t min, ngx_quic_socket_t *qsock) |
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 size_t len, pad, min_payload, max_payload; |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
534 u_char *p; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
535 ssize_t flen; |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
536 ngx_str_t res; |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
537 ngx_int_t rc; |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
538 ngx_uint_t nframes, expand; |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
539 ngx_msec_t now; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
540 ngx_queue_t *q; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
541 ngx_quic_frame_t *f; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
542 ngx_quic_header_t pkt; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
543 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
|
544 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
545 if (ngx_queue_empty(&ctx->frames)) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
546 return 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
547 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
548 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
549 ngx_log_debug4(NGX_LOG_DEBUG_EVENT, c->log, 0, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
550 "quic output sock #%uL %s packet max:%uz min:%uz", |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
551 qsock->sid.seqnum, ngx_quic_level_name(ctx->level), |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
552 max, min); |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
553 |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
554 ngx_quic_init_packet(c, ctx, qsock, &pkt); |
8411
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 min_payload = ngx_quic_payload_size(&pkt, min); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
557 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
|
558 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
559 /* RFC 9001, 5.4.2. Header Protection Sample */ |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
560 pad = 4 - pkt.num_len; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
561 min_payload = ngx_max(min_payload, pad); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
562 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
563 if (min_payload > max_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
564 return 0; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
565 } |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
566 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
567 now = ngx_current_msec; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
568 nframes = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
569 p = src; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
570 len = 0; |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
571 expand = 0; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
572 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
573 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
|
574 q != ngx_queue_sentinel(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
575 q = ngx_queue_next(q)) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
576 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
577 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
|
578 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
579 if (!expand && (f->type == NGX_QUIC_FT_PATH_RESPONSE |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
580 || f->type == NGX_QUIC_FT_PATH_CHALLENGE)) |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
581 { |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
582 /* |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
583 * RFC 9000, 8.2.1. Initiating Path Validation |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
584 * |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
585 * An endpoint MUST expand datagrams that contain a |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
586 * PATH_CHALLENGE frame to at least the smallest allowed |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
587 * maximum datagram size of 1200 bytes... |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
588 * |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
589 * (same applies to PATH_RESPONSE frames) |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
590 */ |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
591 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
592 if (max < 1200) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
593 /* expanded packet will not fit */ |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
594 break; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
595 } |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
596 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
597 if (min < 1200) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
598 min = 1200; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
599 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
600 min_payload = ngx_quic_payload_size(&pkt, min); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
601 } |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
602 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
603 expand = 1; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
604 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
605 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
606 if (len >= max_payload) { |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
607 break; |
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 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
610 if (len + f->len > max_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
611 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
|
612 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
613 if (rc == NGX_ERROR) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
614 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
615 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
616 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
617 if (rc == NGX_DECLINED) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
618 break; |
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 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
621 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
622 if (f->need_ack) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
623 pkt.need_ack = 1; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
626 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
|
627 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
628 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
|
629 if (flen == -1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
630 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
631 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
632 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
633 len += flen; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
634 p += flen; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
635 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
636 f->pnum = ctx->pnum; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
637 f->first = now; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
638 f->last = now; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
639 f->plen = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
640 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
641 nframes++; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
642 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
643 if (f->flush) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
644 break; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
645 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
646 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
647 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
648 if (nframes == 0) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
649 return 0; |
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 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
652 if (len < min_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
653 ngx_memset(p, NGX_QUIC_FT_PADDING, min_payload - len); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
654 len = min_payload; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
655 } |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
656 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
657 pkt.payload.data = src; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
658 pkt.payload.len = len; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
659 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
660 res.data = data; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
661 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
662 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
|
663 "quic packet tx %s bytes:%ui" |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
664 " 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
|
665 ngx_quic_level_name(ctx->level), pkt.payload.len, |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
666 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
|
667 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
668 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
|
669 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
672 ctx->pnum++; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
673 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
674 if (pkt.need_ack) { |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
675 q = ngx_queue_head(&ctx->frames); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
676 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
|
677 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
678 f->plen = res.len; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
679 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
680 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
681 while (nframes--) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
682 q = ngx_queue_head(&ctx->frames); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
683 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
|
684 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
685 f->pkt_need_ack = pkt.need_ack; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
686 |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
687 ngx_queue_remove(q); |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
688 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
|
689 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
690 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
691 return res.len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
692 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
693 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
694 |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
695 static void |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
696 ngx_quic_init_packet(ngx_connection_t *c, ngx_quic_send_ctx_t *ctx, |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
697 ngx_quic_socket_t *qsock, ngx_quic_header_t *pkt) |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
698 { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
699 ngx_quic_connection_t *qc; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
700 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
701 qc = ngx_quic_get_connection(c); |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
702 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
703 ngx_memzero(pkt, sizeof(ngx_quic_header_t)); |
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->flags = NGX_QUIC_PKT_FIXED_BIT; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
706 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
707 if (ctx->level == ssl_encryption_initial) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
708 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
|
709 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
710 } else if (ctx->level == ssl_encryption_handshake) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
711 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
|
712 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
713 } else { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
714 if (qc->key_phase) { |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
715 pkt->flags |= NGX_QUIC_PKT_KPHASE; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
716 } |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
717 } |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
718 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
719 pkt->dcid.data = qsock->cid->id; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
720 pkt->dcid.len = qsock->cid->len; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
721 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
722 pkt->scid.data = qsock->sid.id; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
723 pkt->scid.len = qsock->sid.len; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
724 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
725 pkt->version = qc->version; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
726 pkt->log = c->log; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
727 pkt->level = ctx->level; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
728 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
729 pkt->keys = qc->keys; |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
730 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
731 ngx_quic_set_packet_number(pkt, ctx); |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
732 } |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
733 |
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
734 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
735 static ssize_t |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
736 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
|
737 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
|
738 { |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
739 ssize_t n; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
740 struct iovec iov; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
741 struct msghdr msg; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
742 #if defined(NGX_HAVE_ADDRINFO_CMSG) |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
743 struct cmsghdr *cmsg; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
744 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
|
745 #endif |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
746 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
747 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
|
748 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
749 iov.iov_len = len; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
750 iov.iov_base = buf; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
751 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
752 msg.msg_iov = &iov; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
753 msg.msg_iovlen = 1; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
754 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
755 msg.msg_name = sockaddr; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
756 msg.msg_namelen = socklen; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
757 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
758 #if defined(NGX_HAVE_ADDRINFO_CMSG) |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
759 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
|
760 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
761 msg.msg_control = msg_control; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
762 msg.msg_controllen = sizeof(msg_control); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
763 ngx_memzero(msg_control, sizeof(msg_control)); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
764 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
765 cmsg = CMSG_FIRSTHDR(&msg); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
766 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
767 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
|
768 } |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
769 #endif |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
770 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
771 n = ngx_sendmsg(c, &msg, 0); |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
772 if (n < 0) { |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
773 return n; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
774 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
775 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
776 c->sent += n; |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
777 |
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
778 return n; |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
779 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
780 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
781 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
782 static void |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
783 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
|
784 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
785 uint64_t delta; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
786 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
787 delta = ctx->pnum - ctx->largest_ack; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
788 pkt->number = ctx->pnum; |
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 if (delta <= 0x7F) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
791 pkt->num_len = 1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
792 pkt->trunc = ctx->pnum & 0xff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
793 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
794 } else if (delta <= 0x7FFF) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
795 pkt->num_len = 2; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
796 pkt->flags |= 0x1; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
797 pkt->trunc = ctx->pnum & 0xffff; |
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 } else if (delta <= 0x7FFFFF) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
800 pkt->num_len = 3; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
801 pkt->flags |= 0x2; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
802 pkt->trunc = ctx->pnum & 0xffffff; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
803 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
804 } else { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
805 pkt->num_len = 4; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
806 pkt->flags |= 0x3; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
807 pkt->trunc = ctx->pnum & 0xffffffff; |
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 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
810 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
811 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
812 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
813 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
|
814 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
815 size_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
816 ngx_quic_header_t pkt; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
817 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
|
818 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
819 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
|
820 "sending version negotiation packet"); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
821 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
822 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
823 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
|
824 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
825 pkt.scid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
826 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
827 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
|
828 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
829 #ifdef NGX_QUIC_DEBUG_PACKETS |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
830 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
|
831 "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
|
832 #endif |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
833 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
834 (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
|
835 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
836 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
837 } |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
840 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
841 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
|
842 ngx_quic_header_t *pkt) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
843 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
844 u_char *token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
845 size_t len, max; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
846 uint16_t rndbytes; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
847 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
|
848 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
849 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
|
850 "quic handle stateless reset output"); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
851 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
852 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
|
853 return NGX_DECLINED; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
854 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
855 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
856 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
|
857 len = pkt->len - 1; |
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 } else { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
860 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
|
861 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
862 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
|
863 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
864 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
865 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
866 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
|
867 + NGX_QUIC_MIN_SR_PACKET; |
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 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
|
871 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
872 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
873 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
874 buf[0] &= ~NGX_QUIC_PKT_LONG; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
875 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
|
876 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
877 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
|
878 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
879 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
|
880 != 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 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
883 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
884 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
885 (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
|
886 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
887 return NGX_DECLINED; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
891 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
892 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
|
893 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
894 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
895 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
896 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
897 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
898 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
899 if (qc->draining) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
900 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
901 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
902 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
903 if (qc->closing |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
904 && 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
|
905 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
906 /* dot not send CC too often */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
907 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
908 } |
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 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
911 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
912 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
915 frame->level = qc->error_level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
916 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
|
917 : NGX_QUIC_FT_CONNECTION_CLOSE; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
918 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
|
919 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
|
920 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
921 if (qc->error_reason) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
922 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
|
923 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
|
924 } |
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_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
927 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
928 qc->last_cc = ngx_current_msec; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
929 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
930 return ngx_quic_output(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
931 } |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
934 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
935 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
|
936 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
|
937 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
938 ssize_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
939 ngx_str_t res; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
940 ngx_quic_frame_t frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
941 ngx_quic_header_t pkt; |
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 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
|
944 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
|
945 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
946 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
|
947 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
|
948 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
949 frame.level = inpkt->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
950 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
|
951 frame.u.close.error_code = err; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
952 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
953 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
|
954 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
|
955 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
956 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
|
957 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
|
958 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
959 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
960 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
961 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
|
962 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
963 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
|
964 if (len == -1) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
965 return NGX_ERROR; |
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.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
|
969 if (pkt.keys == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
970 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
971 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
972 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
973 if (ngx_quic_keys_set_initial_secret(c->pool, pkt.keys, &inpkt->dcid, |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
974 inpkt->version) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
975 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
976 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
977 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
978 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
979 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
980 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
|
981 | NGX_QUIC_PKT_INITIAL; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
982 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
983 pkt.num_len = 1; |
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 * pkt.num = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
986 * pkt.trunc = 0; |
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 pkt.version = inpkt->version; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
990 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
991 pkt.level = inpkt->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
992 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
993 pkt.scid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
994 pkt.payload.data = src; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
995 pkt.payload.len = len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
996 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
997 res.data = dst; |
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 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
|
1000 return NGX_ERROR; |
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 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
1003 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
|
1004 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1005 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1006 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1007 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1008 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1009 |
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_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1012 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
|
1013 ngx_quic_header_t *inpkt) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1014 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1015 time_t expires; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1016 ssize_t len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1017 ngx_str_t res, token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1018 ngx_quic_header_t pkt; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1019 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1020 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
|
1021 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
|
1022 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1023 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
|
1024 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1025 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
|
1026 &token, &inpkt->dcid, expires, 1) |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1027 != NGX_OK) |
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 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1032 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
|
1033 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
|
1034 pkt.version = inpkt->version; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1035 pkt.log = c->log; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1036 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1037 pkt.odcid = inpkt->dcid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1038 pkt.dcid = inpkt->scid; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1039 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1040 /* TODO: generate routable dcid */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1041 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
|
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 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
|
1046 pkt.scid.data = 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 pkt.token = token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1049 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1050 res.data = buf; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1051 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1052 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
|
1053 return NGX_ERROR; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1056 #ifdef NGX_QUIC_DEBUG_PACKETS |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1057 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
|
1058 "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
|
1059 #endif |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1060 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1061 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
|
1062 if (len < 0) { |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1063 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1064 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1065 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1066 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
|
1067 "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
|
1068 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1069 /* |
8498
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8423
diff
changeset
|
1070 * RFC 9000, 17.2.5.1. Sending a Retry Packet |
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8423
diff
changeset
|
1071 * |
4715f3e669f1
QUIC: updated specification references.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8423
diff
changeset
|
1072 * 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
|
1073 * 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
|
1074 * 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
|
1075 */ |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1076 return NGX_DONE; |
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 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1079 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1080 ngx_int_t |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1081 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
|
1082 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1083 time_t expires; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1084 ngx_str_t token; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1085 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1086 ngx_quic_connection_t *qc; |
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 qc = ngx_quic_get_connection(c); |
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 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
|
1091 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1092 if (ngx_quic_new_token(c, path->sockaddr, path->socklen, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1093 qc->conf->av_token_key, &token, NULL, expires, 0) |
8411
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1094 != NGX_OK) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1095 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1096 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1097 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1098 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1099 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1100 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1101 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1102 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1103 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1104 frame->level = ssl_encryption_application; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1105 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
|
1106 frame->u.token.length = token.len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1107 frame->u.token.data = token.data; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1108 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1109 ngx_quic_queue_frame(qc, frame); |
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 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1112 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1113 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1114 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1115 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1116 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
|
1117 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1118 size_t len, left; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1119 uint64_t ack_delay; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1120 ngx_buf_t *b; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1121 ngx_uint_t i; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1122 ngx_chain_t *cl, **ll; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1123 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1124 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1125 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1126 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1127 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1128 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
|
1129 ack_delay *= 1000; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1130 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
|
1131 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1132 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1133 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1134 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1135 } |
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 ll = &frame->data; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1138 b = NULL; |
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 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
|
1141 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
|
1142 ctx->ranges[i].range); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1143 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1144 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
|
1145 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1146 if (left < len) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1147 cl = ngx_quic_alloc_buf(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1148 if (cl == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1149 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1150 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1151 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1152 *ll = cl; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1153 ll = &cl->next; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1154 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1155 b = cl->buf; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1156 left = b->end - b->last; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1157 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1158 if (left < len) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1159 return NGX_ERROR; |
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 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
|
1164 ctx->ranges[i].range); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1165 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1166 frame->u.ack.ranges_length += len; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1167 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1168 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1169 *ll = NULL; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1170 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1171 frame->level = ctx->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1172 frame->type = NGX_QUIC_FT_ACK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1173 frame->u.ack.largest = ctx->largest_range; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1174 frame->u.ack.delay = ack_delay; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1175 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
|
1176 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
|
1177 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1178 ngx_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1179 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1180 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1181 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1182 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1183 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1184 ngx_int_t |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1185 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
|
1186 uint64_t smallest, uint64_t largest) |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1187 { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1188 ngx_quic_frame_t *frame; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1189 ngx_quic_connection_t *qc; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1190 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1191 qc = ngx_quic_get_connection(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1192 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1193 frame = ngx_quic_alloc_frame(c); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1194 if (frame == NULL) { |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1195 return NGX_ERROR; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1196 } |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1197 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1198 frame->level = ctx->level; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1199 frame->type = NGX_QUIC_FT_ACK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1200 frame->u.ack.largest = largest; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1201 frame->u.ack.delay = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1202 frame->u.ack.range_count = 0; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1203 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
|
1204 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1205 ngx_quic_queue_frame(qc, frame); |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1206 |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1207 return NGX_OK; |
bc910a5ec737
QUIC: separate files for output and ack related processing.
Vladimir Homutov <vl@nginx.com>
parents:
diff
changeset
|
1208 } |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1209 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1210 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1211 ssize_t |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1212 ngx_quic_frame_sendto(ngx_connection_t *c, ngx_quic_frame_t *frame, |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1213 size_t min, struct sockaddr *sockaddr, socklen_t socklen) |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1214 { |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1215 size_t min_payload, pad; |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1216 ssize_t len; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1217 ngx_str_t res; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1218 ngx_quic_header_t pkt; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1219 ngx_quic_send_ctx_t *ctx; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1220 ngx_quic_connection_t *qc; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1221 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1222 static u_char src[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1223 static u_char dst[NGX_QUIC_MAX_UDP_PAYLOAD_SIZE]; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1224 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1225 qc = ngx_quic_get_connection(c); |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
1226 ctx = ngx_quic_get_send_ctx(qc, ssl_encryption_application); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1227 |
8681
d8ac4d3c24ac
QUIC: added function to initialize packet.
Vladimir Homutov <vl@nginx.com>
parents:
8680
diff
changeset
|
1228 ngx_quic_init_packet(c, ctx, qc->socket, &pkt); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1229 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1230 min_payload = min ? ngx_quic_payload_size(&pkt, min) : 0; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1231 |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1232 pad = 4 - pkt.num_len; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1233 min_payload = ngx_max(min_payload, pad); |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1234 |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1235 len = ngx_quic_create_frame(NULL, frame); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1236 if (len > NGX_QUIC_MAX_UDP_PAYLOAD_SIZE) { |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1237 return -1; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1238 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1239 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1240 ngx_quic_log_frame(c->log, frame, 1); |
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 len = ngx_quic_create_frame(src, frame); |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1243 if (len == -1) { |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1244 return -1; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1245 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1246 |
8683
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1247 if (len < (ssize_t) min_payload) { |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1248 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
|
1249 len = min_payload; |
de7b9af30fc6
QUIC: refactored packet creation.
Vladimir Homutov <vl@nginx.com>
parents:
8681
diff
changeset
|
1250 } |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1251 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1252 pkt.payload.data = src; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1253 pkt.payload.len = len; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1254 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1255 res.data = dst; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1256 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1257 if (ngx_quic_encrypt(&pkt, &res) != NGX_OK) { |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1258 return -1; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1259 } |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1260 |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1261 ctx->pnum++; |
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1262 |
8547
ad046179eb91
QUIC: handle EAGAIN properly on UDP sockets.
Vladimir Homutov <vl@nginx.com>
parents:
8540
diff
changeset
|
1263 return ngx_quic_send(c, res.data, res.len, sockaddr, socklen); |
8423
4117aa7fa38e
QUIC: connection migration.
Vladimir Homutov <vl@nginx.com>
parents:
8411
diff
changeset
|
1264 } |