summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2015-11-09 17:39:38 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2015-11-09 17:39:38 +0100
commit93945ca36875f69163c49f4d4b5f9649957a346b (patch)
tree66e8db4ed7aa083f16bf79139ccab60c3fdad930
parent2c71060d25f18e75ae14154bf50d24909e2872c1 (diff)
downloadfastd-93945ca36875f69163c49f4d4b5f9649957a346b.tar
fastd-93945ca36875f69163c49f4d4b5f9649957a346b.zip
Add generic interface cleanup infrastructure
Some systems (like FreeBSD) don't delete TUN/TAP interfaces after closing, add some infrastructure to do that.
-rw-r--r--src/fastd.h1
-rw-r--r--src/iface.c17
2 files changed, 17 insertions, 1 deletions
diff --git a/src/fastd.h b/src/fastd.h
index 7963505..88bd9a2 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -167,6 +167,7 @@ struct fastd_iface {
char *name; /**< The interface name */
fastd_peer_t *peer; /**< The peer associated with the interface (if any) */
uint16_t mtu; /**< The MTU of the interface */
+ bool cleanup; /**< Determines if the interface should be deleted after use; not used on all platforms */
};
diff --git a/src/iface.c b/src/iface.c
index 74dda30..4f132e4 100644
--- a/src/iface.c
+++ b/src/iface.c
@@ -89,6 +89,7 @@ static inline fastd_iface_type_t get_iface_type(void) {
}
static void open_iface(fastd_iface_t *iface, const char *ifname, uint16_t mtu);
+static void cleanup_iface(fastd_iface_t *iface);
#ifdef __linux__
@@ -143,6 +144,9 @@ static void open_iface_linux(fastd_iface_t *iface, const char *ifname, uint16_t
iface->fd.fd = -1;
}
+static void cleanup_iface(UNUSED fastd_iface_t *iface) {
+}
+
#endif
#if defined(__ANDROID__)
@@ -273,6 +277,9 @@ static void open_iface(fastd_iface_t *iface, const char *ifname, uint16_t mtu) {
}
}
+static void cleanup_iface(UNUSED fastd_iface_t *iface) {
+}
+
#else /* __OpenBSD__ */
static void set_link0(fastd_iface_t *iface, bool set) {
@@ -333,6 +340,9 @@ 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__
@@ -374,6 +384,9 @@ static void open_iface(fastd_iface_t *iface, const char *ifname, uint16_t mtu) {
exit_errno("SIOCSIFMTU ioctl failed");
}
+static void cleanup_iface(UNUSED fastd_iface_t *iface) {
+}
+
#else
#error unknown TUN/TAP implementation
@@ -510,7 +523,9 @@ fastd_iface_t * fastd_iface_open(fastd_peer_t *peer) {
/** Closes the TUN/TAP device */
void fastd_iface_close(fastd_iface_t *iface) {
- if (!fastd_poll_fd_close(&iface->fd))
+ if (fastd_poll_fd_close(&iface->fd))
+ cleanup_iface(iface);
+ else
pr_warn_errno("closing TUN/TAP: close");
free(iface->name);