]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Adds filtering to 'show ospf lsadb' command.
authorOndrej Zajicek <santiago@crfreenet.org>
Fri, 16 Mar 2012 11:12:26 +0000 (12:12 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Fri, 16 Mar 2012 11:12:26 +0000 (12:12 +0100)
Thanks Alexander V. Chernikov for the original patch.

conf/confbase.Y
doc/bird.sgml
proto/ospf/config.Y
proto/ospf/ospf.c
proto/ospf/ospf.h

index 14893f47e9d90abc51e786685cd37a4140bd4834..b952f314a89d920e1501d7d34580545144c10d31 100644 (file)
@@ -50,6 +50,7 @@ CF_DECLS
   struct f_path_mask *h;
   struct password_item *p;
   struct rt_show_data *ra;
+  struct lsadb_show_data *ld;
   struct iface *iface;
   void *g;
   bird_clock_t time;
index 4abe706c2a211da5f2099f30943700995217a38e..f5cfdfb124075725d1ea9e2c0c6be089ad063002 100644 (file)
@@ -561,6 +561,9 @@ This argument can be omitted if there exists only a single instance.
        link-state database.  It is just a stripped-down version of
        'show ospf state'.
 
+       <tag>show ospf lsadb [global | area <m/id/ | link] [type <m/num/] [lsid <m/id/] [self | router <m/id/] [<m/name/] </tag>
+       Show contents of an OSPF LSA database. Options could be used to filter entries.
+
        <tag>show static [<m/name/]</tag>
        Show detailed information about static routes.
 
index 24e125a7c419f6459811ee6e753bda9b5fee8453..9c48a9b8b9c928a6f9293b4a2d148209c07fc0b4 100644 (file)
@@ -120,8 +120,10 @@ CF_KEYWORDS(NONE, SIMPLE, AUTHENTICATION, STRICT, CRYPTOGRAPHIC)
 CF_KEYWORDS(ELIGIBLE, POLL, NETWORKS, HIDDEN, VIRTUAL, CHECK, LINK)
 CF_KEYWORDS(RX, BUFFER, LARGE, NORMAL, STUBNET, HIDDEN, SUMMARY, TAG, EXTERNAL)
 CF_KEYWORDS(WAIT, DELAY, LSADB, ECMP, LIMIT, WEIGHT, NSSA, TRANSLATOR, STABILITY)
+CF_KEYWORDS(GLOBAL, LSID, ROUTER, SELF)
 
 %type <t> opttext
+%type <ld> lsadb_args
 
 CF_GRAMMAR
 
@@ -411,8 +413,22 @@ CF_CLI(SHOW OSPF STATE, optsym opttext, [<name>], [[Show information about reach
 CF_CLI(SHOW OSPF STATE ALL, optsym opttext, [<name>], [[Show information about all OSPF network state]])
 { ospf_sh_state(proto_get_named($5, &proto_ospf), 1, 0); };
 
-CF_CLI(SHOW OSPF LSADB, optsym opttext, [<name>], [[Show content of OSPF LSA database]])
-{ ospf_sh_lsadb(proto_get_named($4, &proto_ospf)); };
+CF_CLI(SHOW OSPF LSADB, lsadb_args, [global | area <id> | link] [type <num>] [lsid <id>] [self | router <id>] [<proto>], [[Show content of OSPF LSA database]])
+{ ospf_sh_lsadb($4); };
+
+lsadb_args:
+   /* empty */ {
+     $$ = cfg_allocz(sizeof(struct lsadb_show_data));
+   }
+ | lsadb_args GLOBAL { $$ = $1; $$->scope = LSA_SCOPE_AS; }
+ | lsadb_args AREA idval { $$ = $1; $$->scope = LSA_SCOPE_AREA; $$->area = $3 }
+ | lsadb_args LINK { $$ = $1; $$->scope = 1; /* hack, 0 is no filter */ }
+ | lsadb_args TYPE NUM { $$ = $1; $$->type = $3; }
+ | lsadb_args LSID idval { $$ = $1; $$->lsid = $3; }
+ | lsadb_args SELF { $$ = $1; $$->router = SH_ROUTER_SELF; }
+ | lsadb_args ROUTER idval { $$ = $1; $$->router = $3; }
+ | lsadb_args SYM { $$ = $1; $$->name = $2; }
+ ;
 
 CF_CODE
 
index 73c06c27f241985c7b0321b0e05fd11e43536f84..9872faf28b788da0eda3fae1726513036fbdb524 100644 (file)
@@ -1471,8 +1471,9 @@ lsa_compare_for_lsadb(const void *p1, const void *p2)
 }
 
 void
-ospf_sh_lsadb(struct proto *p)
+ospf_sh_lsadb(struct lsadb_show_data *ld)
 {
+  struct proto *p = proto_get_named(ld->name, &proto_ospf);
   struct proto_ospf *po = (struct proto_ospf *) p;
   int num = po->gr->hash_entries;
   unsigned int i, j;
@@ -1486,6 +1487,9 @@ ospf_sh_lsadb(struct proto *p)
     return;
   }
 
+  if (ld->router == SH_ROUTER_SELF)
+    ld->router = po->router_id;
+
   struct top_hash_entry *hea[num];
   struct top_hash_entry *he;
 
@@ -1502,6 +1506,22 @@ ospf_sh_lsadb(struct proto *p)
   {
     struct ospf_lsa_header *lsa = &(hea[i]->lsa);
     int dscope = LSA_SCOPE(lsa);
+
+    if (ld->scope && (dscope != (ld->scope & 0xf000)))
+      continue;
+
+    if ((ld->scope == LSA_SCOPE_AREA) && (hea[i]->domain != ld->area))
+      continue;
+
+    /* Ignore high nibble */
+    if (ld->type && ((lsa->type & 0x0fff) != (ld->type & 0x0fff)))
+      continue;
+
+    if (ld->lsid && (lsa->id != ld->lsid))
+      continue;
+
+    if (ld->router && (lsa->rt != ld->router))
+      continue;
     
     if ((dscope != last_dscope) || (hea[i]->domain != last_domain))
     {
index d6961519ddb3a1ee03d27830904c0ca2435bffed..96da9aa7f53f2f6875b196aad6072e509c97a61c 100644 (file)
@@ -846,7 +846,19 @@ void ospf_sh_neigh(struct proto *p, char *iff);
 void ospf_sh(struct proto *p);
 void ospf_sh_iface(struct proto *p, char *iff);
 void ospf_sh_state(struct proto *p, int verbose, int reachable);
-void ospf_sh_lsadb(struct proto *p);
+
+#define SH_ROUTER_SELF 0xffffffff
+
+struct lsadb_show_data {
+  struct symbol *name; /* Protocol to request data from */
+  u16 type;            /* LSA Type, 0 -> all */
+  u16 scope;           /* Scope, 0 -> all, hack to handle link scope as 1 */
+  u32 area;            /* Specified for area scope */
+  u32 lsid;            /* LSA ID, 0 -> all */
+  u32 router;          /* Advertising router, 0 -> all */
+};
+
+void ospf_sh_lsadb(struct lsadb_show_data *ld);
 
 
 #define EA_OSPF_METRIC1        EA_CODE(EAP_OSPF, 0)