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.
This commit is contained in:
Ruslan Ermilov 2016-05-23 12:50:59 +03:00
parent 48a16463fa
commit d650688ba5

View File

@ -251,7 +251,7 @@ ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
ngx_str_t *value;
ngx_url_t u;
ngx_uint_t i, backlog;
ngx_stream_listen_t *ls;
ngx_stream_listen_t *ls, *als;
ngx_stream_core_main_conf_t *cmcf;
value = cf->args->elts;
@ -273,22 +273,6 @@ ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
cmcf = ngx_stream_conf_get_module_main_conf(cf, ngx_stream_core_module);
ls = cmcf->listen.elts;
for (i = 0; i < cmcf->listen.nelts; i++) {
if (ngx_cmp_sockaddr(&ls[i].u.sockaddr, ls[i].socklen,
(struct sockaddr *) &u.sockaddr, u.socklen, 1)
!= NGX_OK)
{
continue;
}
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"duplicate \"%V\" address and port pair", &u.url);
return NGX_CONF_ERROR;
}
ls = ngx_array_push(&cmcf->listen);
if (ls == NULL) {
return NGX_CONF_ERROR;
@ -514,5 +498,24 @@ ngx_stream_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
}
als = cmcf->listen.elts;
for (i = 0; i < cmcf->listen.nelts - 1; i++) {
if (ls->type != als[i].type) {
continue;
}
if (ngx_cmp_sockaddr(&als[i].u.sockaddr, als[i].socklen,
&ls->u.sockaddr, ls->socklen, 1)
!= NGX_OK)
{
continue;
}
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"duplicate \"%V\" address and port pair", &u.url);
return NGX_CONF_ERROR;
}
return NGX_CONF_OK;
}