diff options
author | Tobias Brunner <tobias@strongswan.org> | 2017-05-03 10:01:12 +0200 |
---|---|---|
committer | Tobias Brunner <tobias@strongswan.org> | 2017-05-19 15:28:46 +0200 |
commit | 59e6e93323b2b19ee7fbfc111bafc47acf7e5122 (patch) | |
tree | 5d4c23fd1bbf820d33c78e2f34dadb55d93f15bd /src | |
parent | fa959c0732fd39bf530936f69e44869856b51184 (diff) | |
download | strongswan-59e6e93323b2b19ee7fbfc111bafc47acf7e5122.tar.bz2 strongswan-59e6e93323b2b19ee7fbfc111bafc47acf7e5122.tar.xz |
tun-device: Use next free TUN device on FreeBSD
While this API is documented as legacy (and there is a sysctl option to
disable it) the documentation also mentions that it will probably stay
enabled by default due to compatibility issues with existing applications.
With the previous approach only 255 devices could be opened then the
daemon had to be restarted.
Fixes #2313.
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/networking/tun_device.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/libstrongswan/networking/tun_device.c b/src/libstrongswan/networking/tun_device.c index ec6dac7ce..86951f1e7 100644 --- a/src/libstrongswan/networking/tun_device.c +++ b/src/libstrongswan/networking/tun_device.c @@ -490,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__) - /* this works on FreeBSD and might also work on Linux with older TUN - * driver versions (no IFF_TUN) */ + 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 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 |