]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
tun-device: Fix setting IPv6 address on Linux
authorTobias Brunner <tobias@strongswan.org>
Mon, 18 May 2026 13:41:04 +0000 (15:41 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 19 May 2026 15:27:33 +0000 (17:27 +0200)
Unlike `struct ifreq` that's used for IPv4, `struct in6_ifreq` contains
not a `struct sockaddr[_in6]` but only a `struct in6_addr`.

Setting addresses like this is currently not used on Linux (the feature
was added to install virtual IPs on FreeBSD/macOS).

Fixes: fccc76449dc5 ("tun-device: Fix handling of IPv6 addresses")
src/libstrongswan/networking/tun_device.c

index 49cb54f4ebc01612575725fae9d2cf9cc2a404e1..34785fe403f1c7e84fb59c513874e35eebb8f82d 100644 (file)
@@ -159,6 +159,7 @@ static bool set_address_v4(private_tun_device_t *this, host_t *addr,
 static bool set_address_v6(private_tun_device_t *this, host_t *addr,
                                                   uint8_t netmask)
 {
+       struct sockaddr_in6 *sin6;
        struct in6_ifreq ifr6 = {0};
        struct ifreq ifr = {0};
 
@@ -170,8 +171,8 @@ static bool set_address_v6(private_tun_device_t *this, host_t *addr,
                return FALSE;
        }
 
-       memcpy(&ifr6.ifr6_addr, addr->get_sockaddr(addr),
-                  *addr->get_sockaddr_len(addr));
+       sin6 = (struct sockaddr_in6*)addr->get_sockaddr(addr);
+       memcpy(&ifr6.ifr6_addr, &sin6->sin6_addr, sizeof(ifr6.ifr6_addr));
        ifr6.ifr6_prefixlen = netmask;
        ifr6.ifr6_ifindex = ifr.ifr_ifindex;
        if (ioctl(this->sock_v6, SIOCSIFADDR, &ifr6) < 0)