2005-04-07 Paul Jakma <paul.jakma@sun.com>

	* (global): Fix up list loops to match changes in lib/linklist,
	  and some basic auditing of usage.
	* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
	* HACKING: Add notes about deprecating interfaces and commands.
	* lib/linklist.h: Add usage comments.
	  Rename getdata macro to listgetdata.
	  Rename nextnode to listnextnode and fix its odd behaviour to be
	  less dangerous.
	  Make listgetdata macro assert node is not null, NULL list entries
          should be bug condition.
          ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
          with for loop, Suggested by Jim Carlson of Sun.
          Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
          "safety" of previous macro.
	  LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
	  distinguish from the similarly named functions, and reflect their
	  effect better.
	  Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
	  with the old defines which were modified above,
	  for backwards compatibility - guarded to prevent Quagga using it..
	* lib/linklist.c: fix up for linklist.h changes.
	* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
	  scan of the area list, rather than scanning all areas first for
	  INTER_ROUTER and then again for INTER_NETWORK. According to
	  16.2, the scan should be area specific anyway, and further
	  ospf6d does not seem to implement 16.3 anyway.
diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c
index c4f4dd3..f9f79e3 100644
--- a/ospfd/ospf_ase.c
+++ b/ospfd/ospf_ase.c
@@ -71,12 +71,11 @@
 
   /* First try to find intra-area non-bb paths. */
   if (!CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
-    for (node = listhead ((struct list *) rn->info); node; nextnode (node))
-      if ((or = getdata (node)) != NULL)
-	if (or->cost < OSPF_LS_INFINITY)
-	  if (!OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id) &&
-	      or->path_type == OSPF_PATH_INTRA_AREA)
-	    listnode_add (chosen, or);
+    for (ALL_LIST_ELEMENTS_RO ((struct list *) rn->info, node, or))
+      if (or->cost < OSPF_LS_INFINITY)
+        if (!OSPF_IS_AREA_ID_BACKBONE (or->u.std.area_id) &&
+            or->path_type == OSPF_PATH_INTRA_AREA)
+          listnode_add (chosen, or);
 
   /* If none is found -- look through all. */
   if (listcount (chosen) == 0)
@@ -86,19 +85,18 @@
     }
 
   /* Now find the route with least cost. */
-  for (node = listhead (chosen); node; nextnode (node))
-    if ((or = getdata (node)) != NULL)
-      if (or->cost < OSPF_LS_INFINITY)
-	{
-	  if (best == NULL)
-	    best = or;
-	  else if (best->cost > or->cost)
-	    best = or;
-	  else if (best->cost == or->cost &&
-		   IPV4_ADDR_CMP (&best->u.std.area_id,
-				  &or->u.std.area_id) < 0)
-	    best = or;
-	}
+  for (ALL_LIST_ELEMENTS_RO (chosen, node, or))
+    if (or->cost < OSPF_LS_INFINITY)
+      {
+        if (best == NULL)
+          best = or;
+        else if (best->cost > or->cost)
+          best = or;
+        else if (best->cost == or->cost &&
+                 IPV4_ADDR_CMP (&best->u.std.area_id,
+                                &or->u.std.area_id) < 0)
+          best = or;
+      }
 
   if (chosen != rn->info)
     list_delete (chosen);
@@ -126,10 +124,9 @@
 
       route_unlock_node (rn);
 
-      for (node = listhead ((struct list *) rn->info); node; nextnode (node))
-	if ((or = getdata (node)) != NULL)
-	  if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
-	    return or;
+      for (ALL_LIST_ELEMENTS_RO ((struct list *) rn->info, node, or))
+        if (IPV4_ADDR_SAME (&or->u.std.area_id, &area->area_id))
+          return or;
     }
 
   return NULL;
@@ -141,10 +138,9 @@
   struct listnode *node;
   struct ospf_path *op;
 
-  for (node = listhead (ro->paths); node; nextnode (node))
-    if ((op = getdata (node)) != NULL)
-      if (op->nexthop.s_addr == 0)
-	op->nexthop.s_addr = nexthop.s_addr;
+  for (ALL_LIST_ELEMENTS_RO (ro->paths, node, op))
+    if (op->nexthop.s_addr == 0)
+      op->nexthop.s_addr = nexthop.s_addr;
 }
 
 int
@@ -153,12 +149,11 @@
   struct listnode *ifn;
   struct ospf_interface *oi;
 
-  for (ifn = listhead (ospf->oiflist); ifn; nextnode (ifn))
-    if ((oi = getdata (ifn)) != NULL)
-      if (if_is_operative (oi->ifp))
-	if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
-	  if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &fwd_addr))
-	    return 0;
+  for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, ifn, oi))
+    if (if_is_operative (oi->ifp))
+      if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
+        if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &fwd_addr))
+          return 0;
   
   return 1;
 }
@@ -590,10 +585,10 @@
        
    /* Check each path. */
    for (n1 = listhead (or->paths), n2 = listhead (newor->paths);
-	n1 && n2; nextnode (n1), nextnode (n2))
+	n1 && n2; n1 = listnextnode (n1), n2 = listnextnode (n2))
      { 
-       op = getdata (n1);
-       newop = getdata (n2);
+       op = listgetdata (n1);
+       newop = listgetdata (n2);
        
        if (! IPV4_ADDR_SAME (&op->nexthop, &newop->nexthop))
 	 return 0;
@@ -650,9 +645,8 @@
 
       /*  This version simple adds to the table all NSSA areas  */
       if (ospf->anyNSSA)
-	for (node = listhead (ospf->areas); node; nextnode (node))
+	for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
 	  {
-	    area = getdata (node);
 	    if (IS_DEBUG_OSPF_NSSA)
 	      zlog_debug ("ospf_ase_calculate_timer(): looking at area %s",
 			 inet_ntoa (area->area_id));
@@ -758,17 +752,16 @@
   struct route_node *rn;
   struct ospf_lsa *lsa;
   struct list *lst;
-  struct listnode *node;
+  struct listnode *node, *nnode;
   
   for (rn = route_top (rt); rn; rn = route_next (rn))
     if ((lst = rn->info) != NULL)
       {
-	for (node = listhead (lst); node; node = nextnode (node))
-	  if ((lsa = getdata (node)) != NULL)
-	    ospf_lsa_unlock (lsa);
+	for (ALL_LIST_ELEMENTS (lst, node, nnode, lsa))
+          ospf_lsa_unlock (lsa);
 	list_delete (lst);
       }
-  
+    
   route_table_finish (rt);
 }
 
@@ -808,9 +801,8 @@
   assert (rn && rn->info);
   lsas = rn->info;
   
-  for (node = listhead (lsas); node; nextnode (node))
-    if ((lsa = getdata (node)) != NULL)
-      ospf_ase_calculate_route (ospf, lsa);
+  for (ALL_LIST_ELEMENTS_RO (lsas, node, lsa))
+    ospf_ase_calculate_route (ospf, lsa);
 
   /* prepare temporary old routing table for compare */
   tmp_old = route_table_init ();