]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Added few basic commands: show status, show interfaces [summary],
authorMartin Mares <mj@ucw.cz>
Thu, 25 Nov 1999 15:35:30 +0000 (15:35 +0000)
committerMartin Mares <mj@ucw.cz>
Thu, 25 Nov 1999 15:35:30 +0000 (15:35 +0000)
show protocols (incomplete).

doc/reply_codes
nest/config.Y
nest/iface.c
nest/iface.h
nest/proto.c
nest/protocol.h

index 6f991d9d75f4f4dc3e9b167a701c3482a954b510..9a6cbe3f49cc31ebaf641ad358f4d84ea9545ff5 100644 (file)
@@ -11,6 +11,15 @@ Reply codes of BIRD command-line interface
 0000   OK
 0001   Welcome
 
+1002   Protocol list
+
+2000   BIRD version
+2001   Interface list
+2002   Protocol list
+2003   Interface address
+2004   Interface flags
+2005   Interface summary
+
 8000   Reply too long
 
 9000   Command too long
index 4000b6dc200f08253f9b264f016f44dd1547a5c3..7d3cbd724149f39bceb80fd51cffc4ff33aa0af9 100644 (file)
@@ -27,6 +27,7 @@ CF_ENUM(T_ENUM_RTS, RTS_, DUMMY, STATIC, INHERIT, DEVICE, STATIC_DEVICE, REDIREC
 %type <f> imexport
 %type <r> rtable
 %type <p> password_list password_begin
+%type <s> optsym
 
 CF_GRAMMAR
 
@@ -187,9 +188,25 @@ password_list:
 
 /* Core commands */
 
+CF_CLI_HELP(SHOW,,[[Show status information]])
+
+CF_CLI(SHOW STATUS,,, [[Show router status]]) {
+  cli_msg(2000, "BIRD " BIRD_VERSION);
+  /* FIXME: Should include uptime, shutdown flag et cetera */
+} ;
+
+CF_CLI(SHOW PROTOCOLS, optsym, [<name>], [[Show routing protocols]])
+{ proto_show($3); } ;
+
+CF_CLI(SHOW INTERFACES,,, [[Show network interfaces]])
+{ if_show(); } ;
+
+CF_CLI(SHOW INTERFACES SUMMARY,,, [[Show summary of network interfaces]])
+{ if_show_summary(); } ;
+
 /* FIXME: These are examples. Remove them soon. */
 CF_CLI_HELP(TEST, <subsystem>, [[Tests different subsystems]])
-CF_CLI(TEST LEDS, NUM, <N>, [[Flashes each LED <N> times]]) { cli_msg(0, "%d", $3); } ;
+CF_CLI(TEST LEDS, NUM, <N>, [[Flash each LED <N> times]]) { cli_msg(0, "%d", $3); } ;
 CF_CLI(TEST MEMORY,,, [[Replace all useful information by testing patterns]]) { cli_msg(0, "DONE"); } ;
 CF_CLI(TEST LONG,,, [[Test long replies]]) {
        static void test_command(struct cli *);
@@ -198,8 +215,14 @@ CF_CLI(TEST LONG,,, [[Test long replies]]) {
        cli_msg(-2, "Start");
 } ;
 
+optsym:
+   SYM
+ | /* empty */ { $$ = NULL; }
+ ;
+
 CF_CODE
 
+/* FIXME: Test only, remove */
 static void test_command(struct cli *c)
 {
        int i = (int) c->rover;
index debec45d859b58b87225acf85a2398800f76c5b1..4b024e10feea5b83bf2a06d2452e2e28cd06f61e 100644 (file)
@@ -11,6 +11,7 @@
 #include "nest/bird.h"
 #include "nest/iface.h"
 #include "nest/protocol.h"
+#include "nest/cli.h"
 #include "lib/resource.h"
 #include "lib/string.h"
 #include "conf/conf.h"
@@ -626,3 +627,79 @@ iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct ifac
     }
   return (!x->n.next && !y->n.next);
 }
+
+/*
+ *  CLI commands.
+ */
+
+static void
+if_show_addr(struct ifa *a)
+{
+  byte broad[STD_ADDRESS_P_LENGTH + 16];
+  byte opp[STD_ADDRESS_P_LENGTH + 16];
+
+  if (ipa_nonzero(a->brd))
+    bsprintf(broad, ", broadcast %I", a->brd);
+  else
+    broad[0] = 0;
+  if (ipa_nonzero(a->opposite))
+    bsprintf(opp, ", opposite %I", a->opposite);
+  else
+    opp[0] = 0;
+  cli_msg(-2003, "\t%I/%d (%s%s%s, scope %s)",
+         a->ip, a->pxlen,
+         (a->flags & IA_PRIMARY) ? "Primary" : (a->flags & IA_SECONDARY) ? "Secondary" : "???",
+         broad, opp,
+         ip_scope_text(a->scope));
+}
+
+void
+if_show(void)
+{
+  struct iface *i;
+  struct ifa *a;
+  char *type;
+
+  WALK_LIST(i, iface_list)
+    {
+      cli_msg(-2001, "%s %s (index=%d)", i->name, (i->flags & IF_UP) ? "up" : "DOWN", i->index);
+      if (i->flags & IF_UNNUMBERED)
+       type = "UnNum-PtP";
+      else if (!(i->flags & IF_MULTIACCESS))
+       type = "PtP";
+      else
+       type = "MultiAccess";
+      cli_msg(-2004, "\t%s%s%s Admin%s Link%s%s%s MTU=%d",
+             type,
+             (i->flags & IF_BROADCAST) ? " Broadcast" : "",
+             (i->flags & IF_MULTICAST) ? " Multicast" : "",
+             (i->flags & IF_ADMIN_DOWN) ? "Down" : "Up",
+             (i->flags & IF_LINK_UP) ? "Up" : "Down",
+             (i->flags & IF_LOOPBACK) ? " Loopback" : "",
+             (i->flags & IF_IGNORE) ? " Ignored" : "",
+             i->mtu);
+      if (i->addr)
+       if_show_addr(i->addr);
+      WALK_LIST(a, i->addrs)
+       if (a != i->addr)
+         if_show_addr(a);
+    }
+  cli_msg(0, "");
+}
+
+void
+if_show_summary(void)
+{
+  struct iface *i;
+  byte addr[STD_ADDRESS_P_LENGTH + 16];
+
+  WALK_LIST(i, iface_list)
+    {
+      if (i->addr)
+       bsprintf(addr, "%I/%d", i->addr->ip, i->addr->pxlen);
+      else
+       addr[0] = 0;
+      cli_msg(-2005, "%s\t%s\t%s", i->name, (i->flags & IF_UP) ? "up" : "DOWN", addr);
+    }
+  cli_msg(0, "");
+}
index 9f3a239556b4927e5ed3c82ad7b4276a8a8ea804..bee9caf64446f19b7c8b7a89306258164bf710c1 100644 (file)
@@ -43,7 +43,7 @@ struct iface {
 #define IF_UNNUMBERED 4
 #define IF_BROADCAST 8
 #define IF_MULTICAST 0x10
-#define IF_TUNNEL 0x20
+#define IF_TUNNEL 0x20                 /* FIXME: Remove? */
 #define IF_ADMIN_DOWN 0x40
 #define IF_LOOPBACK 0x80
 #define IF_IGNORE 0x100                        /* Not to be used by routing protocols (loopbacks etc.) */
@@ -69,6 +69,8 @@ void if_init(void);
 void if_dump(struct iface *);
 void if_dump_all(void);
 void ifa_dump(struct ifa *);
+void if_show(void);
+void if_show_summary(void);
 struct iface *if_update(struct iface *);
 struct ifa *ifa_update(struct ifa *);
 void ifa_delete(struct ifa *);
index 3430176faf5f4fd8a9ba300e979a64479ccb5424..32e0b3be9244be6abf400e0ddcbbff371edac0ba 100644 (file)
@@ -18,6 +18,7 @@
 #include "conf/conf.h"
 #include "nest/route.h"
 #include "nest/iface.h"
+#include "nest/cli.h"
 #include "filter/filter.h"
 
 static pool *proto_pool;
@@ -420,3 +421,11 @@ proto_flush_all(void *unused)
     }
   return 0;
 }
+
+void
+proto_show(struct symbol *s)
+{
+  cli_msg(-1002, "");
+  cli_msg(-2002, "");
+  cli_msg(0, "");
+}
index a2c0eb93703ee718a646aa3ec818a0b0e1334fbf..d9b5b17fc3b73c83669f4e19b37d3949ac69fed9 100644 (file)
@@ -23,6 +23,7 @@ struct config;
 struct proto;
 struct event;
 struct ea_list;
+struct symbol;
 
 /*
  *     Routing Protocol
@@ -143,6 +144,7 @@ struct proto {
 void proto_build(struct proto_config *);
 void *proto_new(struct proto_config *, unsigned size);
 void *proto_config_new(struct protocol *, unsigned size);
+void proto_show(struct symbol *);
 
 extern list proto_list;