summaryrefslogtreecommitdiffstats
path: root/src/iface.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/iface.c')
-rw-r--r--src/iface.c27
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__