[quagga-dev 7410] [PATCH] ospfd: replace route_nodes with a list

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Thu Nov 26 17:50:36 GMT 2009


It is wasteful to use route nodes for something
as simple as a neighbor list.
Replace with a list.
---

 V2: - fix bug ospf_neighbor_delete()
     - Clenups too.

 ospfd/ospf_flood.c     |   36 ++++-----
 ospfd/ospf_interface.c |   12 +--
 ospfd/ospf_interface.h |    2 +-
 ospfd/ospf_ism.c       |   42 +++++-----
 ospfd/ospf_lsa.c       |   62 ++++++--------
 ospfd/ospf_neighbor.c  |  213 +++++++++++++++---------------------------------
 ospfd/ospf_neighbor.h  |    5 +-
 ospfd/ospf_packet.c    |   78 ++++++++---------
 ospfd/ospf_vty.c       |  105 +++++++++++------------
 ospfd/ospfd.c          |   19 +----
 10 files changed, 226 insertions(+), 348 deletions(-)

diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c
index 41661da..5ebf4f2 100644
--- a/ospfd/ospf_flood.c
+++ b/ospfd/ospf_flood.c
@@ -346,7 +346,7 @@ ospf_flood_through_interface (struct ospf_interface *oi,
 			      struct ospf_lsa *lsa)
 {
   struct ospf_neighbor *onbr;
-  struct route_node *rn;
+  struct listnode *node;
   int retx_flag;
 
   if (IS_DEBUG_OSPF_EVENT)
@@ -364,14 +364,10 @@ ospf_flood_through_interface (struct ospf_interface *oi,
   /* Each of the neighbors attached to this interface are examined,
      to determine whether they must receive the new LSA.  The following
      steps are executed for each neighbor: */
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, onbr))
     {
       struct ospf_lsa *ls_req;
- 
-      if (rn->info == NULL)
-	continue;
 
-      onbr = rn->info;
       if (IS_DEBUG_OSPF_EVENT)
 	zlog_debug ("ospf_flood_through_interface(): considering nbr %s (%s)",
 		   inet_ntoa (onbr->router_id),
@@ -543,13 +539,12 @@ ospf_flood_through_interface (struct ospf_interface *oi,
       addresses.   */
   if (oi->type == OSPF_IFTYPE_NBMA)
     {
-      struct route_node *rn;
+      struct listnode *node;
       struct ospf_neighbor *nbr;
 
-      for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-        if ((nbr = rn->info) != NULL)
-	  if (nbr != oi->nbr_self && nbr->state >= NSM_Exchange)
-	    ospf_ls_upd_send_lsa (nbr, lsa, OSPF_SEND_PACKET_DIRECT);
+      for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+	if (nbr != oi->nbr_self && nbr->state >= NSM_Exchange)
+	  ospf_ls_upd_send_lsa (nbr, lsa, OSPF_SEND_PACKET_DIRECT);
     }
   else
     ospf_ls_upd_send_lsa (oi->nbr_self, lsa, OSPF_SEND_PACKET_INDIRECT);
@@ -934,21 +929,20 @@ static void
 ospf_ls_retransmit_delete_nbr_if (struct ospf_interface *oi,
 				  struct ospf_lsa *lsa)
 {
-  struct route_node *rn;
+  struct listnode *node;
   struct ospf_neighbor *nbr;
   struct ospf_lsa *lsr;
 
   if (ospf_if_is_enable (oi))
-    for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
+    for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
       /* If LSA find in LS-retransmit list, then remove it. */
-      if ((nbr = rn->info) != NULL)
-	{
-	  lsr = ospf_ls_retransmit_lookup (nbr, lsa);
-	     
-	  /* If LSA find in ls-retransmit list, remove it. */
-	  if (lsr != NULL && lsr->data->ls_seqnum == lsa->data->ls_seqnum)
-	    ospf_ls_retransmit_delete (nbr, lsr);
-	}
+      {
+	lsr = ospf_ls_retransmit_lookup (nbr, lsa);
+
+	/* If LSA find in ls-retransmit list, remove it. */
+	if (lsr != NULL && lsr->data->ls_seqnum == lsa->data->ls_seqnum)
+	  ospf_ls_retransmit_delete (nbr, lsr);
+      }
 }
 
 void
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index afe3acf..6039c0c 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -223,7 +223,7 @@ ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p)
   oi->network_lsa_self = NULL;
 
   /* Initialize neighbor list. */
-  oi->nbrs = route_table_init ();
+  oi->nbrs = list_new ();
 
   /* Initialize static neighbor list. */
   oi->nbr_nbma = list_new ();
@@ -258,7 +258,6 @@ ospf_if_new (struct ospf *ospf, struct interface *ifp, struct prefix *p)
 void
 ospf_if_cleanup (struct ospf_interface *oi)
 {
-  struct route_node *rn;
   struct listnode *node, *nnode;
   struct ospf_neighbor *nbr;
   struct ospf_nbr_nbma *nbr_nbma;
@@ -282,10 +281,9 @@ ospf_if_cleanup (struct ospf_interface *oi)
     }
 
   /* send Neighbor event KillNbr to all associated neighbors. */
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info) != NULL)
-      if (nbr != oi->nbr_self)
-	OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    if (nbr != oi->nbr_self)
+      OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
 
   /* Cleanup Link State Acknowlegdment list. */
   for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
