]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Implemented `show static'. It's a relatively good example of how to write
authorMartin Mares <mj@ucw.cz>
Fri, 3 Dec 1999 11:41:23 +0000 (11:41 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 3 Dec 1999 11:41:23 +0000 (11:41 +0000)
show commands for other protocols.

doc/reply_codes
proto/static/config.Y
proto/static/static.c
proto/static/static.h

index abc2e6f68939d602ce0f8ae79c3b423d817a6d7a..844ed435f7f36bea92c04485edf593a48c8338b0 100644 (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
index df9e55b3b0aec0cd6b7e69018c20d5976f340dca..1e2d7a86cb9e4f89d4f72afe278f24976ab43b76 100644 (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
index d245be2f57da0f7b105acd505e484ef6cb578f6f..4217ad037fa776e4a69c06f46dc9033e5627921c 100644 (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, "");
+}
index 5299a9f898cf57b1d5f386bdf5af7bf35017b46c..66451183f9a1567287876aca258e8f438ce58814 100644 (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