From 999b87b80302dbc14e23ef3dff187b91dae7fab5 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Mon, 9 Nov 2015 21:57:52 +0100 Subject: Destroy interfaces on OpenBSD as well --- src/iface.c | 27 +++++++++++++-------------- 1 file 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__ -- cgit v1.2.3