@@ -321,7 +319,7 @@ ospf_if_free (struct ospf_interface *oi)
   /* Free Pseudo Neighbour */
   ospf_nbr_delete (oi->nbr_self);
   
-  route_table_finish (oi->nbrs);
+  list_free (oi->nbrs);
   route_table_finish (oi->ls_upd_queue);
   
   /* Free any lists that should be freed */
diff --git a/ospfd/ospf_interface.h b/ospfd/ospf_interface.h
index ab0b758..18b98cd 100644
--- a/ospfd/ospf_interface.h
+++ b/ospfd/ospf_interface.h
@@ -171,7 +171,7 @@ struct ospf_interface
   u_int32_t output_cost;	        /* Acutual Interface Output Cost */
 
   /* Neighbor information. */
-  struct route_table *nbrs;             /* OSPF Neighbor List */
+  struct list *nbrs;			/* OSPF Neighbor List */
   struct ospf_neighbor *nbr_self;	/* Neighbor Self */
 #define DR(I)			((I)->nbr_self->d_router)
 #define BDR(I)			((I)->nbr_self->bd_router)
diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c
index 1840283..e7bdbf2 100644
--- a/ospfd/ospf_ism.c
+++ b/ospfd/ospf_ism.c
@@ -163,38 +163,36 @@ ospf_ism_state (struct ospf_interface *oi)
 }
 
 static void
-ospf_dr_eligible_routers (struct route_table *nbrs, struct list *el_list)
+ospf_dr_eligible_routers (struct list *nbrs, struct list *el_list)
 {
-  struct route_node *rn;
+  struct listnode *node;
   struct ospf_neighbor *nbr;
 
-  for (rn = route_top (nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info) != NULL)
-      /* Ignore 0.0.0.0 node*/
-      if (nbr->router_id.s_addr != 0)
-	/* Is neighbor eligible? */
-	if (nbr->priority > 0)
-	  /* Is neighbor upper 2-Way? */
-	  if (nbr->state >= NSM_TwoWay)
-	    listnode_add (el_list, nbr);
+  for (ALL_LIST_ELEMENTS_RO (nbrs, node, nbr))
+    /* Ignore 0.0.0.0 node*/
+    if (nbr->router_id.s_addr != 0)
+      /* Is neighbor eligible? */
+      if (nbr->priority > 0)
+	/* Is neighbor upper 2-Way? */
+	if (nbr->state >= NSM_TwoWay)
+	  listnode_add (el_list, nbr);
 }
 
 /* Generate AdjOK? NSM event. */
 static void
-ospf_dr_change (struct ospf *ospf, struct route_table *nbrs)
+ospf_dr_change (struct ospf *ospf, struct list *nbrs)
 {
-  struct route_node *rn;
+  struct listnode *node;
   struct ospf_neighbor *nbr;
 
-  for (rn = route_top (nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info) != NULL)
-      /* Ignore 0.0.0.0 node*/
-      if (nbr->router_id.s_addr != 0)
-	/* Is neighbor upper 2-Way? */
-	if (nbr->state >= NSM_TwoWay)
-	  /* Ignore myself. */
-	  if (!IPV4_ADDR_SAME (&nbr->router_id, &ospf->router_id))
-	    OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_AdjOK);
+  for (ALL_LIST_ELEMENTS_RO (nbrs, node, nbr))
+    /* Ignore 0.0.0.0 node*/
+    if (nbr->router_id.s_addr != 0)
+      /* Is neighbor upper 2-Way? */
+      if (nbr->state >= NSM_TwoWay)
+	/* Ignore myself. */
+	if (!IPV4_ADDR_SAME (&nbr->router_id, &ospf->router_id))
+	  OSPF_NSM_EVENT_SCHEDULE (nbr, NSM_AdjOK);
 }
 
 static int
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index e708d5e..7050469 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -436,17 +436,13 @@ struct ospf_neighbor *
 ospf_nbr_lookup_ptop (struct ospf_interface *oi)
 {
   struct ospf_neighbor *nbr = NULL;
-  struct route_node *rn;
+  struct listnode *node;
 
   /* Search neighbor, there must be one of two nbrs. */
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info))
-      if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
-	if (nbr->state == NSM_Full)
-	  {
-	    route_unlock_node (rn);
-	    break;
-	  }
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
+      if (nbr->state == NSM_Full)
+	  break;
 
   /* PtoP link must have only 1 neighbor. */
   if (ospf_nbr_count (oi, 0) > 1)
