summaryrefslogtreecommitdiff
path: root/ospfd/ospf_lsa.c
diff options
context:
space:
mode:
authorpaul <paul>2005-04-07 07:30:20 +0000
committerpaul <paul>2005-04-07 07:30:20 +0000
commit1eb8ef2584833f18fb674e127d59cb5a7f771482 (patch)
treef5b09d4781de9a9b08839fefb6530e64d2d2ec31 /ospfd/ospf_lsa.c
parent5920990fecba7e2430af3cfaa8bcbaed40d0ba1a (diff)
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.
Diffstat (limited to 'ospfd/ospf_lsa.c')
-rw-r--r--ospfd/ospf_lsa.c119
1 files changed, 50 insertions, 69 deletions
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index 203c4a5e..e02d457e 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -656,11 +656,11 @@ int
router_lsa_link_set (struct stream *s, struct ospf_area *area)
{
struct listnode *node;
+ struct ospf_interface *oi;
int links = 0;
- for (node = listhead (area->oiflist); node; node = nextnode (node))
+ for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi))
{
- struct ospf_interface *oi = node->data;
struct interface *ifp = oi->ifp;
/* Check interface is up, OSPF is enable. */
@@ -890,16 +890,16 @@ int
ospf_router_lsa_update_timer (struct thread *thread)
{
struct ospf *ospf = THREAD_ARG (thread);
- struct listnode *node;
+ struct listnode *node, *nnode;
+ struct ospf_area *area;
if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
zlog_debug ("Timer[router-LSA Update]: (timer expire)");
ospf->t_router_lsa_update = NULL;
- for (node = listhead (ospf->areas); node; nextnode (node))
+ for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
{
- struct ospf_area *area = getdata (node);
struct ospf_lsa *lsa = area->router_lsa_self;
struct router_lsa *rl;
const char *area_str;
@@ -1396,7 +1396,8 @@ ospf_external_lsa_nexthop_get (struct ospf *ospf, struct in_addr nexthop)
{
struct in_addr fwd;
struct prefix nh;
- struct listnode *n1;
+ struct listnode *node;
+ struct ospf_interface *oi;
fwd.s_addr = 0;
@@ -1408,15 +1409,11 @@ ospf_external_lsa_nexthop_get (struct ospf *ospf, struct in_addr nexthop)
nh.u.prefix4 = nexthop;
nh.prefixlen = IPV4_MAX_BITLEN;
- for (n1 = listhead (ospf->oiflist); n1; nextnode (n1))
- {
- struct ospf_interface *oi = getdata (n1);
-
- if (if_is_operative (oi->ifp))
- if (oi->address->family == AF_INET)
- if (prefix_match (oi->address, &nh))
- return nexthop;
- }
+ for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
+ if (if_is_operative (oi->ifp))
+ if (oi->address->family == AF_INET)
+ if (prefix_match (oi->address, &nh))
+ return nexthop;
return fwd;
}
@@ -1444,15 +1441,14 @@ ospf_get_nssa_ip (struct ospf_area *area)
{
struct in_addr fwd;
struct in_addr best_default;
- struct listnode *n1;
+ struct listnode *node;
+ struct ospf_interface *oi;
fwd.s_addr = 0;
best_default.s_addr = 0;
- for (n1 = listhead (area->ospf->oiflist); n1; nextnode (n1))
+ for (ALL_LIST_ELEMENTS_RO (area->ospf->oiflist, node, oi))
{
- struct ospf_interface *oi = getdata (n1);
-
if (if_is_operative (oi->ifp))
if (oi->area->external_routing == OSPF_AREA_NSSA)
if (oi->address && oi->address->family == AF_INET)
@@ -1618,7 +1614,8 @@ ospf_install_flood_nssa (struct ospf *ospf,
{
struct ospf_lsa *new;
struct as_external_lsa *extlsa;
- struct listnode *node;
+ struct ospf_area *area;
+ struct listnode *node, *nnode;
/* LSA may be a Type-5 originated via translation of a Type-7 LSA
* which originated from an NSSA area. In which case it should not be
@@ -1642,10 +1639,8 @@ ospf_install_flood_nssa (struct ospf *ospf,
Later, ABR_TASK and P-bit will scan Type-7 LSDB and translate to
Type-5's to non-NSSA Areas. (it will also attempt a re-install) */
- for (node = listhead (ospf->areas); node; nextnode (node))
+ for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
{
- struct ospf_area *area = getdata (node);
-
/* Don't install Type-7 LSA's into nonNSSA area */
if (area->external_routing != OSPF_AREA_NSSA)
continue;
@@ -1863,12 +1858,12 @@ ospf_translated_nssa_refresh (struct ospf *ospf, struct ospf_lsa *type7,
/* find the type-7 from which supplied type-5 was translated,
* ie find first type-7 with same LSA Id.
*/
- struct listnode *ln;
+ struct listnode *ln, *lnn;
struct route_node *rn;
struct ospf_lsa *lsa;
struct ospf_area *area;
- LIST_LOOP (ospf->areas, area, ln)
+ for (ALL_LIST_ELEMENTS (ospf->areas, ln, lnn, area))
{
if (area->external_routing != OSPF_AREA_NSSA
&& !type7)
@@ -2112,14 +2107,13 @@ ospf_default_originate_timer (struct thread *thread)
void
ospf_nssa_lsa_flush (struct ospf *ospf, struct prefix_ipv4 *p)
{
- struct listnode *node;
+ struct listnode *node, *nnode;
struct ospf_lsa *lsa;
struct ospf_area *area;
- for (node = listhead (ospf->areas); node; nextnode (node))
+ for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
{
- if (((area = getdata (node)) != NULL)
- && (area->external_routing == OSPF_AREA_NSSA))
+ if (area->external_routing == OSPF_AREA_NSSA)
{
if (!(lsa = ospf_lsa_lookup (area, OSPF_AS_NSSA_LSA, p->prefix,
ospf->router_id)))
@@ -2749,11 +2743,11 @@ ospf_lsa_install (struct ospf *ospf, struct ospf_interface *oi,
int
ospf_check_nbr_status (struct ospf *ospf)
{
- struct listnode *node;
-
- for (node = listhead (ospf->oiflist); node; node = nextnode (node))
+ struct listnode *node, *nnode;
+ struct ospf_interface *oi;
+
+ for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
{
- struct ospf_interface *oi = getdata (node);
struct route_node *rn;
struct ospf_neighbor *nbr;
@@ -2805,8 +2799,8 @@ int
ospf_maxage_lsa_remover (struct thread *thread)
{
struct ospf *ospf = THREAD_ARG (thread);
- struct listnode *node;
- struct listnode *next;
+ struct ospf_lsa *lsa;
+ struct listnode *node, *nnode;
int reschedule = 0;
ospf->t_maxage = NULL;
@@ -2817,11 +2811,8 @@ ospf_maxage_lsa_remover (struct thread *thread)
reschedule = !ospf_check_nbr_status (ospf);
if (!reschedule)
- for (node = listhead (ospf->maxage_lsa); node; node = next)
+ for (ALL_LIST_ELEMENTS (ospf->maxage_lsa, node, nnode, lsa))
{
- struct ospf_lsa *lsa = getdata (node);
- next = node->next;
-
if (lsa->retransmit_counter > 0)
{
reschedule = 1;
@@ -2872,9 +2863,10 @@ int
ospf_lsa_maxage_exist (struct ospf *ospf, struct ospf_lsa *new)
{
struct listnode *node;
-
- for (node = listhead (ospf->maxage_lsa); node; nextnode (node))
- if (((struct ospf_lsa *) node->data) == new)
+ struct ospf_lsa *lsa;
+
+ for (ALL_LIST_ELEMENTS_RO (ospf->maxage_lsa, node, lsa))
+ if (lsa == new)
return 1;
return 0;
@@ -2965,14 +2957,13 @@ ospf_lsa_maxage_walker (struct thread *thread)
struct ospf *ospf = THREAD_ARG (thread);
struct route_node *rn;
struct ospf_lsa *lsa;
- struct listnode *node;
+ struct ospf_area *area;
+ struct listnode *node, *nnode;
ospf->t_maxage_walker = NULL;
- for (node = listhead (ospf->areas); node; nextnode (node))
+ for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
{
- struct ospf_area *area = node->data;
-
LSDB_LOOP (ROUTER_LSDB (area), rn, lsa)
ospf_lsa_maxage_walker_remover (ospf, lsa);
LSDB_LOOP (NETWORK_LSDB (area), rn, lsa)
@@ -3292,18 +3283,16 @@ ospf_lsa_flush_schedule (struct ospf *ospf, struct ospf_lsa *lsa)
void
ospf_flush_self_originated_lsas_now (struct ospf *ospf)
{
- struct listnode *n1, *n2;
+ struct listnode *node, *nnode;
+ struct listnode *node2, *nnode2;
struct ospf_area *area;
struct ospf_interface *oi;
struct ospf_lsa *lsa;
struct route_node *rn;
int need_to_flush_ase = 0;
- for (n1 = listhead (ospf->areas); n1; nextnode (n1))
+ for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area))
{
- if ((area = getdata (n1)) == NULL)
- continue;
-
if ((lsa = area->router_lsa_self) != NULL)
{
if (IS_DEBUG_OSPF_EVENT)
@@ -3315,14 +3304,11 @@ ospf_flush_self_originated_lsas_now (struct ospf *ospf)
OSPF_TIMER_OFF (area->t_router_lsa_self);
}
- for (n2 = listhead (area->oiflist); n2; nextnode (n2))
+ for (ALL_LIST_ELEMENTS (area->oiflist, node2, nnode2, oi))
{
- if ((oi = getdata (n2)) == NULL)
- continue;
-
if ((lsa = oi->network_lsa_self) != NULL
- && oi->state == ISM_DR
- && oi->full_nbrs > 0)
+ && oi->state == ISM_DR
+ && oi->full_nbrs > 0)
{
if (IS_DEBUG_OSPF_EVENT)
zlog_debug ("LSA[Type%d:%s]: Schedule self-originated LSA to FLUSH", lsa->data->type, inet_ntoa (lsa->data->id));
@@ -3380,6 +3366,7 @@ int
ospf_lsa_is_self_originated (struct ospf *ospf, struct ospf_lsa *lsa)
{
struct listnode *node;
+ struct ospf_interface *oi;
/* This LSA is already checked. */
if (CHECK_FLAG (lsa->flags, OSPF_LSA_SELF_CHECKED))
@@ -3399,10 +3386,8 @@ ospf_lsa_is_self_originated (struct ospf *ospf, struct ospf_lsa *lsa)
/* LSA is network-LSA. Compare Link ID with all interfaces. */
else if (lsa->data->type == OSPF_NETWORK_LSA)
- for (node = listhead (ospf->oiflist); node; nextnode (node))
+ for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
{
- struct ospf_interface *oi = getdata (node);
-
/* Ignore virtual link. */
if (oi->type != OSPF_IFTYPE_VIRTUALLINK)
if (oi->address->family == AF_INET)
@@ -3662,8 +3647,9 @@ int
ospf_lsa_refresh_walker (struct thread *t)
{
struct list *refresh_list;
- struct listnode *node;
+ struct listnode *node, *nnode;
struct ospf *ospf = THREAD_ARG (t);
+ struct ospf_lsa *lsa;
int i;
struct list *lsa_to_refresh = list_new ();
@@ -3698,12 +3684,8 @@ ospf_lsa_refresh_walker (struct thread *t)
if (refresh_list)
{
- for (node = listhead (refresh_list); node;)
+ for (ALL_LIST_ELEMENTS (refresh_list, node, nnode, lsa))
{
- struct listnode *next;
- struct ospf_lsa *lsa = getdata (node);
- next = node->next;
-
if (IS_DEBUG_OSPF (lsa, LSA_REFRESH))
zlog_debug ("LSA[Refresh:%s]: ospf_lsa_refresh_walker(): "
"refresh lsa %p (slot %d)",
@@ -3713,7 +3695,6 @@ ospf_lsa_refresh_walker (struct thread *t)
ospf_lsa_unlock (lsa);
lsa->refresh_list = -1;
listnode_add (lsa_to_refresh, lsa);
- node = next;
}
list_free (refresh_list);
}
@@ -3723,8 +3704,8 @@ ospf_lsa_refresh_walker (struct thread *t)
ospf, ospf->lsa_refresh_interval);
ospf->lsa_refresher_started = time (NULL);
- for (node = listhead (lsa_to_refresh); node; nextnode (node))
- ospf_lsa_refresh (ospf, getdata (node));
+ for (ALL_LIST_ELEMENTS (lsa_to_refresh, node, nnode, lsa))
+ ospf_lsa_refresh (ospf, lsa);
list_delete (lsa_to_refresh);