[nginx] Stream: fixed duplicate listen address detection.

Ruslan Ermilov ru at nginx.com
Mon May 23 13:22:38 UTC 2016


details:   http://hg.nginx.org/nginx/rev/68854ce64ec7
branches:  
changeset: 6558:68854ce64ec7
user:      Ruslan Ermilov <ru at nginx.com>
date:      Mon May 23 12:50:59 2016 +0300
description:
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.

diffstat:

 src/stream/ngx_stream_core_module.c |  37 ++++++++++++++++++++-----------------
 1 files changed, 20 insertions(+), 17 deletions(-)

diffs (60 lines):

diff -r 6f8254ae61b8 -r 68854ce64ec7 src/stream/ngx_stream_core_module.c
--- a/src/stream/ngx_stream_core_module.c	Fri May 20 19:10:42 2016 +0300
+++ b/src/stream/ngx_stream_core_module.c	Mon May 23 12:50:59 2016 +0300
@@ -251,7 +251,7 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
     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, n
 
     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, n
         }
     }
 
+    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;
 }



More information about the nginx-devel mailing list