summaryrefslogtreecommitdiff
path: root/nest
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1999-11-25 15:35:30 +0000
committerMartin Mares <mj@ucw.cz>1999-11-25 15:35:30 +0000
commitae97b946e99bef043613d210489a926fe4807ec1 (patch)
tree6e8d2e4cd898dd67ef44e7bb851156039f681bbe /nest
parent35793769273f7286aafa0455547d1d7cfeef3931 (diff)
Added few basic commands: show status, show interfaces [summary],
show protocols (incomplete).
Diffstat (limited to 'nest')
-rw-r--r--nest/config.Y25
-rw-r--r--nest/iface.c77
-rw-r--r--nest/iface.h4
-rw-r--r--nest/proto.c9
-rw-r--r--nest/protocol.h2
5 files changed, 115 insertions, 2 deletions
diff --git a/nest/config.Y b/nest/config.Y
index 4000b6dc..7d3cbd72 100644
--- a/nest/config.Y
+++ b/nest/config.Y
@@ -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;
diff --git a/nest/iface.c b/nest/iface.c
index debec45d..4b024e10 100644
--- a/nest/iface.c
+++ b/nest/iface.c
@@ -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, "");
+}
diff --git a/nest/iface.h b/nest/iface.h
index 9f3a2395..bee9caf6 100644
--- a/nest/iface.h
+++ b/nest/iface.h
@@ -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 *);
diff --git a/nest/proto.c b/nest/proto.c
index 3430176f..32e0b3be 100644
--- a/nest/proto.c
+++ b/nest/proto.c
@@ -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, "");
+}
diff --git a/nest/protocol.h b/nest/protocol.h
index a2c0eb93..d9b5b17f 100644
--- a/nest/protocol.h
+++ b/nest/protocol.h
@@ -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;