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_abr.c b/ospfd/ospf_abr.c
index 416b3e7..90ed392 100644
--- a/ospfd/ospf_abr.c
+++ b/ospfd/ospf_abr.c
@@ -174,10 +174,11 @@
 ospf_area_range_match_any (struct ospf *ospf, struct prefix_ipv4 *p)
 {
   struct ospf_area_range *range;
+  struct ospf_area *area;
   struct listnode *node;
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
-    if ((range = ospf_area_range_match (node->data, p)))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
+    if ((range = ospf_area_range_match (area, p)))
       return range;
 
   return NULL;
@@ -407,9 +408,9 @@
 ospf_abr_nssa_check_status (struct ospf *ospf)
 {
   struct ospf_area *area;
-  struct listnode *lnode;
+  struct listnode *lnode, *nnode;
     
-  LIST_LOOP (ospf->areas, area, lnode)
+  for (ALL_LIST_ELEMENTS (ospf->areas, lnode, nnode, area))
     {
     
       if (area->external_routing != OSPF_AREA_NSSA)
@@ -477,7 +478,7 @@
 ospf_check_abr_status (struct ospf *ospf)
 {
   struct ospf_area *area;
-  struct listnode *node;
+  struct listnode *node, *nnode;
   int bb_configured = 0;
   int bb_act_attached = 0;
   int areas_configured = 0;
@@ -487,10 +488,8 @@
   if (IS_DEBUG_OSPF_EVENT)
     zlog_debug ("ospf_check_abr_status(): Start");
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
     {
-      area = getdata (node);
-      
       if (listcount (area->oiflist)) 
 	{
 	  areas_configured++;
@@ -774,10 +773,10 @@
 ospf_abr_nexthops_belong_to_area (struct ospf_route *or,
 				  struct ospf_area *area)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf_path *path;
 
-  LIST_LOOP (or->paths, path, node)
+  for (ALL_LIST_ELEMENTS (or->paths, node, nnode, path))
     {
       struct ospf_interface *oi = path->oi;
 
@@ -851,10 +850,8 @@
   or_area = ospf_area_lookup_by_area_id (ospf, or->u.std.area_id); 
   assert (or_area);
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      area = getdata (node);
-
       if (IS_DEBUG_OSPF_EVENT)
 	zlog_debug ("ospf_abr_announce_network(): looking at area %s",
 		   inet_ntoa (area->area_id));
@@ -958,10 +955,8 @@
   if (IS_DEBUG_OSPF_NSSA)
     zlog_debug ("ospf_abr_process_nssa_translates(): Start");
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      area = getdata (node);
-
       if (! area->NSSATranslatorState)
         continue; /* skip if not translator */
       
@@ -1148,10 +1143,8 @@
   if (IS_DEBUG_OSPF_EVENT)
     zlog_debug ("ospf_abr_announce_rtr(): Start");
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      area = getdata (node);
-
       if (IS_DEBUG_OSPF_EVENT)
 	zlog_debug ("ospf_abr_announce_rtr(): looking at area %s",
 		   inet_ntoa (area->area_id));
@@ -1205,7 +1198,7 @@
 
   for (rn = route_top (rt); rn; rn = route_next (rn))
     {
-      struct listnode *node;
+      struct listnode *node, *nnode;
       char flag = 0;
       struct ospf_route *best = NULL;
 
@@ -1218,12 +1211,8 @@
 	zlog_debug ("ospf_abr_process_router_rt(): this is a route to %s",
 		   inet_ntoa (rn->p.u.prefix4));
 
-      for (node = listhead (l); node; nextnode (node))
+      for (ALL_LIST_ELEMENTS (l, node, nnode, or))
 	{
-	  or = getdata (node);
-	  if (or == NULL)
-	    continue;
-
 	  if (!ospf_area_lookup_by_area_id (ospf, or->u.std.area_id))
 	    {
 	      if (IS_DEBUG_OSPF_EVENT)
@@ -1334,9 +1323,8 @@
   if (IS_DEBUG_OSPF_EVENT)
     zlog_debug ("ospf_abr_unapprove_summaries(): Start");
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      area = getdata (node);
       if (IS_DEBUG_OSPF_EVENT)
         zlog_debug ("ospf_abr_unapprove_summaries(): "
                    "considering area %s",
@@ -1372,14 +1360,13 @@
   struct listnode *node;
   struct route_node *rn;
   struct ospf_area_range *range;
+  struct ospf_area *area;
 
   if (IS_DEBUG_OSPF_EVENT)
     zlog_debug ("ospf_abr_prepare_aggregates(): Start");
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      struct ospf_area *area = getdata (node);
-
       for (rn = route_top (area->ranges); rn; rn = route_next (rn))
 	if ((range = rn->info) != NULL)
 	  {
@@ -1404,10 +1391,8 @@
   if (IS_DEBUG_OSPF_EVENT)
     zlog_debug ("ospf_abr_announce_aggregates(): Start");
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      area = getdata (node);
-
       if (IS_DEBUG_OSPF_EVENT)
 	zlog_debug ("ospf_abr_announce_aggregates(): looking at area %s",
 		   inet_ntoa (area->area_id));
@@ -1444,9 +1429,8 @@
 		if (IS_DEBUG_OSPF_EVENT)
 		  zlog_debug ("ospf_abr_announce_aggregates(): active range");
 
-		for (n = listhead (ospf->areas); n; nextnode (n))
+		for (ALL_LIST_ELEMENTS_RO (ospf->areas, n, ar))
 		  {
-		    ar = getdata (n);
 		    if (ar == area)
 		      continue;
 
@@ -1488,10 +1472,8 @@
   if (IS_DEBUG_OSPF_NSSA)
     zlog_debug ("ospf_abr_send_nssa_aggregates(): Start");
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      area = getdata (node);
-
       if (! area->NSSATranslatorState)
 	continue;
 
@@ -1559,9 +1541,8 @@
   if (IS_DEBUG_OSPF_NSSA)
     zlog_debug ("ospf_abr_announce_stub_defaults(): Start");
 
-  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_abr_announce_nssa_defaults(): looking at area %s",
                    inet_ntoa (area->area_id));
@@ -1601,9 +1582,8 @@
   p.prefix.s_addr = OSPF_DEFAULT_DESTINATION;
   p.prefixlen = 0;
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      area = getdata (node);
       if (IS_DEBUG_OSPF_EVENT)
         zlog_debug ("ospf_abr_announce_stub_defaults(): looking at area %s",
 		    inet_ntoa (area->area_id));
@@ -1675,10 +1655,8 @@
   if (IS_DEBUG_OSPF_EVENT)
     zlog_debug ("ospf_abr_remove_unapproved_summaries(): Start");
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
     {
-      area = getdata (node);
-
       if (IS_DEBUG_OSPF_EVENT)
 	zlog_debug ("ospf_abr_remove_unapproved_summaries(): "
 		   "looking at area %s", inet_ntoa (area->area_id));
@@ -1701,23 +1679,22 @@
 void
 ospf_abr_manage_discard_routes (struct ospf *ospf)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct route_node *rn;
   struct ospf_area *area;
   struct ospf_area_range *range;
 
-  for (node = listhead (ospf->areas); node; nextnode (node))
-    if ((area = node->data) != NULL)
-      for (rn = route_top (area->ranges); rn; rn = route_next (rn))
-	if ((range = rn->info) != NULL)
-	  if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
-	    {
-	      if (range->specifics)
-		ospf_add_discard_route (ospf->new_table, area,
-					(struct prefix_ipv4 *) &rn->p);
-	      else
-		ospf_delete_discard_route ((struct prefix_ipv4 *) &rn->p);
-	    }
+  for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
+    for (rn = route_top (area->ranges); rn; rn = route_next (rn))
+      if ((range = rn->info) != NULL)
+	if (CHECK_FLAG (range->flags, OSPF_AREA_RANGE_ADVERTISE))
+	  {
+	    if (range->specifics)
+	      ospf_add_discard_route (ospf->new_table, area,
+				      (struct prefix_ipv4 *) &rn->p);
+	    else
+	      ospf_delete_discard_route ((struct prefix_ipv4 *) &rn->p);
+	  }
 }
 
 /* This is the function taking care about ABR NSSA, i.e.  NSSA