From 83a0ae3c39c9117dd59bb6f4fee117612b893577 Mon Sep 17 00:00:00 2001
From: Alexander von Gluck IV <kallisti5@unixzen.com>
Date: Fri, 17 Nov 2023 14:39:01 -0600
Subject: [PATCH] Haiku: Introduce basic platform support
* Based on the original work of GSOC student Swangeon
---
configure.ac | 4 ++++
src/openvpn/route.c | 15 +++++++++++++++
src/openvpn/tun.c | 19 ++++++++++++++++++-
3 files changed, 37 insertions(+), 1 deletion(-)
diff --git a/configure.ac b/configure.ac
index 84eaad60..4ca8f4f0 100644
a
|
b
|
case "$host" in
|
373 | 373 | have_tap_header="yes" |
374 | 374 | ac_cv_header_net_if_h="no" # exists, but breaks things |
375 | 375 | ;; |
| 376 | *-*-haiku*) |
| 377 | AC_DEFINE([TARGET_HAIKU], [1], [Are we running Haiku?]) |
| 378 | AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["H"], [Target prefix]) |
| 379 | ;; |
376 | 380 | *) |
377 | 381 | AC_DEFINE_UNQUOTED([TARGET_PREFIX], ["X"], [Target prefix]) |
378 | 382 | have_tap_header="yes" |
diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index ff64938a..fa6dc1d5 100644
a
|
b
|
add_route(struct route_ipv4 *r,
|
1842 | 1842 | status = ret ? RTA_SUCCESS : RTA_ERROR; |
1843 | 1843 | } |
1844 | 1844 | |
| 1845 | #elif defined(TARGET_HAIKU) |
| 1846 | |
| 1847 | { |
| 1848 | /* ex: route add /dev/net/ipro1000/0 default gw 192.168.1.1 netmask 255.255.255.0 */ |
| 1849 | argv_printf(&argv, "route add %s default gw %s netmask %s", |
| 1850 | rgi->iface, |
| 1851 | gateway, |
| 1852 | netmask); |
| 1853 | |
| 1854 | argv_msg(D_ROUTE, &argv); |
| 1855 | bool ret = openvpn_execve_check(&argv, es, 0, |
| 1856 | "ERROR: Haiku route add command failed"); |
| 1857 | status = ret ? RTA_SUCCESS : RTA_ERROR; |
| 1858 | } |
| 1859 | |
1845 | 1860 | #else /* if defined(TARGET_LINUX) */ |
1846 | 1861 | 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"); |
1847 | 1862 | #endif /* if defined(TARGET_LINUX) */ |
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 82ab6c05..28a78881 100644
a
|
b
|
do_ifconfig_ipv4(struct tuntap *tt, const char *ifname, int tun_mtu,
|
1643 | 1643 | { |
1644 | 1644 | windows_set_mtu(tt->adapter_index, AF_INET, tun_mtu); |
1645 | 1645 | } |
| 1646 | #elif defined(TARGET_HAIKU) |
| 1647 | { |
| 1648 | /* example: ifconfig tap0 inet 1.1.1.1 255.255.255.0 mtu 1450 up */ |
| 1649 | // Need to add ifconfig_remote_netmask since right now it is just NULL |
| 1650 | argv_printf(&argv, "%s %s inet %s 255.255.255.0 mtu %d up", IFCONFIG_PATH, |
| 1651 | ifname, ifconfig_local, tun_mtu); |
| 1652 | |
| 1653 | argv_msg(M_INFO, &argv); |
| 1654 | openvpn_execve_check(&argv, es, S_FATAL, "Haiku ifconfig failed"); |
| 1655 | } |
1646 | 1656 | #else /* if defined(TARGET_LINUX) */ |
1647 | 1657 | 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."); |
1648 | 1658 | #endif /* if defined(TARGET_LINUX) */ |
… |
… |
tun_dco_enabled(struct tuntap *tt)
|
1899 | 1909 | } |
1900 | 1910 | #endif |
1901 | 1911 | |
1902 | | |
1903 | 1912 | #if !(defined(_WIN32) || defined(TARGET_LINUX)) |
1904 | 1913 | static void |
1905 | 1914 | open_tun_generic(const char *dev, const char *dev_type, const char *dev_node, |
… |
… |
open_tun_generic(const char *dev, const char *dev_type, const char *dev_node,
|
1934 | 1943 | { |
1935 | 1944 | for (int i = 0; i < 256; ++i) |
1936 | 1945 | { |
| 1946 | #if defined(TARGET_HAIKU) |
| 1947 | // Haiku just uses literal names |
| 1948 | openvpn_snprintf(tunname, sizeof(tunname), |
| 1949 | "/dev/net/%s/%d", dev, i); |
| 1950 | openvpn_snprintf(dynamic_name, sizeof(dynamic_name), |
| 1951 | "/dev/net/%s/%d", dev, i); |
| 1952 | #else |
1937 | 1953 | openvpn_snprintf(tunname, sizeof(tunname), |
1938 | 1954 | "/dev/%s%d", dev, i); |
1939 | 1955 | openvpn_snprintf(dynamic_name, sizeof(dynamic_name), |
1940 | 1956 | "%s%d", dev, i); |
| 1957 | #endif |
1941 | 1958 | if ((tt->fd = open(tunname, O_RDWR)) > 0) |
1942 | 1959 | { |
1943 | 1960 | dynamic_opened = true; |