]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
BIRD sends notification to clients about interface updates client-next
authorPavel Tvrdik <pawel.tvrdik@gmail.com>
Wed, 27 Apr 2016 12:02:18 +0000 (14:02 +0200)
committerPavel Tvrdik <pawel.tvrdik@gmail.com>
Wed, 27 Apr 2016 13:22:30 +0000 (15:22 +0200)
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
nest/cli.h
nest/cmds.c
nest/iface.c

index d6c36636cd8f9cdb5b64a3946fc681b9091e3cc6..b49426845214e4b861b0054e39b67fb0ac7b0460 100644 (file)
 #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);
+  }
 }
index 92f3c3d75262486c0560b20af940abbf6e8bfce2..b1ed821f6c19be1c6c2d89d9db36e860a60b7139 100644 (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)
 {
index f3edf2a48343cdc8e49caa7922e1c17fd94b9caf..b1c1ae4872855d0237f79d8be4d40cac085096ae 100644 (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, "");
 }
index 00af5052926ff8343cafbaf812224fd6648c073a..2c89e31ee06961e2da0f5be50a05a26b116d3a72 100644 (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);