chiark / gitweb /
build system: provide configure option --enable-hacky-parallel
[secnet.git] / tun.c
diff --git a/tun.c b/tun.c
index f7c0561179480d43f5d8aae40932afd76736b24a..d899f0c6d006219573fc60ef6e3f43943e4ba032 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -95,8 +95,7 @@ static cstring_t tun_flavour_str(uint32_t flavour)
 }
 
 static int tun_beforepoll(void *sst, struct pollfd *fds, int *nfds_io,
-                         int *timeout_io, const struct timeval *tv_now,
-                         uint64_t *now)
+                         int *timeout_io)
 {
     struct tun *st=sst;
     *nfds_io=1;
@@ -105,8 +104,7 @@ static int tun_beforepoll(void *sst, struct pollfd *fds, int *nfds_io,
     return 0;
 }
 
-static void tun_afterpoll(void *sst, struct pollfd *fds, int nfds,
-                         const struct timeval *tv_now, uint64_t *now)
+static void tun_afterpoll(void *sst, struct pollfd *fds, int nfds)
 {
     struct tun *st=sst;
     int l;
@@ -149,7 +147,7 @@ static bool_t tun_set_route(void *sst, struct netlink_client *routes)
     struct tun *st=sst;
     string_t network, mask, secnetaddr;
     struct subnet_list *nets;
-    uint32_t i;
+    int32_t i;
     int fd=-1;
 
     if (routes->up == routes->kup) return False;
@@ -190,7 +188,8 @@ static bool_t tun_set_route(void *sst, struct netlink_client *routes)
            break;
        case TUN_CONFIG_IOCTL:
        {
-#ifdef HAVE_NET_ROUTE_H
+         /* darwin rtentry has a different format, use /sbin/route instead */
+#if HAVE_NET_ROUTE_H && ! __APPLE__
            struct rtentry rt;
            struct sockaddr_in *sa;
            int action;
@@ -233,7 +232,7 @@ static void tun_phase_hook(void *sst, uint32_t newphase)
 {
     struct tun *st=sst;
     string_t hostaddr,secnetaddr;
-    uint8_t mtu[6];
+    char mtu[6];
     struct netlink_client *r;
 
     if (st->tun_flavour==TUN_FLAVOUR_BSD) {
@@ -353,7 +352,7 @@ static void tun_phase_hook(void *sst, uint32_t newphase)
                hostaddr,secnetaddr,"mtu",mtu,"up",(char *)0);
        break;
     case TUN_CONFIG_IOCTL:
-#ifdef HAVE_NET_IF_H
+#if HAVE_NET_IF_H && ! __APPLE__
     {
        int fd;
        struct ifreq ifr;
@@ -486,7 +485,8 @@ static list_t *tun_create(closure_t *self, struct cloc loc, dict_t *context,
            }
        } else if (strcmp(u.sysname,"SunOS")==0) {
            st->tun_flavour=TUN_FLAVOUR_STREAMS;
-       } else if (strcmp(u.sysname,"FreeBSD")==0) {
+       } else if (strcmp(u.sysname,"FreeBSD")==0
+                  || strcmp(u.sysname,"Darwin")==0) {
            st->tun_flavour=TUN_FLAVOUR_BSD;
        }
     }
@@ -501,9 +501,13 @@ static list_t *tun_create(closure_t *self, struct cloc loc, dict_t *context,
            st->ifconfig_type=TUN_CONFIG_IOCTL;
            break;
        case TUN_FLAVOUR_BSD:
+#if __linux__
            /* XXX on Linux we still want TUN_CONFIG_IOCTL.  Perhaps we can
               use this on BSD too. */
            st->ifconfig_type=TUN_CONFIG_IOCTL;
+#else    
+           st->ifconfig_type=TUN_CONFIG_BSD;
+#endif
            break;
        case TUN_FLAVOUR_STREAMS:
            st->ifconfig_type=TUN_CONFIG_BSD;
@@ -597,7 +601,6 @@ static list_t *tun_bsd_apply(closure_t *self, struct cloc loc, dict_t *context,
     return tun_create(self,loc,context,args,TUN_FLAVOUR_BSD);
 }
 
-init_module tun_module;
 void tun_module(dict_t *dict)
 {
     add_closure(dict,"tun",tun_apply);