Added few basic commands: show status, show interfaces [summary],

show protocols (incomplete).
This commit is contained in:
Martin Mares 1999-11-25 15:35:30 +00:00
parent 3579376927
commit ae97b946e9
6 changed files with 124 additions and 2 deletions

View 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

View 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;

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

View 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 *);

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

View 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;