[PATCH 1/1] * Implement show ospf lsadb filtering by router id

Alexander V. Chernikov melifaro at ipfw.ru
Tue Mar 6 23:38:55 CET 2012


Conflicts:

	conf/confbase.Y
---
 conf/confbase.Y     |    1 +
 proto/ospf/config.Y |   15 ++++++++++++---
 proto/ospf/ospf.c   |   16 +++++++++++++---
 proto/ospf/ospf.h   |    8 +++++++-
 4 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/conf/confbase.Y b/conf/confbase.Y
index 14893f4..b952f31 100644
--- a/conf/confbase.Y
+++ b/conf/confbase.Y
@@ -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;
diff --git a/proto/ospf/config.Y b/proto/ospf/config.Y
index 24e125a..aa1cb10 100644
--- a/proto/ospf/config.Y
+++ b/proto/ospf/config.Y
@@ -119,9 +119,10 @@ CF_KEYWORDS(NONBROADCAST, NBMA, POINTOPOINT, PTP, POINTOMULTIPOINT, PTMP)
 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(WAIT, DELAY, LSADB, ECMP, LIMIT, WEIGHT, NSSA, TRANSLATOR, STABILITY, ADVROUTER)
 
 %type <t> opttext
+%type <ld> lsadb_args
 
 CF_GRAMMAR
 
@@ -411,8 +412,16 @@ 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, [advrouter|<protocol name>], [[Show content of OSPF LSA database]])
+{ ospf_sh_lsadb($4); };
+
+lsadb_args:
+   /* empty */ {
+     $$ = cfg_allocz(sizeof(struct lsadb_show_data));
+   }
+ | lsadb_args ADVROUTER idval { $$->advrouter = $3; }
+ | lsadb_args SYM { $$->p = proto_get_named($2, &proto_ospf); }
+ ;
 
 CF_CODE
 
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c
index 73c06c2..5e72b09 100644
--- a/proto/ospf/ospf.c
+++ b/proto/ospf/ospf.c
@@ -1471,14 +1471,22 @@ 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_ospf *po = (struct proto_ospf *) p;
-  int num = po->gr->hash_entries;
+  struct proto_ospf *po;
+  struct proto *p;
+  int num;
   unsigned int i, j;
   int last_dscope = -1;
   u32 last_domain = 0;
 
+  if (!ld->p)
+    ld->p = proto_get_named(NULL, &proto_ospf);
+
+  p = ld->p;
+  po = (struct proto_ospf *) p;
+  num = po->gr->hash_entries;
+
   if (p->proto_state != PS_UP)
   {
     cli_msg(-1017, "%s: is not up", p->name);
@@ -1530,6 +1538,8 @@ ospf_sh_lsadb(struct proto *p)
       last_domain = hea[i]->domain;
     }
 
+    if ((ld->advrouter) && (ld->advrouter != lsa->rt))
+      continue;
 
     cli_msg(-1017," %04x  %-15R %-15R %5u  %08x    %04x",
 	    lsa->type, lsa->id, lsa->rt, lsa->age, lsa->sn, lsa->checksum);
diff --git a/proto/ospf/ospf.h b/proto/ospf/ospf.h
index d696151..3dec090 100644
--- a/proto/ospf/ospf.h
+++ b/proto/ospf/ospf.h
@@ -846,7 +846,13 @@ 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);
+
+struct lsadb_show_data {
+	struct proto *p;	/* Protocol to request data from */
+	u32 advrouter;		/* Advertising router */
+};
+
+void ospf_sh_lsadb(struct lsadb_show_data *ld);
 
 
 #define EA_OSPF_METRIC1	EA_CODE(EAP_OSPF, 0)
-- 
1.7.3.2


--------------040304020808000900050901--



More information about the Bird-users mailing list