Mercurial > hg > nginx-quic
annotate src/stream/ngx_stream_core_module.c @ 7334:f17e313009b0
Skipping spaces in configuration files (ticket #1557).
Previously, a chunk of spaces larger than NGX_CONF_BUFFER (4096 bytes)
resulted in the "too long parameter" error during parsing such a
configuration. This was because the code only set start and start_line
on non-whitespace characters, and hence adjacent whitespace characters
were preserved when reading additional data from the configuration file.
Fix is to always move start and start_line if the last character was
a space.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 09 Aug 2018 12:15:42 +0300 |
parents | 7f955d3b9a0d |
children | fe767c99c2ad |
rev | line source |
---|---|
6115 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_stream.h> | |
11 | |
12 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
13 static ngx_int_t ngx_stream_core_preconfiguration(ngx_conf_t *cf); |
6115 | 14 static void *ngx_stream_core_create_main_conf(ngx_conf_t *cf); |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
15 static char *ngx_stream_core_init_main_conf(ngx_conf_t *cf, void *conf); |
6115 | 16 static void *ngx_stream_core_create_srv_conf(ngx_conf_t *cf); |
17 static char *ngx_stream_core_merge_srv_conf(ngx_conf_t *cf, void *parent, | |
18 void *child); | |
19 static char *ngx_stream_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, | |
20 void *conf); | |
21 static char *ngx_stream_core_server(ngx_conf_t *cf, ngx_command_t *cmd, | |
22 void *conf); | |
23 static char *ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, | |
24 void *conf); | |
6618 | 25 static char *ngx_stream_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, |
26 void *conf); | |
6115 | 27 |
28 | |
29 static ngx_command_t ngx_stream_core_commands[] = { | |
30 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
31 { ngx_string("variables_hash_max_size"), |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
32 NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
33 ngx_conf_set_num_slot, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
34 NGX_STREAM_MAIN_CONF_OFFSET, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
35 offsetof(ngx_stream_core_main_conf_t, variables_hash_max_size), |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
36 NULL }, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
37 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
38 { ngx_string("variables_hash_bucket_size"), |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
39 NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
40 ngx_conf_set_num_slot, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
41 NGX_STREAM_MAIN_CONF_OFFSET, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
42 offsetof(ngx_stream_core_main_conf_t, variables_hash_bucket_size), |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
43 NULL }, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
44 |
6115 | 45 { ngx_string("server"), |
46 NGX_STREAM_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
47 ngx_stream_core_server, | |
48 0, | |
49 0, | |
50 NULL }, | |
51 | |
52 { ngx_string("listen"), | |
53 NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, | |
54 ngx_stream_core_listen, | |
55 NGX_STREAM_SRV_CONF_OFFSET, | |
56 0, | |
57 NULL }, | |
58 | |
59 { ngx_string("error_log"), | |
60 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, | |
61 ngx_stream_core_error_log, | |
62 NGX_STREAM_SRV_CONF_OFFSET, | |
63 0, | |
64 NULL }, | |
65 | |
6618 | 66 { ngx_string("resolver"), |
67 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, | |
68 ngx_stream_core_resolver, | |
69 NGX_STREAM_SRV_CONF_OFFSET, | |
70 0, | |
71 NULL }, | |
72 | |
73 { ngx_string("resolver_timeout"), | |
74 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
75 ngx_conf_set_msec_slot, | |
76 NGX_STREAM_SRV_CONF_OFFSET, | |
77 offsetof(ngx_stream_core_srv_conf_t, resolver_timeout), | |
78 NULL }, | |
79 | |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
80 { ngx_string("proxy_protocol_timeout"), |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
81 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
82 ngx_conf_set_msec_slot, |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
83 NGX_STREAM_SRV_CONF_OFFSET, |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
84 offsetof(ngx_stream_core_srv_conf_t, proxy_protocol_timeout), |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
85 NULL }, |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
86 |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
87 { ngx_string("tcp_nodelay"), |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
88 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_FLAG, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
89 ngx_conf_set_flag_slot, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
90 NGX_STREAM_SRV_CONF_OFFSET, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
91 offsetof(ngx_stream_core_srv_conf_t, tcp_nodelay), |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
92 NULL }, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
93 |
6694 | 94 { ngx_string("preread_buffer_size"), |
95 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
96 ngx_conf_set_size_slot, | |
97 NGX_STREAM_SRV_CONF_OFFSET, | |
98 offsetof(ngx_stream_core_srv_conf_t, preread_buffer_size), | |
99 NULL }, | |
100 | |
101 { ngx_string("preread_timeout"), | |
102 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1, | |
103 ngx_conf_set_msec_slot, | |
104 NGX_STREAM_SRV_CONF_OFFSET, | |
105 offsetof(ngx_stream_core_srv_conf_t, preread_timeout), | |
106 NULL }, | |
107 | |
6115 | 108 ngx_null_command |
109 }; | |
110 | |
111 | |
112 static ngx_stream_module_t ngx_stream_core_module_ctx = { | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
113 ngx_stream_core_preconfiguration, /* preconfiguration */ |
6174
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
114 NULL, /* postconfiguration */ |
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
115 |
6115 | 116 ngx_stream_core_create_main_conf, /* create main configuration */ |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
117 ngx_stream_core_init_main_conf, /* init main configuration */ |
6115 | 118 |
119 ngx_stream_core_create_srv_conf, /* create server configuration */ | |
120 ngx_stream_core_merge_srv_conf /* merge server configuration */ | |
121 }; | |
122 | |
123 | |
124 ngx_module_t ngx_stream_core_module = { | |
125 NGX_MODULE_V1, | |
126 &ngx_stream_core_module_ctx, /* module context */ | |
127 ngx_stream_core_commands, /* module directives */ | |
128 NGX_STREAM_MODULE, /* module type */ | |
129 NULL, /* init master */ | |
130 NULL, /* init module */ | |
131 NULL, /* init process */ | |
132 NULL, /* init thread */ | |
133 NULL, /* exit thread */ | |
134 NULL, /* exit process */ | |
135 NULL, /* exit master */ | |
136 NGX_MODULE_V1_PADDING | |
137 }; | |
138 | |
139 | |
6693 | 140 void |
141 ngx_stream_core_run_phases(ngx_stream_session_t *s) | |
142 { | |
143 ngx_int_t rc; | |
144 ngx_stream_phase_handler_t *ph; | |
145 ngx_stream_core_main_conf_t *cmcf; | |
146 | |
147 cmcf = ngx_stream_get_module_main_conf(s, ngx_stream_core_module); | |
148 | |
149 ph = cmcf->phase_engine.handlers; | |
150 | |
151 while (ph[s->phase_handler].checker) { | |
152 | |
153 rc = ph[s->phase_handler].checker(s, &ph[s->phase_handler]); | |
154 | |
155 if (rc == NGX_OK) { | |
156 return; | |
157 } | |
158 } | |
159 } | |
160 | |
161 | |
162 ngx_int_t | |
163 ngx_stream_core_generic_phase(ngx_stream_session_t *s, | |
164 ngx_stream_phase_handler_t *ph) | |
165 { | |
166 ngx_int_t rc; | |
167 | |
168 /* | |
169 * generic phase checker, | |
6694 | 170 * used by all phases, except for preread and content |
6693 | 171 */ |
172 | |
173 ngx_log_debug1(NGX_LOG_DEBUG_STREAM, s->connection->log, 0, | |
174 "generic phase: %ui", s->phase_handler); | |
175 | |
176 rc = ph->handler(s); | |
177 | |
178 if (rc == NGX_OK) { | |
179 s->phase_handler = ph->next; | |
180 return NGX_AGAIN; | |
181 } | |
182 | |
183 if (rc == NGX_DECLINED) { | |
184 s->phase_handler++; | |
185 return NGX_AGAIN; | |
186 } | |
187 | |
188 if (rc == NGX_AGAIN || rc == NGX_DONE) { | |
189 return NGX_OK; | |
190 } | |
191 | |
192 if (rc == NGX_ERROR) { | |
193 rc = NGX_STREAM_INTERNAL_SERVER_ERROR; | |
194 } | |
195 | |
196 ngx_stream_finalize_session(s, rc); | |
197 | |
198 return NGX_OK; | |
199 } | |
200 | |
201 | |
202 ngx_int_t | |
6694 | 203 ngx_stream_core_preread_phase(ngx_stream_session_t *s, |
204 ngx_stream_phase_handler_t *ph) | |
205 { | |
206 size_t size; | |
207 ssize_t n; | |
208 ngx_int_t rc; | |
209 ngx_connection_t *c; | |
210 ngx_stream_core_srv_conf_t *cscf; | |
211 | |
212 c = s->connection; | |
213 | |
214 c->log->action = "prereading client data"; | |
215 | |
216 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); | |
217 | |
218 if (c->read->timedout) { | |
219 rc = NGX_STREAM_OK; | |
220 | |
221 } else if (c->read->timer_set) { | |
222 rc = NGX_AGAIN; | |
223 | |
224 } else { | |
225 rc = ph->handler(s); | |
226 } | |
227 | |
228 while (rc == NGX_AGAIN) { | |
229 | |
230 if (c->buffer == NULL) { | |
231 c->buffer = ngx_create_temp_buf(c->pool, cscf->preread_buffer_size); | |
232 if (c->buffer == NULL) { | |
233 rc = NGX_ERROR; | |
234 break; | |
235 } | |
236 } | |
237 | |
238 size = c->buffer->end - c->buffer->last; | |
239 | |
240 if (size == 0) { | |
241 ngx_log_error(NGX_LOG_ERR, c->log, 0, "preread buffer full"); | |
242 rc = NGX_STREAM_BAD_REQUEST; | |
243 break; | |
244 } | |
245 | |
246 if (c->read->eof) { | |
247 rc = NGX_STREAM_OK; | |
248 break; | |
249 } | |
250 | |
251 if (!c->read->ready) { | |
252 if (ngx_handle_read_event(c->read, 0) != NGX_OK) { | |
253 rc = NGX_ERROR; | |
254 break; | |
255 } | |
256 | |
257 if (!c->read->timer_set) { | |
258 ngx_add_timer(c->read, cscf->preread_timeout); | |
259 } | |
260 | |
261 c->read->handler = ngx_stream_session_handler; | |
262 | |
263 return NGX_OK; | |
264 } | |
265 | |
266 n = c->recv(c, c->buffer->last, size); | |
267 | |
268 if (n == NGX_ERROR) { | |
269 rc = NGX_STREAM_OK; | |
270 break; | |
271 } | |
272 | |
273 if (n > 0) { | |
274 c->buffer->last += n; | |
275 } | |
276 | |
277 rc = ph->handler(s); | |
278 } | |
279 | |
280 if (c->read->timer_set) { | |
281 ngx_del_timer(c->read); | |
282 } | |
283 | |
284 if (rc == NGX_OK) { | |
285 s->phase_handler = ph->next; | |
286 return NGX_AGAIN; | |
287 } | |
288 | |
289 if (rc == NGX_DECLINED) { | |
290 s->phase_handler++; | |
291 return NGX_AGAIN; | |
292 } | |
293 | |
294 if (rc == NGX_DONE) { | |
295 return NGX_OK; | |
296 } | |
297 | |
298 if (rc == NGX_ERROR) { | |
299 rc = NGX_STREAM_INTERNAL_SERVER_ERROR; | |
300 } | |
301 | |
302 ngx_stream_finalize_session(s, rc); | |
303 | |
304 return NGX_OK; | |
305 } | |
306 | |
307 | |
308 ngx_int_t | |
6693 | 309 ngx_stream_core_content_phase(ngx_stream_session_t *s, |
310 ngx_stream_phase_handler_t *ph) | |
311 { | |
312 ngx_connection_t *c; | |
313 ngx_stream_core_srv_conf_t *cscf; | |
314 | |
315 c = s->connection; | |
316 | |
317 c->log->action = NULL; | |
318 | |
319 cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module); | |
320 | |
321 if (c->type == SOCK_STREAM | |
322 && cscf->tcp_nodelay | |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
6975
diff
changeset
|
323 && ngx_tcp_nodelay(c) != NGX_OK) |
6693 | 324 { |
7007
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
6975
diff
changeset
|
325 ngx_stream_finalize_session(s, NGX_STREAM_INTERNAL_SERVER_ERROR); |
ed1101bbf19f
Introduced ngx_tcp_nodelay().
Ruslan Ermilov <ru@nginx.com>
parents:
6975
diff
changeset
|
326 return NGX_OK; |
6693 | 327 } |
328 | |
329 cscf->handler(s); | |
330 | |
331 return NGX_OK; | |
332 } | |
333 | |
334 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
335 static ngx_int_t |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
336 ngx_stream_core_preconfiguration(ngx_conf_t *cf) |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
337 { |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
338 return ngx_stream_variables_add_core_vars(cf); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
339 } |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
340 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
341 |
6115 | 342 static void * |
343 ngx_stream_core_create_main_conf(ngx_conf_t *cf) | |
344 { | |
345 ngx_stream_core_main_conf_t *cmcf; | |
346 | |
347 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_core_main_conf_t)); | |
348 if (cmcf == NULL) { | |
349 return NULL; | |
350 } | |
351 | |
352 if (ngx_array_init(&cmcf->servers, cf->pool, 4, | |
353 sizeof(ngx_stream_core_srv_conf_t *)) | |
354 != NGX_OK) | |
355 { | |
356 return NULL; | |
357 } | |
358 | |
359 if (ngx_array_init(&cmcf->listen, cf->pool, 4, sizeof(ngx_stream_listen_t)) | |
360 != NGX_OK) | |
361 { | |
362 return NULL; | |
363 } | |
364 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
365 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
366 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
367 |
6115 | 368 return cmcf; |
369 } | |
370 | |
371 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
372 static char * |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
373 ngx_stream_core_init_main_conf(ngx_conf_t *cf, void *conf) |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
374 { |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
375 ngx_stream_core_main_conf_t *cmcf = conf; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
376 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
377 ngx_conf_init_uint_value(cmcf->variables_hash_max_size, 1024); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
378 ngx_conf_init_uint_value(cmcf->variables_hash_bucket_size, 64); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
379 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
380 cmcf->variables_hash_bucket_size = |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
381 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
382 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
383 if (cmcf->ncaptures) { |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
384 cmcf->ncaptures = (cmcf->ncaptures + 1) * 3; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
385 } |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
386 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
387 return NGX_CONF_OK; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
388 } |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
389 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
390 |
6115 | 391 static void * |
392 ngx_stream_core_create_srv_conf(ngx_conf_t *cf) | |
393 { | |
394 ngx_stream_core_srv_conf_t *cscf; | |
395 | |
396 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_core_srv_conf_t)); | |
397 if (cscf == NULL) { | |
398 return NULL; | |
399 } | |
400 | |
401 /* | |
402 * set by ngx_pcalloc(): | |
403 * | |
404 * cscf->handler = NULL; | |
405 * cscf->error_log = NULL; | |
406 */ | |
407 | |
408 cscf->file_name = cf->conf_file->file.name.data; | |
409 cscf->line = cf->conf_file->line; | |
6618 | 410 cscf->resolver_timeout = NGX_CONF_UNSET_MSEC; |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
411 cscf->proxy_protocol_timeout = NGX_CONF_UNSET_MSEC; |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
412 cscf->tcp_nodelay = NGX_CONF_UNSET; |
6694 | 413 cscf->preread_buffer_size = NGX_CONF_UNSET_SIZE; |
414 cscf->preread_timeout = NGX_CONF_UNSET_MSEC; | |
6115 | 415 |
416 return cscf; | |
417 } | |
418 | |
419 | |
420 static char * | |
421 ngx_stream_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | |
422 { | |
423 ngx_stream_core_srv_conf_t *prev = parent; | |
424 ngx_stream_core_srv_conf_t *conf = child; | |
425 | |
6618 | 426 ngx_conf_merge_msec_value(conf->resolver_timeout, |
427 prev->resolver_timeout, 30000); | |
428 | |
429 if (conf->resolver == NULL) { | |
430 | |
431 if (prev->resolver == NULL) { | |
432 | |
433 /* | |
434 * create dummy resolver in stream {} context | |
435 * to inherit it in all servers | |
436 */ | |
437 | |
438 prev->resolver = ngx_resolver_create(cf, NULL, 0); | |
439 if (prev->resolver == NULL) { | |
440 return NGX_CONF_ERROR; | |
441 } | |
442 } | |
443 | |
444 conf->resolver = prev->resolver; | |
445 } | |
446 | |
6115 | 447 if (conf->handler == NULL) { |
448 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
449 "no handler for server in %s:%ui", | |
450 conf->file_name, conf->line); | |
451 return NGX_CONF_ERROR; | |
452 } | |
453 | |
454 if (conf->error_log == NULL) { | |
455 if (prev->error_log) { | |
456 conf->error_log = prev->error_log; | |
457 } else { | |
458 conf->error_log = &cf->cycle->new_log; | |
459 } | |
460 } | |
461 | |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
462 ngx_conf_merge_msec_value(conf->proxy_protocol_timeout, |
6685
4a16fceea03b
Stream: increase default value for proxy_protocol_timeout to 30s.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6680
diff
changeset
|
463 prev->proxy_protocol_timeout, 30000); |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
464 |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
465 ngx_conf_merge_value(conf->tcp_nodelay, prev->tcp_nodelay, 1); |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
466 |
6694 | 467 ngx_conf_merge_size_value(conf->preread_buffer_size, |
468 prev->preread_buffer_size, 16384); | |
469 | |
470 ngx_conf_merge_msec_value(conf->preread_timeout, | |
471 prev->preread_timeout, 30000); | |
472 | |
6115 | 473 return NGX_CONF_OK; |
474 } | |
475 | |
476 | |
477 static char * | |
478 ngx_stream_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
479 { | |
480 ngx_stream_core_srv_conf_t *cscf = conf; | |
481 | |
482 return ngx_log_set_log(cf, &cscf->error_log); | |
483 } | |
484 | |
485 | |
486 static char * | |
487 ngx_stream_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
488 { | |
489 char *rv; | |
490 void *mconf; | |
491 ngx_uint_t m; | |
492 ngx_conf_t pcf; | |
493 ngx_stream_module_t *module; | |
494 ngx_stream_conf_ctx_t *ctx, *stream_ctx; | |
495 ngx_stream_core_srv_conf_t *cscf, **cscfp; | |
496 ngx_stream_core_main_conf_t *cmcf; | |
497 | |
498 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_stream_conf_ctx_t)); | |
499 if (ctx == NULL) { | |
500 return NGX_CONF_ERROR; | |
501 } | |
502 | |
503 stream_ctx = cf->ctx; | |
504 ctx->main_conf = stream_ctx->main_conf; | |
505 | |
506 /* the server{}'s srv_conf */ | |
507 | |
508 ctx->srv_conf = ngx_pcalloc(cf->pool, | |
509 sizeof(void *) * ngx_stream_max_module); | |
510 if (ctx->srv_conf == NULL) { | |
511 return NGX_CONF_ERROR; | |
512 } | |
513 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6230
diff
changeset
|
514 for (m = 0; cf->cycle->modules[m]; m++) { |
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6230
diff
changeset
|
515 if (cf->cycle->modules[m]->type != NGX_STREAM_MODULE) { |
6115 | 516 continue; |
517 } | |
518 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6230
diff
changeset
|
519 module = cf->cycle->modules[m]->ctx; |
6115 | 520 |
521 if (module->create_srv_conf) { | |
522 mconf = module->create_srv_conf(cf); | |
523 if (mconf == NULL) { | |
524 return NGX_CONF_ERROR; | |
525 } | |
526 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6230
diff
changeset
|
527 ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf; |
6115 | 528 } |
529 } | |
530 | |
531 /* the server configuration context */ | |
532 | |
533 cscf = ctx->srv_conf[ngx_stream_core_module.ctx_index]; | |
534 cscf->ctx = ctx; | |
535 | |
536 cmcf = ctx->main_conf[ngx_stream_core_module.ctx_index]; | |
537 | |
538 cscfp = ngx_array_push(&cmcf->servers); | |
539 if (cscfp == NULL) { | |
540 return NGX_CONF_ERROR; | |
541 } | |
542 | |
543 *cscfp = cscf; | |
544 | |
545 | |
546 /* parse inside server{} */ | |
547 | |
548 pcf = *cf; | |
549 cf->ctx = ctx; | |
550 cf->cmd_type = NGX_STREAM_SRV_CONF; | |
551 | |
552 rv = ngx_conf_parse(cf, NULL); | |
553 | |
554 *cf = pcf; | |
555 | |
6657
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
556 if (rv == NGX_CONF_OK && !cscf->listen) { |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
557 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
558 "no \"listen\" is defined for server in %s:%ui", |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
559 cscf->file_name, cscf->line); |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
560 return NGX_CONF_ERROR; |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
561 } |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
562 |
6115 | 563 return rv; |
564 } | |
565 | |
566 | |
567 static char * | |
568 ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
569 { | |
6657
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
570 ngx_stream_core_srv_conf_t *cscf = conf; |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
571 |
6975
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
572 ngx_str_t *value, size; |
6115 | 573 ngx_url_t u; |
6436 | 574 ngx_uint_t i, backlog; |
6558
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
575 ngx_stream_listen_t *ls, *als; |
6115 | 576 ngx_stream_core_main_conf_t *cmcf; |
577 | |
6657
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
578 cscf->listen = 1; |
3d5202c71f94
Ensure "listen" exists in a mail or stream server (ticket #1049).
Roman Arutyunyan <arut@nginx.com>
parents:
6618
diff
changeset
|
579 |
6115 | 580 value = cf->args->elts; |
581 | |
582 ngx_memzero(&u, sizeof(ngx_url_t)); | |
583 | |
584 u.url = value[1]; | |
585 u.listen = 1; | |
586 | |
587 if (ngx_parse_url(cf->pool, &u) != NGX_OK) { | |
588 if (u.err) { | |
589 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
590 "%s in \"%V\" of the \"listen\" directive", | |
591 u.err, &u.url); | |
592 } | |
593 | |
594 return NGX_CONF_ERROR; | |
595 } | |
596 | |
597 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
598 | |
599 ls = ngx_array_push(&cmcf->listen); | |
600 if (ls == NULL) { | |
601 return NGX_CONF_ERROR; | |
602 } | |
603 | |
604 ngx_memzero(ls, sizeof(ngx_stream_listen_t)); | |
605 | |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
606 ngx_memcpy(&ls->sockaddr.sockaddr, &u.sockaddr, u.socklen); |
6115 | 607 |
608 ls->socklen = u.socklen; | |
6172 | 609 ls->backlog = NGX_LISTEN_BACKLOG; |
6975
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
610 ls->rcvbuf = -1; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
611 ls->sndbuf = -1; |
6436 | 612 ls->type = SOCK_STREAM; |
6115 | 613 ls->wildcard = u.wildcard; |
614 ls->ctx = cf->ctx; | |
615 | |
6719
cebf5fed00bf
Modules compatibility: removed unneeded IPV6_V6ONLY checks.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6694
diff
changeset
|
616 #if (NGX_HAVE_INET6) |
6115 | 617 ls->ipv6only = 1; |
618 #endif | |
619 | |
6436 | 620 backlog = 0; |
621 | |
6115 | 622 for (i = 2; i < cf->args->nelts; i++) { |
623 | |
6436 | 624 #if !(NGX_WIN32) |
625 if (ngx_strcmp(value[i].data, "udp") == 0) { | |
626 ls->type = SOCK_DGRAM; | |
627 continue; | |
628 } | |
629 #endif | |
630 | |
6115 | 631 if (ngx_strcmp(value[i].data, "bind") == 0) { |
632 ls->bind = 1; | |
633 continue; | |
634 } | |
635 | |
6172 | 636 if (ngx_strncmp(value[i].data, "backlog=", 8) == 0) { |
637 ls->backlog = ngx_atoi(value[i].data + 8, value[i].len - 8); | |
638 ls->bind = 1; | |
639 | |
640 if (ls->backlog == NGX_ERROR || ls->backlog == 0) { | |
641 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
642 "invalid backlog \"%V\"", &value[i]); | |
643 return NGX_CONF_ERROR; | |
644 } | |
645 | |
6436 | 646 backlog = 1; |
647 | |
6172 | 648 continue; |
649 } | |
650 | |
6975
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
651 if (ngx_strncmp(value[i].data, "rcvbuf=", 7) == 0) { |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
652 size.len = value[i].len - 7; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
653 size.data = value[i].data + 7; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
654 |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
655 ls->rcvbuf = ngx_parse_size(&size); |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
656 ls->bind = 1; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
657 |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
658 if (ls->rcvbuf == NGX_ERROR) { |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
659 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
660 "invalid rcvbuf \"%V\"", &value[i]); |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
661 return NGX_CONF_ERROR; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
662 } |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
663 |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
664 continue; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
665 } |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
666 |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
667 if (ngx_strncmp(value[i].data, "sndbuf=", 7) == 0) { |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
668 size.len = value[i].len - 7; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
669 size.data = value[i].data + 7; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
670 |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
671 ls->sndbuf = ngx_parse_size(&size); |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
672 ls->bind = 1; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
673 |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
674 if (ls->sndbuf == NGX_ERROR) { |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
675 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
676 "invalid sndbuf \"%V\"", &value[i]); |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
677 return NGX_CONF_ERROR; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
678 } |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
679 |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
680 continue; |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
681 } |
d7ce41bdf050
Stream: configurable socket buffer sizes.
Vladimir Homutov <vl@nginx.com>
parents:
6719
diff
changeset
|
682 |
6115 | 683 if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) { |
684 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
6557
6f8254ae61b8
Use ngx_cmp_sockaddr() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6436
diff
changeset
|
685 size_t len; |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6221
diff
changeset
|
686 u_char buf[NGX_SOCKADDR_STRLEN]; |
6115 | 687 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
688 if (ls->sockaddr.sockaddr.sa_family == AF_INET6) { |
6115 | 689 |
690 if (ngx_strcmp(&value[i].data[10], "n") == 0) { | |
691 ls->ipv6only = 1; | |
692 | |
693 } else if (ngx_strcmp(&value[i].data[10], "ff") == 0) { | |
694 ls->ipv6only = 0; | |
695 | |
696 } else { | |
697 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
698 "invalid ipv6only flags \"%s\"", | |
699 &value[i].data[9]); | |
700 return NGX_CONF_ERROR; | |
701 } | |
702 | |
703 ls->bind = 1; | |
704 | |
705 } else { | |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
706 len = ngx_sock_ntop(&ls->sockaddr.sockaddr, ls->socklen, buf, |
6115 | 707 NGX_SOCKADDR_STRLEN, 1); |
708 | |
709 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
710 "ipv6only is not supported " | |
711 "on addr \"%*s\", ignored", len, buf); | |
712 } | |
713 | |
714 continue; | |
715 #else | |
716 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
717 "bind ipv6only is not supported " | |
718 "on this platform"); | |
719 return NGX_CONF_ERROR; | |
720 #endif | |
721 } | |
722 | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
723 if (ngx_strcmp(value[i].data, "reuseport") == 0) { |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
724 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
725 ls->reuseport = 1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
726 ls->bind = 1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
727 #else |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
728 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
729 "reuseport is not supported " |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
730 "on this platform, ignored"); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
731 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
732 continue; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
733 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
734 |
6115 | 735 if (ngx_strcmp(value[i].data, "ssl") == 0) { |
736 #if (NGX_STREAM_SSL) | |
7269
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
737 ngx_stream_ssl_conf_t *sslcf; |
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
738 |
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
739 sslcf = ngx_stream_conf_get_module_srv_conf(cf, |
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
740 ngx_stream_ssl_module); |
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
741 |
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
742 sslcf->listen = 1; |
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
743 sslcf->file = cf->conf_file->file.name.data; |
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
744 sslcf->line = cf->conf_file->line; |
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
745 |
6115 | 746 ls->ssl = 1; |
7269
7f955d3b9a0d
SSL: detect "listen ... ssl" without certificates (ticket #178).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7007
diff
changeset
|
747 |
6115 | 748 continue; |
749 #else | |
750 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
751 "the \"ssl\" parameter requires " | |
752 "ngx_stream_ssl_module"); | |
753 return NGX_CONF_ERROR; | |
754 #endif | |
755 } | |
756 | |
757 if (ngx_strncmp(value[i].data, "so_keepalive=", 13) == 0) { | |
758 | |
759 if (ngx_strcmp(&value[i].data[13], "on") == 0) { | |
760 ls->so_keepalive = 1; | |
761 | |
762 } else if (ngx_strcmp(&value[i].data[13], "off") == 0) { | |
763 ls->so_keepalive = 2; | |
764 | |
765 } else { | |
766 | |
767 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
768 u_char *p, *end; | |
769 ngx_str_t s; | |
770 | |
771 end = value[i].data + value[i].len; | |
772 s.data = value[i].data + 13; | |
773 | |
774 p = ngx_strlchr(s.data, end, ':'); | |
775 if (p == NULL) { | |
776 p = end; | |
777 } | |
778 | |
779 if (p > s.data) { | |
780 s.len = p - s.data; | |
781 | |
782 ls->tcp_keepidle = ngx_parse_time(&s, 1); | |
783 if (ls->tcp_keepidle == (time_t) NGX_ERROR) { | |
784 goto invalid_so_keepalive; | |
785 } | |
786 } | |
787 | |
788 s.data = (p < end) ? (p + 1) : end; | |
789 | |
790 p = ngx_strlchr(s.data, end, ':'); | |
791 if (p == NULL) { | |
792 p = end; | |
793 } | |
794 | |
795 if (p > s.data) { | |
796 s.len = p - s.data; | |
797 | |
798 ls->tcp_keepintvl = ngx_parse_time(&s, 1); | |
799 if (ls->tcp_keepintvl == (time_t) NGX_ERROR) { | |
800 goto invalid_so_keepalive; | |
801 } | |
802 } | |
803 | |
804 s.data = (p < end) ? (p + 1) : end; | |
805 | |
806 if (s.data < end) { | |
807 s.len = end - s.data; | |
808 | |
809 ls->tcp_keepcnt = ngx_atoi(s.data, s.len); | |
810 if (ls->tcp_keepcnt == NGX_ERROR) { | |
811 goto invalid_so_keepalive; | |
812 } | |
813 } | |
814 | |
815 if (ls->tcp_keepidle == 0 && ls->tcp_keepintvl == 0 | |
816 && ls->tcp_keepcnt == 0) | |
817 { | |
818 goto invalid_so_keepalive; | |
819 } | |
820 | |
821 ls->so_keepalive = 1; | |
822 | |
823 #else | |
824 | |
825 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
826 "the \"so_keepalive\" parameter accepts " | |
827 "only \"on\" or \"off\" on this platform"); | |
828 return NGX_CONF_ERROR; | |
829 | |
830 #endif | |
831 } | |
832 | |
833 ls->bind = 1; | |
834 | |
835 continue; | |
836 | |
837 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
838 invalid_so_keepalive: | |
839 | |
840 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
841 "invalid so_keepalive value: \"%s\"", | |
842 &value[i].data[13]); | |
843 return NGX_CONF_ERROR; | |
844 #endif | |
845 } | |
846 | |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
847 if (ngx_strcmp(value[i].data, "proxy_protocol") == 0) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
848 ls->proxy_protocol = 1; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
849 continue; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
850 } |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
851 |
6115 | 852 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
853 "the invalid \"%V\" parameter", &value[i]); | |
854 return NGX_CONF_ERROR; | |
855 } | |
856 | |
6436 | 857 if (ls->type == SOCK_DGRAM) { |
858 if (backlog) { | |
859 return "\"backlog\" parameter is incompatible with \"udp\""; | |
860 } | |
861 | |
862 #if (NGX_STREAM_SSL) | |
863 if (ls->ssl) { | |
864 return "\"ssl\" parameter is incompatible with \"udp\""; | |
865 } | |
866 #endif | |
867 | |
868 if (ls->so_keepalive) { | |
869 return "\"so_keepalive\" parameter is incompatible with \"udp\""; | |
870 } | |
6680
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
871 |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
872 if (ls->proxy_protocol) { |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
873 return "\"proxy_protocol\" parameter is incompatible with \"udp\""; |
7357abd1fa8c
Stream: the "proxy_protocol" parameter of the "listen" directive.
Dmitry Volyntsev <xeioex@nginx.com>
parents:
6657
diff
changeset
|
874 } |
6436 | 875 } |
876 | |
6558
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
877 als = cmcf->listen.elts; |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
878 |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
879 for (i = 0; i < cmcf->listen.nelts - 1; i++) { |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
880 if (ls->type != als[i].type) { |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
881 continue; |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
882 } |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
883 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
884 if (ngx_cmp_sockaddr(&als[i].sockaddr.sockaddr, als[i].socklen, |
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
885 &ls->sockaddr.sockaddr, ls->socklen, 1) |
6558
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
886 != NGX_OK) |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
887 { |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
888 continue; |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
889 } |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
890 |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
891 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
892 "duplicate \"%V\" address and port pair", &u.url); |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
893 return NGX_CONF_ERROR; |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
894 } |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
895 |
6115 | 896 return NGX_CONF_OK; |
897 } | |
6618 | 898 |
899 | |
900 static char * | |
901 ngx_stream_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
902 { | |
903 ngx_stream_core_srv_conf_t *cscf = conf; | |
904 | |
905 ngx_str_t *value; | |
906 | |
907 if (cscf->resolver) { | |
908 return "is duplicate"; | |
909 } | |
910 | |
911 value = cf->args->elts; | |
912 | |
913 cscf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1); | |
914 if (cscf->resolver == NULL) { | |
915 return NGX_CONF_ERROR; | |
916 } | |
917 | |
918 return NGX_CONF_OK; | |
919 } |