In some cases, lookups for a given host name returns the same address
multiple times.  Allow this, but ignore any duplicate addresses.
---
 lib/libvcl/vcc_backend.c |   38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/lib/libvcl/vcc_backend.c b/lib/libvcl/vcc_backend.c
index 78cb0b2..5cc98ae 100644
--- a/lib/libvcl/vcc_backend.c
+++ b/lib/libvcl/vcc_backend.c
@@ -106,7 +106,7 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, 
const char *port)
        struct addrinfo *res, *res0, *res1, hint;
        int n4, n6, error, retval, x;
        const char *emit, *multiple;
-       char hbuf[NI_MAXHOST];
+       char hbuf[NI_MAXHOST], v4[NI_MAXHOST], v6[NI_MAXHOST];
        char *hop, *pop;
 
        AN(t_host->dec);
@@ -145,16 +145,36 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, 
const char *port)
 
        for (res = res0; res; res = res->ai_next) {
                emit = NULL;
+
+               error = getnameinfo(res->ai_addr,
+                   res->ai_addrlen, hbuf, sizeof hbuf,
+                   NULL, 0, NI_NUMERICHOST);
+               AZ(error);
+
                if (res->ai_family == PF_INET) {
-                       if (n4++ == 0)
+                       if (n4++ == 0) {
                                emit = "ipv4";
-                       else
-                               multiple = "IPv4";
+                               strcpy(v4, hbuf);
+                       } else {
+                               if (strcmp(v4, hbuf) != 0) {
+                                       multiple = "IPv4";
+                               } else {
+                                       /* Ignore duplicate address */
+                                       continue;
+                               }
+                       }
                } else if (res->ai_family == PF_INET6) {
-                       if (n6++ == 0)
+                       if (n6++ == 0) {
                                emit = "ipv6";
-                       else
-                               multiple = "IPv6";
+                               strcpy(v6, hbuf);
+                       } else {
+                               if (strcmp(v6, hbuf) != 0) {
+                                       multiple = "IPv6";
+                               } else {
+                                       /* Ignore duplicate address */
+                                       continue;
+                               }
+                       }
                } else
                        continue;
 
@@ -179,10 +199,6 @@ Emit_Sockaddr(struct vcc *tl, const struct token *t_host, 
const char *port)
                AN(emit);
                x = emit_sockaddr(tl, res->ai_addr, res->ai_addrlen);
                Fb(tl, 0, "\t.%s_sockaddr = sockaddr%u,\n", emit, x);
-               error = getnameinfo(res->ai_addr,
-                   res->ai_addrlen, hbuf, sizeof hbuf,
-                   NULL, 0, NI_NUMERICHOST);
-               AZ(error);
                Fb(tl, 0, "\t.%s_addr = \"%s\",\n", emit, hbuf);
                retval++;
        }
-- 
1.7.10.4


_______________________________________________
varnish-dev mailing list
varnish-dev@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to