PATCH: innd: seperate sockets for IPv4 and IPV6

Julien ÉLIE julien at trigofacile.com
Sun Mar 23 19:16:04 UTC 2008


Hi Miquel,

> This patch makes innd listen on seperate sockets for IPv4 and IPv6
> connections if the IPV6_V6ONLY socketoption is available.

Does it look good if I modify bind_ipv6() in backends/innbind.c as follows?
  [I do not use your condition:
    if (addr_specified == 0 && addr6_specified == 0)
  ]

Does anyone have the IPV6_V6ONLY socket option to test if it works?


#ifdef HAVE_INET6
static bool
bind_ipv6(int fd, const char *address, unsigned short port, const char *spec)
{
     struct sockaddr_in6 server;
     struct in6_addr addr;

+    /* If we have the IPV6_V6ONLY socket option, and it works,
+     * always open separate IPv4 and IPv6 sockets. */
+#ifdef IPV6_V6ONLY
+    int i, j;
+
+    j = socket(PF_INET6, SOCK_STREAM, 0);
+    if (j >= 0) {
+        i = 1;
+        if (setsockopt (j, IPPROTO_IPV6, IPV6_V6ONLY, &i, sizeof(i)) == 0) {
+            if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &i, sizeof(i)) < 0)
+                syswarn("cannot set IPV6_V6ONLY");
+        }
+        close(j);
+    }
+#endif
+
     memset(&server, '\0', sizeof(server));
     server.sin6_family = AF_INET6;
     server.sin6_port = htons(port);
    if (inet_pton(AF_INET6, address, &addr) < 1)
        die("invalid IPv6 address %s in %s", address, spec);
    server.sin6_addr = addr;
    sin6_set_length(&server);
    if (bind(fd, (struct sockaddr *) &server, sizeof(server)) < 0) {
        if (errno == EACCES)
            return false;
        else
            sysdie("cannot bind socket for %s", spec);
    }
    return true;
}
#endif /* HAVE_INET6 */


-- 
Julien ÉLIE

« -- Maintenant les Romains sont alertés.
  -- En tout cas, ceux-là ne sont plus très alertes ! » (Astérix)



More information about the inn-workers mailing list