From feed82267663c6826da896309de180417bd0b39f Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 3 Dec 1999 11:41:23 +0000 Subject: [PATCH] Implemented `show static'. It's a relatively good example of how to write show commands for other protocols. --- doc/reply_codes | 1 + proto/static/config.Y | 3 +++ proto/static/static.c | 34 ++++++++++++++++++++++++++++++++++ proto/static/static.h | 3 +++ 4 files changed, 41 insertions(+) diff --git a/doc/reply_codes b/doc/reply_codes index abc2e6f68..844ed435f 100644 --- a/doc/reply_codes +++ b/doc/reply_codes @@ -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 diff --git a/proto/static/config.Y b/proto/static/config.Y index df9e55b3b..1e2d7a86c 100644 --- a/proto/static/config.Y +++ b/proto/static/config.Y @@ -57,6 +57,9 @@ stat_route: | stat_route0 PROHIBIT { this_srt->dest = RTD_PROHIBIT; } ; +CF_CLI(SHOW STATIC, optsym, [], [[Show details of static protocol]]) +{ static_show(proto_get_named($3, &proto_static)); } ; + CF_CODE CF_END diff --git a/proto/static/static.c b/proto/static/static.c index d245be2f5..4217ad037 100644 --- a/proto/static/static.c +++ b/proto/static/static.c @@ -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, ""); +} diff --git a/proto/static/static.h b/proto/static/static.h index 5299a9f89..66451183f 100644 --- a/proto/static/static.h +++ b/proto/static/static.h @@ -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 -- 2.39.2