Skip to content

Commit 8f09713

Browse files
babeld: add del_interface function
This commit adds the ubus function to dynamically delete filters on runtime: ubus call babeld del_filters '{"ifname":"eth0"}' Signed-off-by: Nick Hainke <vincent@systemli.org>
1 parent 6cccf1f commit 8f09713

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
From 7dc87f39dc5d1db7654f6ad89eca77766812affd Mon Sep 17 00:00:00 2001
2+
From: Nick Hainke <vincent@systemli.org>
3+
Date: Tue, 18 Oct 2022 21:34:03 +0200
4+
Subject: [PATCH] Add functions to delete filters from an interface
5+
6+
Adding a delete function at runtime allows the babeld ipc to add and
7+
remove interfaces with filters. Further, it also allows more dynamic
8+
routing selection.
9+
10+
Signed-off-by: Nick Hainke <vincent@systemli.org>
11+
---
12+
configuration.c | 42 ++++++++++++++++++++++++++++++++++++++++++
13+
1 file changed, 42 insertions(+)
14+
15+
diff --git a/configuration.c b/configuration.c
16+
index 95a71aa..6ec4e78 100644
17+
--- a/configuration.c
18+
+++ b/configuration.c
19+
@@ -837,6 +837,48 @@ parse_key(int c, gnc_t gnc, void *closure, struct key **key_return)
20+
return -2;
21+
}
22+
23+
+void
24+
+delete_filters_from_interface(char* ifname, struct filter **filters)
25+
+{
26+
+ struct filter *f;
27+
+
28+
+ while(*filters && (*filters)->ifname && strcmp(ifname, (*filters)->ifname) == 0)
29+
+ {
30+
+ f = *filters;
31+
+ *filters = f->next;
32+
+ free(f);
33+
+ }
34+
+
35+
+ f = *filters;
36+
+ while(f && f->next)
37+
+ {
38+
+ if(!f->next->ifname)
39+
+ {
40+
+ f = f->next;
41+
+ continue;
42+
+ }
43+
+
44+
+ if(strcmp(ifname, f->next->ifname) == 0)
45+
+ {
46+
+ struct filter *tmp;
47+
+ tmp = f->next;
48+
+ f->next = f->next->next;
49+
+ free(tmp);
50+
+ } else {
51+
+ f = f->next;
52+
+ }
53+
+ }
54+
+}
55+
+
56+
+void
57+
+delete_all_filters_from_interface(char* ifname)
58+
+{
59+
+ delete_filters_from_interface(ifname, &input_filters);
60+
+ delete_filters_from_interface(ifname, &output_filters);
61+
+ delete_filters_from_interface(ifname, &redistribute_filters);
62+
+ delete_filters_from_interface(ifname, &install_filters);
63+
+}
64+
+
65+
int
66+
add_filter(struct filter *filter, int type)
67+
{
68+
--
69+
2.38.1
70+

babeld/src/ubus.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,30 @@ static int babeld_ubus_add_filter(struct ubus_context *ctx_local,
117117
return UBUS_STATUS_OK;
118118
}
119119

120+
// Deletes filters for a given interface.
121+
static int babeld_ubus_del_filters(struct ubus_context *ctx_local,
122+
struct ubus_object *obj,
123+
struct ubus_request_data *req,
124+
const char *method,
125+
struct blob_attr *msg) {
126+
struct blob_attr *tb[__INTERFACE_MAX];
127+
struct blob_buf b = {0};
128+
struct interface *ifp = NULL;
129+
char *ifname;
130+
131+
blobmsg_parse(interface_policy, __INTERFACE_MAX, tb, blob_data(msg),
132+
blob_len(msg));
133+
134+
if (!tb[INTERFACE_IFNAME])
135+
return UBUS_STATUS_INVALID_ARGUMENT;
136+
137+
ifname = blobmsg_get_string(tb[INTERFACE_IFNAME]);
138+
139+
delete_all_filters_from_interface(ifname);
140+
141+
return UBUS_STATUS_OK;
142+
}
143+
120144
// Adds an inteface (ubus equivalent to "interface"-function).
121145
static int babeld_ubus_add_interface(struct ubus_context *ctx_local,
122146
struct ubus_object *obj,
@@ -419,6 +443,7 @@ static int babeld_ubus_get_neighbours(struct ubus_context *ctx_local,
419443
static const struct ubus_method babeld_methods[] = {
420444
UBUS_METHOD("add_interface", babeld_ubus_add_interface, interface_policy),
421445
UBUS_METHOD("add_filter", babeld_ubus_add_filter, filter_policy),
446+
UBUS_METHOD("del_filters", babeld_ubus_del_filters, interface_policy),
422447
UBUS_METHOD_NOARG("get_info", babeld_ubus_babeld_info),
423448
UBUS_METHOD_NOARG("get_xroutes", babeld_ubus_get_xroutes),
424449
UBUS_METHOD_NOARG("get_routes", babeld_ubus_get_routes),

babeld/src/ubus.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
2: FILTER_TYPE_REDISTRIBUTE
1010
3: FILTER_TYPE_INSTALL
1111
- add_interface '{"ifname":"eth0"}'
12+
- del_filters '{"ifname":"eth0"}'
1213
- get_info
1314
- get_neighbours
1415
- get_xroutes

0 commit comments

Comments
 (0)