]> granicus.if.org Git - pgbouncer/commitdiff
ipv6: Set IPV6_V6ONLY on listen socket.
authorMarko Kreen <markokr@gmail.com>
Mon, 18 Mar 2013 15:44:15 +0000 (17:44 +0200)
committerMarko Kreen <markokr@gmail.com>
Mon, 18 Mar 2013 15:44:15 +0000 (17:44 +0200)
Otherwise it attempts to take over ipv4 port
which fails if the ipv4 was initialized previously.

Reported-by: Guillaume Lelarge
src/pooler.c

index f2eed47bfd25babdce9a06c6884be137cf0d5400..16cef9c4ef11343256c227d57b664f72d9cf639d 100644 (file)
@@ -106,6 +106,17 @@ static bool add_listen(int af, const struct sockaddr *sa, int salen)
                        goto failed;
        }
 
+#ifdef IPV6_V6ONLY
+       /* avoid ipv6 socket's attempt to takeover ipv4 port */
+       if (af == AF_INET6) {
+               val = 1;
+               errpos = "setsockopt/IPV6_V6ONLY";
+               res = setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val));
+               if (res < 0)
+                       goto failed;
+       }
+#endif
+
        /* bind it */
        errpos = "bind";
        res = bind(sock, sa, salen);