[nginx] Modules compatibility: removed unneeded IPV6_V6ONLY checks.

Ruslan Ermilov ru at nginx.com
Mon Oct 3 13:00:25 UTC 2016


details:   http://hg.nginx.org/nginx/rev/cebf5fed00bf
branches:  
changeset: 6719:cebf5fed00bf
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Mon Oct 03 15:58:25 2016 +0300
description:
Modules compatibility: removed unneeded IPV6_V6ONLY checks.

The IPV6_V6ONLY macro is now checked only while parsing appropriate flag
and when using the macro.

The ipv6only field in listen structures is always initialized to 1,
even if not supported on a given platform.  This is expected to prevent
a module compiled without IPV6_V6ONLY from accidentally creating dual
sockets if loaded into main binary with proper IPV6_V6ONLY support.

diffstat:

 src/core/ngx_connection.h           |    2 +-
 src/core/ngx_module.h               |    4 -
 src/http/ngx_http.c                 |  134 ++++++++++++++++++------------------
 src/http/ngx_http_core_module.c     |    2 +-
 src/http/ngx_http_core_module.h     |    2 +-
 src/mail/ngx_mail.c                 |    2 +-
 src/mail/ngx_mail.h                 |    2 +-
 src/mail/ngx_mail_core_module.c     |    2 +-
 src/stream/ngx_stream.c             |    2 +-
 src/stream/ngx_stream.h             |    2 +-
 src/stream/ngx_stream_core_module.c |    2 +-
 11 files changed, 76 insertions(+), 80 deletions(-)

diffs (281 lines):

