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/ospf6d/ospf6_flood.c b/ospf6d/ospf6_flood.c
index 9971ef1..39b7c1f 100644
--- a/ospf6d/ospf6_flood.c
+++ b/ospf6d/ospf6_flood.c
@@ -245,7 +245,7 @@
 ospf6_flood_interface (struct ospf6_neighbor *from,
                        struct ospf6_lsa *lsa, struct ospf6_interface *oi)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf6_neighbor *on;
   struct ospf6_lsa *req;
   int retrans_added = 0;
@@ -259,10 +259,8 @@
     }
 
   /* (1) For each neighbor */
-  for (node = listhead (oi->neighbor_list); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
     {
-      on = (struct ospf6_neighbor *) getdata (node);
-
       if (is_debug)
         zlog_debug ("To neighbor %s", on->name);
 
@@ -380,9 +378,8 @@
   else
     {
       /* reschedule retransmissions to all neighbors */
-      for (node = listhead (oi->neighbor_list); node; nextnode (node))
+      for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
         {
-          on = (struct ospf6_neighbor *) getdata (node);
           THREAD_OFF (on->thread_send_lsupdate);
           on->thread_send_lsupdate =
             thread_add_event (master, ospf6_lsupdate_send_neighbor, on, 0);
@@ -394,13 +391,11 @@
 ospf6_flood_area (struct ospf6_neighbor *from,
                   struct ospf6_lsa *lsa, struct ospf6_area *oa)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf6_interface *oi;
 
-  for (node = listhead (oa->if_list); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
     {
-      oi = OSPF6_INTERFACE (getdata (node));
-
       if (OSPF6_LSA_SCOPE (lsa->header->type) == OSPF6_SCOPE_LINKLOCAL &&
           oi != OSPF6_INTERFACE (lsa->lsdb->data))
         continue;
@@ -419,13 +414,11 @@
 ospf6_flood_process (struct ospf6_neighbor *from,
                      struct ospf6_lsa *lsa, struct ospf6 *process)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf6_area *oa;
 
-  for (node = listhead (process->area_list); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS (process->area_list, node, nnode, oa))
     {
-      oa = OSPF6_AREA (getdata (node));
-
       if (OSPF6_LSA_SCOPE (lsa->header->type) == OSPF6_SCOPE_AREA &&
           oa != OSPF6_AREA (lsa->lsdb->data))
         continue;
@@ -450,13 +443,12 @@
 void
 ospf6_flood_clear_interface (struct ospf6_lsa *lsa, struct ospf6_interface *oi)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf6_neighbor *on;
   struct ospf6_lsa *rem;
 
-  for (node = listhead (oi->neighbor_list); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on))
     {
-      on = OSPF6_NEIGHBOR (getdata (node));
       rem = ospf6_lsdb_lookup (lsa->header->type, lsa->header->id,
                                lsa->header->adv_router, on->retrans_list);
       if (rem && ! ospf6_lsa_compare (rem, lsa))
@@ -474,13 +466,11 @@
 void
 ospf6_flood_clear_area (struct ospf6_lsa *lsa, struct ospf6_area *oa)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf6_interface *oi;
 
-  for (node = listhead (oa->if_list); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
     {
-      oi = OSPF6_INTERFACE (getdata (node));
-
       if (OSPF6_LSA_SCOPE (lsa->header->type) == OSPF6_SCOPE_LINKLOCAL &&
           oi != OSPF6_INTERFACE (lsa->lsdb->data))
         continue;
@@ -498,13 +488,11 @@
 void
 ospf6_flood_clear_process (struct ospf6_lsa *lsa, struct ospf6 *process)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf6_area *oa;
 
-  for (node = listhead (process->area_list); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS (process->area_list, node, nnode, oa))
     {
-      oa = OSPF6_AREA (getdata (node));
-
       if (OSPF6_LSA_SCOPE (lsa->header->type) == OSPF6_SCOPE_AREA &&
           oa != OSPF6_AREA (lsa->lsdb->data))
         continue;
@@ -725,21 +713,13 @@
     return 0;
 
   process = from->ospf6_if->area->ospf6;
-  for (i = listhead (process->area_list); i; nextnode (i))
-    {
-      oa = OSPF6_AREA (getdata (i));
-      for (j = listhead (oa->if_list); j; nextnode (j))
-        {
-          oi = OSPF6_INTERFACE (getdata (j));
-          for (k = listhead (oi->neighbor_list); k; nextnode (k))
-            {
-              on = OSPF6_NEIGHBOR (getdata (k));
-              if (on->state == OSPF6_NEIGHBOR_EXCHANGE ||
-                  on->state == OSPF6_NEIGHBOR_LOADING)
-                count++;
-            }
-        }
-    }
+
+  for (ALL_LIST_ELEMENTS_RO (process->area_list, i, oa))
+    for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi))
+      for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on))
+        if (on->state == OSPF6_NEIGHBOR_EXCHANGE ||
+            on->state == OSPF6_NEIGHBOR_LOADING)
+          count++;
 
   if (count == 0)
     return 1;