From: "plaisthos (Code Review)" Date: Tue, 16 Sep 2025 13:50:06 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <5e035703013523d210889d8da514154ba70d3a73-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="y9EjhHettlM="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Allowing installing FreeBSD routes with interface instead of next-hop List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --y9EjhHettlM= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1193?usp=3Demail to review the following change. Change subject: Allowing installing FreeBSD routes with interface instead o= f next-hop ...................................................................... Allowing installing FreeBSD routes with interface instead of next-hop This matches the Linux behaviour of the net_route add/delete commands Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5 Signed-off-by: Arne Schwabe --- M src/openvpn/networking_freebsd.c 1 file changed, 35 insertions(+), 11 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/93/1193/1 diff --git a/src/openvpn/networking_freebsd.c b/src/openvpn/networking_free= bsd.c index b47444c..a0e7571 100644 --- a/src/openvpn/networking_freebsd.c +++ b/src/openvpn/networking_freebsd.c @@ -15,17 +15,29 @@ char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN]; in_addr_t _dst, _gw; struct argv argv =3D argv_new(); - bool status; + + ASSERT(gw || iface); _dst =3D ntohl(*dst); - _gw =3D ntohl(*gw); - argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op, - inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen, - inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table); + /* if gw is 0 (=3D0.0.0.0), which is not a valid gateway, + * we are installing a route with the interface as target instead */ + if (gw) + { + _gw =3D ntohl(*gw); + argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op, + inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixl= en, + inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table); + } + else + { + argv_printf(&argv, "%s %s -net %s/%d -iface %s -fib %d", ROUTE_PAT= H, op, + inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixl= en, + iface, table); + } =20 argv_msg(M_INFO, &argv); - status =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route = command failed"); + bool status =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD r= oute command failed"); argv_free(&argv); @@ -38,14 +50,26 @@ { char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN]; struct argv argv =3D argv_new(); - bool status; - argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op, - inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen, - inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table); + ASSERT(gw || iface); + /* if gw is NULL, we are installing a route with the interface as targ= et + * instead */ + if (gw) + { + argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, o= p, + inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixle= n, + inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table); + } + else + { + argv_printf(&argv, "%s -6 %s -net %s/%d -iface %s -fib %d", ROUTE_= PATH, op, + inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixle= n, + iface, table); + } + argv_msg(M_INFO, &argv); - status =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route = command failed"); + bool status =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD r= oute command failed"); argv_free(&argv); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1193?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: I88e16e15fad065cb310d38f09924053efc3a6ce5 Gerrit-Change-Number: 1193 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --y9EjhHettlM= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

V= iew Change

Allowing installing FreeBSD routes with interface instead of=
 next-hop

This matches the Linux behaviour of the net_route add/dele= te commands

Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5
= Signed-off-by: Arne Schwabe <arne@...1227...>
---
M src/openvpn= /networking_freebsd.c
1 file changed, 35 insertions(+), 11 deletions(-)<= br>
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/93/1=
193/1
diff --git a/src/openvpn/networking_freebsd.c b/src/openvpn/n=
etworking_freebsd.c
index b47444c..a0e7571 100644--- a/src/openvpn/networking_freebsd.c
+++ b/src/ope= nvpn/networking_freebsd.c
@@ -15,17 +15,29 @@
char buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
= in_addr_t _dst, _gw;
struct argv argv =3D argv_ne= w();
- bool status;<= /span>
+
+ ASSERT(gw || iface);

_dst =3D ntohl(*dst);
- _gw =3D ntohl(*gw);
- argv_printf(&argv, &qu= ot;%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
- inet_ntop(AF_INET, &_ds= t, buf1, sizeof(buf1)), prefixlen,
- inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2= )), table);
+ /* i= f gw is 0 (=3D0.0.0.0), which is not a valid gateway,
+ * we are installing a route with the= interface as target instead */
+ if (gw)
+ {
+ _g= w =3D ntohl(*gw);
+ = argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE= _PATH, op,
+ = inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
+ in= et_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+ }
+ else
+ {
+ = argv_printf(&argv, "%s %s -net %s/%d -iface %s -fib %d",= ROUTE_PATH, op,
+ = inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixl= en,
+ = iface, table);
+ = }

argv_msg(M_INFO, &argv);
- status =3D openvpn_e= xecve_check(&argv, NULL, 0, "ERROR: FreeBSD route command failed&q= uot;);
+ bool stat= us =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route = command failed");

argv_free(&am= p;argv);

@@ -38,14 +50,26 @@
{

char buf1[INET6_ADDRSTRLEN], buf2[INET6_ADDRSTR= LEN];
struct argv argv =3D argv_new();
- bool status;


- argv_printf(&arg= v, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
- inet_ntop(AF_INET6= , dst, buf1, sizeof(buf1)), prefixlen,

- inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)= ), table);
+ ASSER= T(gw || iface);
+ = /* if gw is NULL, we are installing a route with the interface as target
+ * instead */
+ if (gw)
+ {

+ argv_printf(&argv, "%s -6 %s = -net %s/%d %s -fib %d", ROUTE_PATH, op,
+ inet_ntop(AF_INET6, dst, buf1,= sizeof(buf1)), prefixlen,
+ inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), tab= le);
+ }+ else
+ {
+ argv_printf(&argv, "%s -6 %s -net %s/= %d -iface %s -fib %d", ROUTE_PATH, op,
+ inet_ntop(AF_INET6, dst, buf1, = sizeof(buf1)), prefixlen,
+ iface, table);
+ }
+

argv_msg(M_INFO, &argv);=
- status =3D openvp= n_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route command faile= d");
+ bool s= tatus =3D openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD rou= te command failed");

argv_free(= &argv);


To view, = visit ch= ange 1193. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I88e16e15fad065cb310d38f0992= 4053efc3a6ce5
Gerrit-Change-Number: 1193
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--y9EjhHettlM=--