summaryrefslogtreecommitdiffstats
path: root/src/iface.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/iface.c')
-rw-r--r--src/iface.c17
1 files changed, 16 insertions, 1 deletions
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);