Skip to content

Commit

Permalink
Fix nits in independent monitor code.
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterDA committed Apr 21, 2020
1 parent 758a9b8 commit 13226d1
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 49 deletions.
52 changes: 26 additions & 26 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,38 +969,38 @@ parse_option(int c, gnc_t gnc, void *closure, char *token)

}

int
parse_monitor_dump_filter(char *token, int *action_return, int c, gnc_t *gnc, void *closure)
static int
parse_monitor_dump_filter(int *action_return, int c, gnc_t *gnc, void *closure)
{
char *token2 = NULL;
c = skip_whitespace(c, *gnc, closure);

c = getword(c, &token2, *gnc, closure);

int filter = 0;
if(token2) {
if(strcmp(token2, "route") == 0)
filter = FILTER_ROUTE;
else if(strcmp(token2, "interface") == 0)
filter = FILTER_INTERFACE;
else if(strcmp(token2, "xroute") == 0)
filter = FILTER_XROUTE;
else if(strcmp(token2, "neighbour") == 0)
filter = FILTER_NEIGHBOUR;
else
filter = FILTER_INVALID;
free(token2);
char *token = NULL;

c = skip_whitespace(c, *gnc, closure);
c = getword(c, &token, *gnc, closure);
if(c < -1 || token == NULL) {
free(token);
return c;
}

if(strcmp(token, "route") == 0)
filter = FILTER_ROUTE;
else if(strcmp(token, "interface") == 0)
filter = FILTER_INTERFACE;
else if(strcmp(token, "xroute") == 0)
filter = FILTER_XROUTE;
else if(strcmp(token, "neighbour") == 0)
filter = FILTER_NEIGHBOUR;
else
filter = FILTER_INVALID;
free(token);

c = skip_eol(c, *gnc, closure);
if(filter < FILTER_INVALID) {
*action_return += filter;
if(!filter) // no (invalid) filters detected, show everything
c = -1;
} else {
c = -2;
return -1;
}
return c;
return -2;
}

static int
Expand Down Expand Up @@ -1031,13 +1031,13 @@ parse_config_line(int c, gnc_t gnc, void *closure,
*action_return = CONFIG_ACTION_QUIT;
} else if(strcmp(token, "dump") == 0) {
*action_return = CONFIG_ACTION_DUMP;
c = parse_monitor_dump_filter(token, action_return, c, &gnc, closure);
c = parse_monitor_dump_filter(action_return, c, &gnc, closure);
} else if(strcmp(token, "monitor") == 0) {
*action_return = CONFIG_ACTION_MONITOR;
c = parse_monitor_dump_filter(token, action_return, c, &gnc, closure);
c = parse_monitor_dump_filter(action_return, c, &gnc, closure);
} else if(strcmp(token, "unmonitor") == 0) {
*action_return = CONFIG_ACTION_UNMONITOR;
c = parse_monitor_dump_filter(token, action_return, c, &gnc, closure);
c = parse_monitor_dump_filter(action_return, c, &gnc, closure);
} else if(config_finalised && !local_server_write) {
/* The remaining directives are only allowed in read-write mode. */
c = skip_to_eol(c, gnc, closure);
Expand Down
35 changes: 16 additions & 19 deletions local.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,11 @@ local_notify_interface(struct interface *ifp, int kind)
{
int i;
for(i = 0; i < num_local_sockets; i++) {
if(local_sockets[i].monitor & (0x01 << SHOW_INTERFACE))
if(local_sockets[i].monitor & SHOW_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)
Expand Down Expand Up @@ -189,7 +188,7 @@ local_notify_neighbour(struct neighbour *neigh, int kind)
{
int i;
for(i = 0; i < num_local_sockets; i++) {
if(local_sockets[i].monitor & (0x01 << SHOW_NEIGHBOUR))
if(local_sockets[i].monitor & SHOW_NEIGHBOUR)
local_notify_neighbour_1(&local_sockets[i], neigh, kind);
}
}
Expand Down Expand Up @@ -226,7 +225,7 @@ local_notify_xroute(struct xroute *xroute, int kind)
{
int i;
for(i = 0; i < num_local_sockets; i++) {
if(local_sockets[i].monitor & (0x01 << SHOW_XROUTE))
if(local_sockets[i].monitor & SHOW_XROUTE)
local_notify_xroute_1(&local_sockets[i], xroute, kind);
}
}
Expand Down Expand Up @@ -271,7 +270,7 @@ local_notify_route(struct babel_route *route, int kind)
{
int i;
for(i = 0; i < num_local_sockets; i++) {
if(local_sockets[i].monitor & (0x01 << SHOW_ROUTE))
if(local_sockets[i].monitor & SHOW_ROUTE)
local_notify_route_1(&local_sockets[i], route, kind);
}
}
Expand Down Expand Up @@ -334,13 +333,13 @@ local_notify_all_route_1(struct local_socket *s)
static void
local_notify_all(struct local_socket *s, unsigned int mask)
{
if(mask & (0x01 << SHOW_INTERFACE))
if(mask & SHOW_INTERFACE)
local_notify_all_interface_1(s);
if(mask & (0x01 << SHOW_NEIGHBOUR))
if(mask & SHOW_NEIGHBOUR)
local_notify_all_neighbour_1(s);
if(mask & (0x01 << SHOW_ROUTE))
if(mask & SHOW_ROUTE)
local_notify_all_route_1(s);
if(mask & (0x01 << SHOW_XROUTE))
if(mask & SHOW_XROUTE)
local_notify_all_xroute_1(s);
}

Expand All @@ -360,29 +359,27 @@ show_flags_map(int rc)
case CONFIG_ACTION_MONITOR_ROUTE:
case CONFIG_ACTION_UNMONITOR_ROUTE:
case CONFIG_ACTION_DUMP_ROUTE:
return 0x01 << SHOW_ROUTE;
return SHOW_ROUTE;
case CONFIG_ACTION_MONITOR_INTERFACE:
case CONFIG_ACTION_UNMONITOR_INTERFACE:
case CONFIG_ACTION_DUMP_INTERFACE:
return 0x01 << SHOW_INTERFACE;
return SHOW_INTERFACE;
case CONFIG_ACTION_MONITOR_XROUTE:
case CONFIG_ACTION_UNMONITOR_XROUTE:
case CONFIG_ACTION_DUMP_XROUTE:
return 0x01 << SHOW_XROUTE;
return SHOW_XROUTE;
case CONFIG_ACTION_MONITOR_NEIGHBOUR:
case CONFIG_ACTION_UNMONITOR_NEIGHBOUR:
case CONFIG_ACTION_DUMP_NEIGHBOUR:
return 0x01 << SHOW_NEIGHBOUR;
return SHOW_NEIGHBOUR;
case CONFIG_ACTION_MONITOR:
case CONFIG_ACTION_UNMONITOR:
case CONFIG_ACTION_DUMP:
return 0xff;
return ~0U;
}
return 0;
return 0U;
}



int
local_read(struct local_socket *s)
{
Expand Down Expand Up @@ -445,11 +442,11 @@ local_read(struct local_socket *s)
s->monitor &= ~show_flags_map(rc);
break;
case CONFIG_ACTION_UNMONITOR:
s->monitor = 0x00;
s->monitor = 0U;
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");
Expand Down
8 changes: 4 additions & 4 deletions local.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ struct local_socket {
unsigned int monitor;
};

#define SHOW_NEIGHBOUR 1
#define SHOW_INTERFACE 2
#define SHOW_ROUTE 3
#define SHOW_XROUTE 4
#define SHOW_NEIGHBOUR (1 << 0)
#define SHOW_INTERFACE (1 << 1)
#define SHOW_ROUTE (1 << 2)
#define SHOW_XROUTE (1 << 3)

extern int local_server_socket;
extern struct local_socket local_sockets[MAX_LOCAL_SOCKETS];
Expand Down

0 comments on commit 13226d1

Please sign in to comment.