diff -r bdf64ae3376b -r cebf5fed00bf src/core/ngx_connection.h
--- a/src/core/ngx_connection.h	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/core/ngx_connection.h	Mon Oct 03 15:58:25 2016 +0300
@@ -66,7 +66,7 @@ struct ngx_listening_s {
     unsigned            addr_ntop:1;
     unsigned            wildcard:1;
 
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
     unsigned            ipv6only:1;
 #endif
 #if (NGX_HAVE_REUSEPORT)
diff -r bdf64ae3376b -r cebf5fed00bf src/core/ngx_module.h
--- a/src/core/ngx_module.h	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/core/ngx_module.h	Mon Oct 03 15:58:25 2016 +0300
@@ -71,11 +71,7 @@
 #define NGX_MODULE_SIGNATURE_8   "0"
 #endif
 
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
 #define NGX_MODULE_SIGNATURE_9   "1"
-#else
-#define NGX_MODULE_SIGNATURE_9   "0"
-#endif
 
 #if (NGX_HAVE_REUSEPORT)
 #define NGX_MODULE_SIGNATURE_10  "1"
diff -r bdf64ae3376b -r cebf5fed00bf src/http/ngx_http.c
--- a/src/http/ngx_http.c	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/http/ngx_http.c	Mon Oct 03 15:58:25 2016 +0300
@@ -1756,7 +1756,7 @@ ngx_http_add_listening(ngx_conf_t *cf, n
     ls->deferred_accept = addr->opt.deferred_accept;
 #endif
 
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
     ls->ipv6only = addr->opt.ipv6only;
 #endif
 
@@ -1824,72 +1824,7 @@ ngx_http_add_addrs(ngx_conf_t *cf, ngx_h
             return NGX_ERROR;
         }
 
-        addrs[i].conf.virtual_names = vn;
-
-        vn->names.hash = addr[i].hash;
-        vn->names.wc_head = addr[i].wc_head;
-        vn->names.wc_tail = addr[i].wc_tail;
-#if (NGX_PCRE)
-        vn->nregex = addr[i].nregex;
-        vn->regex = addr[i].regex;
-#endif
-    }
-
-    return NGX_OK;
-}
-
-
-#if (NGX_HAVE_INET6)
-
-static ngx_int_t
-ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport,
-    ngx_http_conf_addr_t *addr)
-{
-    ngx_uint_t                 i;
-    ngx_http_in6_addr_t       *addrs6;
-    struct sockaddr_in6       *sin6;
-    ngx_http_virtual_names_t  *vn;
-
-    hport->addrs = ngx_pcalloc(cf->pool,
-                               hport->naddrs * sizeof(ngx_http_in6_addr_t));
-    if (hport->addrs == NULL) {
-        return NGX_ERROR;
-    }
-
-    addrs6 = hport->addrs;
-
-    for (i = 0; i < hport->naddrs; i++) {
-
-        sin6 = &addr[i].opt.sockaddr.sockaddr_in6;
-        addrs6[i].addr6 = sin6->sin6_addr;
-        addrs6[i].conf.default_server = addr[i].default_server;
-#if (NGX_HTTP_SSL)
-        addrs6[i].conf.ssl = addr[i].opt.ssl;
-#endif
-#if (NGX_HTTP_V2)
-        addrs6[i].conf.http2 = addr[i].opt.http2;
-#endif
-        addrs6[i].conf.proxy_protocol = addr[i].opt.proxy_protocol;
-
-        if (addr[i].hash.buckets == NULL
-            && (addr[i].wc_head == NULL
-                || addr[i].wc_head->hash.buckets == NULL)
-            && (addr[i].wc_tail == NULL
-                || addr[i].wc_tail->hash.buckets == NULL)
-#if (NGX_PCRE)
-            && addr[i].nregex == 0
-#endif
-            )
-        {
-            continue;
-        }
-
-        vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
-        if (vn == NULL) {
-            return NGX_ERROR;
-        }
-
-        addrs6[i].conf.virtual_names = vn;
+        addrs[i].conf.virtual_names = vn;
 
         vn->names.hash = addr[i].hash;
         vn->names.wc_head = addr[i].wc_head;
@@ -1903,6 +1838,71 @@ ngx_http_add_addrs6(ngx_conf_t *cf, ngx_
     return NGX_OK;
 }
 
+
+#if (NGX_HAVE_INET6)
+
+static ngx_int_t
+ngx_http_add_addrs6(ngx_conf_t *cf, ngx_http_port_t *hport,
+    ngx_http_conf_addr_t *addr)
+{
+    ngx_uint_t                 i;
+    ngx_http_in6_addr_t       *addrs6;
+    struct sockaddr_in6       *sin6;
+    ngx_http_virtual_names_t  *vn;
+
+    hport->addrs = ngx_pcalloc(cf->pool,
+                               hport->naddrs * sizeof(ngx_http_in6_addr_t));
+    if (hport->addrs == NULL) {
+        return NGX_ERROR;
+    }
+
+    addrs6 = hport->addrs;
+
+    for (i = 0; i < hport->naddrs; i++) {
+
+        sin6 = &addr[i].opt.sockaddr.sockaddr_in6;
+        addrs6[i].addr6 = sin6->sin6_addr;
+        addrs6[i].conf.default_server = addr[i].default_server;
+#if (NGX_HTTP_SSL)
+        addrs6[i].conf.ssl = addr[i].opt.ssl;
+#endif
+#if (NGX_HTTP_V2)
+        addrs6[i].conf.http2 = addr[i].opt.http2;
+#endif
+        addrs6[i].conf.proxy_protocol = addr[i].opt.proxy_protocol;
+
+        if (addr[i].hash.buckets == NULL
+            && (addr[i].wc_head == NULL
+                || addr[i].wc_head->hash.buckets == NULL)
+            && (addr[i].wc_tail == NULL
+                || addr[i].wc_tail->hash.buckets == NULL)
+#if (NGX_PCRE)
+            && addr[i].nregex == 0
+#endif
+            )
+        {
+            continue;
+        }
+
+        vn = ngx_palloc(cf->pool, sizeof(ngx_http_virtual_names_t));
+        if (vn == NULL) {
+            return NGX_ERROR;
+        }
+
+        addrs6[i].conf.virtual_names = vn;
+
+        vn->names.hash = addr[i].hash;
+        vn->names.wc_head = addr[i].wc_head;
+        vn->names.wc_tail = addr[i].wc_tail;
+#if (NGX_PCRE)
+        vn->nregex = addr[i].nregex;
+        vn->regex = addr[i].regex;
+#endif
+    }
+
+    return NGX_OK;
+}
+
 #endif
 
 
diff -r bdf64ae3376b -r cebf5fed00bf src/http/ngx_http_core_module.c
--- a/src/http/ngx_http_core_module.c	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/http/ngx_http_core_module.c	Mon Oct 03 15:58:25 2016 +0300
@@ -3939,7 +3939,7 @@ ngx_http_core_listen(ngx_conf_t *cf, ngx
     lsopt.fastopen = -1;
 #endif
     lsopt.wildcard = u.wildcard;
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
     lsopt.ipv6only = 1;
 #endif
 
diff -r bdf64ae3376b -r cebf5fed00bf src/http/ngx_http_core_module.h
--- a/src/http/ngx_http_core_module.h	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/http/ngx_http_core_module.h	Mon Oct 03 15:58:25 2016 +0300
@@ -69,7 +69,7 @@ typedef struct {
     unsigned                   ssl:1;
 #endif
     unsigned                   http2:1;
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
     unsigned                   ipv6only:1;
 #endif
 #if (NGX_HAVE_REUSEPORT)
diff -r bdf64ae3376b -r cebf5fed00bf src/mail/ngx_mail.c
--- a/src/mail/ngx_mail.c	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/mail/ngx_mail.c	Mon Oct 03 15:58:25 2016 +0300
@@ -341,7 +341,7 @@ ngx_mail_optimize_servers(ngx_conf_t *cf
             ls->keepcnt = addr[i].opt.tcp_keepcnt;
 #endif
 
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
             ls->ipv6only = addr[i].opt.ipv6only;
 #endif
 
diff -r bdf64ae3376b -r cebf5fed00bf src/mail/ngx_mail.h
--- a/src/mail/ngx_mail.h	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/mail/ngx_mail.h	Mon Oct 03 15:58:25 2016 +0300
@@ -38,7 +38,7 @@ typedef struct {
 #if (NGX_MAIL_SSL)
     unsigned                ssl:1;
 #endif
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
     unsigned                ipv6only:1;
 #endif
     unsigned                so_keepalive:2;
diff -r bdf64ae3376b -r cebf5fed00bf src/mail/ngx_mail_core_module.c
--- a/src/mail/ngx_mail_core_module.c	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/mail/ngx_mail_core_module.c	Mon Oct 03 15:58:25 2016 +0300
@@ -353,7 +353,7 @@ ngx_mail_core_listen(ngx_conf_t *cf, ngx
     ls->wildcard = u.wildcard;
     ls->ctx = cf->ctx;
 
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
     ls->ipv6only = 1;
 #endif
 
diff -r bdf64ae3376b -r cebf5fed00bf src/stream/ngx_stream.c
--- a/src/stream/ngx_stream.c	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/stream/ngx_stream.c	Mon Oct 03 15:58:25 2016 +0300
@@ -506,7 +506,7 @@ ngx_stream_optimize_servers(ngx_conf_t *
             ls->keepcnt = addr[i].opt.tcp_keepcnt;
 #endif
 
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
             ls->ipv6only = addr[i].opt.ipv6only;
 #endif
 
diff -r bdf64ae3376b -r cebf5fed00bf src/stream/ngx_stream.h
--- a/src/stream/ngx_stream.h	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/stream/ngx_stream.h	Mon Oct 03 15:58:25 2016 +0300
@@ -52,7 +52,7 @@ typedef struct {
 #if (NGX_STREAM_SSL)
     unsigned                       ssl:1;
 #endif
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
     unsigned                       ipv6only:1;
 #endif
 #if (NGX_HAVE_REUSEPORT)
diff -r bdf64ae3376b -r cebf5fed00bf src/stream/ngx_stream_core_module.c
--- a/src/stream/ngx_stream_core_module.c	Mon Oct 03 15:58:22 2016 +0300
+++ b/src/stream/ngx_stream_core_module.c	Mon Oct 03 15:58:25 2016 +0300
@@ -624,7 +624,7 @@ ngx_stream_core_listen(ngx_conf_t *cf, n
     ls->wildcard = u.wildcard;
     ls->ctx = cf->ctx;
 
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
+#if (NGX_HAVE_INET6)
     ls->ipv6only = 1;
 #endif
 



More information about the nginx-devel mailing list