0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

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.
This commit is contained in:
Pavel Tvrdik 2016-04-27 14:02:18 +02:00
parent df0f4cc92f
commit 0fc263c985
4 changed files with 34 additions and 3 deletions

View File

@ -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);
}
}

View File

@ -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)
{

View File

@ -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, "");
}

View File

@ -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);