Mercurial > hg > nginx
comparison src/event/quic/ngx_event_quic.c @ 8736:714e9af983de quic
QUIC: separate header for ngx_quic_connection_t.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Wed, 31 Mar 2021 14:56:16 +0300 |
parents | 9ce6d80df113 |
children | 76f476ce4d31 |
comparison
equal
deleted
inserted
replaced
8735:9ce6d80df113 | 8736:714e9af983de |
---|---|
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 #include <ngx_event_quic_transport.h> | 10 #include <ngx_event_quic_transport.h> |
11 #include <ngx_event_quic_protection.h> | 11 #include <ngx_event_quic_protection.h> |
12 #include <ngx_event_quic_connection.h> | |
12 #include <ngx_sha1.h> | 13 #include <ngx_sha1.h> |
13 | 14 |
14 | 15 |
15 /* 0-RTT and 1-RTT data exist in the same packet number space, | 16 /* 0-RTT and 1-RTT data exist in the same packet number space, |
16 * so we have 3 packet number spaces: | 17 * so we have 3 packet number spaces: |
26 | 27 |
27 #define ngx_quic_lost_threshold(qc) \ | 28 #define ngx_quic_lost_threshold(qc) \ |
28 ngx_max(NGX_QUIC_TIME_THR * ngx_max((qc)->latest_rtt, (qc)->avg_rtt), \ | 29 ngx_max(NGX_QUIC_TIME_THR * ngx_max((qc)->latest_rtt, (qc)->avg_rtt), \ |
29 NGX_QUIC_TIME_GRANULARITY) | 30 NGX_QUIC_TIME_GRANULARITY) |
30 | 31 |
31 #define NGX_QUIC_SEND_CTX_LAST (NGX_QUIC_ENCRYPTION_LAST - 1) | |
32 | |
33 /* | 32 /* |
34 * 7.4. Cryptographic Message Buffering | 33 * 7.4. Cryptographic Message Buffering |
35 * Implementations MUST support buffering at least 4096 bytes of data | 34 * Implementations MUST support buffering at least 4096 bytes of data |
36 */ | 35 */ |
37 #define NGX_QUIC_MAX_BUFFERED 65535 | 36 #define NGX_QUIC_MAX_BUFFERED 65535 |
49 | 48 |
50 #define NGX_QUIC_MIN_SR_PACKET 43 /* 5 random + 16 srt + 22 padding */ | 49 #define NGX_QUIC_MIN_SR_PACKET 43 /* 5 random + 16 srt + 22 padding */ |
51 #define NGX_QUIC_MAX_SR_PACKET 1200 | 50 #define NGX_QUIC_MAX_SR_PACKET 1200 |
52 | 51 |
53 #define NGX_QUIC_MAX_ACK_GAP 2 | 52 #define NGX_QUIC_MAX_ACK_GAP 2 |
54 | |
55 | |
56 typedef struct { | |
57 ngx_rbtree_t tree; | |
58 ngx_rbtree_node_t sentinel; | |
59 | |
60 uint64_t received; | |
61 uint64_t sent; | |
62 uint64_t recv_max_data; | |
63 uint64_t send_max_data; | |
64 | |
65 uint64_t server_max_streams_uni; | |
66 uint64_t server_max_streams_bidi; | |
67 uint64_t server_streams_uni; | |
68 uint64_t server_streams_bidi; | |
69 | |
70 uint64_t client_max_streams_uni; | |
71 uint64_t client_max_streams_bidi; | |
72 uint64_t client_streams_uni; | |
73 uint64_t client_streams_bidi; | |
74 } ngx_quic_streams_t; | |
75 | |
76 | |
77 typedef struct { | |
78 size_t in_flight; | |
79 size_t window; | |
80 size_t ssthresh; | |
81 ngx_msec_t recovery_start; | |
82 } ngx_quic_congestion_t; | |
83 | |
84 | |
85 /* | |
86 * 12.3. Packet Numbers | |
87 * | |
88 * Conceptually, a packet number space is the context in which a packet | |
89 * can be processed and acknowledged. Initial packets can only be sent | |
90 * with Initial packet protection keys and acknowledged in packets which | |
91 * are also Initial packets. | |
92 */ | |
93 typedef struct { | |
94 enum ssl_encryption_level_t level; | |
95 | |
96 uint64_t pnum; /* to be sent */ | |
97 uint64_t largest_ack; /* received from peer */ | |
98 uint64_t largest_pn; /* received from peer */ | |
99 | |
100 ngx_queue_t frames; | |
101 ngx_queue_t sent; | |
102 | |
103 uint64_t pending_ack; /* non sent ack-eliciting */ | |
104 uint64_t largest_range; | |
105 uint64_t first_range; | |
106 ngx_msec_t largest_received; | |
107 ngx_msec_t ack_delay_start; | |
108 ngx_uint_t nranges; | |
109 ngx_quic_ack_range_t ranges[NGX_QUIC_MAX_RANGES]; | |
110 ngx_uint_t send_ack; | |
111 } ngx_quic_send_ctx_t; | |
112 | |
113 | |
114 typedef struct { | |
115 uint32_t version; | |
116 ngx_str_t scid; /* initial client ID */ | |
117 ngx_str_t dcid; /* server (our own) ID */ | |
118 ngx_str_t odcid; /* original server ID */ | |
119 | |
120 struct sockaddr *sockaddr; | |
121 socklen_t socklen; | |
122 | |
123 ngx_queue_t client_ids; | |
124 ngx_queue_t server_ids; | |
125 ngx_queue_t free_client_ids; | |
126 ngx_queue_t free_server_ids; | |
127 ngx_uint_t nclient_ids; | |
128 ngx_uint_t nserver_ids; | |
129 uint64_t max_retired_seqnum; | |
130 uint64_t client_seqnum; | |
131 uint64_t server_seqnum; | |
132 | |
133 ngx_uint_t client_tp_done; | |
134 ngx_quic_tp_t tp; | |
135 ngx_quic_tp_t ctp; | |
136 | |
137 ngx_quic_send_ctx_t send_ctx[NGX_QUIC_SEND_CTX_LAST]; | |
138 | |
139 ngx_quic_frames_stream_t crypto[NGX_QUIC_ENCRYPTION_LAST]; | |
140 | |
141 ngx_quic_keys_t *keys; | |
142 | |
143 ngx_quic_conf_t *conf; | |
144 | |
145 ngx_event_t push; | |
146 ngx_event_t pto; | |
147 ngx_event_t close; | |
148 ngx_msec_t last_cc; | |
149 | |
150 ngx_msec_t latest_rtt; | |
151 ngx_msec_t avg_rtt; | |
152 ngx_msec_t min_rtt; | |
153 ngx_msec_t rttvar; | |
154 | |
155 ngx_uint_t pto_count; | |
156 | |
157 ngx_queue_t free_frames; | |
158 ngx_chain_t *free_bufs; | |
159 ngx_buf_t *free_shadow_bufs; | |
160 | |
161 #ifdef NGX_QUIC_DEBUG_ALLOC | |
162 ngx_uint_t nframes; | |
163 ngx_uint_t nbufs; | |
164 #endif | |
165 | |
166 ngx_quic_streams_t streams; | |
167 ngx_quic_congestion_t congestion; | |
168 off_t received; | |
169 | |
170 ngx_uint_t error; | |
171 enum ssl_encryption_level_t error_level; | |
172 ngx_uint_t error_ftype; | |
173 const char *error_reason; | |
174 | |
175 ngx_uint_t shutdown_code; | |
176 const char *shutdown_reason; | |
177 | |
178 unsigned error_app:1; | |
179 unsigned send_timer_set:1; | |
180 unsigned closing:1; | |
181 unsigned shutdown:1; | |
182 unsigned draining:1; | |
183 unsigned key_phase:1; | |
184 unsigned validated:1; | |
185 } ngx_quic_connection_t; | |
186 | |
187 | |
188 typedef struct { | |
189 ngx_queue_t queue; | |
190 uint64_t seqnum; | |
191 size_t len; | |
192 u_char id[NGX_QUIC_CID_LEN_MAX]; | |
193 u_char sr_token[NGX_QUIC_SR_TOKEN_LEN]; | |
194 } ngx_quic_client_id_t; | |
195 | |
196 | |
197 typedef struct { | |
198 ngx_udp_connection_t udp; | |
199 ngx_quic_connection_t *quic; | |
200 ngx_queue_t queue; | |
201 uint64_t seqnum; | |
202 size_t len; | |
203 u_char id[NGX_QUIC_CID_LEN_MAX]; | |
204 } ngx_quic_server_id_t; | |
205 | 53 |
206 | 54 |
207 typedef ngx_int_t (*ngx_quic_frame_handler_pt)(ngx_connection_t *c, | 55 typedef ngx_int_t (*ngx_quic_frame_handler_pt)(ngx_connection_t *c, |
208 ngx_quic_frame_t *frame, void *data); | 56 ngx_quic_frame_t *frame, void *data); |
209 | 57 |
254 u_char *key, ngx_quic_header_t *pkt); | 102 u_char *key, ngx_quic_header_t *pkt); |
255 static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c); | 103 static ngx_int_t ngx_quic_init_connection(ngx_connection_t *c); |
256 static ngx_inline size_t ngx_quic_max_udp_payload(ngx_connection_t *c); | 104 static ngx_inline size_t ngx_quic_max_udp_payload(ngx_connection_t *c); |
257 static void ngx_quic_input_handler(ngx_event_t *rev); | 105 static void ngx_quic_input_handler(ngx_event_t *rev); |
258 | 106 |
259 static void ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc); | |
260 static ngx_int_t ngx_quic_close_quic(ngx_connection_t *c, ngx_int_t rc); | 107 static ngx_int_t ngx_quic_close_quic(ngx_connection_t *c, ngx_int_t rc); |
261 static void ngx_quic_close_timer_handler(ngx_event_t *ev); | 108 static void ngx_quic_close_timer_handler(ngx_event_t *ev); |
262 static ngx_int_t ngx_quic_close_streams(ngx_connection_t *c, | 109 static ngx_int_t ngx_quic_close_streams(ngx_connection_t *c, |
263 ngx_quic_connection_t *qc); | 110 ngx_quic_connection_t *qc); |
264 | 111 |
345 static ngx_quic_client_id_t *ngx_quic_alloc_client_id(ngx_connection_t *c, | 192 static ngx_quic_client_id_t *ngx_quic_alloc_client_id(ngx_connection_t *c, |
346 ngx_quic_connection_t *qc); | 193 ngx_quic_connection_t *qc); |
347 static ngx_quic_server_id_t *ngx_quic_alloc_server_id(ngx_connection_t *c, | 194 static ngx_quic_server_id_t *ngx_quic_alloc_server_id(ngx_connection_t *c, |
348 ngx_quic_connection_t *qc); | 195 ngx_quic_connection_t *qc); |
349 | 196 |
350 static void ngx_quic_queue_frame(ngx_quic_connection_t *qc, | |
351 ngx_quic_frame_t *frame); | |
352 | |
353 static ngx_int_t ngx_quic_output(ngx_connection_t *c); | 197 static ngx_int_t ngx_quic_output(ngx_connection_t *c); |
354 static ngx_uint_t ngx_quic_get_padding_level(ngx_connection_t *c); | 198 static ngx_uint_t ngx_quic_get_padding_level(ngx_connection_t *c); |
355 static ngx_int_t ngx_quic_generate_ack(ngx_connection_t *c, | 199 static ngx_int_t ngx_quic_generate_ack(ngx_connection_t *c, |
356 ngx_quic_send_ctx_t *ctx); | 200 ngx_quic_send_ctx_t *ctx); |
357 static ssize_t ngx_quic_output_packet(ngx_connection_t *c, | 201 static ssize_t ngx_quic_output_packet(ngx_connection_t *c, |
386 static ngx_chain_t *ngx_quic_stream_send_chain(ngx_connection_t *c, | 230 static ngx_chain_t *ngx_quic_stream_send_chain(ngx_connection_t *c, |
387 ngx_chain_t *in, off_t limit); | 231 ngx_chain_t *in, off_t limit); |
388 static size_t ngx_quic_max_stream_flow(ngx_connection_t *c); | 232 static size_t ngx_quic_max_stream_flow(ngx_connection_t *c); |
389 static void ngx_quic_stream_cleanup_handler(void *data); | 233 static void ngx_quic_stream_cleanup_handler(void *data); |
390 static void ngx_quic_shutdown_quic(ngx_connection_t *c); | 234 static void ngx_quic_shutdown_quic(ngx_connection_t *c); |
391 static ngx_quic_frame_t *ngx_quic_alloc_frame(ngx_connection_t *c); | |
392 static void ngx_quic_free_frame(ngx_connection_t *c, ngx_quic_frame_t *frame); | 235 static void ngx_quic_free_frame(ngx_connection_t *c, ngx_quic_frame_t *frame); |
393 | 236 |
394 static void ngx_quic_congestion_ack(ngx_connection_t *c, | 237 static void ngx_quic_congestion_ack(ngx_connection_t *c, |
395 ngx_quic_frame_t *frame); | 238 ngx_quic_frame_t *frame); |
396 static void ngx_quic_congestion_lost(ngx_connection_t *c, | 239 static void ngx_quic_congestion_lost(ngx_connection_t *c, |
1943 | 1786 |
1944 ngx_quic_connstate_dbg(c); | 1787 ngx_quic_connstate_dbg(c); |
1945 } | 1788 } |
1946 | 1789 |
1947 | 1790 |
1948 static void | 1791 void |
1949 ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc) | 1792 ngx_quic_close_connection(ngx_connection_t *c, ngx_int_t rc) |
1950 { | 1793 { |
1951 ngx_pool_t *pool; | 1794 ngx_pool_t *pool; |
1952 ngx_quic_connection_t *qc; | 1795 ngx_quic_connection_t *qc; |
1953 | 1796 |
4931 | 4774 |
4932 return sid; | 4775 return sid; |
4933 } | 4776 } |
4934 | 4777 |
4935 | 4778 |
4936 static void | 4779 void |
4937 ngx_quic_queue_frame(ngx_quic_connection_t *qc, ngx_quic_frame_t *frame) | 4780 ngx_quic_queue_frame(ngx_quic_connection_t *qc, ngx_quic_frame_t *frame) |
4938 { | 4781 { |
4939 ngx_quic_send_ctx_t *ctx; | 4782 ngx_quic_send_ctx_t *ctx; |
4940 | 4783 |
4941 ctx = ngx_quic_get_send_ctx(qc, frame->level); | 4784 ctx = ngx_quic_get_send_ctx(qc, frame->level); |
6529 | 6372 |
6530 ngx_quic_finalize_connection(c, qc->shutdown_code, qc->shutdown_reason); | 6373 ngx_quic_finalize_connection(c, qc->shutdown_code, qc->shutdown_reason); |
6531 } | 6374 } |
6532 | 6375 |
6533 | 6376 |
6534 static ngx_quic_frame_t * | 6377 ngx_quic_frame_t * |
6535 ngx_quic_alloc_frame(ngx_connection_t *c) | 6378 ngx_quic_alloc_frame(ngx_connection_t *c) |
6536 { | 6379 { |
6537 ngx_queue_t *q; | 6380 ngx_queue_t *q; |
6538 ngx_quic_frame_t *frame; | 6381 ngx_quic_frame_t *frame; |
6539 ngx_quic_connection_t *qc; | 6382 ngx_quic_connection_t *qc; |