chiark / gitweb /
MacOS X support
authorStephen Early <steve@greenend.org.uk>
Wed, 6 Apr 2005 00:58:29 +0000 (01:58 +0100)
committerStephen Early <steve@greenend.org.uk>
Wed, 18 May 2011 18:05:49 +0000 (19:05 +0100)
Patch from Richard Kettlewell <richard@sfere.greenend.org.uk> to
support MacOS X; see also http://www.greenend.org.uk/rjk/2004/osx.html

Makefile.in
netlink.c
tun.c

index 4c69b64901f411770e6708ac4d396ed86a07fe25..0461854486e7ce617f38ad96210e5a698e885226 100644 (file)
@@ -36,6 +36,7 @@ INSTALL_PROGRAM:=@INSTALL_PROGRAM@
 #CFLAGS:=-Wall @WRITESTRINGS@ @CFLAGS@ -DHACKY_PARALLEL
 CFLAGS:=-Wall @WRITESTRINGS@ @CFLAGS@
 ALL_CFLAGS:=@DEFS@ -I$(srcdir) -I. $(CFLAGS)
+CPPFLAGS:=@CPPFLAGS@
 LDFLAGS:=@LDFLAGS@
 LDLIBS:=@LIBS@
 
@@ -117,7 +118,7 @@ DEPENDS:=$(OBJECTS:.o=.d)
 $(DEPENDS): ${srcdir}/depend.sh
 
 %.d: %.c
-       ${srcdir}/depend.sh $(srcdir) $(ALL_CFLAGS) $< > $@
+       ${srcdir}/depend.sh $(srcdir) $(CPPFLAGS) $(ALL_CFLAGS) $< > $@
 
 -include $(DEPENDS)
 
index ecad16cb73e6d8cb18b724148912648a2482a219..cc954fd748bd7d8677cd2487987aac8f84f434c4 100644 (file)
--- a/netlink.c
+++ b/netlink.c
@@ -498,18 +498,19 @@ static void netlink_packet_deliver(struct netlink *st,
            netlink_icmp_simple(st,buf,client,ICMP_TYPE_UNREACHABLE,
                                ICMP_CODE_NET_PROHIBITED);
            BUF_FREE(buf);
-       }
-       if (best_quality>0) {
-           /* XXX Fragment if required */
-           st->routes[best_match]->deliver(
-               st->routes[best_match]->dst, buf);
-           st->routes[best_match]->outcount++;
-           BUF_ASSERT_FREE(buf);
        } else {
-           /* Generate ICMP destination unreachable */
-           netlink_icmp_simple(st,buf,client,ICMP_TYPE_UNREACHABLE,
-                               ICMP_CODE_NET_UNREACHABLE); /* client==NULL */
-           BUF_FREE(buf);
+           if (best_quality>0) {
+               /* XXX Fragment if required */
+               st->routes[best_match]->deliver(
+                   st->routes[best_match]->dst, buf);
+               st->routes[best_match]->outcount++;
+               BUF_ASSERT_FREE(buf);
+           } else {
+               /* Generate ICMP destination unreachable */
+               netlink_icmp_simple(st,buf,client,ICMP_TYPE_UNREACHABLE,
+                                   ICMP_CODE_NET_UNREACHABLE); /* client==NULL */
+               BUF_FREE(buf);
+           }
        }
     }
     BUF_ASSERT_FREE(buf);
@@ -721,14 +722,15 @@ static void netlink_dump_routes(struct netlink *st, bool_t requested)
        for (i=0; i<st->n_clients; i++) {
            netlink_output_subnets(st,c,st->routes[i]->subnets);
            Message(c,"-> tunnel %s (%s,mtu %d,%s routes,%s,"
-                   "quality %d,use %d)\n",
+                   "quality %d,use %d,pri %lu)\n",
                    st->routes[i]->name,
                    st->routes[i]->up?"up":"down",
                    st->routes[i]->mtu,
                    st->routes[i]->options&OPT_SOFTROUTE?"soft":"hard",
                    st->routes[i]->options&OPT_ALLOWROUTE?"free":"restricted",
                    st->routes[i]->link_quality,
-                   st->routes[i]->outcount);
+                   st->routes[i]->outcount,
+                   (unsigned long)st->routes[i]->priority);
        }
        net=ipaddr_to_string(st->secnet_address);
        Message(c,"%s/32 -> netlink \"%s\" (use %d)\n",
diff --git a/tun.c b/tun.c
index f7c0561179480d43f5d8aae40932afd76736b24a..eaa7b8aa6e0f5ce46877dc66de7c8941485108b7 100644 (file)
--- a/tun.c
+++ b/tun.c
@@ -190,7 +190,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;
@@ -353,7 +354,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 +487,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 +503,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;