@@ -623,7 +619,7 @@ static int
 lsa_link_ptomp_set (struct stream *s, struct ospf_interface *oi)
 {
   int links = 0;
-  struct route_node *rn;
+  struct listnode *node;
   struct ospf_neighbor *nbr = NULL;
   struct in_addr id, mask;
   u_int16_t cost = ospf_link_cost (oi);
@@ -636,20 +632,18 @@ lsa_link_ptomp_set (struct stream *s, struct ospf_interface *oi)
     zlog_debug ("PointToMultipoint: running ptomultip_set");
 
   /* Search neighbor, */
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info) != NULL)
-      /* Ignore myself. */
-      if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
-	if (nbr->state == NSM_Full)
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    /* Ignore myself. */
+    if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
+      if (nbr->state == NSM_Full)
+	{
+	  links += link_info_set (s, nbr->router_id, oi->address->u.prefix4,
+				  LSA_LINK_TYPE_POINTOPOINT, 0, cost);
+	  if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
+	    zlog_debug ("PointToMultipoint: set link to %s",
+			inet_ntoa(oi->address->u.prefix4));
+	}
 
-	  {
-	    links += link_info_set (s, nbr->router_id, oi->address->u.prefix4,
-			            LSA_LINK_TYPE_POINTOPOINT, 0, cost);
-            if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
- 	      zlog_debug ("PointToMultipoint: set link to %s",
-		         inet_ntoa(oi->address->u.prefix4));
-	  }
-  
   return links;
 }
 
@@ -1025,7 +1019,7 @@ static void
 ospf_network_lsa_body_set (struct stream *s, struct ospf_interface *oi)
 {
   struct in_addr mask;
-  struct route_node *rn;
+  struct listnode *node;
   struct ospf_neighbor *nbr;
 
   masklen2ip (oi->address->prefixlen, &mask);
@@ -1036,10 +1030,9 @@ ospf_network_lsa_body_set (struct stream *s, struct ospf_interface *oi)
     its OSPF Router ID.  The Designated Router includes itself in this
     list. RFC2328, Section 12.4.2 */
 
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info) != NULL)
-      if (nbr->state == NSM_Full || nbr == oi->nbr_self)
-	stream_put_ipv4 (s, nbr->router_id.s_addr);
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    if (nbr->state == NSM_Full || nbr == oi->nbr_self)
+      stream_put_ipv4 (s, nbr->router_id.s_addr);
 }
 
 static struct ospf_lsa *
@@ -2839,19 +2832,14 @@ ospf_check_nbr_status (struct ospf *ospf)
   struct listnode *node, *nnode;
   struct ospf_interface *oi;
   
-  for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
+  for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
     {
-      struct route_node *rn;
       struct ospf_neighbor *nbr;
 
       if (ospf_if_is_enable (oi))
-	for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-          if ((nbr = rn->info) != NULL)
-	    if (nbr->state == NSM_Exchange || nbr->state == NSM_Loading)
-	      {
-		route_unlock_node (rn);
-		return 0;
-	      }
+	for (ALL_LIST_ELEMENTS_RO (oi->nbrs, nnode, nbr))
+	  if (nbr->state == NSM_Exchange || nbr->state == NSM_Loading)
+	    return 0;
     }
 
   return 1;
diff --git a/ospfd/ospf_neighbor.c b/ospfd/ospf_neighbor.c
index 81b3fdc..169a7da 100644
--- a/ospfd/ospf_neighbor.c
+++ b/ospfd/ospf_neighbor.c
@@ -43,26 +43,6 @@
 #include "ospfd/ospf_flood.h"
 #include "ospfd/ospf_dump.h"
 
-/* Fill in the the 'key' as appropriate to retrieve the entry for nbr
- * from the ospf_interface's nbrs table. Indexed by interface address
- * for all cases except Virtual-link interfaces, where neighbours are
- * indexed by router-ID instead.
- */
-static void
-ospf_nbr_key (struct ospf_interface *oi, struct ospf_neighbor *nbr,
-              struct prefix *key)
-{
-  key->family = AF_INET;
-  key->prefixlen = IPV4_MAX_BITLEN;
-
-  /* vlinks are indexed by router-id */
-  if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
-    key->u.prefix4 = nbr->router_id;
-  else
-    key->u.prefix4 = nbr->src;
-  return;
-}
-
 struct ospf_neighbor *
 ospf_nbr_new (struct ospf_interface *oi)
 {
@@ -143,44 +123,43 @@ ospf_nbr_free (struct ospf_neighbor *nbr)
 
   XFREE (MTYPE_OSPF_NEIGHBOR, nbr);
 }
