warp-vpn

point to point VPN implementation
git clone git://git.2f30.org/warp-vpn
Log | Files | Refs | README

commit 632b5d2419c2c12d097469b295d67ea86d6b7683
parent bef958646410654d1d339c02d1b50f682e410ef9
Author: sin <sin@2f30.org>
Date:   Tue, 22 Mar 2016 14:37:12 +0000

add dfly support

Diffstat:
Mconfig.mk | 2+-
Mstun.c | 26++++++++++++++++----------
2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/config.mk b/config.mk @@ -25,4 +25,4 @@ LDFLAGS = -lcrypto -s #CFLAGS = -static -O2 -std=c99 #LDFLAGS = -lcrypto -static -s -CPPFLAGS = -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -D_BSD_SOURCE +CPPFLAGS = -D_DEFAULT_SOURCE diff --git a/stun.c b/stun.c @@ -1,14 +1,17 @@ /* See LICENSE file for copyright and license details. */ #include <sys/types.h> +#include <sys/uio.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <net/if.h> -#ifdef __linux__ +#if defined(__linux__) #include <linux/if_tun.h> #include <bsd/stdlib.h> -#elif __OpenBSD__ +#elif defined(__OpenBSD__) #include <net/if_tun.h> +#elif defined(__DragonFly__) +#include <net/tun/if_tun.h> #endif #include <netinet/in.h> #include <netinet/tcp.h> @@ -32,7 +35,7 @@ #include "arg.h" -#ifdef __linux__ +#if defined(__linux__) || defined(__DragonFly__) #undef explicit_bzero #define explicit_bzero bzero #endif @@ -140,7 +143,7 @@ aesdec(EVP_CIPHER_CTX *ectx, unsigned char *plaintext, } /* useful for debugging purposes */ -#ifdef NOCRYPTO +#if defined(NOCRYPTO) #define aesinit dummyinit #define aesenc dummyenc #define aesdec dummydec @@ -168,7 +171,7 @@ dummydec(EVP_CIPHER_CTX *ectx, unsigned char *plaintext, return len; } -#ifdef __linux__ +#if defined(__linux__) int opentun(char *tundev) { @@ -194,7 +197,7 @@ opentun(char *tundev) ret = ioctl(s, SIOCGIFFLAGS, &ifr); if (ret < 0) logerr("failed to set SIOCGIFFLAGS on %s", tundev); - ifr.ifr_flags |= IFF_UP | IFF_RUNNING | IFF_POINTOPOINT; + ifr.ifr_flags |= IFF_UP | IFF_RUNNING; ret = ioctl(s, SIOCSIFFLAGS, &ifr); if (ret < 0) logerr("failed to set SIOCSIFFLAGS on %s", tundev); @@ -218,23 +221,26 @@ readtun(int fd, unsigned char *buf, int len) { return read(fd, buf, len); } -#elif __OpenBSD__ +#elif defined(__OpenBSD__) || defined(__DragonFly__) int opentun(char *tundev) { struct tuninfo ti; - int fd, mode = IFF_UP | IFF_POINTOPOINT; + int fd; fd = open(tundev, O_RDWR); if (fd < 0) logerr("failed to open %s", tundev); - if (ioctl(fd, TUNSIFMODE, &mode) < 0) - logerr("failed to set TUNSIFMODE on %s", tundev); if (ioctl(fd, TUNGIFINFO, &ti) < 0) logerr("failed to set TUNGIFINFO on %s", tundev); ti.mtu = MTU; if (ioctl(fd, TUNSIFINFO, &ti) < 0) logerr("failed to set TUNSIFINFO on %s", tundev); +#if defined(TUNSIFHEAD) + int one = 1; + if (ioctl(fd, TUNSIFHEAD, &one) < 0) + logerr("failed to set TUNSIFHEAD on %s", tundev); +#endif return fd; }