]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
socket-default: Use IPv6-only mode for IPv6 sockets
authorTobias Brunner <tobias@strongswan.org>
Thu, 22 Sep 2022 15:33:52 +0000 (17:33 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 22 Sep 2022 15:33:52 +0000 (17:33 +0200)
Otherwise, we can't open a dedicated IPv4 socket on the same port as the
IPv6 socket already is set up do receive IPv4 packets (unless we'd again
enable SO_REUSEADDR).

Fixes: 83da13371292 ("socket-default: Don't set SO_REUSEADDR on IKE sockets anymore")
src/libcharon/plugins/socket_default/socket_default_socket.c

index f55171017741a9fdec66158898078f9e40d683ed..89d2ac15c84e7c3830e441314a50af763afb5f0e 100644 (file)
@@ -699,6 +699,14 @@ static int open_socket(private_socket_default_socket_t *this,
                return -1;
        }
 
+       if (family == AF_INET6 &&
+               setsockopt(skt, SOL_IPV6, IPV6_V6ONLY, &on, sizeof(on)) < 0)
+       {
+               DBG1(DBG_NET, "unable to set IPV6_V6ONLY on socket: %s", strerror(errno));
+               close(skt);
+               return -1;
+       }
+
        /* bind the socket */
        if (bind(skt, &addr.sockaddr, addrlen) < 0)
        {