diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-11-09 21:57:52 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-11-09 21:57:52 +0100 |
commit | 999b87b80302dbc14e23ef3dff187b91dae7fab5 (patch) | |
tree | ae85ed0a33f142c7d0ddb56b408bca99baf172f5 /src | |
parent | 57bf9f904a6e093df987507d879937c7de9f799f (diff) | |
download | fastd-999b87b80302dbc14e23ef3dff187b91dae7fab5.tar fastd-999b87b80302dbc14e23ef3dff187b91dae7fab5.zip |
Destroy interfaces on OpenBSD as well
Diffstat (limited to 'src')
-rw-r--r-- | src/iface.c | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/iface.c b/src/iface.c index 1c2b55b..4f55807 100644 --- a/src/iface.c +++ b/src/iface.c @@ -190,6 +190,17 @@ static void set_tun_mtu(fastd_iface_t *iface, uint16_t mtu) { exit_errno("TUNSIFINFO ioctl failed"); } +static void cleanup_iface(fastd_iface_t *iface) { + if (!iface->cleanup) + return; + + struct ifreq ifr = {}; + strncpy(ifr.ifr_name, iface->name, IFNAMSIZ-1); + + if (ioctl(ctx.ioctl_sock, SIOCIFDESTROY, &ifr) < 0) + pr_warn_errno("unable to destroy TUN/TAP interface"); +} + #ifdef __FreeBSD__ @@ -282,17 +293,6 @@ static void open_iface(fastd_iface_t *iface, const char *ifname, uint16_t mtu) { } } -static void cleanup_iface(fastd_iface_t *iface) { - if (!iface->cleanup) - return; - - struct ifreq ifr = {}; - strncpy(ifr.ifr_name, iface->name, IFNAMSIZ-1); - - if (ioctl(ctx.ioctl_sock, SIOCIFDESTROY, &ifr) < 0) - pr_warn_errno("unable to destroy TUN/TAP interface"); -} - #else /* __OpenBSD__ */ static void set_link0(fastd_iface_t *iface, bool set) { @@ -333,6 +333,8 @@ static void open_iface(fastd_iface_t *iface, const char *ifname, uint16_t mtu) { else strncat(dev_name, ifname, IFNAMSIZ-1); + iface->cleanup = !if_nametoindex(ifname); + iface->fd = FASTD_POLL_FD(POLL_TYPE_IFACE, open(dev_name, O_RDWR|O_NONBLOCK)); if (iface->fd.fd < 0) exit_errno("could not open tun device file"); @@ -353,9 +355,6 @@ static void open_iface(fastd_iface_t *iface, const char *ifname, uint16_t mtu) { } } -static void cleanup_iface(UNUSED fastd_iface_t *iface) { -} - #endif #elif __APPLE__ |