From: "mrbff (Code Review)" Date: Thu, 5 Sep 2024 13:18:42 +0000 In-Reply-To: References: Reply-To: marco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <23e55ac7226785333942ba5ac35448bdb1e8ea65-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="cGbhOdG/ENc="; 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 --cGbhOdG/ENc= 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 (#6). The following approvals got outdated and were removed: Code-Review-1 by flichtenheld 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, 40 insertions(+), 3 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/77/677/6 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 91f2032..2033433 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,43 @@ 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; + } +#endif + +#if defined(TARGET_LINUX) int metric =3D -1; if (is_on_link(is_local_route, flags, rgi)) @@ -1610,7 +1646,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: 6 Gerrit-Owner: mrbff Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: mrbff Gerrit-MessageType: newpatchset --cGbhOdG/ENc= 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 #6 to this change.

View Change

The following approvals got outdated and were removed: Code-Review-1 by flichtenheld

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_rou= te_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-of= f-by: Marco Baffo <marco@...2726...>
---
M src/openvpn/route.c<= br>1 file changed, 40 insertions(+), 3 deletions(-)

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

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

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

}

+#ifndef _WIN32

+
+ if (rgi && (rgi->flags & RGI_IFACE_DEF= INED) && 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;<= /span>
+ }
+

+ if (gateway_needed && r->gateway =3D= =3D 0)
+ {<= br>+ msg(M_WARN, "R= OUTE WARNING: " PACKAGE_NAME " needs a gateway "
<= span style=3D"color: hsl(120, 100%, 40%);">+ "parameter for= a --route option and no default was set via "
+ "--route-gateway or --if= config option. Not installing "
+ "IPv4 route to %s/%d.", network, net= mask_to_netbits2(r->netmask));
+ status =3D 0;
+ goto done;
+ }
= +
#if defined(TARGET_LINUX)
- const char *iface =3D NULL;
+ const char *iface =3D tt->actual_= name;
+ if (!gatew= ay_needed && rgi && (rgi->flags & RGI_IFACE_DEFINED)= && rgi->iface[0] !=3D 0) /* vpn server special route */=
+ {
+ iface =3D rgi->iface;<= br>+ }
+#endif
+
+#if defined(TARGET_LINUX)
int metric =3D -1;<= br>
if (is_on_link(is_local_route, flags, rgi))=
@@ -1610,7 +1646,8 @@

= status =3D RTA_SUCCESS;
int ret =3D net_route_v4_ad= d(ctx, &r->network, netmask_to_netbits2(r->netmask),
- &am= p;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 exists");

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

<= /div>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Id1ec0c6e4c391604ec5dbb8b712= 2f2e47ad186d1
Gerrit-Change-Number: 677
Gerrit-PatchSet: 6
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-Attention: mrbff <marco@...2726...&g= t;
Gerrit-MessageType: newpatchset
--cGbhOdG/ENc=--