From 0fc263c985e2a33b5a98d5dd8c7244e0290d9dfe Mon Sep 17 00:00:00 2001 From: Pavel Tvrdik Date: Wed, 27 Apr 2016 14:02:18 +0200 Subject: [PATCH] BIRD sends notification to clients about interface updates Adds a list of all connected cli clients to deamon. Send to all cli clients notification about interfaces states up and down. --- nest/cli.c | 23 +++++++++++++++++++++++ nest/cli.h | 2 ++ nest/cmds.c | 3 ++- nest/iface.c | 9 +++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/nest/cli.c b/nest/cli.c index d6c36636..b4942684 100644 --- a/nest/cli.c +++ b/nest/cli.c @@ -68,8 +68,10 @@ #include "nest/cli.h" #include "conf/conf.h" #include "lib/string.h" +#include "client/reply_codes.h" pool *cli_pool; +static list cli_client_list; static byte * cli_alloc_out(cli *c, int size) @@ -310,6 +312,7 @@ cli_new(void *priv) c->parser_pool = lp_new(c->pool, 4096); c->rx_buf = mb_alloc(c->pool, CLI_RX_BUF_SIZE); ev_schedule(c->event); + add_tail(&cli_client_list, &c->cli_client_node); return c; } @@ -401,6 +404,7 @@ cli_free(cli *c) c->cleanup(c); if (c == cmd_reconfig_stored_cli) cmd_reconfig_stored_cli = NULL; + rem2_node(&c->cli_client_node); rfree(c->pool); } @@ -416,4 +420,23 @@ cli_init(void) cli_pool = rp_new(&root_pool, "CLI"); init_list(&cli_log_hooks); cli_log_inited = 1; + init_list(&cli_client_list); +} + +/** + * cli_notify_all_clients - send push notification to all cli clients + * + * Send a notification to all command line clients about some news. + * Client could then send a request for pulling symbols. + */ +void +cli_notify_all_clients(void) +{ + struct cli *cli; + node *n; + WALK_LIST2(cli, n, cli_client_list, cli_client_node) + { + cli_printf(cli, RC_NOTIFY, ""); + cli_write_trigger(cli); + } } diff --git a/nest/cli.h b/nest/cli.h index 92f3c3d7..b1ed821f 100644 --- a/nest/cli.h +++ b/nest/cli.h @@ -27,6 +27,7 @@ struct cli_out { typedef struct cli { node n; /* Node in list of all log hooks */ + node cli_client_node; /* Node in list of all cli clients */ pool *pool; void *priv; /* Private to sysdep layer */ byte *rx_buf, *rx_pos, *rx_aux; /* sysdep */ @@ -65,6 +66,7 @@ void cli_free(cli *); void cli_kick(cli *); void cli_written(cli *); void cli_echo(uint class, byte *msg); +void cli_notify_all_clients(void); static inline int cli_access_restricted(void) { diff --git a/nest/cmds.c b/nest/cmds.c index f3edf2a4..b1c1ae48 100644 --- a/nest/cmds.c +++ b/nest/cmds.c @@ -105,7 +105,8 @@ cmd_send_symbols(void) struct iface *i; WALK_LIST(i, iface_list) - cli_msg(RC_INTERFACE_NAME, "\"%s\"", i->name); + if (!(i->flags & IF_SHUTDOWN)) + cli_msg(RC_INTERFACE_NAME, "\"%s\"", i->name); cli_msg(0, ""); } diff --git a/nest/iface.c b/nest/iface.c index 00af5052..2c89e31e 100644 --- a/nest/iface.c +++ b/nest/iface.c @@ -206,27 +206,32 @@ if_notify_change(unsigned c, struct iface *i) #endif if (c & IF_CHANGE_DOWN) + { neigh_if_down(i); - if (c & IF_CHANGE_DOWN) WALK_LIST(a, i->addrs) { a->flags = (i->flags & ~IA_FLAGS) | (a->flags & IA_FLAGS); ifa_notify_change_(IF_CHANGE_DOWN, a); } + cli_notify_all_clients(); + } + WALK_LIST(p, proto_list) if_send_notify(p, c, i); if (c & IF_CHANGE_UP) + { WALK_LIST(a, i->addrs) { a->flags = (i->flags & ~IA_FLAGS) | (a->flags & IA_FLAGS); ifa_notify_change_(IF_CHANGE_UP, a); } - if (c & IF_CHANGE_UP) neigh_if_up(i); + cli_notify_all_clients(); + } if ((c & (IF_CHANGE_UP | IF_CHANGE_DOWN | IF_CHANGE_LINK)) == IF_CHANGE_LINK) neigh_if_link(i);