+/* lookup nbr by address - use this only if you know you must
+ * otherwise use the ospf_nbr_lookup() wrapper, which deals 
+ * with virtual link neighbours
+ */
+struct ospf_neighbor *
+ospf_nbr_lookup_by_addr (struct list *nbrs,
+			 struct in_addr *addr)
+{
+  struct listnode *node;
+  struct ospf_neighbor *nbr;
 
-/* Delete specified OSPF neighbor from interface. */
-void
-ospf_nbr_delete (struct ospf_neighbor *nbr)
+  for (ALL_LIST_ELEMENTS_RO (nbrs, node, nbr))
+    if (IPV4_ADDR_SAME (&nbr->src, addr))
+	return nbr;
+
+  return NULL;
+}
+
+struct ospf_neighbor *
+ospf_nbr_lookup_by_routerid (struct list *nbrs,
+			     struct in_addr *id)
 {
-  struct ospf_interface *oi;
-  struct route_node *rn;
-  struct prefix p;
+  struct listnode *node;
+  struct ospf_neighbor *nbr;
 
-  oi = nbr->oi;
-  
-  /* get appropriate prefix 'key' */
-  ospf_nbr_key (oi, nbr, &p);
+  for (ALL_LIST_ELEMENTS_RO (nbrs, node, nbr))
+    if (IPV4_ADDR_SAME (&nbr->router_id, id))
+	return nbr;
 
-  rn = route_node_lookup (oi->nbrs, &p);
-  if (rn)
-    {
-      /* If lookup for a NBR succeeds, the leaf route_node could
-       * only exist because there is (or was) a nbr there.
-       * If the nbr was deleted, the leaf route_node should have
-       * lost its last refcount too, and be deleted.
-       * Therefore a looked-up leaf route_node in nbrs table
-       * should never have NULL info.
-       */
-      assert (rn->info);
-      
-      if (rn->info)
-	{
-	  rn->info = NULL;
-	  route_unlock_node (rn);
-	}
-      else
-	zlog_info ("Can't find neighbor %s in the interface %s",
-		   inet_ntoa (nbr->src), IF_NAME (oi));
-
-      route_unlock_node (rn);
-    }
+  return NULL;
+}
 
+/* Delete specified OSPF neighbor from interface. */
+void
+ospf_nbr_delete (struct ospf_neighbor *nbr)
+{
+  listnode_delete(nbr->oi->nbrs, nbr);
   /* Free ospf_neighbor structure. */
   ospf_nbr_free (nbr);
 }
@@ -206,8 +185,7 @@ ospf_nbr_bidirectional (struct in_addr *router_id,
 void
 ospf_nbr_add_self (struct ospf_interface *oi)
 {
-  struct prefix p;
-  struct route_node *rn;
+  struct ospf_neighbor *nbr;
 
   /* Initial state */
   oi->nbr_self->address = *oi->address;
@@ -229,19 +207,22 @@ ospf_nbr_add_self (struct ospf_interface *oi)
         SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP);
         break;
     }
-  
-  /* Add nbr_self to nbrs table */
-  ospf_nbr_key (oi, oi->nbr_self, &p);
-  
-  rn = route_node_get (oi->nbrs, &p);
-  if (rn->info)
+
+  /* Sanity check, should not be needed */
+  if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
+    nbr = ospf_nbr_lookup_by_routerid (oi->nbrs, &oi->nbr_self->router_id);
+  else
+    nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &oi->nbr_self->src);
+  if (nbr)
     {
-      /* There is already pseudo neighbor. */
-      assert (oi->nbr_self == rn->info);
-      route_unlock_node (rn);
+      assert (oi->nbr_self == nbr);
+      zlog_info("Self neighbor already added for ospf I/F:%s",
+		oi->ifp->name);
+      return;
     }
-  else
-    rn->info = oi->nbr_self;
+
+  /* Add nbr_self to nbrs table */
+  listnode_add(oi->nbrs, oi->nbr_self);
 }
 
 /* Get neighbor count by status.
@@ -250,14 +231,13 @@ int
 ospf_nbr_count (struct ospf_interface *oi, int state)
 {
   struct ospf_neighbor *nbr;
-  struct route_node *rn;
+  struct listnode *node;
   int count = 0;
 
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info))
-      if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
-	if (state == 0 || nbr->state == state)
-	  count++;
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
+      if (state == 0 || nbr->state == state)
+	count++;
 
   return count;
 }
@@ -267,67 +247,24 @@ int
 ospf_nbr_count_opaque_capable (struct ospf_interface *oi)
 {
   struct ospf_neighbor *nbr;
-  struct route_node *rn;
+  struct listnode *node;
   int count = 0;
 
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info))
-      if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
-	if (nbr->state == NSM_Full)
-	  if (CHECK_FLAG (nbr->options, OSPF_OPTION_O))
-	    count++;
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
+      if (nbr->state == NSM_Full)
+	if (CHECK_FLAG (nbr->options, OSPF_OPTION_O))
+	  count++;
 
   return count;
 }
 #endif /* HAVE_OPAQUE_LSA */
 
