From: "cron2 (Code Review)" Date: Fri, 14 Feb 2025 16:03:51 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., marco@...2726..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="oGNpTLRX7Sk="; charset=UTF-8 Subject: [Openvpn-devel] [XS] Change in openvpn[master]: get_default_gateway(): Prevent passing IPV4_INVALID_ADDR as a destina... List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: mrbff , plaisthos , flichtenheld Cc: openvpn-devel --oGNpTLRX7Sk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#4) to the change originally created by= mrbff. ( http://gerrit.openvpn.net/c/openvpn/+/898?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: get_default_gateway(): Prevent passing IPV4_INVALID_ADDR as= a destination ...................................................................... get_default_gateway(): Prevent passing IPV4_INVALID_ADDR as a destination 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 Acked-by: Gert Doering Message-Id: <20250214153434.18539-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30= 895.html Signed-off-by: Gert Doering --- M src/openvpn/route.c 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/98/898/4 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index d895e1c..bc41492 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -655,7 +655,7 @@ rl->spec.flags |=3D RTSA_DEFAULT_METRIC; } - get_default_gateway(&rl->rgi, remote_host, ctx); + get_default_gateway(&rl->rgi, remote_host !=3D IPV4_INVALID_ADDR ? rem= ote_host : INADDR_ANY, ctx); if (rl->rgi.flags & RGI_ADDR_DEFINED) { setenv_route_addr(es, "net_gateway", rl->rgi.gateway.addr, -1); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/898?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I02afe6817433ca21aae76671c35151ec6a066933 Gerrit-Change-Number: 898 Gerrit-PatchSet: 4 Gerrit-Owner: mrbff Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --oGNpTLRX7Sk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #4 to the change originally cr= eated by mrbff.

View Change

The following approvals got outdated and= were removed: Code-Review+2 by cron2

get_default_gateway(): Prevent passing IPV4_INVALID_=
ADDR as a destination

When using --redirect-gateway (IPv4) while con= nected to an IPv6 remote,
OpenVPN still attempts to determine the IPv4 d= efault gateway,
so link_socket_current_remote() returns IPV4_INVALID_ADD= R (0xffffffff)
as the destination, leading to unintended behavior:
- the IPv4 default gateway (rl->rgi.gateway.addr) gets wiped.
- thi= s 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: I02afe6817433ca21aae76671c351= 51ec6a066933
Signed-off-by: Marco Baffo <marco@...2726...>
Acke= d-by: Gert Doering <gert@...1296...>
Message-Id: <2025021415343= 4.18539-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-= devel@lists.sourceforge.net/msg30895.html
Signed-off-by: Gert Doering &l= t;gert@...1296...>
---
M src/openvpn/route.c
1 file changed, 1 = insertion(+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net:294=
18/openvpn refs/changes/98/898/4
diff --git a/src/openvpn/route.c b=
/src/openvpn/route.c
index d895e1c..bc41492 100644--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c=
@@ -655,7 +655,7 @@
rl->spec.f= lags |=3D RTSA_DEFAULT_METRIC;
}

- get_default_gateway(&= amp;rl->rgi, remote_host, ctx);
+ get_default_gateway(&rl->rgi, remote_host !=3D IP= V4_INVALID_ADDR ? remote_host : INADDR_ANY, ctx);
if (= rl->rgi.flags & RGI_ADDR_DEFINED)
{
<= span> setenv_route_addr(es, "net_gateway", rl->rgi.gat= eway.addr, -1);


To view, visit change 898. = To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I02afe6817433ca21aae76671c35= 151ec6a066933
Gerrit-Change-Number: 898
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <marco@...2726...> <= /div>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--oGNpTLRX7Sk=--