From: "cron2 (Code Review)" Date: Mon, 6 Oct 2025 16:57:15 +0000 In-Reply-To: References: Reply-To: gert@...1296..., 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="tNf8XDdDBkk="; charset=UTF-8 Subject: [Openvpn-devel] [M] 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: plaisthos Cc: flichtenheld , openvpn-devel --tNf8XDdDBkk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/11= 93?usp=3Demail ) 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 Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1193 Message-Id: <20251006145844.27794-1-gert@...1296...> URL: https://sourceforge.net/p/openvpn/mailman/message/59242876/ Signed-off-by: Gert Doering --- M src/openvpn/networking_freebsd.c 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/openvpn/networking_freebsd.c b/src/openvpn/networking_free= bsd.c index b47444c..04051a6 100644 --- a/src/openvpn/networking_freebsd.c +++ b/src/openvpn/networking_freebsd.c @@ -15,17 +15,31 @@ 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 we have a gateway (GW !=3D NULL) install route to gateway IP + * if not, install "connected" route to interface + * (needed to make 'ifconfig-push IPs outside server subnet' work) + */ + 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); + } 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 +52,29 @@ { 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 we have a gateway (GW !=3D NULL) install route to gateway IP + * if not, install "connected" route to interface + * (needed to make 'ifconfig-push IPs outside server subnet' work) + */ + 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?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I88e16e15fad065cb310d38f09924053efc3a6ce5 Gerrit-Change-Number: 1193 Gerrit-PatchSet: 5 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel --tNf8XDdDBkk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

Allowing installing FreeBSD routes with interfac=
e instead of next-hop

This matches the Linux behaviour of the net_ro= ute add/delete commands

Change-Id: I88e16e15fad065cb310d38f09924053e= fc3a6ce5
Signed-off-by: Arne Schwabe <arne@...1227...>
Gerrit U= RL: https://gerrit.openvpn.net/c/openvpn/+/1193
Message-Id: <20251006= 145844.27794-1-gert@...1296...>
URL: https://sourceforge.net/p/openvp= n/mailman/message/59242876/
Signed-off-by: Gert Doering <gert@...1726...= ...>
---
M src/openvpn/networking_freebsd.c
1 file changed, 40 = insertions(+), 11 deletions(-)

diff --git a/src/openvpn/networking_freebsd.c b/src/openvpn/networking_f=
reebsd.c
index b47444c..04051a6 100644
--- = a/src/openvpn/networking_freebsd.c
+++ b/src/openvpn/networ= king_freebsd.c
@@ -15,17 +15,31 @@
cha= r buf1[INET_ADDRSTRLEN], buf2[INET_ADDRSTRLEN];
in_add= r_t _dst, _gw;
struct argv argv =3D argv_new();=
- bool status;
<= span style=3D"color: hsl(120, 100%, 40%);">+
+ ASSERT(gw || iface);
<= br> _dst =3D ntohl(*dst);
- _gw =3D ntohl(*gw);

- argv_printf(&argv, "%s %s -n= et %s/%d %s -fib %d", ROUTE_PATH, op,
- inet_ntop(AF_INET, &_dst, buf1, si= zeof(buf1)), prefixlen,
- inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);=
+ /* if we have a= gateway (GW !=3D NULL) install route to gateway IP
+ * if not, install "connected&qu= ot; route to interface
+ */
+ if (gw)
+ {

+ _gw =3D ntohl(*gw);
+ argv_printf(&argv, "%s= %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
+ inet_ntop(AF_INET, &_d= st, buf1, sizeof(buf1)), prefixlen,
+ inet_ntop(AF_INET, &_gw, buf2, size= of(buf2)), table);
+ = }
+ else=
+ {
+ argv_printf(&argv, "%s = %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,
+ inet_ntop(AF_INET, &= amp;_dst, buf1, sizeof(buf1)), prefixlen,
+ 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 route command failed");

argv_free(&argv);

= @@ -38,14 +52,29 @@
{
char buf1= [INET6_ADDRSTRLEN], buf2[INET6_ADDRSTRLEN];
struct arg= v 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 we have a gateway (GW !=3D NULL) install route to = gateway IP
+ * if= not, install "connected" route to interface
+ * (needed to make 'ifconfig-pus= h IPs outside server subnet' work)
+ */
+ if (gw)
+ = {
+ argv_pr= intf(&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_INET= 6, gw, buf2, sizeof(buf2)), table);
+ }
+ else
+ {

+ argv_printf(&am= p;argv, "%s -6 %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, op,<= /span>
+ = inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
+ iface, table);
+ }
+

= argv_msg(M_INFO, &argv);
- status =3D openvpn_execve_check(&argv, NULL, 0, "ERR= OR: FreeBSD route command failed");
+ bool status =3D openvpn_execve_check(&argv, NU= LL, 0, "ERROR: FreeBSD route command failed");
<= /span>
argv_free(&argv);


To view, visit change 1193. To unsubscribe, or for help w= riting mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I88e16e15fad065cb310d38f0992= 4053efc3a6ce5
Gerrit-Change-Number: 1193
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --tNf8XDdDBkk=--