From: "mrbff (Code Review)" Date: Thu, 19 Sep 2024 12:54:55 +0000 In-Reply-To: References: Reply-To: marco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: <4718d941c57ce7fb58af1e215aa19cc5a773e25c-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="fcD8PH4vo+Q="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: route: copied 'gateway_needed' logic from add_route_ipv6 to add_route List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: cron2 , openvpn-devel --fcD8PH4vo+Q= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, mrbff, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/677?usp=3Demail to look at the new patch set (#10). Change subject: route: copied 'gateway_needed' logic from add_route_ipv6 to= add_route ...................................................................... route: copied 'gateway_needed' logic from add_route_ipv6 to add_route Under certain circumstances it may not be necessary to pass the gateway when adding a new route via net_route_v4_add() API function. add_route_ipv6() already accounts for some of these cases and therefore this patch copies the same logic to add_route(). Change-Id: Id1ec0c6e4c391604ec5dbb8b7122f2e47ad186d1 Signed-off-by: Marco Baffo --- M src/openvpn/route.c 1 file changed, 36 insertions(+), 3 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/77/677/10 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 91f2032..ae7707c 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1571,6 +1571,7 @@ { int status =3D 0; int is_local_route; + bool gateway_needed =3D false; if (!(r->flags & RT_DEFINED)) { @@ -1580,8 +1581,8 @@ struct argv argv =3D argv_new(); struct gc_arena gc =3D gc_new(); -#if !defined(TARGET_LINUX) const char *network =3D print_in_addr_t(r->network, 0, &gc); +#if !defined(TARGET_LINUX) #if !defined(TARGET_AIX) const char *netmask =3D print_in_addr_t(r->netmask, 0, &gc); #endif @@ -1594,8 +1595,39 @@ goto done; } +#ifndef _WIN32 + if (rgi && (rgi->flags & RGI_IFACE_DEFINED) && rgi->iface[0] !=3D 0) = /* vpn server special route */ + { + if (rgi->flags & RGI_ADDR_DEFINED && r->gateway !=3D 0) + { + gateway_needed =3D true; + } + } +#endif + + if (tt->type =3D=3D DEV_TYPE_TAP + && !( (r->flags & RT_METRIC_DEFINED) && r->metric =3D=3D 0 ) ) + { + gateway_needed =3D true; + } + + if (gateway_needed && r->gateway =3D=3D 0) + { + msg(M_WARN, "ROUTE WARNING: " PACKAGE_NAME " needs a gateway " + "parameter for a --route option and no default was set via " + "--route-gateway or --ifconfig option. Not installing " + "IPv4 route to %s/%d.", network, netmask_to_netbits2(r->netmas= k)); + status =3D 0; + goto done; + } + #if defined(TARGET_LINUX) - const char *iface =3D NULL; + const char *iface =3D tt->actual_name; + if (!gateway_needed && rgi && (rgi->flags & RGI_IFACE_DEFINED) && rgi-= >iface[0] !=3D 0) /* vpn server special route */ + { + iface =3D rgi->iface; + } + int metric =3D -1; if (is_on_link(is_local_route, flags, rgi)) @@ -1610,7 +1642,8 @@ status =3D RTA_SUCCESS; int ret =3D net_route_v4_add(ctx, &r->network, netmask_to_netbits2(r->= netmask), - &r->gateway, iface, 0, metric); + gateway_needed ? &r->gateway : NULL, + iface, 0, metric); if (ret =3D=3D -EEXIST) { msg(D_ROUTE, "NOTE: Linux route add command failed because route e= xists"); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/677?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: Id1ec0c6e4c391604ec5dbb8b7122f2e47ad186d1 Gerrit-Change-Number: 677 Gerrit-PatchSet: 10 Gerrit-Owner: mrbff Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: mrbff Gerrit-MessageType: newpatchset --fcD8PH4vo+Q= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, mrbff, plaisthos. <= /p>

mrbff uploaded patch set #10 to this change.

View Change

route: copied 'gateway_needed' logic from add_route_ipv6 to add_=
route

Under certain circumstances it may not be necessary to pass th= e
gateway when adding a new route via net_route_v4_add() API function.add_route_ipv6() already accounts for some of these cases and
therefor= e this patch copies the same logic to add_route().

Change-Id: Id1ec0= c6e4c391604ec5dbb8b7122f2e47ad186d1
Signed-off-by: Marco Baffo <marco= @...2726...>
---
M src/openvpn/route.c
1 file changed, 36 inser= tions(+), 3 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/=
openvpn refs/changes/77/677/10
diff --git a/src/openvpn/route.c b/s=
rc/openvpn/route.c
index 91f2032..ae7707c 100644
= --- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -1571,6 +1571,7 @@
{
= int status =3D 0;
int is_local_route;
+ bool gateway_needed =3D false;=


if (!(r->flags & RT_DEFINED)= )
{
@@ -1580,8 +1581,8 @@
struct argv argv =3D argv_new();
struct gc_ar= ena gc =3D gc_new();

-#if !defined(TARGET_LINUX)
const char= *network =3D print_in_addr_t(r->network, 0, &gc);
+#if !defined(TARGET_LINUX)
= #if !defined(TARGET_AIX)
const char *netmask = =3D print_in_addr_t(r->netmask, 0, &gc);
#endif
@@ -1594,8 +1595,39 @@
goto done;
}

+#ifndef _WIN32
+ if (rgi && (rgi->flags & RGI_IFACE_DEFINED)= && rgi->iface[0] !=3D 0) /* vpn server special route */=
+ {
+ if (rgi->flags & RGI_ADDR= _DEFINED && r->gateway !=3D 0)
+ {
+ gateway_needed =3D true;
+ }
+ }
+#endif
+<= br>+ if (tt->type =3D=3D = DEV_TYPE_TAP
+ = && !( (r->flags & RT_METRIC_DEFINED) && r->metri= c =3D=3D 0 ) )
+ {=
+ gateway_nee= ded =3D true;
+ }<= /span>
+
+ if (gateway_needed && r->= ;gateway =3D=3D 0)
+ = {
+ msg(M_W= ARN, "ROUTE WARNING: " PACKAGE_NAME " needs a gateway "=
+ "p= arameter for a --route option and no default was set via "
<= span style=3D"color: hsl(120, 100%, 40%);">+ "--route-gatew= ay or --ifconfig option. Not installing "

+ "IPv4 route to %s/%d.", ne= twork, netmask_to_netbits2(r->netmask));
+ status =3D 0;
+ goto done;
+ }
+
#if defined(TARGET_LINUX)
- const char *iface =3D NULL;
= + const char *iface =3D tt-&= gt;actual_name;
+ = if (!gateway_needed && rgi && (rgi->flags & RGI_IFAC= E_DEFINED) && rgi->iface[0] !=3D 0) /* vpn server special route= */
+ {
= + iface =3D rgi->ifac= e;
+ }
<= span style=3D"color: hsl(120, 100%, 40%);">+

int metri= c =3D -1;

if (is_on_link(is_local_ro= ute, flags, rgi))
@@ -1610,7 +1642,8 @@

status =3D RTA_SUCCESS;
int ret = =3D net_route_v4_add(ctx, &r->network, netmask_to_netbits2(r->net= mask),
- = &r->gateway, iface, 0, metric);
+ gateway_n= eeded ? &r->gateway : NULL,
+ iface, 0, metric);
= if (ret =3D=3D -EEXIST)
{
= msg(D_ROUTE, "NOTE: Linux route add command failed because rou= te exists");

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id1ec0c6e4c391604ec5dbb8b712= 2f2e47ad186d1
Gerrit-Change-Number: 677
Gerrit-PatchSet: 10
Gerrit-Owner: mrbff <marco@...2726...> <= /div>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: cron2 <gert@...1296...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: mrbff <marco@...2726...&g= t;
Gerrit-MessageType: newpatchset
--fcD8PH4vo+Q=--