From: "cron2 (Code Review)" Date: Thu, 5 Dec 2024 18:38:04 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., alex@...2837..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <1d056af53150e3274782b02de7a38bbcf193b287-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="T9eF5YddQyQ="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Haiku: Add calls to manage routing table List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kallisti5 , plaisthos , flichtenheld Cc: openvpn-devel --T9eF5YddQyQ= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: kallisti5. cron2 has uploaded a new patch set (#12) to the change originally created b= y kallisti5. ( http://gerrit.openvpn.net/c/openvpn/+/688?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+1 by kallisti5, Code-Review+2 by cron2 Change subject: Haiku: Add calls to manage routing table ...................................................................... Haiku: Add calls to manage routing table Note: the full functionality of these changes depends on https://review.haiku-os.org/c/haiku/+/8592 Signed-off-by: Alexander von Gluck Acked-by: Gert Doering Change-Id: I1a22724f28c5cd47f6df178b49f44087d7c2b6fd Message-Id: <20241205172459.4783-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30= 023.html Signed-off-by: Gert Doering --- M src/openvpn/route.c M src/openvpn/syshead.h 2 files changed, 140 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/688/12 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 2e584c7..df06fdf 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1853,7 +1853,21 @@ status =3D ret ? RTA_SUCCESS : RTA_ERROR; } -#else /* if defined(TARGET_LINUX) */ +#elif defined(TARGET_HAIKU) + + /* ex: route add /dev/net/ipro1000/0 0.0.0.0 gw 192.168.1.1 netmask 12= 8.0.0.0 */ + argv_printf(&argv, "%s add %s inet %s gw %s netmask %s", + ROUTE_PATH, + rgi->iface, + network, + gateway, + netmask); + argv_msg(D_ROUTE, &argv); + bool ret =3D openvpn_execve_check(&argv, es, 0, + "ERROR: Haiku inet route add command f= ailed"); + status =3D ret ? RTA_SUCCESS : RTA_ERROR; + +#else /* if defined(TARGET_LINUX) */ msg(M_FATAL, "Sorry, but I don't know how to do 'route' commands on th= is operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ @@ -2126,6 +2140,20 @@ "ERROR: AIX route add command failed"); status =3D ret ? RTA_SUCCESS : RTA_ERROR; +#elif defined(TARGET_HAIKU) + + /* ex: route add /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen = 64 */ + argv_printf(&argv, "%s add %s inet6 %s gw %s prefixlen %d", + ROUTE_PATH, + r6->iface, + network, + gateway, + r6->netbits); + argv_msg(D_ROUTE, &argv); + bool ret =3D openvpn_execve_check(&argv, es, 0, + "ERROR: Haiku inet6 route add command = failed"); + status =3D ret ? RTA_SUCCESS : RTA_ERROR; + #else /* if defined(TARGET_LINUX) */ msg(M_FATAL, "Sorry, but I don't know how to do 'route ipv6' commands = on this operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ @@ -2329,6 +2357,18 @@ openvpn_execve_check(&argv, es, 0, "ERROR: AIX route delete comman= d failed"); } =20 +#elif defined(TARGET_HAIKU) + + /* ex: route del /dev/net/ipro1000/0 inet 192.168.0.0 gw 192.168.1.1 n= etmask 255.255.0.0 */ + argv_printf(&argv, "%s del %s inet %s gw %s netmask %s", + ROUTE_PATH, + rgi->iface, + network, + gateway, + netmask); + argv_msg(D_ROUTE, &argv); + openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet route delete com= mand failed"); + #else /* if defined(TARGET_LINUX) */ msg(M_FATAL, "Sorry, but I don't know how to do 'route' commands on th= is operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ @@ -2504,10 +2544,23 @@ network, r6->netbits, gateway); argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: AIX route add command faile= d"); + #elif defined(TARGET_ANDROID) msg(D_ROUTE_DEBUG, "Deleting routes on Android is not possible/not " "needed. The VpnService API allows routes to be set " "on connect only and will clean up automatically."); +#elif defined(TARGET_HAIKU) + + /* ex: route del /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen = 64 */ + argv_printf(&argv, "%s del %s inet6 %s gw %s prefixlen %d", + ROUTE_PATH, + r6->iface, + network, + gateway, + r6->netbits); + argv_msg(D_ROUTE, &argv); + openvpn_execve_check(&argv, es, 0, "ERROR: Haiku inet6 route delete co= mmand failed"); + #else /* if defined(TARGET_LINUX) */ msg(M_FATAL, "Sorry, but I don't know how to do 'route ipv6' commands = on this operating system. Try putting your routes in a --route-down script= "); #endif /* if defined(TARGET_LINUX) */ @@ -3886,6 +3939,86 @@ #undef max +#elif defined(TARGET_HAIKU) + +void +get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) +{ + CLEAR(*rgi); + + int sockfd =3D socket(AF_INET, SOCK_DGRAM, 0); + if (sockfd < 0) + { + msg(M_ERRNO, "%s: Error opening socket for AF_INET", __func__); + return; + } + + struct ifconf config; + config.ifc_len =3D sizeof(config.ifc_value); + if (ioctl(sockfd, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < 0) + { + msg(M_ERRNO, "%s: Error getting routing table size", __func__); + return; + } + + uint32 size =3D (uint32)config.ifc_value; + if (size =3D=3D 0) + { + return; + } + + void *buffer =3D malloc(size); + check_malloc_return(buffer); + + config.ifc_len =3D size; + config.ifc_buf =3D buffer; + if (ioctl(sockfd, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0) + { + free(buffer); + return; + } + + struct ifreq *interface =3D (struct ifreq *)buffer; + struct ifreq *end =3D (struct ifreq *)((uint8 *)buffer + size); + + while (interface < end) + { + struct route_entry route =3D interface->ifr_route; + if ((route.flags & RTF_GATEWAY) !=3D 0 && (route.flags & RTF_DEFAU= LT) !=3D 0) + { + rgi->gateway.addr =3D ntohl(((struct sockaddr_in *)route.gatew= ay)->sin_addr.s_addr); + rgi->flags =3D RGI_ADDR_DEFINED | RGI_IFACE_DEFINED; + strncpy(rgi->iface, interface->ifr_name, sizeof(rgi->iface)); + } + + int32 address_size =3D 0; + if (route.destination !=3D NULL) + { + address_size +=3D route.destination->sa_len; + } + if (route.mask !=3D NULL) + { + address_size +=3D route.mask->sa_len; + } + if (route.gateway !=3D NULL) + { + address_size +=3D route.gateway->sa_len; + } + + interface =3D (struct ifreq *)((addr_t)interface + IF_NAMESIZE + + sizeof(struct route_entry) + addres= s_size); + } + free(buffer); +} + +void +get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6, + const struct in6_addr *dest, openvpn_net_ctx_t *c= tx) +{ + /* TODO: Same for ipv6 with AF_INET6 */ + CLEAR(*rgi6); +} + #else /* if defined(_WIN32) */ /* diff --git a/src/openvpn/syshead.h b/src/openvpn/syshead.h index 33a90c1..844e47a 100644 --- a/src/openvpn/syshead.h +++ b/src/openvpn/syshead.h @@ -166,6 +166,12 @@ #include #endif +#if defined(TARGET_HAIKU) +#include /* uint32, etc */ +#include /* ifconf etc */ +#include /* SIOCGRTTABLE, etc */ +#endif /* TARGET_HAIKU */ + #ifdef HAVE_ARPA_INET_H #include #endif -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/688?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: I1a22724f28c5cd47f6df178b49f44087d7c2b6fd Gerrit-Change-Number: 688 Gerrit-PatchSet: 12 Gerrit-Owner: kallisti5 Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: kallisti5 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: kallisti5 Gerrit-MessageType: newpatchset --T9eF5YddQyQ= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: kallisti5.

cron2 uploaded patch set #12 to the change originally c= reated by kallisti5.

View Change

The following approvals got outdate= d and were removed: Code-Review+1 by kallisti5, Code-Review+2 by cron2

Haiku: Add calls to mana=
ge routing table

Note: the full functionality of these changes depen= ds on
https://review.haiku-os.org/c/haiku/+/8592

Signed-off= -by: Alexander von Gluck <alex@...2837...>
Acked-by: Gert Doering = <gert@...1296...>
Change-Id: I1a22724f28c5cd47f6df178b49f44087d7c2= b6fd
Message-Id: <20241205172459.4783-1-gert@...1296...>
URL: h= ttps://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30023.ht= ml
Signed-off-by: Gert Doering <gert@...1296...>
---
M src/o= penvpn/route.c
M src/openvpn/syshead.h
2 files changed, 140 insertion= s(+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net:29418/openv=
pn refs/changes/88/688/12
diff --git a/src/openvpn/route.c b/src/op=
envpn/route.c
index 2e584c7..df06fdf 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c=
@@ -1853,7 +1853,21 @@
status =3D ret ? = RTA_SUCCESS : RTA_ERROR;
}
-#else /* if defined(TARGET_LIN= UX) */
+#elif defined= (TARGET_HAIKU)
+
+ /* ex: route add /de= v/net/ipro1000/0 0.0.0.0 gw 192.168.1.1 netmask 128.0.0.0 */
+ argv_printf(&argv, "%= s add %s inet %s gw %s netmask %s",

+ ROUTE_PATH,
+ rgi->iface,
+ network,
= + gateway,

+ netmask);=
+ argv_msg(D_ROUT= E, &argv);
+ b= ool ret =3D openvpn_execve_check(&argv, es, 0,
+ "ER= ROR: Haiku inet route add command failed");
+ status =3D ret ? RTA_SUCCESS : RTA_ERROR;<= /span>
+
+#else /* if defined(TARGET_LINUX) */
msg(M_FATAL, "Sorry, but I don't know how to do= 'route' commands on this operating system. Try putting your route= s in a --route-up script");
#endif /* if defined(TARG= ET_LINUX) */

@@ -2126,6 +2140,20 @@

"ERROR: AIX route add = command failed");
status =3D ret ? RTA_SUCCESS : = RTA_ERROR;

