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_interface.c b/ospfd/ospf_interface.c
index 027dfb9..f8490f5 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -258,16 +258,15 @@
 ospf_if_cleanup (struct ospf_interface *oi)
 {
   struct route_node *rn;
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf_neighbor *nbr;
+  struct ospf_nbr_nbma *nbr_nbma;
+  struct ospf_lsa *lsa;
 
   /* oi->nbrs and oi->nbr_nbma should be deletete on InterafceDown event */
   /* delete all static neighbors attached to this interface */
-  for (node = listhead (oi->nbr_nbma); node; )
+  for (ALL_LIST_ELEMENTS (oi->nbr_nbma, node, nnode, nbr_nbma))
     {
-      struct ospf_nbr_nbma *nbr_nbma = getdata (node);
-      nextnode (node);
-
       OSPF_POLL_TIMER_OFF (nbr_nbma->t_poll);
 
       if (nbr_nbma->nbr)
@@ -288,8 +287,8 @@
 	OSPF_NSM_EVENT_EXECUTE (nbr, NSM_KillNbr);
 
   /* Cleanup Link State Acknowlegdment list. */
-  for (node = listhead (oi->ls_ack); node; nextnode (node))
-    ospf_lsa_unlock (node->data);
+  for (ALL_LIST_ELEMENTS (oi->ls_ack, node, nnode, lsa))
+    ospf_lsa_unlock (lsa);
   list_delete_all_node (oi->ls_ack);
 
   oi->crypt_seqnum = 0;
@@ -362,7 +361,7 @@
 struct ospf_interface *
 ospf_if_is_configured (struct ospf *ospf, struct in_addr *address)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf_interface *oi;
   struct prefix_ipv4 addr;
 
@@ -370,8 +369,8 @@
   addr.prefix = *address;
   addr.prefixlen = IPV4_MAX_PREFIXLEN;
   
-  for (node = listhead (ospf->oiflist); node; nextnode (node))
-    if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
+  for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
+    if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
       {
 	if (oi->type == OSPF_IFTYPE_POINTOPOINT)
 	  {
@@ -414,11 +413,10 @@
 
   ospf = ospf_lookup ();
 
-  for (node = listhead (ospf->oiflist); node; nextnode (node))
-  {
-    if (((oi = getdata (node)) != NULL) && (oi == oic))
+  for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
+    if (oi == oic)
       return oi;
-  }
+
   return NULL;
 }
 
@@ -429,8 +427,8 @@
   struct listnode *node;
   struct ospf_interface *oi;
   
-  for (node = listhead (ospf->oiflist); node; nextnode (node))
-    if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
+  for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
+    if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
       {
 	if (ifp && oi->ifp != ifp)
 	  continue;
@@ -450,9 +448,9 @@
   struct prefix ptmp;
   
   /* Check each Interface. */
-  for (node = listhead (ospf->oiflist); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
     {
-      if ((oi = getdata (node)) != NULL && oi->type != OSPF_IFTYPE_VIRTUALLINK)
+      if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
 	{
 	  if ((oi->type == OSPF_IFTYPE_POINTOPOINT) &&
 	      CONNECTED_DEST_HOST(oi->connected))
@@ -485,10 +483,8 @@
 
   match = NULL;
 
-  for (node = listhead (ospf->oiflist); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
     {
-      oi = getdata (node);
-      
       if (oi->type == OSPF_IFTYPE_VIRTUALLINK)
 	continue;
       
@@ -944,11 +940,10 @@
   struct ospf_vl_data *vl_data;
   struct listnode *node;
 
-  for (node = listhead (area->ospf->vlinks); node; nextnode (node))
-    if ((vl_data = getdata (node)) != NULL)
-      if (vl_data->vl_peer.s_addr == vl_peer.s_addr &&
-          IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
-        return vl_data;
+  for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
+    if (vl_data->vl_peer.s_addr == vl_peer.s_addr &&
+        IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
+      return vl_data;
 
   return NULL;
 }
@@ -1011,20 +1006,19 @@
       changed = 1;
     }
 
-  for (node = listhead (v->nexthop); node; nextnode (node))
-    if ((nh = getdata (node)) != NULL)
-      {
-        vl_data->out_oi = (struct ospf_interface *) nh->oi;
+  for (ALL_LIST_ELEMENTS_RO (v->nexthop, node, nh))
+    {
+      vl_data->out_oi = (struct ospf_interface *) nh->oi;
+      
+      if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
+                          &vl_data->out_oi->address->u.prefix4))
+        changed = 1;
         
-        if (!IPV4_ADDR_SAME(&voi->address->u.prefix4,
-                            &vl_data->out_oi->address->u.prefix4))
-          changed = 1;
-          
-        voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4;
-        voi->address->prefixlen = vl_data->out_oi->address->prefixlen;
+      voi->address->u.prefix4 = vl_data->out_oi->address->u.prefix4;
+      voi->address->prefixlen = vl_data->out_oi->address->prefixlen;
 
-        break; /* We take the first interface. */
-      }
+      break; /* We take the first interface. */
+    }
 
   rl = (struct router_lsa *)v->lsa;
 
@@ -1093,11 +1087,8 @@
       zlog_debug ("ospf_vl_up_check(): Area is %s", inet_ntoa (area->area_id));
     }
 
-  for (node = listhead (ospf->vlinks); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
     {
-      if ((vl_data = getdata (node)) == NULL)
-        continue;
-  
       if (IS_DEBUG_OSPF_EVENT)
 	{
 	  zlog_debug ("ospf_vl_up_check(): considering VL, name: %s", 
@@ -1144,21 +1135,19 @@
   struct listnode *node;
   struct ospf_vl_data *vl_data;
 
-  for (node = listhead (ospf->vlinks); node; nextnode (node))
-    if ((vl_data = getdata (node)) != NULL)
-      UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
+  for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data))
+    UNSET_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED);
 }
 
 void
 ospf_vl_shut_unapproved (struct ospf *ospf)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct ospf_vl_data *vl_data;
 
-  for (node = listhead (ospf->vlinks); node; nextnode (node))
-    if ((vl_data = getdata (node)) != NULL)
-      if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
-        ospf_vl_shutdown (vl_data);
+  for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data))
+    if (!CHECK_FLAG (vl_data->flags, OSPF_VL_FLAG_APPROVED))
+      ospf_vl_shutdown (vl_data);
 }
 
 int
@@ -1181,10 +1170,9 @@
   struct ospf_vl_data *vl_data;
   int c = 0;
 
-  for (node = listhead (area->ospf->vlinks); node; nextnode (node))
-    if ((vl_data = getdata (node)) != NULL)
-      if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
-        c++;
+  for (ALL_LIST_ELEMENTS_RO (area->ospf->vlinks, node, vl_data))
+    if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id))
+      c++;
 
   return c;
 }
@@ -1213,12 +1201,9 @@
   struct listnode *node;
   struct crypt_key *ck;
 
-  for (node = listhead (auth_crypt); node; nextnode (node))
-    {
-      ck = getdata (node);
-      if (ck->key_id == key_id)
-        return ck;
-    }
+  for (ALL_LIST_ELEMENTS_RO (auth_crypt, node, ck))
+    if (ck->key_id == key_id)
+      return ck;
 
   return NULL;
 }
@@ -1226,12 +1211,11 @@
 int
 ospf_crypt_key_delete (struct list *auth_crypt, u_char key_id)
 {
-  struct listnode *node;
+  struct listnode *node, *nnode;
   struct crypt_key *ck;
 
-  for (node = listhead (auth_crypt); node; nextnode (node))
+  for (ALL_LIST_ELEMENTS (auth_crypt, node, nnode, ck))
     {
-      ck = getdata (node);
       if (ck->key_id == key_id)
         {
           listnode_delete (auth_crypt, ck);