comparison src/stream/ngx_stream_core_module.c @ 6558:68854ce64ec7

Stream: fixed duplicate listen address detection. The 6f8254ae61b8 change inadvertently fixed the duplicate port detection similar to how it was fixed for mail in b2920b517490. It also revealed another issue: the socket type (tcp vs. udp) wasn't taken into account.
author Ruslan Ermilov <ru@nginx.com>
date Mon, 23 May 2016 12:50:59 +0300
parents 6f8254ae61b8
children adf25b8d0431
comparison
equal deleted inserted replaced
6557:6f8254ae61b8 6558:68854ce64ec7
249 ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 249 ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
250 { 250 {
251 ngx_str_t *value; 251 ngx_str_t *value;
252 ngx_url_t u; 252 ngx_url_t u;
253 ngx_uint_t i, backlog; 253 ngx_uint_t i, backlog;
254 ngx_stream_listen_t *ls; 254 ngx_stream_listen_t *ls, *als;
255 ngx_stream_core_main_conf_t *cmcf; 255 ngx_stream_core_main_conf_t *cmcf;
256 256
257 value = cf->args->elts; 257 value = cf->args->elts;
258 258
259 ngx_memzero(&u, sizeof(ngx_url_t)); 259 ngx_memzero(&u, sizeof(ngx_url_t));
270 270
271 return NGX_CONF_ERROR; 271 return NGX_CONF_ERROR;
272 } 272 }
273 273
274 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module); 274 cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module);
275
276 ls = cmcf->listen.elts;
277
278 for (i = 0; i < cmcf->listen.nelts; i++) {
279
280 if (ngx_cmp_sockaddr(&ls[i].u.sockaddr, ls[i].socklen,
281 (struct sockaddr *) &u.sockaddr, u.socklen, 1)
282 != NGX_OK)
283 {
284 continue;
285 }
286
287 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
288 "duplicate \"%V\" address and port pair", &u.url);
289 return NGX_CONF_ERROR;
290 }
291 275
292 ls = ngx_array_push(&cmcf->listen); 276 ls = ngx_array_push(&cmcf->listen);
293 if (ls == NULL) { 277 if (ls == NULL) {
294 return NGX_CONF_ERROR; 278 return NGX_CONF_ERROR;
295 } 279 }
512 if (ls->so_keepalive) { 496 if (ls->so_keepalive) {
513 return "\"so_keepalive\" parameter is incompatible with \"udp\""; 497 return "\"so_keepalive\" parameter is incompatible with \"udp\"";
514 } 498 }
515 } 499 }
516 500
501 als = cmcf->listen.elts;
502
503 for (i = 0; i < cmcf->listen.nelts - 1; i++) {
504 if (ls->type != als[i].type) {
505 continue;
506 }
507
508 if (ngx_cmp_sockaddr(&als[i].u.sockaddr, als[i].socklen,
509 &ls->u.sockaddr, ls->socklen, 1)
510 != NGX_OK)
511 {
512 continue;
513 }
514
515 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
516 "duplicate \"%V\" address and port pair", &u.url);
517 return NGX_CONF_ERROR;
518 }
519
517 return NGX_CONF_OK; 520 return NGX_CONF_OK;
518 } 521 }