-/* lookup nbr by address - use this only if you know you must
- * otherwise use the ospf_nbr_lookup() wrapper, which deals 
- * with virtual link neighbours
- */
-struct ospf_neighbor *
-ospf_nbr_lookup_by_addr (struct route_table *nbrs,
-			 struct in_addr *addr)
-{
-  struct route_node *rn;
-  struct ospf_neighbor *nbr;
-
-  for (rn = route_top (nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info) != NULL)
-      if (IPV4_ADDR_SAME (&nbr->src, addr))
-	{
-	  route_unlock_node(rn);
-	  return nbr;
-	}
-
-  return NULL;
-}
-
-struct ospf_neighbor *
-ospf_nbr_lookup_by_routerid (struct route_table *nbrs,
-			     struct in_addr *id)
-{
-  struct route_node *rn;
-  struct ospf_neighbor *nbr;
-
-  for (rn = route_top (nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info) != NULL)
-      if (IPV4_ADDR_SAME (&nbr->router_id, id))
-	{
-	  route_unlock_node(rn);
-	  return nbr;
-	}
-
-  return NULL;
-}
-
 void
 ospf_renegotiate_optional_capabilities (struct ospf *top)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf_interface *oi;
-  struct route_table *nbrs;
-  struct route_node *rn;
   struct ospf_neighbor *nbr;
 
   /* At first, flush self-originated LSAs from routing domain. */
