diff --git a/babeld/patches/100-interface-local-add-remove-interface-function.patch b/babeld/patches/100-interface-local-add-remove-interface-function.patch new file mode 100644 index 0000000000..c70e8df381 --- /dev/null +++ b/babeld/patches/100-interface-local-add-remove-interface-function.patch @@ -0,0 +1,78 @@ +From 2f75f3d7073bad9b4b0c031aa792013fd6b61c19 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(+) + +--- a/interface.c ++++ b/interface.c +@@ -94,6 +94,39 @@ add_interface(char *ifname, struct inter + return ifp; + } + ++void ++remove_interface(char *ifname) ++{ ++ struct interface *tmp_ifp, *ifp = NULL; ++ ++ if(interfaces == NULL) ++ return; ++ ++ if(strcmp(interfaces->name, ifname) == 0) { ++ tmp_ifp = interfaces; ++ interface_updown(tmp_ifp, 0); ++ interfaces = tmp_ifp->next; ++ free(tmp_ifp); ++ return; ++ } ++ ++ FOR_ALL_INTERFACES(ifp) { ++ if(ifp->next == NULL) ++ break; ++ if(strcmp(ifp->next->name, ifname) == 0) { ++ break; ++ } ++ } ++ ++ if(ifp->next == NULL) ++ return; ++ ++ tmp_ifp = ifp->next; ++ interface_updown(tmp_ifp, 0); ++ ifp->next = tmp_ifp->next; ++ free(tmp_ifp); ++} ++ + int + flush_interface(char *ifname) + { +--- a/interface.h ++++ b/interface.h +@@ -147,6 +147,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); +--- 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 diff --git a/babeld/src/ubus.c b/babeld/src/ubus.c index 2066994efc..3bc952defb 100644 --- a/babeld/src/ubus.c +++ b/babeld/src/ubus.c @@ -89,6 +89,30 @@ static int babeld_ubus_add_interface(struct ubus_context *ctx_local, return UBUS_STATUS_OK; } +// Remove an inteface (ubus equivalent to "interface"-function). +static int babeld_ubus_remove_interface(struct ubus_context *ctx_local, + struct ubus_object *obj, + struct ubus_request_data *req, + const char *method, + struct blob_attr *msg) { + struct blob_attr *tb[__INTERFACE_MAX]; + struct blob_buf b = {0}; + struct interface *ifp = NULL; + char *ifname; + + blobmsg_parse(interface_policy, __INTERFACE_MAX, tb, blob_data(msg), + blob_len(msg)); + + if (!tb[INTERFACE_IFNAME]) + return UBUS_STATUS_INVALID_ARGUMENT; + + ifname = blobmsg_get_string(tb[INTERFACE_IFNAME]); + + remove_interface(ifname); + + return UBUS_STATUS_OK; +} + // Sends a babel info message on ubus socket. static int babeld_ubus_babeld_info(struct ubus_context *ctx_local, struct ubus_object *obj, @@ -364,6 +388,8 @@ static int babeld_ubus_get_neighbours(struct ubus_context *ctx_local, // List of functions we expose via the ubus bus. static const struct ubus_method babeld_methods[] = { UBUS_METHOD("add_interface", babeld_ubus_add_interface, interface_policy), + UBUS_METHOD("remove_interface", babeld_ubus_remove_interface, + interface_policy), UBUS_METHOD_NOARG("get_info", babeld_ubus_babeld_info), UBUS_METHOD_NOARG("get_xroutes", babeld_ubus_get_xroutes), UBUS_METHOD_NOARG("get_routes", babeld_ubus_get_routes),