From 1bda73a7b0f45a2502ae93e33e30b98152d893f3 Mon Sep 17 00:00:00 2001 From: james Date: Mon, 12 May 2008 20:31:43 +0000 Subject: Moved branch into official BETA21 position. git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@2959 e7ae566f-a301-0410-adde-c780ea21d3b5 --- tun.c | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 8 deletions(-) (limited to 'tun.c') diff --git a/tun.c b/tun.c index 349a4de..3877ca8 100644 --- a/tun.c +++ b/tun.c @@ -30,12 +30,6 @@ * from VTun by Maxim Krasnyansky . */ -#ifdef WIN32 -#include "config-win32.h" -#else -#include "config.h" -#endif - #include "syshead.h" #include "tun.h" @@ -799,7 +793,7 @@ do_ifconfig (struct tuntap *tt, add_route (&r, tt, 0, es); } -#elif defined(TARGET_FREEBSD) +#elif defined(TARGET_FREEBSD)||defined(TARGET_DRAGONFLY) /* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.255.255 up */ if (tun) @@ -1248,7 +1242,7 @@ close_tun (struct tuntap *tt) } #else openvpn_snprintf (command_line, sizeof (command_line), - IFCONFIG_PATH "%s addr 0.0.0.0", + IFCONFIG_PATH " %s 0.0.0.0", tt->actual_name ); #endif @@ -1753,6 +1747,89 @@ read_tun (struct tuntap* tt, uint8_t *buf, int len) return read (tt->fd, buf, len); } +#elif defined(TARGET_DRAGONFLY) + +static inline int +dragonfly_modify_read_write_return (int len) +{ + if (len > 0) + return len > sizeof (u_int32_t) ? len - sizeof (u_int32_t) : 0; + else + return len; +} + +void +open_tun (const char *dev, const char *dev_type, const char *dev_node, bool ipv6, struct tuntap *tt) +{ + open_tun_generic (dev, dev_type, dev_node, ipv6, true, true, tt); + + if (tt->fd >= 0) + { + int i = 0; + + /* Disable extended modes */ + ioctl (tt->fd, TUNSLMODE, &i); + i = 1; + ioctl (tt->fd, TUNSIFHEAD, &i); + } +} + +void +close_tun (struct tuntap *tt) +{ + if (tt) + { + close_tun_generic (tt); + free (tt); + } +} + +int +write_tun (struct tuntap* tt, uint8_t *buf, int len) +{ + if (tt->type == DEV_TYPE_TUN) + { + u_int32_t type; + struct iovec iv[2]; + struct ip *iph; + + iph = (struct ip *) buf; + + if (tt->ipv6 && iph->ip_v == 6) + type = htonl (AF_INET6); + else + type = htonl (AF_INET); + + iv[0].iov_base = (char *)&type; + iv[0].iov_len = sizeof (type); + iv[1].iov_base = buf; + iv[1].iov_len = len; + + return dragonfly_modify_read_write_return (writev (tt->fd, iv, 2)); + } + else + return write (tt->fd, buf, len); +} + +int +read_tun (struct tuntap* tt, uint8_t *buf, int len) +{ + if (tt->type == DEV_TYPE_TUN) + { + u_int32_t type; + struct iovec iv[2]; + + iv[0].iov_base = (char *)&type; + iv[0].iov_len = sizeof (type); + iv[1].iov_base = buf; + iv[1].iov_len = len; + + return dragonfly_modify_read_write_return (readv (tt->fd, iv, 2)); + } + else + return read (tt->fd, buf, len); +} + #elif defined(WIN32) int -- cgit