Skip to content

Commit 758a9b8

Browse files
christfMisterDA
authored andcommitted
Allow to independently monitor and dump events.
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.
1 parent 5f02903 commit 758a9b8

File tree

5 files changed

+169
-38
lines changed

5 files changed

+169
-38
lines changed

babeld.man

+4-9
Original file line numberDiff line numberDiff line change
@@ -607,18 +607,13 @@ replies with one or more lines of data terminated by one of
607607
or
608608
.BR bad .
609609

610-
The following requests are currently defined:
611-
.IP \(bu 2
612-
any configuration file directive, including
613-
.BR interface ;
610+
All configuration file directives are valid socket requests, including:
614611
.IP \(bu
615-
.BR "flush interface" ;
612+
.BR "[flush] interface"
616613
.IP \(bu
617-
.BR dump ;
614+
.BR "dump [neighbour|route|xroute|interface]"
618615
.IP \(bu
619-
.B monitor
620-
and
621-
.BR unmonitor ;
616+
.BR "[un]monitor [neighbour|route|xroute|interface]"
622617
.IP \(bu
623618
.BR quit .
624619
.SH EXAMPLES

configuration.c

+37-9
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,40 @@ parse_option(int c, gnc_t gnc, void *closure, char *token)
969969

970970
}
971971

972+
int
973+
parse_monitor_dump_filter(char *token, int *action_return, int c, gnc_t *gnc, void *closure)
974+
{
975+
char *token2 = NULL;
976+
c = skip_whitespace(c, *gnc, closure);
977+
978+
c = getword(c, &token2, *gnc, closure);
979+
980+
int filter = 0;
981+
if(token2) {
982+
if(strcmp(token2, "route") == 0)
983+
filter = FILTER_ROUTE;
984+
else if(strcmp(token2, "interface") == 0)
985+
filter = FILTER_INTERFACE;
986+
else if(strcmp(token2, "xroute") == 0)
987+
filter = FILTER_XROUTE;
988+
else if(strcmp(token2, "neighbour") == 0)
989+
filter = FILTER_NEIGHBOUR;
990+
else
991+
filter = FILTER_INVALID;
992+
free(token2);
993+
}
994+
995+
c = skip_eol(c, *gnc, closure);
996+
if(filter < FILTER_INVALID) {
997+
*action_return += filter;
998+
if(!filter) // no (invalid) filters detected, show everything
999+
c = -1;
1000+
} else {
1001+
c = -2;
1002+
}
1003+
return c;
1004+
}
1005+
9721006
static int
9731007
parse_config_line(int c, gnc_t gnc, void *closure,
9741008
int *action_return, const char **message_return)
@@ -996,20 +1030,14 @@ parse_config_line(int c, gnc_t gnc, void *closure,
9961030
goto fail;
9971031
*action_return = CONFIG_ACTION_QUIT;
9981032
} else if(strcmp(token, "dump") == 0) {
999-
c = skip_eol(c, gnc, closure);
1000-
if(c < -1 || !action_return)
1001-
goto fail;
10021033
*action_return = CONFIG_ACTION_DUMP;
1034+
c = parse_monitor_dump_filter(token, action_return, c, &gnc, closure);
10031035
} else if(strcmp(token, "monitor") == 0) {
1004-
c = skip_eol(c, gnc, closure);
1005-
if(c < -1 || !action_return)
1006-
goto fail;
10071036
*action_return = CONFIG_ACTION_MONITOR;
1037+
c = parse_monitor_dump_filter(token, action_return, c, &gnc, closure);
10081038
} else if(strcmp(token, "unmonitor") == 0) {
1009-
c = skip_eol(c, gnc, closure);
1010-
if(c < -1 || !action_return)
1011-
goto fail;
10121039
*action_return = CONFIG_ACTION_UNMONITOR;
1040+
c = parse_monitor_dump_filter(token, action_return, c, &gnc, closure);
10131041
} else if(config_finalised && !local_server_write) {
10141042
/* The remaining directives are only allowed in read-write mode. */
10151043
c = skip_to_eol(c, gnc, closure);

configuration.h

+21-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,27 @@ THE SOFTWARE.
2525
#define CONFIG_ACTION_DONE 0
2626
#define CONFIG_ACTION_QUIT 1
2727
#define CONFIG_ACTION_DUMP 2
28-
#define CONFIG_ACTION_MONITOR 3
29-
#define CONFIG_ACTION_UNMONITOR 4
30-
#define CONFIG_ACTION_NO 5
28+
#define CONFIG_ACTION_DUMP_NEIGHBOUR 3
29+
#define CONFIG_ACTION_DUMP_ROUTE 4
30+
#define CONFIG_ACTION_DUMP_XROUTE 5
31+
#define CONFIG_ACTION_DUMP_INTERFACE 6
32+
#define CONFIG_ACTION_NO 7
33+
#define CONFIG_ACTION_MONITOR 8
34+
#define CONFIG_ACTION_MONITOR_NEIGHBOUR 9
35+
#define CONFIG_ACTION_MONITOR_ROUTE 10
36+
#define CONFIG_ACTION_MONITOR_XROUTE 11
37+
#define CONFIG_ACTION_MONITOR_INTERFACE 12
38+
#define CONFIG_ACTION_UNMONITOR 13
39+
#define CONFIG_ACTION_UNMONITOR_NEIGHBOUR 14
40+
#define CONFIG_ACTION_UNMONITOR_ROUTE 15
41+
#define CONFIG_ACTION_UNMONITOR_XROUTE 16
42+
#define CONFIG_ACTION_UNMONITOR_INTERFACE 17
43+
44+
#define FILTER_NEIGHBOUR 1
45+
#define FILTER_ROUTE 2
46+
#define FILTER_XROUTE 3
47+
#define FILTER_INTERFACE 4
48+
#define FILTER_INVALID 255
3149

3250
struct filter_result {
3351
unsigned int add_metric; /* allow = 0, deny = INF, metric = <0..INF> */

local.c

+101-16
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ local_notify_interface(struct interface *ifp, int kind)
133133
{
134134
int i;
135135
for(i = 0; i < num_local_sockets; i++) {
136-
if(local_sockets[i].monitor)
136+
if(local_sockets[i].monitor & (0x01 << SHOW_INTERFACE))
137137
local_notify_interface_1(&local_sockets[i], ifp, kind);
138138
}
139139
}
140140

141+
141142
static void
142143
local_notify_neighbour_1(struct local_socket *s,
143144
struct neighbour *neigh, int kind)
@@ -188,7 +189,7 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
188189
{
189190
int i;
190191
for(i = 0; i < num_local_sockets; i++) {
191-
if(local_sockets[i].monitor)
192+
if(local_sockets[i].monitor & (0x01 << SHOW_NEIGHBOUR))
192193
local_notify_neighbour_1(&local_sockets[i], neigh, kind);
193194
}
194195
}
@@ -225,7 +226,7 @@ local_notify_xroute(struct xroute *xroute, int kind)
225226
{
226227
int i;
227228
for(i = 0; i < num_local_sockets; i++) {
228-
if(local_sockets[i].monitor)
229+
if(local_sockets[i].monitor & (0x01 << SHOW_XROUTE))
229230
local_notify_xroute_1(&local_sockets[i], xroute, kind);
230231
}
231232
}
@@ -270,26 +271,36 @@ local_notify_route(struct babel_route *route, int kind)
270271
{
271272
int i;
272273
for(i = 0; i < num_local_sockets; i++) {
273-
if(local_sockets[i].monitor)
274+
if(local_sockets[i].monitor & (0x01 << SHOW_ROUTE))
274275
local_notify_route_1(&local_sockets[i], route, kind);
275276
}
276277
}
277278

279+
278280
static void
279-
local_notify_all_1(struct local_socket *s)
281+
local_notify_all_neighbour_1(struct local_socket *s)
280282
{
281-
struct interface *ifp;
282283
struct neighbour *neigh;
283-
struct xroute_stream *xroutes;
284-
struct route_stream *routes;
284+
285+
FOR_ALL_NEIGHBOURS(neigh) {
286+
local_notify_neighbour_1(s, neigh, LOCAL_ADD);
287+
}
288+
}
289+
290+
static void
291+
local_notify_all_interface_1(struct local_socket *s)
292+
{
293+
struct interface *ifp;
285294

286295
FOR_ALL_INTERFACES(ifp) {
287296
local_notify_interface_1(s, ifp, LOCAL_ADD);
288297
}
298+
}
289299

290-
FOR_ALL_NEIGHBOURS(neigh) {
291-
local_notify_neighbour_1(s, neigh, LOCAL_ADD);
292-
}
300+
static void
301+
local_notify_all_xroute_1(struct local_socket *s)
302+
{
303+
struct xroute_stream *xroutes;
293304

294305
xroutes = xroute_stream();
295306
if(xroutes) {
@@ -301,6 +312,12 @@ local_notify_all_1(struct local_socket *s)
301312
}
302313
xroute_stream_done(xroutes);
303314
}
315+
}
316+
317+
static void
318+
local_notify_all_route_1(struct local_socket *s)
319+
{
320+
struct route_stream *routes;
304321

305322
routes = route_stream(ROUTE_ALL);
306323
if(routes) {
@@ -312,9 +329,60 @@ local_notify_all_1(struct local_socket *s)
312329
}
313330
route_stream_done(routes);
314331
}
315-
return;
316332
}
317333

334+
static void
335+
local_notify_all(struct local_socket *s, unsigned int mask)
336+
{
337+
if(mask & (0x01 << SHOW_INTERFACE))
338+
local_notify_all_interface_1(s);
339+
if(mask & (0x01 << SHOW_NEIGHBOUR))
340+
local_notify_all_neighbour_1(s);
341+
if(mask & (0x01 << SHOW_ROUTE))
342+
local_notify_all_route_1(s);
343+
if(mask & (0x01 << SHOW_XROUTE))
344+
local_notify_all_xroute_1(s);
345+
}
346+
347+
static void
348+
local_notify_all_1(struct local_socket *s)
349+
{
350+
local_notify_all_interface_1(s);
351+
local_notify_all_neighbour_1(s);
352+
local_notify_all_xroute_1(s);
353+
local_notify_all_route_1(s);
354+
}
355+
356+
static unsigned int
357+
show_flags_map(int rc)
358+
{
359+
switch(rc) {
360+
case CONFIG_ACTION_MONITOR_ROUTE:
361+
case CONFIG_ACTION_UNMONITOR_ROUTE:
362+
case CONFIG_ACTION_DUMP_ROUTE:
363+
return 0x01 << SHOW_ROUTE;
364+
case CONFIG_ACTION_MONITOR_INTERFACE:
365+
case CONFIG_ACTION_UNMONITOR_INTERFACE:
366+
case CONFIG_ACTION_DUMP_INTERFACE:
367+
return 0x01 << SHOW_INTERFACE;
368+
case CONFIG_ACTION_MONITOR_XROUTE:
369+
case CONFIG_ACTION_UNMONITOR_XROUTE:
370+
case CONFIG_ACTION_DUMP_XROUTE:
371+
return 0x01 << SHOW_XROUTE;
372+
case CONFIG_ACTION_MONITOR_NEIGHBOUR:
373+
case CONFIG_ACTION_UNMONITOR_NEIGHBOUR:
374+
case CONFIG_ACTION_DUMP_NEIGHBOUR:
375+
return 0x01 << SHOW_NEIGHBOUR;
376+
case CONFIG_ACTION_MONITOR:
377+
case CONFIG_ACTION_UNMONITOR:
378+
case CONFIG_ACTION_DUMP:
379+
return 0xff;
380+
}
381+
return 0;
382+
}
383+
384+
385+
318386
int
319387
local_read(struct local_socket *s)
320388
{
@@ -352,19 +420,36 @@ local_read(struct local_socket *s)
352420
shutdown(s->fd, 1);
353421
reply[0] = '\0';
354422
break;
423+
case CONFIG_ACTION_DUMP_INTERFACE:
424+
case CONFIG_ACTION_DUMP_ROUTE:
425+
case CONFIG_ACTION_DUMP_XROUTE:
426+
case CONFIG_ACTION_DUMP_NEIGHBOUR:
355427
case CONFIG_ACTION_DUMP:
356-
local_notify_all_1(s);
428+
local_notify_all(s, show_flags_map(rc));
357429
break;
358430
case CONFIG_ACTION_MONITOR:
431+
s->monitor = 0xff;
359432
local_notify_all_1(s);
360-
s->monitor = 1;
433+
break;
434+
case CONFIG_ACTION_MONITOR_NEIGHBOUR:
435+
case CONFIG_ACTION_MONITOR_INTERFACE:
436+
case CONFIG_ACTION_MONITOR_ROUTE:
437+
case CONFIG_ACTION_MONITOR_XROUTE:
438+
s->monitor |= show_flags_map(rc);
439+
local_notify_all(s, show_flags_map(rc));
440+
break;
441+
case CONFIG_ACTION_UNMONITOR_NEIGHBOUR:
442+
case CONFIG_ACTION_UNMONITOR_INTERFACE:
443+
case CONFIG_ACTION_UNMONITOR_ROUTE:
444+
case CONFIG_ACTION_UNMONITOR_XROUTE:
445+
s->monitor &= ~show_flags_map(rc);
361446
break;
362447
case CONFIG_ACTION_UNMONITOR:
363-
s->monitor = 0;
448+
s->monitor = 0x00;
364449
break;
365450
case CONFIG_ACTION_NO:
366451
snprintf(reply, sizeof(reply), "no%s%s\n",
367-
message ? " " : "", message ? message : "");
452+
message ? " " : "", message ? message : "");
368453
break;
369454
default:
370455
snprintf(reply, sizeof(reply), "bad\n");

local.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ struct local_socket {
3838
int fd;
3939
char *buf;
4040
int n;
41-
int monitor;
41+
unsigned int monitor;
4242
};
4343

44+
#define SHOW_NEIGHBOUR 1
45+
#define SHOW_INTERFACE 2
46+
#define SHOW_ROUTE 3
47+
#define SHOW_XROUTE 4
48+
4449
extern int local_server_socket;
4550
extern struct local_socket local_sockets[MAX_LOCAL_SOCKETS];
4651
extern int num_local_sockets;

0 commit comments

Comments
 (0)