Mercurial > hg > nginx
annotate src/stream/ngx_stream_core_module.c @ 6607:c70b7f4537e1
Stream: variables and script.
This is a port of corresponding http code with unrelated features excluded.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Mon, 04 Jul 2016 16:37:36 +0300 |
parents | 2f41d383c9c7 |
children | 070c31a482e6 |
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); | |
25 | |
26 | |
27 static ngx_command_t ngx_stream_core_commands[] = { | |
28 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
29 { ngx_string("variables_hash_max_size"), |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
30 NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
31 ngx_conf_set_num_slot, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
32 NGX_STREAM_MAIN_CONF_OFFSET, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
33 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
|
34 NULL }, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
35 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
36 { ngx_string("variables_hash_bucket_size"), |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
37 NGX_STREAM_MAIN_CONF|NGX_CONF_TAKE1, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
38 ngx_conf_set_num_slot, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
39 NGX_STREAM_MAIN_CONF_OFFSET, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
40 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
|
41 NULL }, |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
42 |
6115 | 43 { ngx_string("server"), |
44 NGX_STREAM_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS, | |
45 ngx_stream_core_server, | |
46 0, | |
47 0, | |
48 NULL }, | |
49 | |
50 { ngx_string("listen"), | |
51 NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, | |
52 ngx_stream_core_listen, | |
53 NGX_STREAM_SRV_CONF_OFFSET, | |
54 0, | |
55 NULL }, | |
56 | |
57 { ngx_string("error_log"), | |
58 NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_1MORE, | |
59 ngx_stream_core_error_log, | |
60 NGX_STREAM_SRV_CONF_OFFSET, | |
61 0, | |
62 NULL }, | |
63 | |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
64 { ngx_string("tcp_nodelay"), |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
65 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
|
66 ngx_conf_set_flag_slot, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
67 NGX_STREAM_SRV_CONF_OFFSET, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
68 offsetof(ngx_stream_core_srv_conf_t, tcp_nodelay), |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
69 NULL }, |
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
70 |
6115 | 71 ngx_null_command |
72 }; | |
73 | |
74 | |
75 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
|
76 ngx_stream_core_preconfiguration, /* preconfiguration */ |
6174
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
77 NULL, /* postconfiguration */ |
68c106e6fa0a
Stream: added postconfiguration method to stream modules.
Vladimir Homutov <vl@nginx.com>
parents:
6172
diff
changeset
|
78 |
6115 | 79 ngx_stream_core_create_main_conf, /* create main configuration */ |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
80 ngx_stream_core_init_main_conf, /* init main configuration */ |
6115 | 81 |
82 ngx_stream_core_create_srv_conf, /* create server configuration */ | |
83 ngx_stream_core_merge_srv_conf /* merge server configuration */ | |
84 }; | |
85 | |
86 | |
87 ngx_module_t ngx_stream_core_module = { | |
88 NGX_MODULE_V1, | |
89 &ngx_stream_core_module_ctx, /* module context */ | |
90 ngx_stream_core_commands, /* module directives */ | |
91 NGX_STREAM_MODULE, /* module type */ | |
92 NULL, /* init master */ | |
93 NULL, /* init module */ | |
94 NULL, /* init process */ | |
95 NULL, /* init thread */ | |
96 NULL, /* exit thread */ | |
97 NULL, /* exit process */ | |
98 NULL, /* exit master */ | |
99 NGX_MODULE_V1_PADDING | |
100 }; | |
101 | |
102 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
103 static ngx_int_t |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
104 ngx_stream_core_preconfiguration(ngx_conf_t *cf) |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
105 { |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
106 return ngx_stream_variables_add_core_vars(cf); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
107 } |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
108 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
109 |
6115 | 110 static void * |
111 ngx_stream_core_create_main_conf(ngx_conf_t *cf) | |
112 { | |
113 ngx_stream_core_main_conf_t *cmcf; | |
114 | |
115 cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_core_main_conf_t)); | |
116 if (cmcf == NULL) { | |
117 return NULL; | |
118 } | |
119 | |
120 if (ngx_array_init(&cmcf->servers, cf->pool, 4, | |
121 sizeof(ngx_stream_core_srv_conf_t *)) | |
122 != NGX_OK) | |
123 { | |
124 return NULL; | |
125 } | |
126 | |
127 if (ngx_array_init(&cmcf->listen, cf->pool, 4, sizeof(ngx_stream_listen_t)) | |
128 != NGX_OK) | |
129 { | |
130 return NULL; | |
131 } | |
132 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
133 cmcf->variables_hash_max_size = NGX_CONF_UNSET_UINT; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
134 cmcf->variables_hash_bucket_size = NGX_CONF_UNSET_UINT; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
135 |
6115 | 136 return cmcf; |
137 } | |
138 | |
139 | |
6607
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
140 static char * |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
141 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
|
142 { |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
143 ngx_stream_core_main_conf_t *cmcf = conf; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
144 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
145 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
|
146 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
|
147 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
148 cmcf->variables_hash_bucket_size = |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
149 ngx_align(cmcf->variables_hash_bucket_size, ngx_cacheline_size); |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
150 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
151 if (cmcf->ncaptures) { |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
152 cmcf->ncaptures = (cmcf->ncaptures + 1) * 3; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
153 } |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
154 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
155 return NGX_CONF_OK; |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
156 } |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
157 |
c70b7f4537e1
Stream: variables and script.
Vladimir Homutov <vl@nginx.com>
parents:
6606
diff
changeset
|
158 |
6115 | 159 static void * |
160 ngx_stream_core_create_srv_conf(ngx_conf_t *cf) | |
161 { | |
162 ngx_stream_core_srv_conf_t *cscf; | |
163 | |
164 cscf = ngx_pcalloc(cf->pool, sizeof(ngx_stream_core_srv_conf_t)); | |
165 if (cscf == NULL) { | |
166 return NULL; | |
167 } | |
168 | |
169 /* | |
170 * set by ngx_pcalloc(): | |
171 * | |
172 * cscf->handler = NULL; | |
173 * cscf->error_log = NULL; | |
174 */ | |
175 | |
176 cscf->file_name = cf->conf_file->file.name.data; | |
177 cscf->line = cf->conf_file->line; | |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
178 cscf->tcp_nodelay = NGX_CONF_UNSET; |
6115 | 179 |
180 return cscf; | |
181 } | |
182 | |
183 | |
184 static char * | |
185 ngx_stream_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) | |
186 { | |
187 ngx_stream_core_srv_conf_t *prev = parent; | |
188 ngx_stream_core_srv_conf_t *conf = child; | |
189 | |
190 if (conf->handler == NULL) { | |
191 ngx_log_error(NGX_LOG_EMERG, cf->log, 0, | |
192 "no handler for server in %s:%ui", | |
193 conf->file_name, conf->line); | |
194 return NGX_CONF_ERROR; | |
195 } | |
196 | |
197 if (conf->error_log == NULL) { | |
198 if (prev->error_log) { | |
199 conf->error_log = prev->error_log; | |
200 } else { | |
201 conf->error_log = &cf->cycle->new_log; | |
202 } | |
203 } | |
204 | |
6221
7565e056fad6
Stream: the "tcp_nodelay" directive.
Vladimir Homutov <vl@nginx.com>
parents:
6174
diff
changeset
|
205 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
|
206 |
6115 | 207 return NGX_CONF_OK; |
208 } | |
209 | |
210 | |
211 static char * | |
212 ngx_stream_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
213 { | |
214 ngx_stream_core_srv_conf_t *cscf = conf; | |
215 | |
216 return ngx_log_set_log(cf, &cscf->error_log); | |
217 } | |
218 | |
219 | |
220 static char * | |
221 ngx_stream_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
222 { | |
223 char *rv; | |
224 void *mconf; | |
225 ngx_uint_t m; | |
226 ngx_conf_t pcf; | |
227 ngx_stream_module_t *module; | |
228 ngx_stream_conf_ctx_t *ctx, *stream_ctx; | |
229 ngx_stream_core_srv_conf_t *cscf, **cscfp; | |
230 ngx_stream_core_main_conf_t *cmcf; | |
231 | |
232 ctx = ngx_pcalloc(cf->pool, sizeof(ngx_stream_conf_ctx_t)); | |
233 if (ctx == NULL) { | |
234 return NGX_CONF_ERROR; | |
235 } | |
236 | |
237 stream_ctx = cf->ctx; | |
238 ctx->main_conf = stream_ctx->main_conf; | |
239 | |
240 /* the server{}'s srv_conf */ | |
241 | |
242 ctx->srv_conf = ngx_pcalloc(cf->pool, | |
243 sizeof(void *) * ngx_stream_max_module); | |
244 if (ctx->srv_conf == NULL) { | |
245 return NGX_CONF_ERROR; | |
246 } | |
247 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6230
diff
changeset
|
248 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
|
249 if (cf->cycle->modules[m]->type != NGX_STREAM_MODULE) { |
6115 | 250 continue; |
251 } | |
252 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6230
diff
changeset
|
253 module = cf->cycle->modules[m]->ctx; |
6115 | 254 |
255 if (module->create_srv_conf) { | |
256 mconf = module->create_srv_conf(cf); | |
257 if (mconf == NULL) { | |
258 return NGX_CONF_ERROR; | |
259 } | |
260 | |
6379
cf5e822cf470
Dynamic modules: changed ngx_modules to cycle->modules.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6230
diff
changeset
|
261 ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf; |
6115 | 262 } |
263 } | |
264 | |
265 /* the server configuration context */ | |
266 | |
267 cscf = ctx->srv_conf[ngx_stream_core_module.ctx_index]; | |
268 cscf->ctx = ctx; | |
269 | |
270 cmcf = ctx->main_conf[ngx_stream_core_module.ctx_index]; | |
271 | |
272 cscfp = ngx_array_push(&cmcf->servers); | |
273 if (cscfp == NULL) { | |
274 return NGX_CONF_ERROR; | |
275 } | |
276 | |
277 *cscfp = cscf; | |
278 | |
279 | |
280 /* parse inside server{} */ | |
281 | |
282 pcf = *cf; | |
283 cf->ctx = ctx; | |
284 cf->cmd_type = NGX_STREAM_SRV_CONF; | |
285 | |
286 rv = ngx_conf_parse(cf, NULL); | |
287 | |
288 *cf = pcf; | |
289 | |
290 return rv; | |
291 } | |
292 | |
293 | |
294 static char * | |
295 ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | |
296 { | |
297 ngx_str_t *value; | |
298 ngx_url_t u; | |
6436 | 299 ngx_uint_t i, backlog; |
6558
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
300 ngx_stream_listen_t *ls, *als; |
6115 | 301 ngx_stream_core_main_conf_t *cmcf; |
302 | |
303 value = cf->args->elts; | |
304 | |
305 ngx_memzero(&u, sizeof(ngx_url_t)); | |
306 | |
307 u.url = value[1]; | |
308 u.listen = 1; | |
309 | |
310 if (ngx_parse_url(cf->pool, &u) != NGX_OK) { | |
311 if (u.err) { | |
312 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
313 "%s in \"%V\" of the \"listen\" directive", | |
314 u.err, &u.url); | |
315 } | |
316 | |
317 return NGX_CONF_ERROR; | |
318 } | |
319 | |
320 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); | |
321 | |
322 ls = ngx_array_push(&cmcf->listen); | |
323 if (ls == NULL) { | |
324 return NGX_CONF_ERROR; | |
325 } | |
326 | |
327 ngx_memzero(ls, sizeof(ngx_stream_listen_t)); | |
328 | |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
329 ngx_memcpy(&ls->sockaddr.sockaddr, &u.sockaddr, u.socklen); |
6115 | 330 |
331 ls->socklen = u.socklen; | |
6172 | 332 ls->backlog = NGX_LISTEN_BACKLOG; |
6436 | 333 ls->type = SOCK_STREAM; |
6115 | 334 ls->wildcard = u.wildcard; |
335 ls->ctx = cf->ctx; | |
336 | |
337 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
338 ls->ipv6only = 1; | |
339 #endif | |
340 | |
6436 | 341 backlog = 0; |
342 | |
6115 | 343 for (i = 2; i < cf->args->nelts; i++) { |
344 | |
6436 | 345 #if !(NGX_WIN32) |
346 if (ngx_strcmp(value[i].data, "udp") == 0) { | |
347 ls->type = SOCK_DGRAM; | |
348 continue; | |
349 } | |
350 #endif | |
351 | |
6115 | 352 if (ngx_strcmp(value[i].data, "bind") == 0) { |
353 ls->bind = 1; | |
354 continue; | |
355 } | |
356 | |
6172 | 357 if (ngx_strncmp(value[i].data, "backlog=", 8) == 0) { |
358 ls->backlog = ngx_atoi(value[i].data + 8, value[i].len - 8); | |
359 ls->bind = 1; | |
360 | |
361 if (ls->backlog == NGX_ERROR || ls->backlog == 0) { | |
362 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
363 "invalid backlog \"%V\"", &value[i]); | |
364 return NGX_CONF_ERROR; | |
365 } | |
366 | |
6436 | 367 backlog = 1; |
368 | |
6172 | 369 continue; |
370 } | |
371 | |
6115 | 372 if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) { |
373 #if (NGX_HAVE_INET6 && defined IPV6_V6ONLY) | |
6557
6f8254ae61b8
Use ngx_cmp_sockaddr() where appropriate.
Ruslan Ermilov <ru@nginx.com>
parents:
6436
diff
changeset
|
374 size_t len; |
6230
2a621245f4cf
Win32: MSVC 2015 compatibility.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6221
diff
changeset
|
375 u_char buf[NGX_SOCKADDR_STRLEN]; |
6115 | 376 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
377 if (ls->sockaddr.sockaddr.sa_family == AF_INET6) { |
6115 | 378 |
379 if (ngx_strcmp(&value[i].data[10], "n") == 0) { | |
380 ls->ipv6only = 1; | |
381 | |
382 } else if (ngx_strcmp(&value[i].data[10], "ff") == 0) { | |
383 ls->ipv6only = 0; | |
384 | |
385 } else { | |
386 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
387 "invalid ipv6only flags \"%s\"", | |
388 &value[i].data[9]); | |
389 return NGX_CONF_ERROR; | |
390 } | |
391 | |
392 ls->bind = 1; | |
393 | |
394 } else { | |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
395 len = ngx_sock_ntop(&ls->sockaddr.sockaddr, ls->socklen, buf, |
6115 | 396 NGX_SOCKADDR_STRLEN, 1); |
397 | |
398 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
399 "ipv6only is not supported " | |
400 "on addr \"%*s\", ignored", len, buf); | |
401 } | |
402 | |
403 continue; | |
404 #else | |
405 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
406 "bind ipv6only is not supported " | |
407 "on this platform"); | |
408 return NGX_CONF_ERROR; | |
409 #endif | |
410 } | |
411 | |
6153
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
412 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
|
413 #if (NGX_HAVE_REUSEPORT) |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
414 ls->reuseport = 1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
415 ls->bind = 1; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
416 #else |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
417 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
|
418 "reuseport is not supported " |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
419 "on this platform, ignored"); |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
420 #endif |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
421 continue; |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
422 } |
4f6efabcb09b
The "reuseport" option of the "listen" directive.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6115
diff
changeset
|
423 |
6115 | 424 if (ngx_strcmp(value[i].data, "ssl") == 0) { |
425 #if (NGX_STREAM_SSL) | |
426 ls->ssl = 1; | |
427 continue; | |
428 #else | |
429 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
430 "the \"ssl\" parameter requires " | |
431 "ngx_stream_ssl_module"); | |
432 return NGX_CONF_ERROR; | |
433 #endif | |
434 } | |
435 | |
436 if (ngx_strncmp(value[i].data, "so_keepalive=", 13) == 0) { | |
437 | |
438 if (ngx_strcmp(&value[i].data[13], "on") == 0) { | |
439 ls->so_keepalive = 1; | |
440 | |
441 } else if (ngx_strcmp(&value[i].data[13], "off") == 0) { | |
442 ls->so_keepalive = 2; | |
443 | |
444 } else { | |
445 | |
446 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
447 u_char *p, *end; | |
448 ngx_str_t s; | |
449 | |
450 end = value[i].data + value[i].len; | |
451 s.data = value[i].data + 13; | |
452 | |
453 p = ngx_strlchr(s.data, end, ':'); | |
454 if (p == NULL) { | |
455 p = end; | |
456 } | |
457 | |
458 if (p > s.data) { | |
459 s.len = p - s.data; | |
460 | |
461 ls->tcp_keepidle = ngx_parse_time(&s, 1); | |
462 if (ls->tcp_keepidle == (time_t) NGX_ERROR) { | |
463 goto invalid_so_keepalive; | |
464 } | |
465 } | |
466 | |
467 s.data = (p < end) ? (p + 1) : end; | |
468 | |
469 p = ngx_strlchr(s.data, end, ':'); | |
470 if (p == NULL) { | |
471 p = end; | |
472 } | |
473 | |
474 if (p > s.data) { | |
475 s.len = p - s.data; | |
476 | |
477 ls->tcp_keepintvl = ngx_parse_time(&s, 1); | |
478 if (ls->tcp_keepintvl == (time_t) NGX_ERROR) { | |
479 goto invalid_so_keepalive; | |
480 } | |
481 } | |
482 | |
483 s.data = (p < end) ? (p + 1) : end; | |
484 | |
485 if (s.data < end) { | |
486 s.len = end - s.data; | |
487 | |
488 ls->tcp_keepcnt = ngx_atoi(s.data, s.len); | |
489 if (ls->tcp_keepcnt == NGX_ERROR) { | |
490 goto invalid_so_keepalive; | |
491 } | |
492 } | |
493 | |
494 if (ls->tcp_keepidle == 0 && ls->tcp_keepintvl == 0 | |
495 && ls->tcp_keepcnt == 0) | |
496 { | |
497 goto invalid_so_keepalive; | |
498 } | |
499 | |
500 ls->so_keepalive = 1; | |
501 | |
502 #else | |
503 | |
504 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
505 "the \"so_keepalive\" parameter accepts " | |
506 "only \"on\" or \"off\" on this platform"); | |
507 return NGX_CONF_ERROR; | |
508 | |
509 #endif | |
510 } | |
511 | |
512 ls->bind = 1; | |
513 | |
514 continue; | |
515 | |
516 #if (NGX_HAVE_KEEPALIVE_TUNABLE) | |
517 invalid_so_keepalive: | |
518 | |
519 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
520 "invalid so_keepalive value: \"%s\"", | |
521 &value[i].data[13]); | |
522 return NGX_CONF_ERROR; | |
523 #endif | |
524 } | |
525 | |
526 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
527 "the invalid \"%V\" parameter", &value[i]); | |
528 return NGX_CONF_ERROR; | |
529 } | |
530 | |
6436 | 531 if (ls->type == SOCK_DGRAM) { |
532 if (backlog) { | |
533 return "\"backlog\" parameter is incompatible with \"udp\""; | |
534 } | |
535 | |
536 #if (NGX_STREAM_SSL) | |
537 if (ls->ssl) { | |
538 return "\"ssl\" parameter is incompatible with \"udp\""; | |
539 } | |
540 #endif | |
541 | |
542 if (ls->so_keepalive) { | |
543 return "\"so_keepalive\" parameter is incompatible with \"udp\""; | |
544 } | |
545 } | |
546 | |
6558
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
547 als = cmcf->listen.elts; |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
548 |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
549 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
|
550 if (ls->type != als[i].type) { |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
551 continue; |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
552 } |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
553 |
6560
c90cf79d0e1d
Renamed "u" to "sockaddr" in listen options types.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6559
diff
changeset
|
554 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
|
555 &ls->sockaddr.sockaddr, ls->socklen, 1) |
6558
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
556 != NGX_OK) |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
557 { |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
558 continue; |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
559 } |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
560 |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
561 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
|
562 "duplicate \"%V\" address and port pair", &u.url); |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
563 return NGX_CONF_ERROR; |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
564 } |
68854ce64ec7
Stream: fixed duplicate listen address detection.
Ruslan Ermilov <ru@nginx.com>
parents:
6557
diff
changeset
|
565 |
6115 | 566 return NGX_CONF_OK; |
567 } |