X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=tun.c;h=eaa7b8aa6e0f5ce46877dc66de7c8941485108b7;hp=35d64186f7b4fee1503c89de5b5237c64878b9a6;hb=94759fd3273af5d0f432f2ea50e1e739eaf7aa0d;hpb=4f5e39ecfaa49376b0a5c3a4c384e91a828c1105 diff --git a/tun.c b/tun.c index 35d6418..eaa7b8a 100644 --- a/tun.c +++ b/tun.c @@ -68,12 +68,12 @@ static struct flagstr config_types[]={ struct tun { struct netlink nl; int fd; - string_t device_path; - string_t ip_path; + cstring_t device_path; + cstring_t ip_path; string_t interface_name; - string_t ifconfig_path; + cstring_t ifconfig_path; uint32_t ifconfig_type; - string_t route_path; + cstring_t route_path; uint32_t route_type; uint32_t tun_flavour; bool_t search_for_if; /* Applies to tun-BSD only */ @@ -83,7 +83,7 @@ struct tun { uint32_t local_address; /* host interface address */ }; -static string_t tun_flavour_str(uint32_t flavour) +static cstring_t tun_flavour_str(uint32_t flavour) { switch (flavour) { case TUN_FLAVOUR_GUESS: return "guess"; @@ -101,12 +101,12 @@ static int tun_beforepoll(void *sst, struct pollfd *fds, int *nfds_io, struct tun *st=sst; *nfds_io=1; fds[0].fd=st->fd; - fds[0].events=POLLIN|POLLERR|POLLHUP; + fds[0].events=POLLIN; return 0; } static void tun_afterpoll(void *sst, struct pollfd *fds, int nfds, - const struct timeval *tv_now, uint64_t *now) + const struct timeval *tv_now, uint64_t *now) { struct tun *st=sst; int l; @@ -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; @@ -336,7 +337,7 @@ static void tun_phase_hook(void *sst, uint32_t newphase) snprintf(mtu,6,"%d",st->nl.mtu); mtu[5]=0; - switch (st->route_type) { + switch (st->ifconfig_type) { case TUN_CONFIG_LINUX: sys_cmd(st->ifconfig_path,"ifconfig",st->interface_name, hostaddr,"netmask","255.255.255.255","-broadcast", @@ -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;