From: "kallisti5 (Code Review)" Date: Tue, 26 Nov 2024 19:14:26 +0000 In-Reply-To: References: Reply-To: alex@...2837..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <2f28db55bc01cf18b72a5317e0a503bf65bd5aae-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="VhnpfnuxUlo="; 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: plaisthos , flichtenheld Cc: openvpn-devel --VhnpfnuxUlo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/688?usp=3Demail to look at the new patch set (#8). Change subject: Haiku: Add calls to manage routing table ...................................................................... Haiku: Add calls to manage routing table Change-Id: I1a22724f28c5cd47f6df178b49f44087d7c2b6fd --- M src/openvpn/route.c M src/openvpn/route.h M src/openvpn/syshead.h 3 files changed, 124 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/88/688/8 diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 2e584c7..dcce09c 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -1853,7 +1853,23 @@ 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 netmas= k 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_ROUTE, &argv); + bool ret =3D openvpn_execve_check(&argv, es, 0, + "ERROR: Haiku inet route add comma= nd 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' commands on th= is operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */ @@ -2329,6 +2345,20 @@ openvpn_execve_check(&argv, es, 0, "ERROR: AIX route delete comman= d failed"); } +#elif defined(TARGET_HAIKU) + + { + /* ex: route del /dev/net/ipro1000/0 inet 192.168.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_check(&argv, es, 0, "ERROR: Haiku inet route delete= command 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 +2534,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 prefix= len 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 delet= e command 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 +3929,73 @@ #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) + address_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/route.h b/src/openvpn/route.h index 421e7d2..69b06b8 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -155,6 +155,8 @@ /* gateway interface */ #ifdef _WIN32 DWORD adapter_index; /* interface or ~0 if undefined */ +#elif defined(TARGET_HAIKU) + char iface[PATH_MAX]; /* iface names are full /dev path with driver na= me */ #else char iface[16]; /* interface name (null terminated), may be empty */ #endif @@ -186,8 +188,13 @@ #else /* non linux platform don't have this constant defined */ #ifndef IFNAMSIZ +#if defined(TARGET_HAIKU) +/* iface names are full /dev path with driver name */ +#define IFNAMSIZ PATH_MAX +#else #define IFNAMSIZ 16 #endif +#endif char iface[IFNAMSIZ]; /* interface name (null terminated), may be empt= y */ #endif 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: 8 Gerrit-Owner: kallisti5 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --VhnpfnuxUlo= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

kallisti5 uploaded patch set #8 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/688?usp=3Demail">View Chang= e

Haiku: Add calls to manage routing table

Change-Id: I1a22724f2= 8c5cd47f6df178b49f44087d7c2b6fd
---
M src/openvpn/route.c
M src/op= envpn/route.h
M src/openvpn/syshead.h
3 files changed, 124 insertions= (+), 1 deletion(-)

git pull ssh://gerrit.openvpn.net:29418/openvp=
n refs/changes/88/688/8
diff --git a/src/openvpn/route.c b/src/open=
vpn/route.c
index 2e584c7..dcce09c 100644
-= -- a/src/openvpn/route.c
+++ b/src/openvpn/route.c@@ -1853,7 +1853,23 @@
status =3D ret ? RT= A_SUCCESS : RTA_ERROR;
}

<= span style=3D"color: hsl(0, 100%, 40%);">-#else /* if defined(TARGET_LINUX= ) */
+#elif defined(T= ARGET_HAIKU)
+=
+ {
+ /* ex: route add /dev/net/ipro10= 00/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,=
+ gatewa= y,
+ = netmask);
+ = argv_msg(D_ROUTE, &argv);
+ bool ret =3D openvpn_execve_check(&argv, es, 0,
+ = "ERROR: Haiku inet route add command failed");
+ status =3D ret= ? RTA_SUCCESS : RTA_ERROR;
+ }
+

+#else /* if defined(TARGE= T_LINUX) */
msg(M_FATAL, "Sorry, but I don't = know how to do 'route' commands on this operating system. Try putt= ing your routes in a --route-up script");
#endif /* i= f defined(TARGET_LINUX) */

@@ -2329,6 +23= 45,20 @@
openvpn_execve_check(&argv, es, 0, &q= uot;ERROR: AIX route delete command failed");
}

+#el= if defined(TARGET_HAIKU)
+
+ {+ /* ex: route del /de= v/net/ipro1000/0 inet 192.168.0.0 gw 192.168.1.1 netmask 255.255.0.0 */
+ argv_printf(&am= p;argv, "%s del %s inet %s gw %s netmask %s",
+ ROUTE_PATH,<= br>+ rgi->= ;iface,
+ = network,
+ = gateway,
+ netmask);
+ argv_msg(D_ROUTE, &argv);
+ openvpn_execve_check(&argv, e= s, 0, "ERROR: Haiku inet route delete command failed");+ }
+
#else /* if defined(TA= RGET_LINUX) */
msg(M_FATAL, "Sorry, but I don'= ;t know how to do 'route' commands on this operating system. Try p= utting your routes in a --route-up script");
#endif /= * if defined(TARGET_LINUX) */
@@ -2504,10 +2534,23 @@
network, r6->netbits, gateway);
argv_msg(D_ROUTE, &argv);