+#elif defined(TARGET_HAIKU)
+
+ = /* ex: route add /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen 64 = */
+ argv_printf(&= amp;argv, "%s add %s inet6 %s gw %s prefixlen %d",
+ ROUTE_PATH,=
+ r6->ifa= ce,
+ = network,
+ = gateway,
+ = r6->netbits);
+ argv_msg(D_ROUTE, &argv);
+ bool ret =3D openvpn_execve_check(&argv, es, 0= ,
+ = "ERROR: Haiku inet6 route add command failed");=
+ status =3D ret = ? RTA_SUCCESS : RTA_ERROR;
+
#else /* if defined(TARGET_LINUX) */
msg(M_FATAL, "Sorry, but I don't know how to do 'rout= e ipv6' commands on this operating system. Try putting your routes in = a --route-up script");
#endif /* if defined(TARGET_LI= NUX) */
@@ -2329,6 +2357,18 @@
ope= nvpn_execve_check(&argv, es, 0, "ERROR: AIX route delete command f= ailed");
}

+#elif defined(TARGET_HAIKU)
+
+ /* ex: route del /dev/net/ipro1000/0 inet 192.1= 68.0.0 gw 192.168.1.1 netmask 255.255.0.0 */
+ argv_printf(&argv, "%s del %s inet %s= gw %s netmask %s",
+ ROUTE_PATH,
+ rgi->iface,
+ network,
+ gateway,
+ netmask);
+ argv_msg(D_ROUTE, &argv);
+ openvpn_execve_ch= eck(&argv, es, 0, "ERROR: Haiku inet route delete command failed&q= uot;);
+
#else /* if defined(TARGET_LINUX) */
msg(M_FATAL= , "Sorry, but I don't know how to do 'route' commands on t= his operating system. Try putting your routes in a --route-up script"= );
#endif /* if defined(TARGET_LINUX) */
@= @ -2504,10 +2544,23 @@
network, r6->net= bits, gateway);
argv_msg(D_ROUTE, &argv); openvpn_execve_check(&argv, es, 0, "ERROR: AIX route = add command failed");
+
#elif defined(TARGET_ANDROID)
= msg(D_ROUTE_DEBUG, "Deleting routes on Android is not possible/not &q= uot;
"needed. The VpnService API allows route= s to be set "
"on connect only and will = clean up automatically.");
+#elif defined(TARGET_HAIKU)
+
= + /* ex: route del /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen = 64 */
+ argv_print= f(&argv, "%s del %s inet6 %s gw %s prefixlen %d",
<= span style=3D"color: hsl(120, 100%, 40%);">+ ROUTE_PATH,
+ r6->= iface,
+ = network,
+ = gateway,
+ = r6->netbits);
+ argv_msg(D_ROUTE, &argv);
+ openvpn_execve_check(&argv, es, 0, "ER= ROR: Haiku inet6 route delete command failed");
+
#else /* if defined(TA= RGET_LINUX) */
msg(M_FATAL, "Sorry, but I don'= ;t know how to do 'route ipv6' commands on this operating system. = Try putting your routes in a --route-down script");
#= endif /* if defined(TARGET_LINUX) */
@@ -3886,6 +3939,86 @@=