@@ -336,12 +273,9 @@ ospf_renegotiate_optional_capabilities (struct ospf *top)
   /* Revert all neighbor status to ExStart. */
   for (ALL_LIST_ELEMENTS_RO (top->oiflist, node, oi))
     {
-      if ((nbrs = oi->nbrs) == NULL)
-        continue;
-
-      for (rn = route_top (nbrs); rn; rn = route_next (rn))
-        {
-          if ((nbr = rn->info) == NULL || nbr == oi->nbr_self)
+      for (ALL_LIST_ELEMENTS_RO (oi->nbrs, nnode, nbr))
+	{
+          if (nbr == oi->nbr_self)
             continue;
 
           if (nbr->state < NSM_ExStart)
@@ -363,9 +297,9 @@ ospf_nbr_lookup (struct ospf_interface *oi, struct ip *iph,
                  struct ospf_header *ospfh)
 {
   if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
-    return (ospf_nbr_lookup_by_routerid (oi->nbrs, &ospfh->router_id));
+    return ospf_nbr_lookup_by_routerid (oi->nbrs, &ospfh->router_id);
   else
-    return (ospf_nbr_lookup_by_addr (oi->nbrs, &iph->ip_src));
+    return ospf_nbr_lookup_by_addr (oi->nbrs, &iph->ip_src);
 }
 
 static struct ospf_neighbor *
@@ -415,24 +349,11 @@ struct ospf_neighbor *
 ospf_nbr_get (struct ospf_interface *oi, struct ospf_header *ospfh,
               struct ip *iph, struct prefix *p)
 {
-  struct route_node *rn;
-  struct prefix key;
   struct ospf_neighbor *nbr;
-  
-  key.family = AF_INET;
-  key.prefixlen = IPV4_MAX_BITLEN;
 
-  if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
-    key.u.prefix4 = ospfh->router_id;   /* index vlink nbrs by router-id */
-  else
-    key.u.prefix4 = iph->ip_src;
-
-  rn = route_node_get (oi->nbrs, &key);
-  if (rn->info)
+  nbr = ospf_nbr_lookup (oi, iph, ospfh);
+  if (nbr)
     {
-      route_unlock_node (rn);
-      nbr = rn->info;
-      
       if (oi->type == OSPF_IFTYPE_NBMA && nbr->state == NSM_Attempt)
         {
           nbr->src = iph->ip_src;
@@ -441,7 +362,7 @@ ospf_nbr_get (struct ospf_interface *oi, struct ospf_header *ospfh,
     }
   else
     {
-      rn->info = nbr = ospf_nbr_add (oi, ospfh, p);
+      nbr = ospf_nbr_add (oi, ospfh, p);
     }
   
   nbr->router_id = ospfh->router_id;
diff --git a/ospfd/ospf_neighbor.h b/ospfd/ospf_neighbor.h
index 25f1352..af8fb2c 100644
--- a/ospfd/ospf_neighbor.h
+++ b/ospfd/ospf_neighbor.h
@@ -110,10 +110,9 @@ extern struct ospf_neighbor *ospf_nbr_get (struct ospf_interface *,
 extern struct ospf_neighbor *ospf_nbr_lookup (struct ospf_interface *,
 					      struct ip *,
 					      struct ospf_header *);
-extern struct ospf_neighbor *ospf_nbr_lookup_by_addr (struct route_table *,
+extern struct ospf_neighbor *ospf_nbr_lookup_by_addr (struct list *,
 						      struct in_addr *);
-extern struct ospf_neighbor *ospf_nbr_lookup_by_routerid (struct route_table
-							  *,
+extern struct ospf_neighbor *ospf_nbr_lookup_by_routerid (struct list *,
 							  struct in_addr *);
 extern void ospf_renegotiate_optional_capabilities (struct ospf *top);
 
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 8990e45..90bbd6f 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -2624,7 +2624,7 @@ static int
 ospf_make_hello (struct ospf_interface *oi, struct stream *s)
 {
   struct ospf_neighbor *nbr;
-  struct route_node *rn;
+  struct listnode *node;
   u_int16_t length = OSPF_HELLO_MIN_SIZE;
   struct in_addr mask;
   unsigned long p;
@@ -2666,10 +2666,9 @@ ospf_make_hello (struct ospf_interface *oi, struct stream *s)
   stream_put_ipv4 (s, BDR (oi).s_addr);
 
   /* Add neighbor seen. */
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info))
-      if (nbr->router_id.s_addr != 0)	/* Ignore 0.0.0.0 node. */
-	if (nbr->state != NSM_Attempt)  /* Ignore Down neighbor. */
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    if (nbr->router_id.s_addr != 0)	/* Ignore 0.0.0.0 node. */
+      if (nbr->state != NSM_Attempt)	/* Ignore Down neighbor. */
 	if (nbr->state != NSM_Down)     /* This is myself for DR election. */
 	  if (!IPV4_ADDR_SAME (&nbr->router_id, &oi->ospf->router_id))
 	    {
@@ -3085,45 +3084,43 @@ ospf_hello_send (struct ospf_interface *oi)
   if (oi->type == OSPF_IFTYPE_NBMA)
     {
       struct ospf_neighbor *nbr;
-      struct route_node *rn;
+      struct listnode *node;
 
-      for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-	if ((nbr = rn->info))
-	  if (nbr != oi->nbr_self)
-	    if (nbr->state != NSM_Down)
+      for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+	if (nbr != oi->nbr_self)
+	  if (nbr->state != NSM_Down)
+	    {
+	      /*  RFC 2328  Section 9.5.1
+		  If the router is not eligible to become Designated Router,
+		  it must periodically send Hello Packets to both the
+		  Designated Router and the Backup Designated Router (if they
+		  exist).  */
+	      if (PRIORITY(oi) == 0 &&
+		  IPV4_ADDR_CMP(&DR(oi),  &nbr->address.u.prefix4) &&
+		  IPV4_ADDR_CMP(&BDR(oi), &nbr->address.u.prefix4))
+		continue;
+
+	      /*  If the router is eligible to become Designated Router, it
+		  must periodically send Hello Packets to all neighbors that
+		  are also eligible. In addition, if the router is itself the
+		  Designated Router or Backup Designated Router, it must also
+		  send periodic Hello Packets to all other neighbors. */
+
+	      if (nbr->priority == 0 && oi->state == ISM_DROther)
+		continue;
+	      /* if oi->state == Waiting, send hello to all neighbors */
 	      {
-		/*  RFC 2328  Section 9.5.1
-		    If the router is not eligible to become Designated Router,
-		    it must periodically send Hello Packets to both the
-		    Designated Router and the Backup Designated Router (if they
-		    exist).  */
-		if (PRIORITY(oi) == 0 &&
-		    IPV4_ADDR_CMP(&DR(oi),  &nbr->address.u.prefix4) &&
-		    IPV4_ADDR_CMP(&BDR(oi), &nbr->address.u.prefix4))
-		  continue;
-
-		/*  If the router is eligible to become Designated Router, it
-		    must periodically send Hello Packets to all neighbors that
-		    are also eligible. In addition, if the router is itself the
-		    Designated Router or Backup Designated Router, it must also
-		    send periodic Hello Packets to all other neighbors. */
-
-		if (nbr->priority == 0 && oi->state == ISM_DROther)
-		  continue;
-		/* if oi->state == Waiting, send hello to all neighbors */
-		{
-		  struct ospf_packet *op_dup;
+		struct ospf_packet *op_dup;
 
-		  op_dup = ospf_packet_dup(op);
-		  op_dup->dst = nbr->address.u.prefix4;
+		op_dup = ospf_packet_dup(op);
+		op_dup->dst = nbr->address.u.prefix4;
 
-		  /* Add packet to the interface output queue. */
-		  ospf_packet_add (oi, op_dup);
-
-		  OSPF_ISM_WRITE_ON (oi->ospf);
-		}
+		/* Add packet to the interface output queue. */
+		ospf_packet_add (oi, op_dup);
 
+		OSPF_ISM_WRITE_ON (oi->ospf);
 	      }
+	    }
       ospf_packet_free (op);
     }
   else
@@ -3541,10 +3538,9 @@ ospf_ls_ack_send_delayed (struct ospf_interface *oi)
   if (oi->type == OSPF_IFTYPE_NBMA)
     {
       struct ospf_neighbor *nbr;
-      struct route_node *rn;
+      struct listnode *node;
 
-      for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-	if ((nbr = rn->info) != NULL)
+      for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
 	  if (nbr != oi->nbr_self && nbr->state >= NSM_Exchange)
 	    while (listcount (oi->ls_ack))
 	      ospf_ls_ack_send_list (oi, oi->ls_ack, nbr->address.u.prefix4);
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index e144c29..05e0f27 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -3024,39 +3024,37 @@ show_ip_ospf_neighbour_header (struct vty *vty)
 static void
 show_ip_ospf_neighbor_sub (struct vty *vty, struct ospf_interface *oi)
 {
-  struct route_node *rn;
+  struct listnode *node;
   struct ospf_neighbor *nbr;
   char msgbuf[16];
   char timebuf[OSPF_TIME_DUMP_SIZE];
 
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info))
-      /* Do not show myself. */
-      if (nbr != oi->nbr_self)
-	/* Down state is not shown. */
-	if (nbr->state != NSM_Down)
-	  {
-	    ospf_nbr_state_message (nbr, msgbuf, 16);
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    /* Do not show myself. */
+    if (nbr != oi->nbr_self)
+      /* Down state is not shown. */
+      if (nbr->state != NSM_Down)
+	{
+	  ospf_nbr_state_message (nbr, msgbuf, 16);
+	  if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
+	    vty_out (vty, "%-15s %3d %-15s ",
+		     "-", nbr->priority,
+		     msgbuf);
+	  else
+	    vty_out (vty, "%-15s %3d %-15s ",
+		     inet_ntoa (nbr->router_id), nbr->priority,
+		     msgbuf);
 
-	    if (nbr->state == NSM_Attempt && nbr->router_id.s_addr == 0)
-	      vty_out (vty, "%-15s %3d %-15s ",
-		       "-", nbr->priority,
-		       msgbuf);
-            else
-	      vty_out (vty, "%-15s %3d %-15s ",
-		       inet_ntoa (nbr->router_id), nbr->priority,
-		       msgbuf);
-            
-            vty_out (vty, "%9s ",
-                     ospf_timer_dump (nbr->t_inactivity, timebuf, 
+	  vty_out (vty, "%9s ",
+		   ospf_timer_dump (nbr->t_inactivity, timebuf, 
                                       sizeof(timebuf)));
-            
-	    vty_out (vty, "%-15s ", inet_ntoa (nbr->src));
-	    vty_out (vty, "%-20s %5ld %5ld %5d%s",
-		     IF_NAME (oi), ospf_ls_retransmit_count (nbr),
-		     ospf_ls_request_count (nbr), ospf_db_summary_count (nbr),
-		     VTY_NEWLINE);
-	  }
+
+	  vty_out (vty, "%-15s ", inet_ntoa (nbr->src));
+	  vty_out (vty, "%-20s %5ld %5ld %5d%s",
+		   IF_NAME (oi), ospf_ls_retransmit_count (nbr),
+		   ospf_ls_request_count (nbr), ospf_db_summary_count (nbr),
+		   VTY_NEWLINE);
+	}
 }
 
 DEFUN (show_ip_ospf_neighbor,
@@ -3343,14 +3341,13 @@ DEFUN (show_ip_ospf_neighbor_detail,
 
   for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
     {
-      struct route_node *rn;
+      struct listnode *nnode;
       struct ospf_neighbor *nbr;
 
-      for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-	if ((nbr = rn->info))
-	  if (nbr != oi->nbr_self)
-	    if (nbr->state != NSM_Down)
-	      show_ip_ospf_neighbor_detail_sub (vty, oi, nbr);
+      for (ALL_LIST_ELEMENTS_RO (oi->nbrs, nnode, nbr))
+	if (nbr != oi->nbr_self)
+	  if (nbr->state != NSM_Down)
+	    show_ip_ospf_neighbor_detail_sub (vty, oi, nbr);
     }
 
   return CMD_SUCCESS;
@@ -3379,15 +3376,14 @@ DEFUN (show_ip_ospf_neighbor_detail_all,
 
   for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
     {
-      struct route_node *rn;
+      struct listnode *nnode;
       struct ospf_neighbor *nbr;
       struct ospf_nbr_nbma *nbr_nbma;
 
-      for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-	if ((nbr = rn->info))
-	  if (nbr != oi->nbr_self)
-	    if (oi->type == OSPF_IFTYPE_NBMA && nbr->state != NSM_Down)
-	      show_ip_ospf_neighbor_detail_sub (vty, oi, rn->info);
+      for (ALL_LIST_ELEMENTS_RO (oi->nbrs, nnode, nbr))
+	if (nbr != oi->nbr_self)
+	  if (oi->type == OSPF_IFTYPE_NBMA && nbr->state != NSM_Down)
+	    show_ip_ospf_neighbor_detail_sub (vty, oi, nbr);
 
       if (oi->type == OSPF_IFTYPE_NBMA)
 	{
@@ -3416,8 +3412,9 @@ DEFUN (show_ip_ospf_neighbor_int_detail,
   struct ospf *ospf;
   struct ospf_interface *oi;
   struct interface *ifp;
-  struct route_node *rn, *nrn;
+  struct route_node *rn;
   struct ospf_neighbor *nbr;
+  struct listnode *node;
 
   ifp = if_lookup_by_name (argv[0]);
   if (!ifp)
@@ -3436,11 +3433,10 @@ DEFUN (show_ip_ospf_neighbor_int_detail,
 
   for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn))
     if ((oi = rn->info))
-      for (nrn = route_top (oi->nbrs); nrn; nrn = route_next (nrn))
-	if ((nbr = nrn->info))
-	  if (nbr != oi->nbr_self)
-	    if (nbr->state != NSM_Down)
-	      show_ip_ospf_neighbor_detail_sub (vty, oi, nbr);
+      for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+	if (nbr != oi->nbr_self)
+	  if (nbr->state != NSM_Down)
+	    show_ip_ospf_neighbor_detail_sub (vty, oi, nbr);
 
   return CMD_SUCCESS;
 }
@@ -4965,17 +4961,16 @@ ALIAS (no_ip_ospf_cost2,
 static void
 ospf_nbr_timer_update (struct ospf_interface *oi)
 {
-  struct route_node *rn;
+  struct listnode *node;
   struct ospf_neighbor *nbr;
 
-  for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
-    if ((nbr = rn->info))
-      {
-	nbr->v_inactivity = OSPF_IF_PARAM (oi, v_wait);
-	nbr->v_db_desc = OSPF_IF_PARAM (oi, retransmit_interval);
-	nbr->v_ls_req = OSPF_IF_PARAM (oi, retransmit_interval);
-	nbr->v_ls_upd = OSPF_IF_PARAM (oi, retransmit_interval);
-      }
+  for (ALL_LIST_ELEMENTS_RO (oi->nbrs, node, nbr))
+    {
+      nbr->v_inactivity = OSPF_IF_PARAM (oi, v_wait);
+      nbr->v_db_desc = OSPF_IF_PARAM (oi, retransmit_interval);
+      nbr->v_ls_req = OSPF_IF_PARAM (oi, retransmit_interval);
+      nbr->v_ls_upd = OSPF_IF_PARAM (oi, retransmit_interval);
+    }
 }
 
 static int
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index b86986b..7cc82b0 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -1443,8 +1443,6 @@ ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma,
 		   struct ospf_interface *oi)
 {
   struct ospf_neighbor *nbr;
-  struct route_node *rn;
-  struct prefix p;
 
   if (oi->type != OSPF_IFTYPE_NBMA)
     return;
@@ -1459,30 +1457,21 @@ ospf_nbr_nbma_add (struct ospf_nbr_nbma *nbr_nbma,
   listnode_add (oi->nbr_nbma, nbr_nbma);
 
   /* Get neighbor information from table. */
-  p.family = AF_INET;
-  p.prefixlen = IPV4_MAX_BITLEN;
-  p.u.prefix4 = nbr_nbma->addr;
-
-  rn = route_node_get (oi->nbrs, (struct prefix *)&p);
-  if (rn->info)
+  nbr = ospf_nbr_lookup_by_addr (oi->nbrs, &nbr_nbma->addr);
+  if (nbr)
     {
-      nbr = rn->info;
       nbr->nbr_nbma = nbr_nbma;
       nbr_nbma->nbr = nbr;
-
-      route_unlock_node (rn);
     }
   else
     {
-      nbr = rn->info = ospf_nbr_new (oi);
+      nbr = ospf_nbr_new (oi);
       nbr->state = NSM_Down;
       nbr->src = nbr_nbma->addr;
       nbr->nbr_nbma = nbr_nbma;
       nbr->priority = nbr_nbma->priority;
-      nbr->address = p;
-
+      nbr->address.u.prefix4 = nbr_nbma->addr;
       nbr_nbma->nbr = nbr;
-
       OSPF_NSM_EVENT_EXECUTE (nbr, NSM_Start);
     }
 }
-- 
1.6.4.4




More information about the Quagga-dev mailing list