]> git.kaiwu.me - nginx.git/commitdiff
Removed sorting of getaddrinfo() results.
authorRoman Arutyunyan <arut@nginx.com>
Wed, 20 Mar 2019 17:31:59 +0000 (20:31 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Wed, 20 Mar 2019 17:31:59 +0000 (20:31 +0300)
Previously the ngx_inet_resolve_host() function sorted addresses in a way that
IPv4 addresses came before IPv6 addresses.  This was implemented in eaf95350d75c
(1.3.10) along with the introduction of getaddrinfo() which could resolve host
names to IPv6 addresses.  Since the "listen" directive only used the first
address, sorting allowed to preserve "listen" compatibility with the previous
behavior and with the behavior of nginx built without IPv6 support.  Now
"listen" uses all resolved addresses which makes sorting pointless.

src/core/ngx_inet.c

index d935fbb67c16db9832df1be3c3842f6936fdbf42..dbb9ff22b149394caf30a5c68f3a26688604f9ff 100644 (file)
@@ -1080,24 +1080,15 @@ ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
 
     /* MP: ngx_shared_palloc() */
 
-    /* AF_INET addresses first */
-
     for (rp = res; rp != NULL; rp = rp->ai_next) {
 
-        if (rp->ai_family != AF_INET) {
-            continue;
-        }
-
-        if (ngx_inet_add_addr(pool, u, rp->ai_addr, rp->ai_addrlen, n)
-            != NGX_OK)
-        {
-            goto failed;
-        }
-    }
+        switch (rp->ai_family) {
 
-    for (rp = res; rp != NULL; rp = rp->ai_next) {
+        case AF_INET:
+        case AF_INET6:
+            break;
 
-        if (rp->ai_family != AF_INET6) {
+        default:
             continue;
         }