Mercurial > hg > nginx
annotate src/http/v3/ngx_http_v3_module.c @ 8824:054f9be0aaf9 quic
HTTP/3: http3_max_uni_streams directive.
The directive limits the number of uni streams client is allowed to create.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 29 Jul 2021 12:17:56 +0300 |
parents | f0882db8c8d4 |
children | 4f922f611135 |
rev | line source |
---|---|
8215 | 1 |
2 /* | |
3 * Copyright (C) Nginx, Inc. | |
4 * Copyright (C) Roman Arutyunyan | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
8493
e533a352d118
Style: moved function declarations to match usual code style.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
13 static void *ngx_http_v3_create_srv_conf(ngx_conf_t *cf); |
e533a352d118
Style: moved function declarations to match usual code style.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
14 static char *ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, void *parent, |
e533a352d118
Style: moved function declarations to match usual code style.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
15 void *child); |
8497 | 16 static void *ngx_http_v3_create_loc_conf(ngx_conf_t *cf); |
17 static char *ngx_http_v3_merge_loc_conf(ngx_conf_t *cf, void *parent, | |
18 void *child); | |
19 static char *ngx_http_v3_push(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | |
8493
e533a352d118
Style: moved function declarations to match usual code style.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
20 |
e533a352d118
Style: moved function declarations to match usual code style.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
21 |
8215 | 22 static ngx_command_t ngx_http_v3_commands[] = { |
8247
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
23 |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
24 { ngx_string("http3_max_table_capacity"), |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
25 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
26 ngx_conf_set_size_slot, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
27 NGX_HTTP_SRV_CONF_OFFSET, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
28 offsetof(ngx_http_v3_srv_conf_t, max_table_capacity), |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
29 NULL }, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
30 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
31 { ngx_string("http3_max_blocked_streams"), |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
32 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
33 ngx_conf_set_num_slot, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
34 NGX_HTTP_SRV_CONF_OFFSET, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
35 offsetof(ngx_http_v3_srv_conf_t, max_blocked_streams), |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
36 NULL }, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
37 |
8497 | 38 { ngx_string("http3_max_concurrent_pushes"), |
39 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, | |
40 ngx_conf_set_num_slot, | |
41 NGX_HTTP_SRV_CONF_OFFSET, | |
42 offsetof(ngx_http_v3_srv_conf_t, max_concurrent_pushes), | |
43 NULL }, | |
44 | |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
45 { ngx_string("http3_max_uni_streams"), |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
46 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
47 ngx_conf_set_num_slot, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
48 NGX_HTTP_SRV_CONF_OFFSET, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
49 offsetof(ngx_http_v3_srv_conf_t, max_uni_streams), |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
50 NULL }, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
51 |
8497 | 52 { ngx_string("http3_push"), |
53 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, | |
54 ngx_http_v3_push, | |
55 NGX_HTTP_LOC_CONF_OFFSET, | |
56 0, | |
57 NULL }, | |
58 | |
59 { ngx_string("http3_push_preload"), | |
60 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | |
61 ngx_conf_set_flag_slot, | |
62 NGX_HTTP_LOC_CONF_OFFSET, | |
63 offsetof(ngx_http_v3_loc_conf_t, push_preload), | |
64 NULL }, | |
65 | |
8215 | 66 ngx_null_command |
67 }; | |
68 | |
69 | |
70 static ngx_http_module_t ngx_http_v3_module_ctx = { | |
8788
f0882db8c8d4
HTTP/3: removed $http3 that served its purpose.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8705
diff
changeset
|
71 NULL, /* preconfiguration */ |
8215 | 72 NULL, /* postconfiguration */ |
73 | |
74 NULL, /* create main configuration */ | |
75 NULL, /* init main configuration */ | |
76 | |
8247
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
77 ngx_http_v3_create_srv_conf, /* create server configuration */ |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
78 ngx_http_v3_merge_srv_conf, /* merge server configuration */ |
8215 | 79 |
8497 | 80 ngx_http_v3_create_loc_conf, /* create location configuration */ |
81 ngx_http_v3_merge_loc_conf /* merge location configuration */ | |
8215 | 82 }; |
83 | |
84 | |
85 ngx_module_t ngx_http_v3_module = { | |
86 NGX_MODULE_V1, | |
87 &ngx_http_v3_module_ctx, /* module context */ | |
88 ngx_http_v3_commands, /* module directives */ | |
89 NGX_HTTP_MODULE, /* module type */ | |
90 NULL, /* init master */ | |
91 NULL, /* init module */ | |
92 NULL, /* init process */ | |
93 NULL, /* init thread */ | |
94 NULL, /* exit thread */ | |
95 NULL, /* exit process */ | |
96 NULL, /* exit master */ | |
97 NGX_MODULE_V1_PADDING | |
98 }; | |
8247
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
99 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
100 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
101 static void * |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
102 ngx_http_v3_create_srv_conf(ngx_conf_t *cf) |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
103 { |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
104 ngx_http_v3_srv_conf_t *h3scf; |
8247
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
105 |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
106 h3scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_v3_srv_conf_t)); |
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
107 if (h3scf == NULL) { |
8247
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
108 return NULL; |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
109 } |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
110 |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
111 h3scf->max_table_capacity = NGX_CONF_UNSET_SIZE; |
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
112 h3scf->max_blocked_streams = NGX_CONF_UNSET_UINT; |
8497 | 113 h3scf->max_concurrent_pushes = NGX_CONF_UNSET_UINT; |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
114 h3scf->max_uni_streams = NGX_CONF_UNSET_UINT; |
8454
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
8417
diff
changeset
|
115 |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
116 return h3scf; |
8247
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
117 } |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
118 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
119 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
120 static char * |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
121 ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
122 { |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
123 ngx_http_v3_srv_conf_t *prev = parent; |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
124 ngx_http_v3_srv_conf_t *conf = child; |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
8215
diff
changeset
|
125 |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
126 ngx_conf_merge_size_value(conf->max_table_capacity, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
127 prev->max_table_capacity, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
128 NGX_HTTP_V3_DEFAULT_MAX_TABLE_CAPACITY); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
129 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
130 ngx_conf_merge_uint_value(conf->max_blocked_streams, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
131 prev->max_blocked_streams, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
132 NGX_HTTP_V3_DEFAULT_MAX_BLOCKED_STREAMS); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
133 |
8497 | 134 ngx_conf_merge_uint_value(conf->max_concurrent_pushes, |
135 prev->max_concurrent_pushes, | |
136 NGX_HTTP_V3_DEFAULT_MAX_CONCURRENT_PUSHES); | |
137 | |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
138 ngx_conf_merge_uint_value(conf->max_uni_streams, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
139 prev->max_uni_streams, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
140 NGX_HTTP_V3_DEFAULT_MAX_UNI_STREAMS); |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8788
diff
changeset
|
141 |
8497 | 142 return NGX_CONF_OK; |
143 } | |
144 | |
145 | |
146 static void * | |
147 ngx_http_v3_create_loc_conf(ngx_conf_t *cf) | |
148 { | |
149 ngx_http_v3_loc_conf_t *h3lcf; | |
150 | |
151 h3lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_v3_loc_conf_t)); | |
152 if (h3lcf == NULL) { | |
153 return NULL; | |
154 } | |
155 | |
156 /* | |
157 * set by ngx_pcalloc(): | |
158 * | |
159 * h3lcf->pushes = NULL; | |
160 */ | |
161 | |
162 h3lcf->push_preload = NGX_CONF_UNSET; | |
163 h3lcf->push = NGX_CONF_UNSET; | |
164 | |
165 return h3lcf; | |
166 } | |
167 | |
168 | |
169 static char * | |
170 ngx_http_v3_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
171 { | |
172 ngx_http_v3_loc_conf_t *prev = parent; | |
173 ngx_http_v3_loc_conf_t *conf = child; | |
174 | |
175 ngx_conf_merge_value(conf->push, prev->push, 1); | |
176 | |
177 if (conf->push && conf->pushes == NULL) { | |
178 conf->pushes = prev->pushes; | |
179 } | |
180 | |
181 ngx_conf_merge_value(conf->push_preload, prev->push_preload, 0); | |
182 | |
8353
036164360fa9
HTTP/3: directives with limited values converted to post handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8352
diff
changeset
|
183 return NGX_CONF_OK; |
036164360fa9
HTTP/3: directives with limited values converted to post handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8352
diff
changeset
|
184 } |
8497 | 185 |
186 | |
187 static char * | |
188 ngx_http_v3_push(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
189 { | |
190 ngx_http_v3_loc_conf_t *h3lcf = conf; | |
191 | |
192 ngx_str_t *value; | |
193 ngx_http_complex_value_t *cv; | |
194 ngx_http_compile_complex_value_t ccv; | |
195 | |
196 value = cf->args->elts; | |
197 | |
198 if (ngx_strcmp(value[1].data, "off") == 0) { | |
199 | |
200 if (h3lcf->pushes) { | |
201 return "\"off\" parameter cannot be used with URI"; | |
202 } | |
203 | |
204 if (h3lcf->push == 0) { | |
205 return "is duplicate"; | |
206 } | |
207 | |
208 h3lcf->push = 0; | |
209 return NGX_CONF_OK; | |
210 } | |
211 | |
212 if (h3lcf->push == 0) { | |
213 return "URI cannot be used with \"off\" parameter"; | |
214 } | |
215 | |
216 h3lcf->push = 1; | |
217 | |
218 if (h3lcf->pushes == NULL) { | |
219 h3lcf->pushes = ngx_array_create(cf->pool, 1, | |
220 sizeof(ngx_http_complex_value_t)); | |
221 if (h3lcf->pushes == NULL) { | |
222 return NGX_CONF_ERROR; | |
223 } | |
224 } | |
225 | |
226 cv = ngx_array_push(h3lcf->pushes); | |
227 if (cv == NULL) { | |
228 return NGX_CONF_ERROR; | |
229 } | |
230 | |
231 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
232 | |
233 ccv.cf = cf; | |
234 ccv.value = &value[1]; | |
235 ccv.complex_value = cv; | |
236 | |
237 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
238 return NGX_CONF_ERROR; | |
239 } | |
240 | |
241 return NGX_CONF_OK; | |
242 } |