From: "mrbff (Code Review)" Date: Thu, 18 Jul 2024 14:03:31 +0000 References: Reply-To: marco@...2726..., arne-openvpn@...1227..., 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="gMKTu+h8tNQ="; 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: openvpn-devel --gMKTu+h8tNQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/677?usp=3Demail to review the following change. 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, 31 insertions(+), 3 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/77/677/1 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 91f2032..bc8f561 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,20 @@ struct argv argv =3D argv_new(); struct gc_arena gc =3D gc_new(); -#if !defined(TARGET_LINUX) +#if defined(TARGET_LINUX) + const char *iface =3D tt->actual_name; + if (rgi && rgi->iface[0] !=3D '\0') /* vpn server special route */ + { + iface =3D rgi->iface; + if (r->gateway !=3D 0) + { + gateway_needed =3D true; + } + } +#endif + 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 +1607,22 @@ goto done; } + 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; int metric =3D -1; if (is_on_link(is_local_route, flags, rgi)) @@ -1610,7 +1637,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: 1 Gerrit-Owner: mrbff Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --gMKTu+h8tNQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

mrbff would like plaisthos and flichtenheld to review t= his change.

Vi= ew Change

route: copied 'gateway_needed' logic from add_route_i=
pv6 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<= br>therefore this patch copies the same logic to add_route().

Change= -Id: Id1ec0c6e4c391604ec5dbb8b7122f2e47ad186d1
Signed-off-by: Marco Baff= o <marco@...2726...>
---
M src/openvpn/route.c
1 file change= d, 31 insertions(+), 3 deletions(-)

git pull ssh://gerrit.openvpn=
.net:29418/openvpn refs/changes/77/677/1
diff --git a/src/openvpn/r=
oute.c b/src/openvpn/route.c
index 91f2032..bc8f561 100644<= /span>
--- 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 & R= T_DEFINED))
{
@@ -1580,8 +1581,20 @@
struct argv argv =3D argv_new();
s= truct gc_arena gc =3D gc_new();

-#if !defined(TARGET_LINUX)
+#if defined(TARGET_LINUX)
+ const char *iface =3D tt->a= ctual_name;

+ if (= rgi && rgi->iface[0] !=3D '\0') /* vpn server special r= oute */
+ {=
+ iface =3D rgi->= iface;
+ if (r= ->gateway !=3D 0)
= + {
+ = gateway_needed =3D true;
+ }
+ = }
+#endif+
const c= har *network =3D print_in_addr_t(r->network, 0, &gc);
+#if !defined(TARGET_LINUX)
<= br> #if !defined(TARGET_AIX)
const char *netmask= =3D print_in_addr_t(r->netmask, 0, &gc);
#endif
@@ -1594,8 +1607,22 @@
goto done;
}

+ if (tt->type =3D=3D DEV_TYPE_TAP && !(r-&= gt;flags & RT_METRIC_DEFINED && r->metric =3D=3D 0))<= br>+ {
+ gateway_needed =3D true;+ }
+
+ if (gateway_needed && r->gateway =3D=3D 0)
+ {
+ msg(M_WARN, "ROUTE WARN= ING: " PACKAGE_NAME " needs a gateway "
+ "parameter for a --rout= e option and no default was set via "
+ "--route-gateway or --ifconfig opti= on. Not installing "
+ "IPv4 route to %s/%d.", network, netmask_to_net= bits2(r->netmask));
+ goto done;
+ }
+ #if defined(TARGET_LINUX)
- const char *iface =3D NULL;
int metric= =3D -1;

if (is_on_link(is_local_rou= te, flags, rgi))
@@ -1610,7 +1637,8 @@

status =3D RTA_SUCCESS;
int ret =3D= net_route_v4_add(ctx, &r->network, netmask_to_netbits2(r->netmas= k),
- = &r->gateway, iface, 0, metric);
+ gateway_ne= eded ? &r->gateway : NULL,
+ iface, 0, metric);
<= span> if (ret =3D=3D -EEXIST)

{
= msg(D_ROUTE, "NOTE: Linux route add command failed because rout= e 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: 1
Gerrit-Owner: mrbff <marco@...2726...> <= /div>
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: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--gMKTu+h8tNQ=--