summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-11-09 19:36:13 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-11-09 21:32:16 +0100
commit57bf9f904a6e093df987507d879937c7de9f799f (patch)
treeb8758b24d292d416723925d86aabc1bd84fdae6e /src
parent93945ca36875f69163c49f4d4b5f9649957a346b (diff)
downloadfastd-57bf9f904a6e093df987507d879937c7de9f799f.tar
fastd-57bf9f904a6e093df987507d879937c7de9f799f.zip
Implement interface cleanup on FreeBSD
Based-on-patch-by: Julian Kornberger <jk+github@digineo.de>
Diffstat (limited to 'src')
-rw-r--r--src/iface.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/iface.c b/src/iface.c
index 4f132e4..1c2b55b 100644
--- a/src/iface.c
+++ b/src/iface.c
@@ -246,11 +246,16 @@ static void open_iface(fastd_iface_t *iface, const char *ifname, uint16_t mtu) {
exit_bug("invalid mode");
}
+ iface->cleanup = true;
+
if (ifname) {
- if (strncmp(ifname, type, 3) != 0)
- exit_error("`%s' doesn't seem to be a %s device", ifname, type);
+ if (strlen(ifname) <= 3 || strncmp(ifname, type, 3) != 0)
+ exit_error("Invalid %s interface `%s'", type, ifname);
strncat(dev_name, ifname, IFNAMSIZ-1);
+
+ if (if_nametoindex(ifname))
+ iface->cleanup = false;
}
else {
strncat(dev_name, type, IFNAMSIZ-1);
@@ -277,7 +282,15 @@ static void open_iface(fastd_iface_t *iface, const char *ifname, uint16_t mtu) {
}
}
-static void cleanup_iface(UNUSED fastd_iface_t *iface) {
+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__ */