[Openvpn-devel,1/2] Haiku: Introduce basic platform support

Message ID 20241126142639.67446-1-alex@terarocket.io
State Changes Requested
Headers show
Series [Openvpn-devel,1/2] Haiku: Introduce basic platform support | expand

Commit Message

Alexander von Gluck Nov. 26, 2024, 2:26 p.m. UTC
From: Alexander von Gluck IV <kallisti5@unixzen.com>

---
 configure.ac        |  5 +++++
 src/openvpn/route.c | 15 +++++++++++++++
 src/openvpn/tun.c   | 17 +++++++++++++++++
 3 files changed, 37 insertions(+)

 #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;

Comments

Gert Doering Nov. 26, 2024, 2:32 p.m. UTC | #1
Hi,

this is great, but alas...

On Tue, Nov 26, 2024 at 02:26:52PM +0000, Alexander von Gluck via Openvpn-devel wrote:
> +#el
> if defined(TARGET_HAIKU)
...
> +#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)

> +        // Need to add ifconfig_remote_netmask since right now it is just NULL

... and while at it: no // comments, please.

gert
Alexander von Gluck Nov. 26, 2024, 3:07 p.m. UTC | #2
On Tuesday, November 26th, 2024 at 8:32 AM, Gert Doering <gert@greenie.muc.de> wrote:
> 

> this is great, but alas...
> On Tue, Nov 26, 2024 at 02:26:52PM +0000, Alexander von Gluck via Openvpn-devel wrote:
> 

> > +#el
> > if defined(TARGET_HAIKU)
> 

> ...
> 

> > +#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.
 

> (https://community.openvpn.net/openvpn/wiki/DeveloperDocumentation#PatchsubmissionviaGerrit)

I'll submit via Gerrit with your recommendations.


> > + // Need to add ifconfig_remote_netmask since right now it is just NULL
> ... and while at it: no // comments, please.

Will fix this (and other review comments)

Thanks!

 -- Alex

Patch

diff --git a/configure.ac b/configure.ac
index 0876a6a5..7f6e43dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -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"
diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index 2e584c71..fa20d08f 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -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) */
diff --git a/src/openvpn/tun.c b/src/openvpn/tun.c
index 85fe01af..65e3b5ba 100644
--- a/src/openvpn/tun.c
+++ b/src/openvpn/tun.c
@@ -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.");