comparison src/stream/ngx_stream_quic_module.c @ 8924:d6ef13c5fd8e quic

QUIC: simplified configuration. Directives that set transport parameters are removed from the configuration. Corresponding values are derived from the quic configuration or initialized to default. Whenever possible, quic configuration parameters are taken from higher-level protocol settings, i.e. HTTP/3.
author Vladimir Homutov <vl@nginx.com>
date Mon, 06 Dec 2021 15:19:54 +0300
parents 41caf5410110
children 7106a918a277
comparison
equal deleted inserted replaced
8923:651cc905b7c2 8924:d6ef13c5fd8e
14 ngx_stream_variable_value_t *v, uintptr_t data); 14 ngx_stream_variable_value_t *v, uintptr_t data);
15 static ngx_int_t ngx_stream_quic_add_variables(ngx_conf_t *cf); 15 static ngx_int_t ngx_stream_quic_add_variables(ngx_conf_t *cf);
16 static void *ngx_stream_quic_create_srv_conf(ngx_conf_t *cf); 16 static void *ngx_stream_quic_create_srv_conf(ngx_conf_t *cf);
17 static char *ngx_stream_quic_merge_srv_conf(ngx_conf_t *cf, void *parent, 17 static char *ngx_stream_quic_merge_srv_conf(ngx_conf_t *cf, void *parent,
18 void *child); 18 void *child);
19 static char *ngx_stream_quic_max_ack_delay(ngx_conf_t *cf, void *post, 19 static char *ngx_stream_quic_mtu(ngx_conf_t *cf, void *post, void *data);
20 void *data);
21 static char *ngx_stream_quic_max_udp_payload_size(ngx_conf_t *cf, void *post,
22 void *data);
23 static char *ngx_stream_quic_host_key(ngx_conf_t *cf, ngx_command_t *cmd, 20 static char *ngx_stream_quic_host_key(ngx_conf_t *cf, ngx_command_t *cmd,
24 void *conf); 21 void *conf);
25 22
26 23 static ngx_conf_post_t ngx_stream_quic_mtu_post =
27 static ngx_conf_post_t ngx_stream_quic_max_ack_delay_post = 24 { ngx_stream_quic_mtu };
28 { ngx_stream_quic_max_ack_delay };
29 static ngx_conf_post_t ngx_stream_quic_max_udp_payload_size_post =
30 { ngx_stream_quic_max_udp_payload_size };
31 static ngx_conf_num_bounds_t ngx_stream_quic_ack_delay_exponent_bounds =
32 { ngx_conf_check_num_bounds, 0, 20 };
33 static ngx_conf_num_bounds_t
34 ngx_stream_quic_active_connection_id_limit_bounds =
35 { ngx_conf_check_num_bounds, 2, -1 };
36
37 25
38 static ngx_command_t ngx_stream_quic_commands[] = { 26 static ngx_command_t ngx_stream_quic_commands[] = {
39 27
40 { ngx_string("quic_max_idle_timeout"), 28 { ngx_string("quic_timeout"),
41 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, 29 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
42 ngx_conf_set_msec_slot, 30 ngx_conf_set_msec_slot,
43 NGX_STREAM_SRV_CONF_OFFSET, 31 NGX_STREAM_SRV_CONF_OFFSET,
44 offsetof(ngx_quic_conf_t, tp.max_idle_timeout), 32 offsetof(ngx_quic_conf_t, timeout),
45 NULL }, 33 NULL },
46 34
47 { ngx_string("quic_max_ack_delay"), 35 { ngx_string("quic_mtu"),
48 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
49 ngx_conf_set_msec_slot,
50 NGX_STREAM_SRV_CONF_OFFSET,
51 offsetof(ngx_quic_conf_t, tp.max_ack_delay),
52 &ngx_stream_quic_max_ack_delay_post },
53
54 { ngx_string("quic_max_udp_payload_size"),
55 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, 36 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
56 ngx_conf_set_size_slot, 37 ngx_conf_set_size_slot,
57 NGX_STREAM_SRV_CONF_OFFSET, 38 NGX_STREAM_SRV_CONF_OFFSET,
58 offsetof(ngx_quic_conf_t, tp.max_udp_payload_size), 39 offsetof(ngx_quic_conf_t, mtu),
59 &ngx_stream_quic_max_udp_payload_size_post }, 40 &ngx_stream_quic_mtu_post },
60 41
61 { ngx_string("quic_initial_max_data"), 42 { ngx_string("quic_stream_buffer_size"),
62 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, 43 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
63 ngx_conf_set_size_slot, 44 ngx_conf_set_size_slot,
64 NGX_STREAM_SRV_CONF_OFFSET, 45 NGX_STREAM_SRV_CONF_OFFSET,
65 offsetof(ngx_quic_conf_t, tp.initial_max_data), 46 offsetof(ngx_quic_conf_t, stream_buffer_size),
66 NULL }, 47 NULL },
67
68 { ngx_string("quic_initial_max_stream_data_bidi_local"),
69 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
70 ngx_conf_set_size_slot,
71 NGX_STREAM_SRV_CONF_OFFSET,
72 offsetof(ngx_quic_conf_t, tp.initial_max_stream_data_bidi_local),
73 NULL },
74
75 { ngx_string("quic_initial_max_stream_data_bidi_remote"),
76 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
77 ngx_conf_set_size_slot,
78 NGX_STREAM_SRV_CONF_OFFSET,
79 offsetof(ngx_quic_conf_t, tp.initial_max_stream_data_bidi_remote),
80 NULL },
81
82 { ngx_string("quic_initial_max_stream_data_uni"),
83 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
84 ngx_conf_set_size_slot,
85 NGX_STREAM_SRV_CONF_OFFSET,
86 offsetof(ngx_quic_conf_t, tp.initial_max_stream_data_uni),
87 NULL },
88
89 { ngx_string("quic_initial_max_streams_bidi"),
90 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
91 ngx_conf_set_num_slot,
92 NGX_STREAM_SRV_CONF_OFFSET,
93 offsetof(ngx_quic_conf_t, tp.initial_max_streams_bidi),
94 NULL },
95
96 { ngx_string("quic_initial_max_streams_uni"),
97 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
98 ngx_conf_set_num_slot,
99 NGX_STREAM_SRV_CONF_OFFSET,
100 offsetof(ngx_quic_conf_t, tp.initial_max_streams_uni),
101 NULL },
102
103 { ngx_string("quic_ack_delay_exponent"),
104 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
105 ngx_conf_set_num_slot,
106 NGX_STREAM_SRV_CONF_OFFSET,
107 offsetof(ngx_quic_conf_t, tp.ack_delay_exponent),
108 &ngx_stream_quic_ack_delay_exponent_bounds },
109
110 { ngx_string("quic_disable_active_migration"),
111 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
112 ngx_conf_set_flag_slot,
113 NGX_STREAM_SRV_CONF_OFFSET,
114 offsetof(ngx_quic_conf_t, tp.disable_active_migration),
115 NULL },
116
117 { ngx_string("quic_active_connection_id_limit"),
118 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
119 ngx_conf_set_num_slot,
120 NGX_STREAM_SRV_CONF_OFFSET,
121 offsetof(ngx_quic_conf_t, tp.active_connection_id_limit),
122 &ngx_stream_quic_active_connection_id_limit_bounds },
123 48
124 { ngx_string("quic_retry"), 49 { ngx_string("quic_retry"),
125 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, 50 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG,
126 ngx_conf_set_flag_slot, 51 ngx_conf_set_flag_slot,
127 NGX_STREAM_SRV_CONF_OFFSET, 52 NGX_STREAM_SRV_CONF_OFFSET,
234 } 159 }
235 160
236 /* 161 /*
237 * set by ngx_pcalloc(): 162 * set by ngx_pcalloc():
238 * 163 *
239 * conf->tp.original_dcid = { 0, NULL };
240 * conf->tp.initial_scid = { 0, NULL };
241 * conf->tp.retry_scid = { 0, NULL };
242 * conf->tp.preferred_address = NULL
243 * conf->host_key = { 0, NULL } 164 * conf->host_key = { 0, NULL }
244 * conf->stream_close_code = 0; 165 * conf->stream_close_code = 0;
245 * conf->stream_reject_code_uni = 0; 166 * conf->stream_reject_code_uni = 0;
246 * conf->stream_reject_code_bidi= 0; 167 * conf->stream_reject_code_bidi= 0;
247 */ 168 */
248 169
249 conf->tp.max_idle_timeout = NGX_CONF_UNSET_MSEC; 170 conf->timeout = NGX_CONF_UNSET_MSEC;
250 conf->tp.max_ack_delay = NGX_CONF_UNSET_MSEC; 171 conf->mtu = NGX_CONF_UNSET_SIZE;
251 conf->tp.max_udp_payload_size = NGX_CONF_UNSET_SIZE; 172 conf->stream_buffer_size = NGX_CONF_UNSET_SIZE;
252 conf->tp.initial_max_data = NGX_CONF_UNSET_SIZE; 173 conf->max_concurrent_streams_bidi = NGX_CONF_UNSET_UINT;
253 conf->tp.initial_max_stream_data_bidi_local = NGX_CONF_UNSET_SIZE; 174 conf->max_concurrent_streams_uni = NGX_CONF_UNSET_UINT;
254 conf->tp.initial_max_stream_data_bidi_remote = NGX_CONF_UNSET_SIZE;
255 conf->tp.initial_max_stream_data_uni = NGX_CONF_UNSET_SIZE;
256 conf->tp.initial_max_streams_bidi = NGX_CONF_UNSET_UINT;
257 conf->tp.initial_max_streams_uni = NGX_CONF_UNSET_UINT;
258 conf->tp.ack_delay_exponent = NGX_CONF_UNSET_UINT;
259 conf->tp.disable_active_migration = NGX_CONF_UNSET;
260 conf->tp.active_connection_id_limit = NGX_CONF_UNSET_UINT;
261 175
262 conf->retry = NGX_CONF_UNSET; 176 conf->retry = NGX_CONF_UNSET;
263 conf->gso_enabled = NGX_CONF_UNSET; 177 conf->gso_enabled = NGX_CONF_UNSET;
264 178
265 return conf; 179 return conf;
272 ngx_quic_conf_t *prev = parent; 186 ngx_quic_conf_t *prev = parent;
273 ngx_quic_conf_t *conf = child; 187 ngx_quic_conf_t *conf = child;
274 188
275 ngx_stream_ssl_conf_t *scf; 189 ngx_stream_ssl_conf_t *scf;
276 190
277 ngx_conf_merge_msec_value(conf->tp.max_idle_timeout, 191 ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
278 prev->tp.max_idle_timeout, 60000); 192
279 193 ngx_conf_merge_size_value(conf->mtu, prev->mtu,
280 ngx_conf_merge_msec_value(conf->tp.max_ack_delay,
281 prev->tp.max_ack_delay,
282 NGX_QUIC_DEFAULT_MAX_ACK_DELAY);
283
284 ngx_conf_merge_size_value(conf->tp.max_udp_payload_size,
285 prev->tp.max_udp_payload_size,
286 NGX_QUIC_MAX_UDP_PAYLOAD_SIZE); 194 NGX_QUIC_MAX_UDP_PAYLOAD_SIZE);
287 195
288 ngx_conf_merge_size_value(conf->tp.initial_max_data, 196 ngx_conf_merge_uint_value(conf->max_concurrent_streams_bidi,
289 prev->tp.initial_max_data, 197 prev->max_concurrent_streams_bidi, 16);
290 16 * NGX_QUIC_STREAM_BUFSIZE); 198
291 199 ngx_conf_merge_uint_value(conf->max_concurrent_streams_uni,
292 ngx_conf_merge_size_value(conf->tp.initial_max_stream_data_bidi_local, 200 prev->max_concurrent_streams_uni, 3);
293 prev->tp.initial_max_stream_data_bidi_local,
294 NGX_QUIC_STREAM_BUFSIZE);
295
296 ngx_conf_merge_size_value(conf->tp.initial_max_stream_data_bidi_remote,
297 prev->tp.initial_max_stream_data_bidi_remote,
298 NGX_QUIC_STREAM_BUFSIZE);
299
300 ngx_conf_merge_size_value(conf->tp.initial_max_stream_data_uni,
301 prev->tp.initial_max_stream_data_uni,
302 NGX_QUIC_STREAM_BUFSIZE);
303
304 ngx_conf_merge_uint_value(conf->tp.initial_max_streams_bidi,
305 prev->tp.initial_max_streams_bidi, 16);
306
307 ngx_conf_merge_uint_value(conf->tp.initial_max_streams_uni,
308 prev->tp.initial_max_streams_uni, 16);
309
310 ngx_conf_merge_uint_value(conf->tp.ack_delay_exponent,
311 prev->tp.ack_delay_exponent,
312 NGX_QUIC_DEFAULT_ACK_DELAY_EXPONENT);
313
314 ngx_conf_merge_value(conf->tp.disable_active_migration,
315 prev->tp.disable_active_migration, 0);
316
317 ngx_conf_merge_uint_value(conf->tp.active_connection_id_limit,
318 prev->tp.active_connection_id_limit, 2);
319 201
320 ngx_conf_merge_value(conf->retry, prev->retry, 0); 202 ngx_conf_merge_value(conf->retry, prev->retry, 0);
321 ngx_conf_merge_value(conf->gso_enabled, prev->gso_enabled, 0); 203 ngx_conf_merge_value(conf->gso_enabled, prev->gso_enabled, 0);
322 204
323 ngx_conf_merge_str_value(conf->host_key, prev->host_key, ""); 205 ngx_conf_merge_str_value(conf->host_key, prev->host_key, "");
359 return NGX_CONF_OK; 241 return NGX_CONF_OK;
360 } 242 }
361 243
362 244
363 static char * 245 static char *
364 ngx_stream_quic_max_ack_delay(ngx_conf_t *cf, void *post, void *data) 246 ngx_stream_quic_mtu(ngx_conf_t *cf, void *post, void *data)
365 {
366 ngx_msec_t *sp = data;
367
368 if (*sp >= 16384) {
369 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
370 "\"quic_max_ack_delay\" must be less than 16384");
371
372 return NGX_CONF_ERROR;
373 }
374
375 return NGX_CONF_OK;
376 }
377
378
379 static char *
380 ngx_stream_quic_max_udp_payload_size(ngx_conf_t *cf, void *post, void *data)
381 { 247 {
382 size_t *sp = data; 248 size_t *sp = data;
383 249
384 if (*sp < NGX_QUIC_MIN_INITIAL_SIZE 250 if (*sp < NGX_QUIC_MIN_INITIAL_SIZE
385 || *sp > NGX_QUIC_MAX_UDP_PAYLOAD_SIZE) 251 || *sp > NGX_QUIC_MAX_UDP_PAYLOAD_SIZE)
386 { 252 {
387 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 253 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
388 "\"quic_max_udp_payload_size\" must be between " 254 "\"quic_mtu\" must be between %d and %d",
389 "%d and %d",
390 NGX_QUIC_MIN_INITIAL_SIZE, 255 NGX_QUIC_MIN_INITIAL_SIZE,
391 NGX_QUIC_MAX_UDP_PAYLOAD_SIZE); 256 NGX_QUIC_MAX_UDP_PAYLOAD_SIZE);
392 257
393 return NGX_CONF_ERROR; 258 return NGX_CONF_ERROR;
394 } 259 }