summaryrefslogtreecommitdiff
path: root/src/libstrongswan/networking/tun_device.c
diff options
context:
space:
mode:
authorYves-Alexis Perez <corsac@corsac.net>2017-05-30 20:59:31 +0200
committerYves-Alexis Perez <corsac@corsac.net>2017-05-30 21:03:44 +0200
commit335b7e322c795d86705aab67d2ecf72f1c9c5614 (patch)
treec3a2256cd4d3c9242c47da2a47077b12b3b7a1a6 /src/libstrongswan/networking/tun_device.c
parent7f6fc258427831ed2e80f7540c4368cf6ceba385 (diff)
downloadvyos-strongswan-335b7e322c795d86705aab67d2ecf72f1c9c5614.tar.gz
vyos-strongswan-335b7e322c795d86705aab67d2ecf72f1c9c5614.zip
New upstream version 5.5.3
Diffstat (limited to 'src/libstrongswan/networking/tun_device.c')
-rw-r--r--src/libstrongswan/networking/tun_device.c32
1 files changed, 28 insertions, 4 deletions
diff --git a/src/libstrongswan/networking/tun_device.c b/src/libstrongswan/networking/tun_device.c
index de925553f..86951f1e7 100644
--- a/src/libstrongswan/networking/tun_device.c
+++ b/src/libstrongswan/networking/tun_device.c
@@ -21,7 +21,16 @@
#include <utils/debug.h>
#include <threading/thread.h>
-#if !defined(__APPLE__) && !defined(__linux__) && !defined(HAVE_NET_IF_TUN_H)
+#if defined(__APPLE__)
+#include "TargetConditionals.h"
+#if !TARGET_OS_OSX
+#define TUN_DEVICE_NOT_SUPPORTED
+#endif
+#elif !defined(__linux__) && !defined(HAVE_NET_IF_TUN_H)
+#define TUN_DEVICE_NOT_SUPPORTED
+#endif
+
+#ifdef TUN_DEVICE_NOT_SUPPORTED
tun_device_t *tun_device_create(const char *name_tmpl)
{
@@ -481,10 +490,25 @@ static bool init_tun(private_tun_device_t *this, const char *name_tmpl)
strncpy(this->if_name, ifr.ifr_name, IFNAMSIZ);
return TRUE;
-#else /* !IFF_TUN */
+#elif defined(__FreeBSD__)
+
+ if (name_tmpl)
+ {
+ DBG1(DBG_LIB, "arbitrary naming of TUN devices is not supported");
+ }
+
+ this->tunfd = open("/dev/tun", O_RDWR);
+ if (this->tunfd < 0)
+ {
+ DBG1(DBG_LIB, "failed to open /dev/tun: %s", strerror(errno));
+ return FALSE;
+ }
+ fdevname_r(this->tunfd, this->if_name, IFNAMSIZ);
+ return TRUE;
+
+#else /* !__FreeBSD__ */
- /* this works on FreeBSD and might also work on Linux with older TUN
- * driver versions (no IFF_TUN) */
+ /* this might work on Linux with older TUN driver versions (no IFF_TUN) */
char devname[IFNAMSIZ];
/* the same process is allowed to open a device again, but that's not what
* we want (unless we previously closed a device, which we don't know at