#undef max

= +#elif defined(TARGET_HAIKU)

+
+void
+get_default_gateway(struct route_gateway_info *rgi, open= vpn_net_ctx_t *ctx)
+= {
+ CLEAR(*rgi);
+
+ int sockfd =3D socket(AF_INET, SOCK_= DGRAM, 0);
+ if (s= ockfd < 0)
+ {<= /span>
+ msg(M_ERRNO,= "%s: Error opening socket for AF_INET", __func__);
+ return;

+ }
+
+ struct ifconf config;
+ config.ifc_len =3D sizeof(config.ifc_value);
+ if (ioctl(sockfd, SIOCGRTSIZE, = &config, sizeof(struct ifconf)) < 0)

+ {
+ msg(M_ERRNO, "%s: Error getting routing table size&q= uot;, __func__);
+ = return;
+ }
+
+ uint32 size =3D (uint32)config.ifc_v= alue;
+ if (size = =3D=3D 0)
+ {

+ return;+ }
+
+ void *buffer =3D malloc(size);
+ check_malloc_return(buffer);
+
+ config.ifc_len =3D size;
+ config.ifc_buf =3D buffer;
= + if (ioctl(sockfd, SIOCGRTT= ABLE, &config, sizeof(struct ifconf)) < 0)
+ {
+ free(buffer);
+ return;
+ }
+=
+ struct ifreq *i= nterface =3D (struct ifreq *)buffer;
+ struct ifreq *end =3D (struct ifreq *)((uint8 *)buffer= + size);
++ while (interface < end= )
+ {
+ struct route_entry route= =3D interface->ifr_route;
+ if ((route.flags & RTF_GATEWAY) !=3D 0 && (ro= ute.flags & RTF_DEFAULT) !=3D 0)
+ {
+ rgi->gateway.addr =3D ntohl(((struct sockaddr_in *)ro= ute.gateway)->sin_addr.s_addr);
+ rgi->flags =3D RGI_ADDR_DEFINED | RGI_IFACE_D= EFINED;
+ = strncpy(rgi->iface, interface->ifr_name, sizeof(rgi->iface));
+ }
+

+ int32 address_size =3D 0;
+ if (route.destination !=3D NULL= )
+ {+ address_size += =3D route.destination->sa_len;
+ }
+ if (route.mask !=3D NULL)
+ {
+ address_size +=3D route.mask->sa_len;
+ }
+ if (route.gateway !=3D NULL)<= br>+ {
+ address_size +=3D route.g= ateway->sa_len;
+ = }
+
= + interface =3D (struct = ifreq *)((addr_t)interface + IF_NAMESIZE
+ + sizeof(struct r= oute_entry) + address_size);
+ }
+ f= ree(buffer);
+}
+
+void
+get_default_gateway_ipv6(struct route_ipv6_gateway_info *rg= i6,
+ = const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
+{

+ /* TODO: Same for ipv6 with AF_INET6 */<= br>+ CLEAR(*rgi6);+}
+
#else /* if defined(_WIN32) = */

/*
diff --git a/src/o= penvpn/syshead.h b/src/openvpn/syshead.h
index 33a90c1..844= e47a 100644
--- a/src/openvpn/syshead.h
+++= b/src/openvpn/syshead.h
@@ -166,6 +166,12 @@
#include <string.h>
#endif

+#if defined(TARGET_HAIK= U)
+#include <Supp= ortDefs.h> /* uint32, etc */
+#include <net/if.h> /* ifconf etc */
<= span style=3D"color: hsl(120, 100%, 40%);">+#include <sys/sockio.h> = /* SIOCGRTTABLE, etc */
+#endif /* TARGET_HAIKU */
+
#ifdef HAVE_ARPA_INET_H
#inc= lude <arpa/inet.h>
#endif

To view, visit change 688. To unsubscribe, or for help writing mail fi= lters, visit settings.

=
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1a22724f28c5cd47f6df178b49f= 44087d7c2b6fd
Gerrit-Change-Number: 688
Gerrit-PatchSet: 12
Gerrit-Owner: kallisti5 <alex@...2837...>= ;
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: kallisti5 <alex@...2837...= >
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: kallisti5 <alex@...2839...= .>
Gerrit-MessageType: newpatchset
--T9eF5YddQyQ=--