openvpn_execve_= check(&argv, es, 0, "ERROR: AIX route add command failed");
+
#el= if defined(TARGET_ANDROID)
msg(D_ROUTE_DEBUG, "De= leting 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(TA= RGET_HAIKU)
+ {
+ /* ex: route d= el /dev/net/ipro1000/0 inet6 :: gw beef::cafe prefixlen 64 */
+ argv_printf(&argv, &q= uot;%s del %s inet6 %s gw %s prefixlen %d",

+ ROUTE_PATH,
+ r6->iface,<= /span>
+ = network,
+ = gateway,
+ = r6->netbits);
+ argv_msg(D_ROUTE, &argv);
+ openvpn_execve_check(&argv, e= s, 0, "ERROR: Haiku inet6 route delete command failed");+ }
#else= /* if defined(TARGET_LINUX) */
msg(M_FATAL, "So= rry, but I don't know how to do 'route ipv6' commands on this o= perating system. Try putting your routes in a --route-down script");<= /span>
#endif /* if defined(TARGET_LINUX) */
@@ -= 3886,6 +3929,73 @@

#undef max
=
+#elif define= d(TARGET_HAIKU)
+
+void
+get_default_gateway(struct route_gatew= ay_info *rgi, openvpn_net_ctx_t *ctx)
+{
+= CLEAR(*rgi);
+
+ int sockfd =3D soc= ket(AF_INET, SOCK_DGRAM, 0);
+ if (sockfd < 0) {
+ msg(M_ERRNO, "%s: Error opening socket for AF_IN= ET", __func__);
= + return;
+ = }
+
+ struct ifconf config;
= + config.ifc_len =3D sizeof(= config.ifc_value);
+ = if (ioctl(sockfd, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < = 0) {
+ msg(M_E= RRNO, "%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);
<= span style=3D"color: hsl(120, 100%, 40%);">+

+ 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 *interface =3D (struct ifreq*)buffer;
+ struct ifreq *end =3D (struct ifreq= *)((uint8*)buffer + size);
+
+ while (i= nterface < end) {
= + struct route_entry route =3D interface->ifr_route;
+ if ((route.flags & R= TF_GATEWAY) !=3D 0 && (route.flags & RTF_DEFAULT) !=3D 0) {
+ rgi->gat= eway.addr =3D ntohl(((struct sockaddr_in *)route.gateway)->sin_addr.s_ad= dr);
+ rgi= ->flags =3D RGI_ADDR_DEFINED | RGI_IFACE_DEFINED;
+ strncpy(rgi->iface, interf= ace->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= )

+ addres= s_size +=3D route.gateway->sa_len;
+
+ = interface =3D (struct ifreq*)((addr_t)interface + IF_NAMESIZE=
+ + sizeof(struc= t route_entry) + address_size);
+ }
+ = free(buffer);
+}
+
+void
+get_default_gateway_ipv6(struct route_ipv6_gateway_info = *rgi6,
+ = const struct in6_addr *dest, openvpn_net_ctx_t *ctx)
= +{
+ /* TODO: Same for ipv6 with AF_INET6 */

+ CLEAR(*rgi6);=
+}
+
#else /* if defined(_WIN3= 2) */

/*
diff --git a/sr= c/openvpn/route.h b/src/openvpn/route.h
index 421e7d2..69b0= 6b8 100644
--- a/src/openvpn/route.h
+++ b/= src/openvpn/route.h
@@ -155,6 +155,8 @@
= /* gateway interface */
#ifdef _WIN32
= DWORD adapter_index; /* interface or ~0 if undefined */
+#elif defined(TARGET_HAIKU)+ char iface[PATH_MAX]; /*= iface names are full /dev path with driver name */
#else<= /span>
char iface[16]; /* interface name (null terminated), m= ay be empty */
#endif
@@ -186,8 +188,13 @@=
#else
/* non linux platform don'= t have this constant defined */
#ifndef IFNAMSIZ+#if defined(TARGET_HAIKU)
+/* iface names are full= /dev path with driver name */
+#define IFNAMSIZ PATH_MAX
+#else
#define IFNAMSIZ 16
#endif

+#endif
char iface[IFNAMSIZ]; /* interface name (null terminated),= may be empty */
#endif

= 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,1= 2 @@
#include <string.h>
#endif

+#if d= efined(TARGET_HAIKU)
= +#include <SupportDefs.h> /* uint32, etc */
+#include <net/if.h> /* ifcon= f etc */
+#include &l= t;sys/sockio.h> /* SIOCGRTTABLE, etc */
+#endif /* TARGET_HAIKU */
+
#ifdef HAVE_ARPA_INET_H=
#include <arpa/inet.h>
#endif

To view, visit change 688. To unsubscribe, or fo= r help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1a22724f28c5cd47f6df178b49f= 44087d7c2b6fd
Gerrit-Change-Number: 688
Gerrit-PatchSet: 8
Gerrit-Owner: kallisti5 <alex@...2837...>= ;
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: newpatchset
--VhnpfnuxUlo=--