From: "kallisti5 (Code Review)" Attention is currently required from: flichtenheld, plaisthos. kallisti5 would like plaisthos and flichtenheld to review this change.
Haiku: Add calls to manage routing table
Change-Id: I1=
a22724f28c5cd47f6df178b49f44087d7c2b6fd
---
M INSTALL
M src/openvp=
n/route.c
M src/openvpn/syshead.h
3 files changed, 125 insertions(+),=
1 deletion(-)git pull ssh://gerrit.openvpn.net:29418/openvpn re=
fs/changes/88/688/1
diff --git a/INSTALL b/INSTALL
<=
p>To view, visit change 688. To unsubscribe, or for help writing mail filters,=
visit settings.
=
index 6007338..e7199f8 100644
--- a/INSTALL
+++ b/INSTALL
@@ -263,6 +263,13 @@
http://www.whiteboard.ne.jp/~admin2/tuntap/
+* Haiku:+
+ Haiku can't yet dynamically create TUN/T=
AP devices, so you need to manually
+ create one before running openvpn:
+
+ # ifconfig tun/0 up
+
* Windows
OpenVPN on Windows needs a TUN/TAP kernel driver to work. OpenVPN=
installers
diff --git a/src/openvpn/route.c b/src/openvpn/=
route.c
index 2e584c7..4813def 100644
--- a=
/src/openvpn/route.c
+++ b/src/openvpn/route.c@@ -1853,7 +1853,23 @@
status =3D ret ? RTA_SU=
CCESS : RTA_ERROR;
}
-#else /* if defined(TARGET_LINUX) */=
+#elif defined(TARGE=
T_HAIKU)
+
=
+ {
+ /* ex: route add /dev/net/ipro1000/0=
0.0.0.0 gw 192.168.1.1 netmask 128.0.0.0 */
+ argv_printf(&argv, "%s add %s ine=
t %s gw %s netmask %s",
+ ROUTE_PATH,
+ rgi->iface,
+ network,
=
+ gateway,=
span>
+ n=
etmask);
+ arg=
v_msg(D_ROUTE, &argv);
+ bool ret =3D openvpn_execve_check(&argv, es, 0,+ =
"ERROR: Haiku inet route add command failed");=
+ status =3D ret ? R=
TA_SUCCESS : RTA_ERROR;
+ }
+
+#else /* if defined(TARGET_LI=
NUX) */
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 de=
fined(TARGET_LINUX) */
@@ -2329,6 +2345,2=
0 @@
openvpn_execve_check(&argv, es, 0, "=
ERROR: AIX route delete command failed");
}
+#elif d=
efined(TARGET_HAIKU)
=
+
+ {+ /* ex: route del /dev/ne=
t/ipro1000/0 inet 192.168.0.0 gw 192.168.1.1 netmask 255.255.0.0 */<=
br>+ argv_printf(&ar=
gv, "%s del %s inet %s gw %s netmask %s",
+ ROUTE_PATH,
+ rgi->i=
face,
+ =
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(TARGET_=
LINUX) */
msg(M_FATAL, "Sorry, but I don't kn=
ow how to do 'route' commands on this operating system. Try puttin=
g 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");=
+
#elif de=
fined(TARGET_ANDROID)
msg(D_ROUTE_DEBUG, "Deletin=
g routes on Android is not possible/not "
&qu=
ot;needed. The VpnService API allows routes to be set "
+#elif defined(TARGET_=
HAIKU)
+ {<=
br>+ /* 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,
<=
span style=3D"color: hsl(120, 100%, 40%);">+ network,
+ ga=
teway,
+ =
r6->netbits);
+ argv_msg(D_ROUTE, &argv);
+ openvpn_execve_check(&argv, es, 0, "=
ERROR: Haiku inet6 route delete command failed");
+ }
#else /* if defined=
(TARGET_LINUX) */
msg(M_FATAL, "Sorry, but I don&=
#39;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,74=
@@
#undef max
<=
br>+#elif defined(TARGET_HAIKU)=
+
+void
+get_default_gateway(struct route_gateway_info *rgi, o=
penvpn_net_ctx_t *ctx)
+{
+ CLEAR(*rgi)=
;
+
+ int sockfd =3D -1;
+ if =
(sockfd < 0) {
+ =
msg(M_INFO, "%s: Error opening socket for AF_INET", __func_=
_);
+ return;<=
/span>
+ }
+ struct ifconf config;
+ config.ifc_len =3D sizeof(config.ifc_value)=
;
+ if (ioctl(sock=
fd, SIOCGRTSIZE, &config, sizeof(struct ifconf)) < 0) {+ msg(M_INFO, "%s: Er=
ror getting routing table size", __func__);
+ return;
+ }
+
+ uint=
32 size =3D (uint32)config.ifc_value;
+ if (size =3D=3D 0)
+ return;
+
+ =
void *buffer =3D malloc(size);
+ if (buffer =3D=3D NULL) {
+ fprintf(stderr, "%s: Out of memory.\n&q=
uot;, __func__);
+ =
return;
+ }=
span>
+
+ config.ifc_len =3D size;
<=
span style=3D"color: hsl(120, 100%, 40%);">+ config.ifc_buf =3D buffer;<=
/span>
+ if (ioctl(sockfd=
, SIOCGRTTABLE, &config, sizeof(struct ifconf)) < 0)
+ 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_ro=
ute;
+ if ((ro=
ute.flags & RTF_GATEWAY) !=3D 0 && (route.flags & RTF_DEFAU=
LT) !=3D 0) {
+ =
rgi->gateway.addr =3D ntohl(((struct sockaddr_in *)route.gateway)-=
>sin_addr.s_addr);
+ rgi->flags =3D RGI_ADDR_DEFINED | RGI_IFACE_DEFINED;
+ strcpy(rgi-&g=
t;iface, interface->ifr_name);
+ }
+
+ int32 a=
ddressSize =3D 0;
+ =
if (route.destination !=3D NULL)
+ addressSize +=3D route.destination->sa_le=
n;
+ if (route=
.mask !=3D NULL)
+ =
addressSize +=3D route.mask->sa_len;
+ if (route.gateway !=3D NULL)
+ addressSize +=3D =
route.gateway->sa_len;
+
+ inter=
face =3D (struct ifreq*)((addr_t)interface + IF_NAMESIZE
+ + sizeof(struct route_entr=
y) + 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);
+}
+
#else /* if defined(_WIN32) */
/*
diff --git a/src/openvpn/s=
yshead.h b/src/openvpn/syshead.h
index 33a90c1..844e47a 100=
644
--- a/src/openvpn/syshead.h
+++ b/src/o=
penvpn/syshead.h
@@ -166,6 +166,12 @@
#inc=
lude <string.h>
#endif
<=
span style=3D"color: hsl(120, 100%, 40%);">+#if defined(TARGET_HAIKU)
+#include <SupportDefs.=
h> /* uint32, etc */
+#include <net/if.h> /* ifconf etc */
+#include <sys/sockio.h> /* SIO=
CGRTTABLE, etc */
+#e=
ndif /* TARGET_HAIKU */
+
#ifdef HAVE_ARPA_INET_H
#include <=
;arpa/inet.h>
#endif