From: "mrbff (Code Review)" Date: Fri, 14 Feb 2025 15:04:13 +0000 In-Reply-To: References: Reply-To: marco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: <93dd934e69ce858c3135e93295b3abc8843ae21f-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Be9hSDoc4/U="; 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: plaisthos , cron2 , flichtenheld Cc: openvpn-devel --Be9hSDoc4/U= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, mrbff, plaisthos. Hello cron2, flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/898?usp=3Demail to look at the new patch set (#3). The following approvals got outdated and were removed: Code-Review+2 by cron2 The change is no longer submittable: Code-Review and checks~ChecksSubmitRul= e are unsatisfied now. 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 --- M src/openvpn/route.c 1 file changed, 1 insertion(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/98/898/3 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: 3 Gerrit-Owner: mrbff Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-Attention: mrbff Gerrit-MessageType: newpatchset --Be9hSDoc4/U= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, mrbff, plais= thos.

mrbff uploaded patch set #3 to this change.

View Change

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

The change is no longer submittable: Code-Revi= ew and checks~ChecksSubmitRule are unsatisfied now.

get_default_gateway(): =
Prevent passing IPV4_INVALID_ADDR as a destination

When using --redi= rect-gateway (IPv4) while connected to an IPv6 remote,
OpenVPN still att= empts to determine the IPv4 default gateway,
so link_socket_current_remo= te() returns IPV4_INVALID_ADDR (0xffffffff)
as the destination, leading = to unintended behavior:

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

To fix this, if link_socket_current_remote() retu= rns IPV4_INVALID_ADDR,
we now pass INADDR_ANY (0x00000000) to get_defaul= t_gateway(),
ensuring the function behaves correctly.

Change-Id: = I02afe6817433ca21aae76671c35151ec6a066933
Signed-off-by: Marco Baffo <= ;marco@...2726...>
---
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/3
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: 3
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-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: mrbff <marco@...2726...&g= t;
Gerrit-MessageType: newpatchset
--Be9hSDoc4/U=--