Implemented `show static'. It's a relatively good example of how to write

show commands for other protocols.
This commit is contained in:
Martin Mares 1999-12-03 11:41:23 +00:00
parent 02c1fbddd4
commit feed822676
4 changed files with 41 additions and 0 deletions

View file

@ -20,6 +20,7 @@ Reply codes of BIRD command-line interface
1006 Protocol details
1007 Route list
1008 Route details
1009 Static route list
8000 Reply too long
8001 Route not found

View file

@ -57,6 +57,9 @@ stat_route:
| stat_route0 PROHIBIT { this_srt->dest = RTD_PROHIBIT; }
;
CF_CLI(SHOW STATIC, optsym, [<name>], [[Show details of static protocol]])
{ static_show(proto_get_named($3, &proto_static)); } ;
CF_CODE
CF_END

View file

@ -14,7 +14,9 @@
#include "nest/iface.h"
#include "nest/protocol.h"
#include "nest/route.h"
#include "nest/cli.h"
#include "conf/conf.h"
#include "lib/string.h"
#include "static.h"
@ -41,6 +43,7 @@ static_install(struct proto *p, struct static_route *r, struct iface *ifa)
e->net = n;
e->pflags = 0;
rte_update(p->table, n, p, e);
r->installed = 1;
}
static void
@ -52,6 +55,7 @@ static_remove(struct proto *p, struct static_route *r)
n = net_find(p->table, r->net, r->masklen);
if (n)
rte_update(p->table, n, p, NULL);
r->installed = 0;
}
static int
@ -177,3 +181,33 @@ struct protocol proto_static = {
dump: static_dump,
start: static_start,
};
static void
static_show_rt(struct static_route *r)
{
byte via[STD_ADDRESS_P_LENGTH + 16];
switch (r->dest)
{
case RTD_ROUTER: bsprintf(via, "via %I", r->via); break;
case RTD_DEVICE: bsprintf(via, "to %s", r->if_name); break;
case RTD_BLACKHOLE: bsprintf(via, "blackhole"); break;
case RTD_UNREACHABLE: bsprintf(via, "unreachable"); break;
case RTD_PROHIBIT: bsprintf(via, "prohibited"); break;
default: bsprintf(via, "???");
}
cli_msg(-1009, "%I/%d %s%s", r->net, r->masklen, via, r->installed ? "" : " (dormant)");
}
void
static_show(struct proto *P)
{
struct static_config *c = (void *) P->cf;
struct static_route *r;
WALK_LIST(r, c->other_routes)
static_show_rt(r);
WALK_LIST(r, c->iface_routes)
static_show_rt(r);
cli_msg(0, "");
}

View file

@ -26,6 +26,9 @@ struct static_route {
ip_addr via; /* Destination router */
struct neighbor *neigh;
byte *if_name; /* Name for RTD_DEVICE routes */
int installed; /* Installed in master table */
};
void static_show(struct proto *);
#endif