]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
get_default_gateway(): Prevent passing IPV4_INVALID_ADDR as a destination
authorMarco Baffo <marco@mandelbit.com>
Fri, 14 Feb 2025 15:34:34 +0000 (16:34 +0100)
committerGert Doering <gert@greenie.muc.de>
Fri, 14 Feb 2025 16:02:33 +0000 (17:02 +0100)
When using --redirect-gateway (IPv4) while connected to an IPv6 remote,
OpenVPN still attempts to determine the IPv4 default gateway,
so link_socket_current_remote() returns IPV4_INVALID_ADDR (0xffffffff)
as the destination, leading to unintended behavior:

- the IPv4 default gateway (rl->rgi.gateway.addr) gets wiped.
- this prevents proper restoration of the original route when needed.

To fix this, if link_socket_current_remote() returns IPV4_INVALID_ADDR,
we now pass INADDR_ANY (0x00000000) to get_default_gateway(),
ensuring the function behaves correctly.

Change-Id: I02afe6817433ca21aae76671c35151ec6a066933
Signed-off-by: Marco Baffo <marco@mandelbit.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250214153434.18539-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30895.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/route.c

index d895e1c2859dd8216c5cd1144eb023b352d45545..bc41492bad521ea0e8565c4432acfc718a05b193 100644 (file)
@@ -655,7 +655,7 @@ init_route_list(struct route_list *rl,
         rl->spec.flags |= RTSA_DEFAULT_METRIC;
     }
 
-    get_default_gateway(&rl->rgi, remote_host, ctx);
+    get_default_gateway(&rl->rgi, remote_host != IPV4_INVALID_ADDR ? remote_host : INADDR_ANY, ctx);
     if (rl->rgi.flags & RGI_ADDR_DEFINED)
     {
         setenv_route_addr(es, "net_gateway", rl->rgi.gateway.addr, -1);