From 84cdb09d6b71cf0bf186a041b33529c1851c6ee1 Mon Sep 17 00:00:00 2001 From: Polynomialdivision Date: Tue, 1 Feb 2022 22:37:29 +0100 Subject: [PATCH] interface/local: add remove_interface function Babeld can add interfaces dynamically. However, babeld is missing a function to remove interfaces and stop meshing on them. Add a function that can do it. Signed-off-by: Nick Hainke --- interface.c | 33 +++++++++++++++++++++++++++++++++ interface.h | 1 + local.h | 1 + 3 files changed, 35 insertions(+) diff --git a/interface.c b/interface.c index 946c7c47..c2076db8 100644 --- a/interface.c +++ b/interface.c @@ -96,6 +96,39 @@ add_interface(char *ifname, struct interface_conf *if_conf) return ifp; } +void +remove_interface(char *ifname) +{ + struct interface *ifp = NULL; + + if(interfaces == NULL) + return; + + if(strcmp(interfaces->name, ifname) == 0) { + ifp = interfaces; + interface_updown(ifp, 0); + interfaces = interfaces->next; + free(ifp); + return; + } + + FOR_ALL_INTERFACES(ifp) { + if(ifp->next == NULL) + break; + if(strcmp(ifp->next->name, ifname) == 0) { + break; + } + } + + if(ifp->next == NULL) + return; + + ifp = interfaces; + interface_updown(ifp, 0); + interfaces = ifp->next; + free(ifp); +} + int flush_interface(char *ifname) { diff --git a/interface.h b/interface.h index 467c144b..ce6fcdb0 100644 --- a/interface.h +++ b/interface.h @@ -163,6 +163,7 @@ if_up(struct interface *ifp) } struct interface *add_interface(char *ifname, struct interface_conf *if_conf); +void remove_interface(char *ifname); int flush_interface(char *ifname); unsigned jitter(struct buffered *buf, int urgent); unsigned update_jitter(struct interface *ifp, int urgent); diff --git a/local.h b/local.h index c300bc5f..53d81ff4 100644 --- a/local.h +++ b/local.h @@ -27,6 +27,7 @@ struct xroute; #define LOCAL_FLUSH 0 #define LOCAL_ADD 1 #define LOCAL_CHANGE 2 +#define LOCAL_REMOVE 3 #ifndef MAX_LOCAL_SOCKETS #define MAX_LOCAL_SOCKETS 4