diff options
author | Martin Mares <mj@ucw.cz> | 1999-12-03 11:41:23 +0000 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 1999-12-03 11:41:23 +0000 |
commit | feed82267663c6826da896309de180417bd0b39f (patch) | |
tree | a67184df9223e16bd0b59b69f5af0c45290deae6 /proto/static/static.c | |
parent | 02c1fbddd462fecc6887a44ef67202870bcae7be (diff) |
Implemented `show static'. It's a relatively good example of how to write
show commands for other protocols.
Diffstat (limited to 'proto/static/static.c')
-rw-r--r-- | proto/static/static.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/proto/static/static.c b/proto/static/static.c index d245be2f..4217ad03 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, ""); +} |