Haiku: Introduce basic platform support
PATCH 1/2 Haiku: Introduce basic platform support
From: Alexander von Gluck IV <[email protected]...>
--- configure.ac | 5 +++++ src/openvpn/route.c | 15 +++++++++++++++ src/openvpn/tun.c | 17 +++++++++++++++++ 3 files changed, 37 insertions(+)
configure.ac +5 -0
@@ -368,6 +368,11 @@ case "$host" in have_tap_header="yes" ac_cv_header_net_if_h="no" # exists, but breaks things ;; + *-*-haiku*) + AC_DEFINE([TARGET_HAIKU], [1], [Are we running Haiku?]) + AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["H"], [Target prefix]) + LIBS="${LIBS} -lnetwork" + ;; *) AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["X"], [Target prefix]) have_tap_header="yes"
src/openvpn/route.c +1 -0
@@ -1853,6 +1853,21 @@ add_route(struct route_ipv4 *r, status = ret ?RTA_SUCCESS :RTA_ERROR ; } +#el
if defined(TARGET_HAIKU)
+
+ {
+ /* ex: route add /dev/net/ipro1000/0 default gw 192.168.1.1 netmask 255.255.255.0 */
+ argv_printf(&argv, "route add %s inet default gw %s netmask %s",
+ rgi->iface, + gateway, + netmask);
+
+ argv_msg(D_ROUTE, &argv);
+ bool ret = openvpn_execve_check(&argv, es, 0,
+ "ERROR: Haiku route add command failed");
+ status = 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 this operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */
src/openvpn/tun.c +10 -0
@@ -1631,6 +1631,16 @@ do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu, {windows_set_mtu (tt->adapter_index,AF_INET , tun_mtu); } +#elif defined(TARGET_HAIKU ) + { +/* example: ifconfig tun/0 inet 1.1.1.1 255.255.255.0 mtu 1450 up */ +// Need to add ifconfig_remote_netmask since right now it is just NULL +argv_printf (&argv,"%s %s inet %s %s mtu %d up" ,IFCONFIG_PATH , + ifname, ifconfig_local, ifconfig_remote_netmask, tun_mtu); + +argv_msg (M_INFO , &argv); +openvpn_execve_check (&argv, es,S_FATAL ,"Haiku ifconfig failed" ); + }#else /* if defined(TARGET_LINUX) */ msg (M_FATAL ,"Sorry, but I don't know how to do 'ifconfig' commands on this operating system. You should ifconfig your TUN/TAP device manually or use an --up script." );
#endif /* if defined(TARGET_LINUX) */
@@ -1909,10 +1919,17 @@ open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
{
for (int i = 0; i < 256; ++i)
{+#if defined(TARGET_H
AIKU)
+ snprintf(tunname, sizeof(tunname),
+ "/dev/%s/%d", dev, i);
+ snprintf(dynamic_name, sizeof(dynamic_name),
+ "%s/%d", dev, i);
+#else
snprintf(tunname, sizeof(tunname),
"/dev/%s%d", dev, i);
snprintf(dynamic_name, sizeof(dynamic_name),
"%s%d", dev, i);
+#endif
if ((tt->fd = open(tunname, O_RDWR)) > 0)
{
dynamic_opened = true;Signature · 1 line
2.47.1
PATCH 2/2 Haiku: Pull in routing table to get default route
--- src/openvpn/route.c | 109 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 107 insertions(+), 2 deletions(-)
src/openvpn/route.c +8 -1
@@ -54,6 +54,12 @@#include <net/route.h> /* RT_ROUNDUP(), RT_ADVANCE() */ #endif +#if defined(TARGET_HAIKU ) +#include <SupportDefs.h> /* uint32, etc */ +#include <net/if.h> /* ifconf etc */ +#include <sys/sockio.h> /* SIOCGRTTABLE, etc */ +#endif /* TARGET_HAIKU */ +#ifdef _WIN32#include "openvpn-msg.h"
@@ -1857,14 +1863,16 @@ add_route(struct route_ipv4 *r, {/* ex: route add /dev/net/ipro1000/0 default gw 192.168.1.1 netmask 255.255.255.0 */ - argv_printf(&argv, "route add %s inet default gw %s netmask %s", + argv_printf(&argv, "%s add %s inet %s gw %s netmask %s", + ROUTE_PATH, rgi-
Quoted 1 line
iface,
+ network,
gateway,
netmask);
argv_msg(D_ROUTE, &argv);
bool ret = openvpn_execve_check(&argv, es, 0,
- "ERROR: Haiku route add command failed");
+ "ERROR: Haiku inet route add command failed");
status = ret ? RTA_SUCCESS : RTA_ERROR;
}@@ -2344,6 +2352,21 @@ delete_route(struct route_ipv4 *r,
openvpn_execve_check(&argv, es, 0, "ERROR: AIX route delete command failed");
}+#elif defined(TARGET_HAIKU)
+
+ {
+ // 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 this operating system. Try putting your routes in a --route-up script"); #endif /* if defined(TARGET_LINUX) */
@@ -2523,6 +2546,19 @@ delete_route_ipv6(const struct route_ipv6 *r6, const struct tuntap *tt,
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)
+ {
+ 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 inet
6 route delete 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) */
@@ -3460,6 +3496,75 @@ get_default_gateway_ipv6(struct route_ipv6_gateway_info *rgi6,
}}
+#elif defined(TARGET_HAIKU)
+
+void
+get_default_gateway(struct route_gateway_info *rgi, openvpn_net_ctx_t *ctx) +{
+ CLEAR(*rgi);
+
+ int sockfd = -1;
+ sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sockfd < 0) {+ msg(M_INFO, "%s: Error opening socket for AF_INET", __func__);
+ return;
+ }
+
+ struct ifconf config;
+ config.ifc_len = sizeof(config.ifc_value);
+ if (ioctl(sockfd, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < 0) {+ msg(M_INFO, "%s: Error getting routing table size", __func__);
+ return;
+ }
+
+ uint32 size = (uin
t32)config.ifc_value;
+ if (size == 0)
+ return;
+
+ void *buffer = malloc(size);
+ if (buffer == NULL) {
+ fprintf(stderr, "%s: Out of memory.\n", __func__);
+ return;
+ }
+
+ config.ifc_len = size; + config.ifc_buf = buffer; + if (ioctl(sockfd, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
+ return;
+
+ struct ifreq *interface = (struct ifreq*)buffer;
+ struct ifreq *end = (struct ifreq*)((uint8*)buffer + size);
+
+ while (interface < end) {
+ struct route_entry route = interface->ifr_route;
+ if ((route.flags & RTF_GATEWAY) != 0 && (route.flags & RTF_DEFAULT) != 0) {
+ //msg(M_INFO, "%s: FOUND DEFAULT GATEWAY ON %s", __func__, interface->ifr_name); + rgi->gateway.addr = ntohl(((struct sockaddr_in *)route.gateway)->sin_addr.s_addr); + rgi->flags = RGI_ADDR_DEFINED | RGI_IFACE_DEFINED; + strcpy(rgi->iface, interface->ifr_name);
+ }
+
+ int32 addressSize = 0;
+ if (route.destination != NULL)
+ addressSize += route.destination->sa_len;
+ if (route.mask != NULL)
+ addressSize += route.mask->sa_len;
+ if (route.gateway != NULL)
+ addressSize += route.gateway->sa_len;
+
+ interface = (struct ifreq*)((addr_t)interface + IF_NAMESIZE
+ + sizeof(struct route_entry) + addressSize);
+ }
+}
+
+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);
+}
+
#elif defined(TARGET_DARWIN) || defined(TARGET_SOLARIS) \
|| defined(TARGET_FREEBSD) || defined(TARGET_DRAGONFLY) \
|| defined(TARGET_OPENBSD) || defined(TARGET_NETBSD)Signature · 1 line
2.47.1
Hi,
this is great, but alas...
Quoted 2 lines · Alexander von Gluck via Openvpn-devel
+#el
ifdefined(TARGET_HAIKU)
...
Quoted 2 lines
+#if defined(TARGET_H
AIKU)
... your mail program is wrapping the lines in weird ways.
Can you please send with git-send-email or push to our gerrit?
(https://community.openvpn.net/openvpn/wiki/DeveloperDocumentation#PatchsubmissionviaGerrit)
Quoted 1 line
+ // Need to add
ifconfig_remote_netmasksince right now it is just NULL
... and while at it: no // comments, please.
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Re: [Openvpn-devel] [PATCH 2/2] Haiku: Pull in routing table to get default route
In reply to Alexander von GluckHi,
Quoted 5 lines · Alexander von Gluck via Openvpn-devel
src/openvpn/route.c +0
-0
src/openvpn/route.c line 62
Quoted 9 lines
src/openvpn/route.c +6
-0@@ -54,6 +54,12 @@#include <net/route.h> /* RT_ROUNDUP(), RT_ADVANCE() */ #endif +#if defined(TARGET_HAIKU ) +#include <SupportDefs.h> /* uint32, etc */ +#include <net/if.h> /* ifconf etc */ +#include <sys/sockio.h> /* SIOCGRTTABLE, etc */ +#endif /* TARGET_HAIKU */ +
System includes go to "syshead.h".
src/openvpn/route.c add_route(struct route_ipv4 *r, · line 1870
Quoted 13 lines
src/openvpn/route.c +3
-1#ifdef _WIN32#include "openvpn-msg.h" @@ -1857,14 +1863,16 @@ add_route(struct route_ipv4 *r, {/* ex: route add /dev/net/ipro1000/0 default gw 192.168.1.1 netmask 255.255.255.0 */ - argv_printf(&argv, "route add %s inet default gw %s netmask %s", + argv_printf(&argv, "%s add %s inet %s gw %s netmask %s", + ROUTE_PATH, rgi- >iface, + network,
Please squash this part into patch 1/2 - having one patch introduce something new for #ifdef TARGET_HAIKU, only to have the next patch modify the very same line is not helpful.
src/openvpn/route.c add_route(struct route_ipv4 *r, · line 1874
Quoted 4 lines
src/openvpn/route.c +4
-0+#elif defined(TARGET_HAIKU ) + + { +// route del /dev/net/ipro1000/0 inet 192.168.0.0 gw 192.168.1.1 netmask 255.255.0.0
No // comments
At least adding/deleting of routes should be "in patch 1".
The get_default_gateway() part could, technically, go into its own patch ("it adds independent new functionality") - but since this all fairly small, it can just be part of the single patch.
A few lines of README would be nice, if anything special is needed to make OpenVPN work on HAIKU, with you patch ("you need to install the tun/tap driver from $url, then reboot twice at midnight, and off you go").
gert
Signature · 6 lines
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany [email protected]...Quoted 13 lines · Gert Doering
this is great, but alas...
Quoted 2 lines · Alexander von Gluck via Openvpn-devel
+#el
ifdefined(TARGET_HAIKU)...
Quoted 7 lines
Quoted 2 lines
+#if defined(TARGET_H
AIKU)... your mail program is wrapping the lines in weird ways.
Can you please send with git-send-email or push to our gerrit?
Weird, yeah. I'm using git-send-email but through a proton mail bridge. Sorry for the noise.
Quoted 1 line
(https://community.openvpn.net/openvpn/wiki/DeveloperDocumentation#PatchsubmissionviaGerrit)
I'll submit via Gerrit with your recommendations.
Quoted 2 lines
Quoted 1 line
+ // Need to add
ifconfig_remote_netmasksince right now it is just NULL... and while at it: no // comments, please.
Will fix this (and other review comments)
Thanks!
-- Alex