Mercurial > hg > nginx-quic
annotate src/http/v3/ngx_http_v3_module.c @ 8605:4ca8035c19a4 quic
Merged with the default branch.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 08 Sep 2021 15:53:00 +0300 |
parents | 4f922f611135 |
children | 33226ac61076 |
rev | line source |
---|---|
7681 | 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 | |
8011
e533a352d118
Style: moved function declarations to match usual code style.
Roman Arutyunyan <arut@nginx.com>
parents:
8010
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:
8010
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:
8010
diff
changeset
|
15 void *child); |
8015 | 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); | |
8011
e533a352d118
Style: moved function declarations to match usual code style.
Roman Arutyunyan <arut@nginx.com>
parents:
8010
diff
changeset
|
20 |
e533a352d118
Style: moved function declarations to match usual code style.
Roman Arutyunyan <arut@nginx.com>
parents:
8010
diff
changeset
|
21 |
7681 | 22 static ngx_command_t ngx_http_v3_commands[] = { |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
23 |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
24 { ngx_string("http3_max_table_capacity"), |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
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:
7949
diff
changeset
|
26 ngx_conf_set_size_slot, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
27 NGX_HTTP_SRV_CONF_OFFSET, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
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:
7949
diff
changeset
|
29 NULL }, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
30 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
31 { ngx_string("http3_max_blocked_streams"), |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
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:
7949
diff
changeset
|
33 ngx_conf_set_num_slot, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
34 NGX_HTTP_SRV_CONF_OFFSET, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
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:
7949
diff
changeset
|
36 NULL }, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
37 |
8015 | 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 | |
8549
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8489
diff
changeset
|
45 { ngx_string("http3_max_uni_streams"), |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8489
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:
8489
diff
changeset
|
47 ngx_conf_set_num_slot, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8489
diff
changeset
|
48 NGX_HTTP_SRV_CONF_OFFSET, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8489
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:
8489
diff
changeset
|
50 NULL }, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8489
diff
changeset
|
51 |
8015 | 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 | |
7681 | 66 ngx_null_command |
67 }; | |
68 | |
69 | |
70 static ngx_http_module_t ngx_http_v3_module_ctx = { | |
8489
f0882db8c8d4
HTTP/3: removed $http3 that served its purpose.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8317
diff
changeset
|
71 NULL, /* preconfiguration */ |
7681 | 72 NULL, /* postconfiguration */ |
73 | |
74 NULL, /* create main configuration */ | |
75 NULL, /* init main configuration */ | |
76 | |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
77 ngx_http_v3_create_srv_conf, /* create server configuration */ |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
78 ngx_http_v3_merge_srv_conf, /* merge server configuration */ |
7681 | 79 |
8015 | 80 ngx_http_v3_create_loc_conf, /* create location configuration */ |
81 ngx_http_v3_merge_loc_conf /* merge location configuration */ | |
7681 | 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 }; | |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
99 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
100 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
101 static void * |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
102 ngx_http_v3_create_srv_conf(ngx_conf_t *cf) |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
103 { |
8010
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
104 ngx_http_v3_srv_conf_t *h3scf; |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
105 |
8010
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
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:
7999
diff
changeset
|
107 if (h3scf == NULL) { |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
108 return NULL; |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
109 } |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
110 |
8010
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
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:
7999
diff
changeset
|
112 h3scf->max_blocked_streams = NGX_CONF_UNSET_UINT; |
8015 | 113 h3scf->max_concurrent_pushes = NGX_CONF_UNSET_UINT; |
8549
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8489
diff
changeset
|
114 h3scf->max_uni_streams = NGX_CONF_UNSET_UINT; |
7949
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
7912
diff
changeset
|
115 |
8010
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
7999
diff
changeset
|
116 return h3scf; |
7713
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
117 } |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
118 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
119 |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
120 static char * |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
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:
7681
diff
changeset
|
122 { |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
123 ngx_http_v3_srv_conf_t *prev = parent; |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
124 ngx_http_v3_srv_conf_t *conf = child; |
e9891e8ee975
Configurable transport parameters.
Vladimir Homutov <vl@nginx.com>
parents:
7681
diff
changeset
|
125 |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
126 ngx_conf_merge_size_value(conf->max_table_capacity, |
8554
4f922f611135
HTTP/3: replaced macros with values.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
127 prev->max_table_capacity, 16384); |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
128 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
129 ngx_conf_merge_uint_value(conf->max_blocked_streams, |
8554
4f922f611135
HTTP/3: replaced macros with values.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
130 prev->max_blocked_streams, 16); |
7951
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
7949
diff
changeset
|
131 |
8015 | 132 ngx_conf_merge_uint_value(conf->max_concurrent_pushes, |
8554
4f922f611135
HTTP/3: replaced macros with values.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
133 prev->max_concurrent_pushes, 10); |
8015 | 134 |
8549
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8489
diff
changeset
|
135 ngx_conf_merge_uint_value(conf->max_uni_streams, |
8554
4f922f611135
HTTP/3: replaced macros with values.
Roman Arutyunyan <arut@nginx.com>
parents:
8549
diff
changeset
|
136 prev->max_uni_streams, 3); |
8549
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8489
diff
changeset
|
137 |
8015 | 138 return NGX_CONF_OK; |
139 } | |
140 | |
141 | |
142 static void * | |
143 ngx_http_v3_create_loc_conf(ngx_conf_t *cf) | |
144 { | |
145 ngx_http_v3_loc_conf_t *h3lcf; | |
146 | |
147 h3lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_v3_loc_conf_t)); | |
148 if (h3lcf == NULL) { | |
149 return NULL; | |
150 } | |
151 | |
152 /* | |
153 * set by ngx_pcalloc(): | |
154 * | |
155 * h3lcf->pushes = NULL; | |
156 */ | |
157 | |
158 h3lcf->push_preload = NGX_CONF_UNSET; | |
159 h3lcf->push = NGX_CONF_UNSET; | |
160 | |
161 return h3lcf; | |
162 } | |
163 | |
164 | |
165 static char * | |
166 ngx_http_v3_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | |
167 { | |
168 ngx_http_v3_loc_conf_t *prev = parent; | |
169 ngx_http_v3_loc_conf_t *conf = child; | |
170 | |
171 ngx_conf_merge_value(conf->push, prev->push, 1); | |
172 | |
173 if (conf->push && conf->pushes == NULL) { | |
174 conf->pushes = prev->pushes; | |
175 } | |
176 | |
177 ngx_conf_merge_value(conf->push_preload, prev->push_preload, 0); | |
178 | |
7830
036164360fa9
HTTP/3: directives with limited values converted to post handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7829
diff
changeset
|
179 return NGX_CONF_OK; |
036164360fa9
HTTP/3: directives with limited values converted to post handler.
Sergey Kandaurov <pluknet@nginx.com>
parents:
7829
diff
changeset
|
180 } |
8015 | 181 |
182 | |
183 static char * | |
184 ngx_http_v3_push(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
185 { | |
186 ngx_http_v3_loc_conf_t *h3lcf = conf; | |
187 | |
188 ngx_str_t *value; | |
189 ngx_http_complex_value_t *cv; | |
190 ngx_http_compile_complex_value_t ccv; | |
191 | |
192 value = cf->args->elts; | |
193 | |
194 if (ngx_strcmp(value[1].data, "off") == 0) { | |
195 | |
196 if (h3lcf->pushes) { | |
197 return "\"off\" parameter cannot be used with URI"; | |
198 } | |
199 | |
200 if (h3lcf->push == 0) { | |
201 return "is duplicate"; | |
202 } | |
203 | |
204 h3lcf->push = 0; | |
205 return NGX_CONF_OK; | |
206 } | |
207 | |
208 if (h3lcf->push == 0) { | |
209 return "URI cannot be used with \"off\" parameter"; | |
210 } | |
211 | |
212 h3lcf->push = 1; | |
213 | |
214 if (h3lcf->pushes == NULL) { | |
215 h3lcf->pushes = ngx_array_create(cf->pool, 1, | |
216 sizeof(ngx_http_complex_value_t)); | |
217 if (h3lcf->pushes == NULL) { | |
218 return NGX_CONF_ERROR; | |
219 } | |
220 } | |
221 | |
222 cv = ngx_array_push(h3lcf->pushes); | |
223 if (cv == NULL) { | |
224 return NGX_CONF_ERROR; | |
225 } | |
226 | |
227 ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t)); | |
228 | |
229 ccv.cf = cf; | |
230 ccv.value = &value[1]; | |
231 ccv.complex_value = cv; | |
232 | |
233 if (ngx_http_compile_complex_value(&ccv) != NGX_OK) { | |
234 return NGX_CONF_ERROR; | |
235 } | |
236 | |
237 return NGX_CONF_OK; | |
238 } |