[Babel-users] [PATCHv3] Allow to independently monitor events for neighbour, interface, route, xroute

Christof Schulze christof.schulze at gmx.net
Sun Aug 25 19:29:56 BST 2019


In large networks there is much traffic on the socket. This induces high load
even when only a subset of the data is relevant. This commit introduces new
commands on the socket for monitor neighbour, monitor route, monitor xroute,
monitor interface that will exclusively show changes for these structures.

This patch includes some style alterations. Specifying garbage as filter
for the monitor command is no longer accepted.

---
   babeld.man      | 16 +++++++++
   configuration.c | 48 +++++++++++++++++++++++----
   configuration.h |  8 +++++
   local.c         | 88 ++++++++++++++++++++++++++++++++++++++++---------
   local.h         | 14 +++++++-
   5 files changed, 151 insertions(+), 23 deletions(-)

diff --git a/babeld.man b/babeld.man
index cde4a2a..03ba1bd 100644
--- a/babeld.man
+++ b/babeld.man
@@ -619,6 +619,22 @@ any configuration file directive, including
   and
   .BR unmonitor ;
   .IP \(bu
+.B monitor neighbour
+and
+.BR unmonitor neighbour;
+.IP \(bu
+.B monitor route
+and
+.BR unmonitor route ;
+.IP \(bu
+.B monitor xroute
+and
+.BR unmonitor xroute ;
+.IP \(bu
+.B monitor interface
+and
+.BR unmonitor interface ;
+.IP \(bu
   .BR quit .
   .SH EXAMPLES
   You can participate in a Babel network by simply running
diff --git a/configuration.c b/configuration.c
index 6a11d53..b0078db 100644
--- a/configuration.c
+++ b/configuration.c
@@ -987,15 +987,49 @@ parse_config_line(int c, gnc_t gnc, void *closure,
               goto fail;
           *action_return = CONFIG_ACTION_DUMP;
       } else if(strcmp(token, "monitor") == 0) {
-        c = skip_eol(c, gnc, closure);
-        if(c < -1 || !action_return)
-            goto fail;
-        *action_return = CONFIG_ACTION_MONITOR;
+	*action_return = CONFIG_ACTION_MONITOR;
+	char *token2 = NULL;
+	c = skip_whitespace(c, gnc, closure);
+	c = getword(c, &token2, gnc, closure);
+	if(token2)
+	{
+            if(strcmp(token2, "route") == 0)
+                *action_return = CONFIG_ACTION_MONITOR_ROUTE;
+            else if(strcmp(token2, "interface") == 0)
+                *action_return = CONFIG_ACTION_MONITOR_INTERFACE;
+            else if(strcmp(token2, "xroute") == 0)
+                *action_return = CONFIG_ACTION_MONITOR_XROUTE;
+            else if(strcmp(token2, "neighbour") == 0)
+                *action_return = CONFIG_ACTION_MONITOR_NEIGHBOUR;
+            else {
+                free(token2);
+                goto fail;
+            }
+            free(token2);
+            c = skip_eol(c, gnc, closure);
+        }
+        else // monitor was detected but none of the specialties - monitoring everything.
+            c = -1;
       } else if(strcmp(token, "unmonitor") == 0) {
-        c = skip_eol(c, gnc, closure);
-        if(c < -1 || !action_return)
-            goto fail;
           *action_return = CONFIG_ACTION_UNMONITOR;
+        char *token2 = NULL;
+        c = skip_whitespace(c, gnc, closure);
+        c = getword(c, &token2, gnc, closure);
+	if(token2)
+	{
+                if(strcmp(token2, "route") == 0)
+                        *action_return = CONFIG_ACTION_UNMONITOR_ROUTE;
+                else if(strcmp(token2, "interface") == 0)
+                        *action_return = CONFIG_ACTION_UNMONITOR_INTERFACE;
+                else if(strcmp(token2, "xroute") == 0)
+                        *action_return = CONFIG_ACTION_UNMONITOR_XROUTE;
+                else if(strcmp(token2, "neighbour") == 0)
+                        *action_return = CONFIG_ACTION_UNMONITOR_NEIGHBOUR;
+                free(token2);
+                c = skip_eol(c, gnc, closure);
+	}
+	else // ummonitor was detected but none of the specialties - unmonitoring everything.
+	    c = -1;
       } else if(config_finalised && !local_server_write) {
           /* The remaining directives are only allowed in read-write mode. */
           c = skip_to_eol(c, gnc, closure);
diff --git a/configuration.h b/configuration.h
index de2b1ba..1a29b91 100644
--- a/configuration.h
+++ b/configuration.h
@@ -28,6 +28,14 @@ THE SOFTWARE.
   #define CONFIG_ACTION_MONITOR 3
   #define CONFIG_ACTION_UNMONITOR 4
   #define CONFIG_ACTION_NO 5
+#define CONFIG_ACTION_MONITOR_NEIGHBOUR 6
+#define CONFIG_ACTION_MONITOR_INTERFACE 7
+#define CONFIG_ACTION_MONITOR_ROUTE 8
+#define CONFIG_ACTION_MONITOR_XROUTE 9
+#define CONFIG_ACTION_UNMONITOR_NEIGHBOUR 10
+#define CONFIG_ACTION_UNMONITOR_INTERFACE 11
+#define CONFIG_ACTION_UNMONITOR_ROUTE 12
+#define CONFIG_ACTION_UNMONITOR_XROUTE 13

   struct filter_result {
       unsigned int add_metric; /* allow = 0, deny = INF, metric = <0..INF> */
diff --git a/local.c b/local.c
index bb8fe8b..ea4ded7 100644
--- a/local.c
+++ b/local.c
@@ -131,11 +131,12 @@ local_notify_interface(struct interface *ifp, int kind)
   {
       int i;
       for(i = 0; i < num_local_sockets; i++) {
-        if(local_sockets[i].monitor)
+        if(get_flag(&local_sockets[i].monitor, MONITOR_INTERFACE))
               local_notify_interface_1(&local_sockets[i], ifp, kind);
       }
   }

+
   static void
   local_notify_neighbour_1(struct local_socket *s,
                            struct neighbour *neigh, int kind)
@@ -186,7 +187,7 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
   {
       int i;
       for(i = 0; i < num_local_sockets; i++) {
-        if(local_sockets[i].monitor)
+        if(get_flag(&local_sockets[i].monitor, MONITOR_NEIGHBOUR))
               local_notify_neighbour_1(&local_sockets[i], neigh, kind);
       }
   }
@@ -223,7 +224,7 @@ local_notify_xroute(struct xroute *xroute, int kind)
   {
       int i;
       for(i = 0; i < num_local_sockets; i++) {
-        if(local_sockets[i].monitor)
+        if(get_flag(&local_sockets[i].monitor, MONITOR_XROUTE))
               local_notify_xroute_1(&local_sockets[i], xroute, kind);
       }
   }
@@ -268,26 +269,36 @@ local_notify_route(struct babel_route *route, int kind)
   {
       int i;
       for(i = 0; i < num_local_sockets; i++) {
-        if(local_sockets[i].monitor)
+        if(get_flag(&local_sockets[i].monitor, MONITOR_ROUTE))
               local_notify_route_1(&local_sockets[i], route, kind);
       }
   }

+
   static void
-local_notify_all_1(struct local_socket *s)
+local_notify_all_neighbour_1(struct local_socket *s)
   {
-    struct interface *ifp;
       struct neighbour *neigh;
-    struct xroute_stream *xroutes;
-    struct route_stream *routes;
+
+    FOR_ALL_NEIGHBOURS(neigh) {
+        local_notify_neighbour_1(s, neigh, LOCAL_ADD);
+    }
+}
+
+static void
+local_notify_all_interface_1(struct local_socket *s)
+{
+    struct interface *ifp;

       FOR_ALL_INTERFACES(ifp) {
           local_notify_interface_1(s, ifp, LOCAL_ADD);
       }
+}

-    FOR_ALL_NEIGHBOURS(neigh) {
-        local_notify_neighbour_1(s, neigh, LOCAL_ADD);
-    }
+static void
+local_notify_all_xroute_1(struct local_socket *s)
+{
+    struct xroute_stream *xroutes;

       xroutes = xroute_stream();
       if(xroutes) {
@@ -299,6 +310,12 @@ local_notify_all_1(struct local_socket *s)
           }
           xroute_stream_done(xroutes);
       }
+}
+
+static void
+local_notify_all_route_1(struct local_socket *s)
+{
+    struct route_stream *routes;

       routes = route_stream(ROUTE_ALL);
       if(routes) {
@@ -310,7 +327,35 @@ local_notify_all_1(struct local_socket *s)
           }
           route_stream_done(routes);
       }
-    return;
+}
+
+static void
+local_notify_all(struct local_socket *s)
+{
+    if(get_flag(&s->monitor, MONITOR_INTERFACE))
+        local_notify_all_interface_1(s);
+    if(get_flag(&s->monitor, MONITOR_NEIGHBOUR))
+        local_notify_all_neighbour_1(s);
+    if(get_flag(&s->monitor, MONITOR_ROUTE))
+        local_notify_all_route_1(s);
+    if(get_flag(&s->monitor, MONITOR_XROUTE))
+        local_notify_all_xroute_1(s);
+
+}
+
+static void
+local_notify_all_1(struct local_socket *s)
+{
+    local_notify_all_interface_1(s);
+    local_notify_all_neighbour_1(s);
+    local_notify_all_xroute_1(s);
+    local_notify_all_route_1(s);
+}
+
+unsigned int set_monitor_flag(unsigned int action)
+{
+    unsigned int flag = (action - (CONFIG_ACTION_MONITOR_NEIGHBOUR)) % (MONITOR_COUNT);
+    return (0x01 << (flag));
   }

   int
@@ -354,15 +399,28 @@ local_read(struct local_socket *s)
               local_notify_all_1(s);
               break;
           case CONFIG_ACTION_MONITOR:
+            s->monitor = 0xff;
               local_notify_all_1(s);
-            s->monitor = 1;
+            break;
+        case CONFIG_ACTION_MONITOR_NEIGHBOUR:
+        case CONFIG_ACTION_MONITOR_INTERFACE:
+        case CONFIG_ACTION_MONITOR_ROUTE:
+        case CONFIG_ACTION_MONITOR_XROUTE:
+            s->monitor |= set_monitor_flag(rc);
+            local_notify_all(s);
+            break;
+        case CONFIG_ACTION_UNMONITOR_NEIGHBOUR:
+        case CONFIG_ACTION_UNMONITOR_INTERFACE:
+        case CONFIG_ACTION_UNMONITOR_ROUTE:
+        case CONFIG_ACTION_UNMONITOR_XROUTE:
+            s->monitor &= ~set_monitor_flag(rc);
               break;
           case CONFIG_ACTION_UNMONITOR:
-            s->monitor = 0;
+            s->monitor = 0x00;
               break;
           case CONFIG_ACTION_NO:
               snprintf(reply, sizeof(reply), "no%s%s\n",
-                     message ? " " : "", message ? message : "");
+                            message ? " " : "", message ? message : "");
               break;
           default:
               snprintf(reply, sizeof(reply), "bad\n");
diff --git a/local.h b/local.h
index 2316111..5c5f7be 100644
--- a/local.h
+++ b/local.h
@@ -38,9 +38,21 @@ struct local_socket {
       int fd;
       char *buf;
       int n;
-    int monitor;
+    unsigned int monitor;
   };

+enum monitor_flags {
+        MONITOR_NEIGHBOUR = 0,
+        MONITOR_INTERFACE,
+        MONITOR_ROUTE,
+        MONITOR_XROUTE,
+        MONITOR_COUNT
+};
+
+inline unsigned int get_flag(unsigned int *monitor, unsigned int flag) {
+    return *monitor & (0x01 << flag);
+}
+
   extern int local_server_socket;
   extern struct local_socket local_sockets[MAX_LOCAL_SOCKETS];
   extern int num_local_sockets;
--
2.20.1




More information about the Babel-users mailing list