summaryrefslogtreecommitdiff
path: root/babeld/src
diff options
context:
space:
mode:
authorPolynomdivision <vincent@systemli.org>2021-02-01 15:26:44 +0100
committerGitHub <noreply@github.com>2021-02-01 15:26:44 +0100
commit519c1ff73168eb57a1b06fd2222710802f441a2a (patch)
tree81cad79804c642df00679ae0e02522327e687a97 /babeld/src
parent2e602f7b33c04a60ee7f8a3c08da8ebb76b5f53b (diff)
babeld: send events via ubus (#633)
* babeld: send events via ubus Send a notification via the ubus bus if we experience any changes in neighbours, routes or xroutes. The format looks like this: {route,xroute,neighbour}.add: Object was added {route,xroute,neighbour}.change: Object was changed {route,xroute,neighbour}.flush: Object was flushed If ubus_bindings is turned off, it will minimally effect performance, since only an if-statement has to be evaluated. If no subscriber is available, it will minimally change the performance, since only an if-statmenet that checks for subscribers has to be evaluated. Signed-off-by: Nick Hainke <vincent@systemli.org>
Diffstat (limited to 'babeld/src')
-rw-r--r--babeld/src/ubus.c69
-rw-r--r--babeld/src/ubus.h56
2 files changed, 114 insertions, 11 deletions
diff --git a/babeld/src/ubus.c b/babeld/src/ubus.c
index 5bec96f..d1909c7 100644
--- a/babeld/src/ubus.c
+++ b/babeld/src/ubus.c
@@ -87,7 +87,8 @@ static void babeld_add_xroute_buf(struct xroute *xroute, struct blob_buf *b) {
blobmsg_close_table(b, prefix);
}
-// Sends an exported routes message on ubus socket, splitting apart IPv4 and IPv6 routes.
+// Sends an exported routes message on ubus socket, splitting apart IPv4 and
+// IPv6 routes.
static void babeld_ubus_get_xroutes(struct ubus_context *ctx_local,
struct ubus_object *obj,
struct ubus_request_data *req,
@@ -187,7 +188,8 @@ static void babeld_add_route_buf(struct babel_route *route,
blobmsg_close_table(b, prefix);
}
-// Sends received routes message on ubus socket, splitting apart IPv4 and IPv6 routes.
+// Sends received routes message on ubus socket, splitting apart IPv4 and IPv6
+// routes.
static void babeld_ubus_get_routes(struct ubus_context *ctx_local,
struct ubus_object *obj,
struct ubus_request_data *req,
@@ -259,7 +261,8 @@ static void babeld_add_neighbour_buf(struct neighbour *neigh,
blobmsg_close_table(b, neighbour);
}
-// Sends neighbours message on ubus socket, splitting apart IPv4 and IPv6 neighbours.
+// Sends neighbours message on ubus socket, splitting apart IPv4 and IPv6
+// neighbours.
static void babeld_ubus_get_neighbours(struct ubus_context *ctx_local,
struct ubus_object *obj,
struct ubus_request_data *req,
@@ -342,7 +345,8 @@ static bool ubus_init_object() {
return true;
}
-// Initializes the global ubus context, connecting to the bus to be able to receive and send messages.
+// Initializes the global ubus context, connecting to the bus to be able to
+// receive and send messages.
static bool babeld_ubus_init(void) {
if (shared_ctx)
return true;
@@ -354,6 +358,63 @@ static bool babeld_ubus_init(void) {
return true;
}
+void ubus_notify_route(struct babel_route *route, int kind) {
+ struct blob_buf b = {0};
+ char method[50]; // possible methods are route.change, route.add, route.flush
+
+ if (!babeld_object.has_subscribers)
+ return;
+
+ if (!route)
+ return;
+
+ if (!shared_ctx)
+ return;
+
+ blob_buf_init(&b, 0);
+ babeld_add_route_buf(route, &b);
+ snprintf(method, sizeof(method), "route.%s", local_kind(kind));
+ ubus_notify(shared_ctx, &babeld_object, method, b.head, -1);
+}
+
+void ubus_notify_xroute(struct xroute *xroute, int kind) {
+ struct blob_buf b = {0};
+ char method[50]; // possible methods are xroute.change, xroute.add, xroute.flush
+
+ if (!babeld_object.has_subscribers)
+ return;
+
+ if (!xroute)
+ return;
+
+ if (!shared_ctx)
+ return;
+
+ blob_buf_init(&b, 0);
+ babeld_add_xroute_buf(xroute, &b);
+ snprintf(method, sizeof(method), "xroute.%s", local_kind(kind));
+ ubus_notify(shared_ctx, &babeld_object, method, b.head, -1);
+}
+
+void ubus_notify_neighbour(struct neighbour *neigh, int kind) {
+ struct blob_buf b = {0};
+ char method[50]; // possible methods are neigh.change, neigh.add, neigh.flush
+
+ if (!babeld_object.has_subscribers)
+ return;
+
+ if (!neigh)
+ return;
+
+ if (!shared_ctx)
+ return;
+
+ blob_buf_init(&b, 0);
+ babeld_add_neighbour_buf(neigh, &b);
+ snprintf(method, sizeof(method), "neigh.%s", local_kind(kind));
+ ubus_notify(shared_ctx, &babeld_object, method, b.head, -1);
+}
+
void babeld_ubus_receive(fd_set *readfds) {
if (!shared_ctx)
return;
diff --git a/babeld/src/ubus.h b/babeld/src/ubus.h
index 84be97f..66ef997 100644
--- a/babeld/src/ubus.h
+++ b/babeld/src/ubus.h
@@ -1,13 +1,24 @@
/*
IPC integration of babeld with OpenWrt.
-
+
The ubus interface offers following functions:
- get_info
- get_neighbours
- get_xroutes
- get_routes
-
+
All output is divided into IPv4 and IPv6.
+
+ Ubus notifications are sent if we receive updates for
+ - xroutes
+ - routes
+ - neighbours
+
+ The format is:
+ - {route,xroute,neighbour}.add: Object was added
+ - {route,xroute,neighbour}.change: Object was changed
+ - {route,xroute,neighbour}.flush: Object was flushed
+
*/
#include <libubus.h>
@@ -28,18 +39,49 @@ bool babeld_add_ubus();
* Add ubus socket to given filedescriptor set.
*
* We need to check repeatedly if the ubus socket has something to read.
- * The functions allows to add the ubus socket to the normal while(1)-loop of babeld.
+ * The functions allows to add the ubus socket to the normal while(1)-loop of
+ * babeld.
*
* @param readfs: the filedescriptor set
* @param maxfd: the current maximum file descriptor
* @return the maximum file descriptor
*/
-int babeld_ubus_add_read_sock(fd_set* readfds, int maxfd);
-
+int babeld_ubus_add_read_sock(fd_set *readfds, int maxfd);
/**
* Check and process ubus socket.
*
- * If the ubus-socket signals that data is available, the ubus_handle_event is called.
+ * If the ubus-socket signals that data is available, the ubus_handle_event is
+ * called.
+ */
+void babeld_ubus_receive(fd_set *readfds);
+
+/***
+ * Notify the ubus bus that a new xroute is received.
+ *
+ * If a new xroute is received or changed, we will notify subscribers.
+ *
+ * @param xroute: xroute that experienced some change
+ * @param kind: kind that describes if we have a flush, add or change
+ */
+void ubus_notify_xroute(struct xroute *xroute, int kind);
+
+/***
+ * Notify the ubus bus that a new route is received.
+ *
+ * If a new route is received or changed, we will notify subscribers.
+ *
+ * @param route: route that experienced some change
+ * @param kind: kind that describes if we have a flush, add or change
+ */
+void ubus_notify_route(struct babel_route *route, int kind);
+
+/***
+ * Notify the ubus bus that a new neighbour is received.
+ *
+ * If a new neighbour is received or changed, we will notify subscribers.
+ *
+ * @param neigh: neighbour that experienced some change
+ * @param kind: kind that describes if we have a flush, add or change
*/
-void babeld_ubus_receive(fd_set* readfds);
+void ubus_notify_neighbour(struct neighbour *neigh, int kind);