diff options
84 files changed, 1886 insertions, 2485 deletions
@@ -1,3 +1,10 @@ +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. + 2005-04-05 Paul Jakma <paul@dishone.st> * HACKING: remove the 'manually patch redhat/quagga.spec' bit @@ -1,5 +1,5 @@ -*- mode: text; -*- -$Id: HACKING,v 1.18 2005/04/05 10:14:50 paul Exp $ +$Id: HACKING,v 1.19 2005/04/07 07:30:20 paul Exp $ GUIDELINES FOR HACKING ON QUAGGA @@ -44,6 +44,32 @@ these header files: lib/log.h logging levels and usage guidance [more to be added] +If changing an exported interface, please try to deprecate the interface in +an orderly manner. If at all possible, try to retain the old deprecated +interface as is, or functionally equivalent. Make a note of when the +interface was deprecated and guard the deprecated interface definitions in +the header file, ie: + +/* Deprecated: 20050406 */ +#if !defined(QUAGGA_NO_DEPRECATED_INTERFACES) +#warning "Using deprecated <libname> (interface(s)|function(s))" +... +#endif /* QUAGGA_NO_DEPRECATED_INTERFACES */ + +To ensure that the core Quagga sources do not use the deprecated interfaces +(you should update Quagga sources to use new interfaces, if applicable) +while allowing external sources to continue to build. Deprecated interfaces +should be excised in the next unstable cycle. + +If changing or removing a command definition, *ensure* that you properly +deprecate it - use the _DEPRECATED form of the appropriate DEFUN macro. This +is *critical*. Even if the command can no longer function, you *must* still +implement it as a do-nothing stub. Failure to follow this causes grief for +systems administrators. Deprecated commands should be excised in the next +unstable cycle. A list of deprecated commands should be collated for each +release. + +See also below regarding SHARED LIBRARY VERSIONING. CHANGELOG @@ -79,6 +105,9 @@ If any errors occur, move tags as needed and start over from the fresh checkouts. Do not append to tarballs, as this has produced non-standards-conforming tarballs in the past. +[TODO: collation of a list of deprecated commands. Possibly can be scripted +to extract from vtysh/vtysh_cmd.c] + TOOL VERSIONS Require versions of support tools are listed in INSTALL.quagga.txt. diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index df377835d..e30486873 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -184,10 +184,8 @@ bgp_update_address (struct interface *ifp) struct connected *connected; struct listnode *node; - for (node = listhead (ifp->connected); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) { - connected = getdata (node); - p = (struct prefix_ipv4 *) connected->address; if (p->family == AF_INET) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 76c1c2a13..df55f326b 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -419,7 +419,7 @@ bgp_scan (afi_t afi, safi_t safi) struct bgp_info *bi; struct bgp_info *next; struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; int valid; int current; int changed; @@ -437,7 +437,7 @@ bgp_scan (afi_t afi, safi_t safi) return; /* Maximum prefix check */ - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer->status != Established) continue; @@ -723,13 +723,10 @@ bgp_nexthop_self (afi_t afi, struct attr *attr) struct connected *ifc; struct prefix *p; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); - - for (node2 = listhead (ifp->connected); node2; nextnode (node2)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc)) { - ifc = getdata (node2); p = ifc->address; if (p && p->family == AF_INET @@ -1033,7 +1030,7 @@ bgp_import (struct thread *t) struct bgp *bgp; struct bgp_node *rn; struct bgp_static *bgp_static; - struct listnode *nn; + struct listnode *node, *nnode; int valid; u_int32_t metric; struct in_addr nexthop; @@ -1046,7 +1043,7 @@ bgp_import (struct thread *t) if (BGP_DEBUG (events, EVENTS)) zlog_debug ("Import timer expired."); - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MPLS_VPN; safi++) diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 8f7577be5..9fa23e52f 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -1121,7 +1121,7 @@ int bgp_collision_detect (struct peer *new, struct in_addr remote_id) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; struct bgp *bgp; bgp = bgp_get_default (); @@ -1137,7 +1137,7 @@ bgp_collision_detect (struct peer *new, struct in_addr remote_id) OPEN message, then the local system performs the following collision resolution procedure: */ - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { /* Under OpenConfirm status, local peer structure already hold remote router ID. */ diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 9009638db..4f3847d66 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1158,7 +1158,7 @@ bgp_process_rsclient (struct bgp *bgp, struct peer *rsclient, struct bgp_info_pair old_and_new; struct attr attr; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; p = &rn->p; @@ -1170,7 +1170,7 @@ bgp_process_rsclient (struct bgp *bgp, struct peer *rsclient, if (CHECK_FLAG(rsclient->sflags, PEER_STATUS_GROUP)) { group = rsclient->group; - LIST_LOOP(group->peer, rsclient, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, rsclient)) { /* Nothing to do. */ if (old_select && old_select == new_select) @@ -1203,7 +1203,7 @@ bgp_process_main (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi) struct bgp_info *new_select; struct bgp_info *old_select; struct bgp_info_pair old_and_new; - struct listnode *nn; + struct listnode *node, *nnode; struct peer *peer; struct attr attr; @@ -1235,7 +1235,7 @@ bgp_process_main (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi) /* Check each BGP peer. */ - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi); } @@ -1954,7 +1954,7 @@ bgp_update (struct peer *peer, struct prefix *p, struct attr *attr, struct prefix_rd *prd, u_char *tag, int soft_reconfig) { struct peer *rsclient; - struct listnode *nn; + struct listnode *node, *nnode; struct bgp *bgp; int ret; @@ -1964,7 +1964,7 @@ bgp_update (struct peer *peer, struct prefix *p, struct attr *attr, bgp = peer->bgp; /* Process the update for each RS-client. */ - LIST_LOOP(bgp->rsclient, rsclient, nn) + for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient)) { if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type, @@ -1984,12 +1984,12 @@ bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr, struct bgp_node *rn; struct bgp_info *ri; struct peer *rsclient; - struct listnode *nn; + struct listnode *node, *nnode; bgp = peer->bgp; /* Process the withdraw for each RS-client. */ - LIST_LOOP (bgp->rsclient, rsclient, nn) + for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient)) { if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag); @@ -2316,7 +2316,7 @@ bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi) struct bgp_node *rn; struct bgp_table *table; struct peer *rsclient; - struct listnode *nn; + struct listnode *node, *nnode; if (safi != SAFI_MPLS_VPN) bgp_clear_route_table (peer, afi, safi, NULL, NULL); @@ -2326,7 +2326,7 @@ bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi) if ((table = rn->info) != NULL) bgp_clear_route_table (peer, afi, safi, table, NULL); - LIST_LOOP (peer->bgp->rsclient, rsclient, nn) + for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient)) { if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) bgp_clear_route_table (peer, afi, safi, NULL, rsclient); @@ -2389,12 +2389,12 @@ void bgp_cleanup_routes () { struct bgp *bgp; - struct listnode *nn; + struct listnode *node, *nnode; struct bgp_node *rn; struct bgp_table *table; struct bgp_info *ri; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) { table = bgp->rib[AFI_IP][SAFI_UNICAST]; @@ -2884,11 +2884,11 @@ bgp_static_update (struct bgp *bgp, struct prefix *p, struct bgp_static *bgp_static, afi_t afi, safi_t safi) { struct peer *rsclient; - struct listnode *nn; + struct listnode *node, *nnode; bgp_static_update_main (bgp, p, bgp_static, afi, safi); - LIST_LOOP(bgp->rsclient, rsclient, nn) + for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient)) { bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi); } @@ -4558,7 +4558,7 @@ bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop, u_int32_t metric, u_char type) { struct bgp *bgp; - struct listnode *nn; + struct listnode *node, *nnode; struct bgp_info *new; struct bgp_info *bi; struct bgp_info info; @@ -4577,7 +4577,7 @@ bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop, attr.med = metric; attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC); - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) { afi = family2afi (p->family); @@ -4673,12 +4673,12 @@ void bgp_redistribute_delete (struct prefix *p, u_char type) { struct bgp *bgp; - struct listnode *nn; + struct listnode *node, *nnode; afi_t afi; struct bgp_node *rn; struct bgp_info *ri; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) { afi = family2afi (p->family); @@ -5590,7 +5590,7 @@ route_vty_out_detail_header (struct vty *vty, struct bgp *bgp, struct bgp_info *ri; struct prefix *p; struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; char buf1[INET6_ADDRSTRLEN]; char buf2[INET6_ADDRSTRLEN]; int count = 0; @@ -5649,7 +5649,7 @@ route_vty_out_detail_header (struct vty *vty, struct bgp *bgp, vty_out (vty, ")%s", VTY_NEWLINE); /* advertised peer */ - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (bgp_adj_out_lookup (peer, p, afi, safi, rn)) { diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index b11aaf235..060c68c0d 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -108,7 +108,7 @@ route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type, union sockunion *su2; struct peer_group *group; struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; if (type == RMAP_BGP) { @@ -147,7 +147,7 @@ route_match_peer (void *rule, struct prefix *prefix, route_map_object_t type, else { group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (sockunion_same (su, &peer->su)) return RMAP_MATCH; @@ -2181,7 +2181,8 @@ bgp_route_map_update (const char *unused) afi_t afi; safi_t safi; int direct; - struct listnode *nn, *nm; + struct listnode *node, *nnode; + struct listnode *mnode, *mnnode; struct bgp *bgp; struct peer *peer; struct peer_group *group; @@ -2190,9 +2191,9 @@ bgp_route_map_update (const char *unused) struct bgp_static *bgp_static; /* For neighbor route-map updates. */ - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) { - LIST_LOOP (bgp->peer, peer, nm) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -2214,7 +2215,7 @@ bgp_route_map_update (const char *unused) filter->usmap.map = NULL; } } - LIST_LOOP (bgp->group, group, nm) + for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -2239,9 +2240,9 @@ bgp_route_map_update (const char *unused) } /* For default-originate route-map updates. */ - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) { - LIST_LOOP (bgp->peer, peer, nm) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -2256,7 +2257,7 @@ bgp_route_map_update (const char *unused) } /* For network route-map updates. */ - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -2273,7 +2274,7 @@ bgp_route_map_update (const char *unused) } /* For redistribute route-map updates. */ - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) { for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index f2d554dfd..344358e37 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -280,7 +280,7 @@ peer_lookup_addr_ipv4 (struct in_addr *src) { struct bgp *bgp; struct peer *peer; - struct listnode *nn; + struct listnode *node; struct in_addr addr; int ret; @@ -288,7 +288,7 @@ peer_lookup_addr_ipv4 (struct in_addr *src) if (! bgp) return NULL; - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer)) { ret = inet_pton (AF_INET, peer->host, &addr); if (ret > 0) @@ -305,7 +305,7 @@ bgp_peer_lookup_next (struct in_addr *src) { struct bgp *bgp; struct peer *peer; - struct listnode *nn; + struct listnode *node; struct in_addr *p; union sockunion su; int ret; @@ -316,7 +316,7 @@ bgp_peer_lookup_next (struct in_addr *src) if (! bgp) return NULL; - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer)) { ret = inet_pton (AF_INET, peer->host, &su.sin.sin_addr); if (ret > 0) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index c4b1ef543..52025b76f 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -1996,7 +1996,7 @@ peer_rsclient_set_vty (struct vty *vty, const char *peer_str, struct bgp *bgp; struct peer *peer; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; struct bgp_filter *pfilter; struct bgp_filter *gfilter; @@ -2032,7 +2032,7 @@ peer_rsclient_set_vty (struct vty *vty, const char *peer_str, group = peer->group; gfilter = &peer->filter[afi][safi]; - LIST_LOOP(group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { pfilter = &peer->filter[afi][safi]; @@ -2078,7 +2078,7 @@ peer_rsclient_unset_vty (struct vty *vty, const char *peer_str, struct bgp *bgp; struct peer *peer; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; bgp = vty->index; @@ -2094,7 +2094,7 @@ peer_rsclient_unset_vty (struct vty *vty, const char *peer_str, { group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { ret = peer_af_flag_unset (peer, afi, safi, PEER_FLAG_RSERVER_CLIENT); if (ret < 0) @@ -3967,12 +3967,12 @@ bgp_clear (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, { int ret; struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; /* Clear all neighbors. */ if (sort == clear_all) { - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (stype == BGP_CLEAR_SOFT_NONE) ret = peer_clear (peer); @@ -4028,7 +4028,7 @@ bgp_clear (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, return -1; } - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (stype == BGP_CLEAR_SOFT_NONE) { @@ -4049,7 +4049,7 @@ bgp_clear (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, if (sort == clear_external) { - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer_sort (peer) == BGP_PEER_IBGP) continue; @@ -4081,7 +4081,7 @@ bgp_clear (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, } as = (as_t) as_ul; - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer->as != as) continue; @@ -6425,7 +6425,7 @@ int bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; int count = 0; char timebuf[BGP_UPTIME_LEN]; int len; @@ -6433,7 +6433,7 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi) /* Header string for each address family. */ static char header[] = "Neighbor V AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd"; - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer->afc[afi][safi]) { @@ -7319,11 +7319,11 @@ int bgp_show_neighbor (struct vty *vty, struct bgp *bgp, enum show_type type, union sockunion *su) { - struct listnode *nn; + struct listnode *node, *nnode; struct peer *peer; int find = 0; - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { switch (type) { @@ -7667,13 +7667,13 @@ bgp_write_rsclient_summary (struct vty *vty, struct peer *rsclient, char rmbuf[14]; const char *rmname; struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; int len; int count = 0; if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP)) { - LIST_LOOP (rsclient->group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, peer)) { count++; bgp_write_rsclient_summary (vty, peer, afi, safi); @@ -7732,13 +7732,13 @@ bgp_show_rsclient_summary (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; int count = 0; /* Header string for each address family. */ static char header[] = "Neighbor V AS Export-Policy Import-Policy Up/Down State"; - LIST_LOOP (bgp->rsclient, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, peer)) { if (peer->afc[afi][safi] && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 176e447a3..0c0c8c0c7 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -46,16 +46,16 @@ int bgp_router_id_update (int command, struct zclient *zclient, zebra_size_t length) { struct prefix router_id; - struct listnode *nn; + struct listnode *node, *nnode; struct bgp *bgp; zebra_router_id_update_read(zclient->ibuf,&router_id); router_id_zebra = router_id.u.prefix4; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) { if (!bgp->router_id_static.s_addr) - bgp_router_id_set (bgp, &router_id.u.prefix4); + bgp_router_id_set (bgp, &router_id.u.prefix4); } return 0; @@ -92,7 +92,7 @@ bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length) struct stream *s; struct interface *ifp; struct connected *c; - struct listnode *node; + struct listnode *node, *nnode; s = zclient->ibuf; ifp = zebra_interface_state_read (s); @@ -100,11 +100,8 @@ bgp_interface_up (int command, struct zclient *zclient, zebra_size_t length) if (! ifp) return 0; - for (node = listhead (ifp->connected); node; nextnode (node)) - { - c = getdata (node); - bgp_connected_add (c); - } + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, c)) + bgp_connected_add (c); return 0; } @@ -115,32 +112,29 @@ bgp_interface_down (int command, struct zclient *zclient, zebra_size_t length) struct stream *s; struct interface *ifp; struct connected *c; - struct listnode *node; + struct listnode *node, *nnode; s = zclient->ibuf; ifp = zebra_interface_state_read (s); if (! ifp) return 0; - for (node = listhead (ifp->connected); node; nextnode (node)) - { - c = getdata (node); - bgp_connected_delete (c); - } + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, c)) + bgp_connected_delete (c); /* Fast external-failover (Currently IPv4 only) */ { - struct listnode *nn, *nm; + struct listnode *mnode; struct bgp *bgp; struct peer *peer; struct interface *peer_if; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS_RO (bm->bgp, mnode, bgp)) { if (CHECK_FLAG (bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) continue; - LIST_LOOP (bgp->peer, peer, nm) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer->ttl != 1) continue; @@ -319,13 +313,10 @@ if_lookup_by_ipv4 (struct in_addr *addr) p.prefix = *addr; p.prefixlen = IPV4_MAX_BITLEN; - for (ifnode = listhead (iflist); ifnode; nextnode (ifnode)) + for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) { - ifp = getdata (ifnode); - - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { - connected = getdata (cnode); cp = connected->address; if (cp->family == AF_INET) @@ -345,13 +336,10 @@ if_lookup_by_ipv4_exact (struct in_addr *addr) struct connected *connected; struct prefix *cp; - for (ifnode = listhead (iflist); ifnode; nextnode (ifnode)) + for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) { - ifp = getdata (ifnode); - - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { - connected = getdata (cnode); cp = connected->address; if (cp->family == AF_INET) @@ -377,13 +365,10 @@ if_lookup_by_ipv6 (struct in6_addr *addr) p.prefix = *addr; p.prefixlen = IPV6_MAX_BITLEN; - for (ifnode = listhead (iflist); ifnode; nextnode (ifnode)) + for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) { - ifp = getdata (ifnode); - - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { - connected = getdata (cnode); cp = connected->address; if (cp->family == AF_INET6) @@ -403,13 +388,10 @@ if_lookup_by_ipv6_exact (struct in6_addr *addr) struct connected *connected; struct prefix *cp; - for (ifnode = listhead (iflist); ifnode; nextnode (ifnode)) + for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) { - ifp = getdata (ifnode); - - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { - connected = getdata (cnode); cp = connected->address; if (cp->family == AF_INET6) @@ -427,9 +409,8 @@ if_get_ipv6_global (struct interface *ifp, struct in6_addr *addr) struct connected *connected; struct prefix *cp; - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { - connected = getdata (cnode); cp = connected->address; if (cp->family == AF_INET6) @@ -449,9 +430,8 @@ if_get_ipv6_local (struct interface *ifp, struct in6_addr *addr) struct connected *connected; struct prefix *cp; - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { - connected = getdata (cnode); cp = connected->address; if (cp->family == AF_INET6) @@ -591,15 +571,12 @@ bgp_ifindex_by_nexthop (struct in6_addr *addr) p.prefix = *addr; p.prefixlen = IPV6_MAX_BITLEN; - for (ifnode = listhead (iflist); ifnode; nextnode (ifnode)) + for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp)) { - ifp = getdata (ifnode); - - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { struct prefix *cp; - connected = getdata (cnode); cp = connected->address; if (cp->family == AF_INET6) diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index f3caf46e9..d1e8d9697 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -160,7 +160,7 @@ int bgp_router_id_set (struct bgp *bgp, struct in_addr *id) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; if (bgp_config_check (bgp, BGP_CONFIG_ROUTER_ID) && IPV4_ADDR_SAME (&bgp->router_id, id)) @@ -170,7 +170,7 @@ bgp_router_id_set (struct bgp *bgp, struct in_addr *id) bgp_config_set (bgp, BGP_CONFIG_ROUTER_ID); /* Set all peer's local identifier with this value. */ - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { IPV4_ADDR_COPY (&peer->local_id, id); @@ -189,7 +189,7 @@ int bgp_cluster_id_set (struct bgp *bgp, struct in_addr *cluster_id) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; if (bgp_config_check (bgp, BGP_CONFIG_CLUSTER_ID) && IPV4_ADDR_SAME (&bgp->cluster_id, cluster_id)) @@ -199,7 +199,7 @@ bgp_cluster_id_set (struct bgp *bgp, struct in_addr *cluster_id) bgp_config_set (bgp, BGP_CONFIG_CLUSTER_ID); /* Clear all IBGP peer. */ - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer_sort (peer) != BGP_PEER_IBGP) continue; @@ -218,7 +218,7 @@ int bgp_cluster_id_unset (struct bgp *bgp) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; if (! bgp_config_check (bgp, BGP_CONFIG_CLUSTER_ID)) return 0; @@ -227,7 +227,7 @@ bgp_cluster_id_unset (struct bgp *bgp) bgp_config_unset (bgp, BGP_CONFIG_CLUSTER_ID); /* Clear all IBGP peer. */ - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer_sort (peer) != BGP_PEER_IBGP) continue; @@ -267,7 +267,7 @@ int bgp_confederation_id_set (struct bgp *bgp, as_t as) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; int already_confed; if (as == 0) @@ -281,7 +281,7 @@ bgp_confederation_id_set (struct bgp *bgp, as_t as) /* If we were doing confederation already, this is just an external AS change. Just Reset EBGP sessions, not CONFED sessions. If we were not doing confederation before, reset all EBGP sessions. */ - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { /* We're looking for peers who's AS is not local or part of our confederation. */ @@ -328,12 +328,12 @@ int bgp_confederation_id_unset (struct bgp *bgp) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; bgp->confed_id = 0; bgp_config_unset (bgp, BGP_CONFIG_CONFEDERATION); - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { /* We're looking for peers who's AS is not local */ if (peer_sort (peer) != BGP_PEER_IBGP) @@ -374,7 +374,7 @@ int bgp_confederation_peers_add (struct bgp *bgp, as_t as) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; if (! bgp) return BGP_ERR_INVALID_BGP; @@ -398,7 +398,7 @@ bgp_confederation_peers_add (struct bgp *bgp, as_t as) if (bgp_config_check (bgp, BGP_CONFIG_CONFEDERATION)) { - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer->as == as) { @@ -424,7 +424,7 @@ bgp_confederation_peers_remove (struct bgp *bgp, as_t as) int i; int j; struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; if (! bgp) return -1; @@ -454,7 +454,7 @@ bgp_confederation_peers_remove (struct bgp *bgp, as_t as) CONFED */ if (bgp_config_check (bgp, BGP_CONFIG_CONFEDERATION)) { - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer->as == as) { @@ -980,13 +980,13 @@ peer_deactivate (struct peer *peer, afi_t afi, safi_t safi) { struct peer_group *group; struct peer *peer1; - struct listnode *nn; + struct listnode *node, *nnode; if (CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP)) { group = peer->group; - LIST_LOOP (group->peer, peer1, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer1)) { if (peer1->af_group[afi][safi]) return BGP_ERR_PEER_GROUP_MEMBER_EXISTS; @@ -1233,9 +1233,9 @@ struct peer_group * peer_group_lookup (struct bgp *bgp, const char *name) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (bgp->group, group, nn) + for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) { if (strcmp (group->name, name) == 0) return group; @@ -1528,7 +1528,7 @@ peer_group_remote_as (struct bgp *bgp, const char *group_name, as_t *as) { struct peer_group *group; struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; group = peer_group_lookup (bgp, group_name); if (! group) @@ -1541,7 +1541,7 @@ peer_group_remote_as (struct bgp *bgp, const char *group_name, as_t *as) number must be updated to same number. */ peer_as_change (group->conf, *as); - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (peer->as != *as) peer_as_change (peer, *as); @@ -1555,11 +1555,11 @@ peer_group_delete (struct peer_group *group) { struct bgp *bgp; struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; bgp = group->bgp; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { peer->group = NULL; peer_delete (peer); @@ -1584,12 +1584,12 @@ int peer_group_remote_as_delete (struct peer_group *group) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; if (! group->conf->as) return 0; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { peer->group = NULL; peer_delete (peer); @@ -1819,7 +1819,7 @@ struct bgp * bgp_get_default () { if (bm->bgp->head) - return bm->bgp->head->data; + return (listgetdata (listhead (bm->bgp))); return NULL; } @@ -1828,9 +1828,9 @@ struct bgp * bgp_lookup (as_t as, const char *name) { struct bgp *bgp; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) if (bgp->as == as && ((bgp->name == NULL && name == NULL) || (bgp->name && name && strcmp (bgp->name, name) == 0))) @@ -1843,9 +1843,9 @@ struct bgp * bgp_lookup_by_name (const char *name) { struct bgp *bgp; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) if ((bgp->name == NULL && name == NULL) || (bgp->name && name && strcmp (bgp->name, name) == 0)) return bgp; @@ -1912,7 +1912,7 @@ int bgp_delete (struct bgp *bgp) { struct peer *peer; - struct listnode *nn; + struct listnode *node; struct listnode *next; afi_t afi; safi_t safi; @@ -1930,12 +1930,8 @@ bgp_delete (struct bgp *bgp) bgp->group->del = (void (*)(void *)) peer_group_delete; list_delete (bgp->group); - for (nn = bgp->peer->head; nn; nn = next) - { - peer = nn->data; - next = nn->next; - peer_delete (peer); - } + for (ALL_LIST_ELEMENTS (bgp->peer, node, next, peer)) + peer_delete (peer); bgp->rsclient->del = (void (*)(void *)) peer_delete; list_delete (bgp->rsclient); @@ -1964,7 +1960,7 @@ struct peer * peer_lookup (struct bgp *bgp, union sockunion *su) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; if (! bgp) bgp = bgp_get_default (); @@ -1972,7 +1968,7 @@ peer_lookup (struct bgp *bgp, union sockunion *su) if (! bgp) return NULL; - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (sockunion_same (&peer->su, su) && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER)) @@ -1986,14 +1982,14 @@ peer_lookup_with_open (union sockunion *su, as_t remote_as, struct in_addr *remote_id, int *as) { struct peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; struct bgp *bgp; bgp = bgp_get_default (); if (! bgp) return NULL; - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (sockunion_same (&peer->su, su) && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER)) @@ -2005,7 +2001,7 @@ peer_lookup_with_open (union sockunion *su, as_t remote_as, *as = 1; } } - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (sockunion_same (&peer->su, su) && ! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER)) @@ -2231,7 +2227,7 @@ peer_flag_modify (struct peer *peer, u_int32_t flag, int set) int found; int size; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; struct peer_flag_action action; memset (&action, 0, sizeof (struct peer_flag_action)); @@ -2288,7 +2284,7 @@ peer_flag_modify (struct peer *peer, u_int32_t flag, int set) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (set && CHECK_FLAG (peer->flags, flag) == flag) continue; @@ -2333,7 +2329,7 @@ peer_af_flag_modify (struct peer *peer, afi_t afi, safi_t safi, u_int32_t flag, { int found; int size; - struct listnode *nn; + struct listnode *node, *nnode; struct peer_group *group; struct peer_flag_action action; @@ -2411,7 +2407,7 @@ peer_af_flag_modify (struct peer *peer, afi_t afi, safi_t safi, u_int32_t flag, { group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (! peer->af_group[afi][safi]) continue; @@ -2467,7 +2463,7 @@ int peer_ebgp_multihop_set (struct peer *peer, int ttl) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (peer_sort (peer) == BGP_PEER_IBGP) return 0; @@ -2482,7 +2478,7 @@ peer_ebgp_multihop_set (struct peer *peer, int ttl) else { group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (peer_sort (peer) == BGP_PEER_IBGP) continue; @@ -2500,7 +2496,7 @@ int peer_ebgp_multihop_unset (struct peer *peer) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (peer_sort (peer) == BGP_PEER_IBGP) return 0; @@ -2518,7 +2514,7 @@ peer_ebgp_multihop_unset (struct peer *peer) else { group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (peer_sort (peer) == BGP_PEER_IBGP) continue; @@ -2560,7 +2556,7 @@ int peer_update_source_if_set (struct peer *peer, const char *ifname) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (peer->update_if) { @@ -2595,7 +2591,7 @@ peer_update_source_if_set (struct peer *peer, const char *ifname) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (peer->update_if) { @@ -2630,7 +2626,7 @@ int peer_update_source_addr_set (struct peer *peer, union sockunion *su) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (peer->update_source) { @@ -2664,7 +2660,7 @@ peer_update_source_addr_set (struct peer *peer, union sockunion *su) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (peer->update_source) { @@ -2699,7 +2695,7 @@ peer_update_source_unset (struct peer *peer) { union sockunion *su; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! CHECK_FLAG (peer->sflags, PEER_STATUS_GROUP) && ! peer->update_source @@ -2746,7 +2742,7 @@ peer_update_source_unset (struct peer *peer) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (! peer->update_source && ! peer->update_if) continue; @@ -2780,7 +2776,7 @@ peer_default_originate_set (struct peer *peer, afi_t afi, safi_t safi, const char *rmap) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; /* Adress family must be activated. */ if (! peer->afc[afi][safi]) @@ -2814,7 +2810,7 @@ peer_default_originate_set (struct peer *peer, afi_t afi, safi_t safi, /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { SET_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE); @@ -2836,7 +2832,7 @@ int peer_default_originate_unset (struct peer *peer, afi_t afi, safi_t safi) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; /* Adress family must be activated. */ if (! peer->afc[afi][safi]) @@ -2865,7 +2861,7 @@ peer_default_originate_unset (struct peer *peer, afi_t afi, safi_t safi) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { UNSET_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE); @@ -2899,7 +2895,7 @@ int peer_weight_set (struct peer *peer, u_int16_t weight) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; SET_FLAG (peer->config, PEER_CONFIG_WEIGHT); peer->weight = weight; @@ -2909,7 +2905,7 @@ peer_weight_set (struct peer *peer, u_int16_t weight) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { peer->weight = group->conf->weight; } @@ -2920,7 +2916,7 @@ int peer_weight_unset (struct peer *peer) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; /* Set default weight. */ if (peer_group_active (peer)) @@ -2935,7 +2931,7 @@ peer_weight_unset (struct peer *peer) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { peer->weight = 0; } @@ -2946,7 +2942,7 @@ int peer_timers_set (struct peer *peer, u_int32_t keepalive, u_int32_t holdtime) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; /* Not for peer group memeber. */ if (peer_group_active (peer)) @@ -2974,7 +2970,7 @@ peer_timers_set (struct peer *peer, u_int32_t keepalive, u_int32_t holdtime) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { SET_FLAG (peer->config, PEER_CONFIG_TIMER); peer->holdtime = group->conf->holdtime; @@ -2987,7 +2983,7 @@ int peer_timers_unset (struct peer *peer) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (peer_group_active (peer)) return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER; @@ -3002,7 +2998,7 @@ peer_timers_unset (struct peer *peer) /* peer-group member updates. */ group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { UNSET_FLAG (peer->config, PEER_CONFIG_TIMER); peer->holdtime = 0; @@ -3106,7 +3102,7 @@ int peer_allowas_in_set (struct peer *peer, afi_t afi, safi_t safi, int allow_num) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (allow_num < 1 || allow_num > 10) return BGP_ERR_INVALID_VALUE; @@ -3122,7 +3118,7 @@ peer_allowas_in_set (struct peer *peer, afi_t afi, safi_t safi, int allow_num) return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (peer->allowas_in[afi][safi] != allow_num) { @@ -3139,7 +3135,7 @@ int peer_allowas_in_unset (struct peer *peer, afi_t afi, safi_t safi) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) { @@ -3151,7 +3147,7 @@ peer_allowas_in_unset (struct peer *peer, afi_t afi, safi_t safi) return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_ALLOWAS_IN)) { @@ -3167,7 +3163,7 @@ peer_local_as_set (struct peer *peer, as_t as, int no_prepend) { struct bgp *bgp = peer->bgp; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (peer_sort (peer) != BGP_PEER_EBGP && peer_sort (peer) != BGP_PEER_INTERNAL) @@ -3205,7 +3201,7 @@ peer_local_as_set (struct peer *peer, as_t as, int no_prepend) } group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { peer->change_local_as = as; if (no_prepend) @@ -3230,7 +3226,7 @@ int peer_local_as_unset (struct peer *peer) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (peer_group_active (peer)) return BGP_ERR_INVALID_FOR_PEER_GROUP_MEMBER; @@ -3256,7 +3252,7 @@ peer_local_as_unset (struct peer *peer) } group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { peer->change_local_as = 0; UNSET_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND); @@ -3280,7 +3276,7 @@ peer_distribute_set (struct peer *peer, afi_t afi, safi_t safi, int direct, { struct bgp_filter *filter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3305,7 +3301,7 @@ peer_distribute_set (struct peer *peer, afi_t afi, safi_t safi, int direct, return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3327,7 +3323,7 @@ peer_distribute_unset (struct peer *peer, afi_t afi, safi_t safi, int direct) struct bgp_filter *filter; struct bgp_filter *gfilter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3364,7 +3360,7 @@ peer_distribute_unset (struct peer *peer, afi_t afi, safi_t safi, int direct) return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3387,15 +3383,16 @@ peer_distribute_update (struct access_list *access) afi_t afi; safi_t safi; int direct; - struct listnode *nn, *nm; + struct listnode *mnode, *mnnode; + struct listnode *node, *nnode; struct bgp *bgp; struct peer *peer; struct peer_group *group; struct bgp_filter *filter; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) { - LIST_LOOP (bgp->peer, peer, nm) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -3412,7 +3409,7 @@ peer_distribute_update (struct access_list *access) } } } - LIST_LOOP (bgp->group, group, nm) + for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -3439,7 +3436,7 @@ peer_prefix_list_set (struct peer *peer, afi_t afi, safi_t safi, int direct, { struct bgp_filter *filter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3464,7 +3461,7 @@ peer_prefix_list_set (struct peer *peer, afi_t afi, safi_t safi, int direct, return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3485,7 +3482,7 @@ peer_prefix_list_unset (struct peer *peer, afi_t afi, safi_t safi, int direct) struct bgp_filter *filter; struct bgp_filter *gfilter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3522,7 +3519,7 @@ peer_prefix_list_unset (struct peer *peer, afi_t afi, safi_t safi, int direct) return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3542,7 +3539,8 @@ peer_prefix_list_unset (struct peer *peer, afi_t afi, safi_t safi, int direct) void peer_prefix_list_update (struct prefix_list *plist) { - struct listnode *nn, *nm; + struct listnode *mnode, *mnnode; + struct listnode *node, *nnode; struct bgp *bgp; struct peer *peer; struct peer_group *group; @@ -3551,9 +3549,9 @@ peer_prefix_list_update (struct prefix_list *plist) safi_t safi; int direct; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) { - LIST_LOOP (bgp->peer, peer, nm) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -3570,7 +3568,7 @@ peer_prefix_list_update (struct prefix_list *plist) } } } - LIST_LOOP (bgp->group, group, nm) + for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -3596,7 +3594,7 @@ peer_aslist_set (struct peer *peer, afi_t afi, safi_t safi, int direct, { struct bgp_filter *filter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3618,7 +3616,7 @@ peer_aslist_set (struct peer *peer, afi_t afi, safi_t safi, int direct, return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3639,7 +3637,7 @@ peer_aslist_unset (struct peer *peer,afi_t afi, safi_t safi, int direct) struct bgp_filter *filter; struct bgp_filter *gfilter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3678,7 +3676,7 @@ peer_aslist_unset (struct peer *peer,afi_t afi, safi_t safi, int direct) return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3700,15 +3698,16 @@ peer_aslist_update () afi_t afi; safi_t safi; int direct; - struct listnode *nn, *nm; + struct listnode *mnode, *mnnode; + struct listnode *node, *nnode; struct bgp *bgp; struct peer *peer; struct peer_group *group; struct bgp_filter *filter; - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) { - LIST_LOOP (bgp->peer, peer, nm) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -3725,7 +3724,7 @@ peer_aslist_update () } } } - LIST_LOOP (bgp->group, group, nm) + for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) { for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) @@ -3752,7 +3751,7 @@ peer_route_map_set (struct peer *peer, afi_t afi, safi_t safi, int direct, { struct bgp_filter *filter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3777,7 +3776,7 @@ peer_route_map_set (struct peer *peer, afi_t afi, safi_t safi, int direct, return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3799,7 +3798,7 @@ peer_route_map_unset (struct peer *peer, afi_t afi, safi_t safi, int direct) struct bgp_filter *filter; struct bgp_filter *gfilter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3836,7 +3835,7 @@ peer_route_map_unset (struct peer *peer, afi_t afi, safi_t safi, int direct) return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3858,7 +3857,7 @@ peer_unsuppress_map_set (struct peer *peer, afi_t afi, safi_t safi, { struct bgp_filter *filter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3878,7 +3877,7 @@ peer_unsuppress_map_set (struct peer *peer, afi_t afi, safi_t safi, return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3899,7 +3898,7 @@ peer_unsuppress_map_unset (struct peer *peer, afi_t afi, safi_t safi) { struct bgp_filter *filter; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3918,7 +3917,7 @@ peer_unsuppress_map_unset (struct peer *peer, afi_t afi, safi_t safi) return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { filter = &peer->filter[afi][safi]; @@ -3939,7 +3938,7 @@ peer_maximum_prefix_set (struct peer *peer, afi_t afi, safi_t safi, int warning, u_int16_t restart) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -3957,7 +3956,7 @@ peer_maximum_prefix_set (struct peer *peer, afi_t afi, safi_t safi, return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (! peer->af_group[afi][safi]) continue; @@ -3978,7 +3977,7 @@ int peer_maximum_prefix_unset (struct peer *peer, afi_t afi, safi_t safi) { struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; if (! peer->afc[afi][safi]) return BGP_ERR_PEER_INACTIVE; @@ -4014,7 +4013,7 @@ peer_maximum_prefix_unset (struct peer *peer, afi_t afi, safi_t safi) return 0; group = peer->group; - LIST_LOOP (group->peer, peer, nn) + for (ALL_LIST_ELEMENTS (group->peer, node, nnode, peer)) { if (! peer->af_group[afi][safi]) continue; @@ -4606,13 +4605,13 @@ bgp_config_write_family (struct vty *vty, struct bgp *bgp, afi_t afi, int write = 0; struct peer *peer; struct peer_group *group; - struct listnode *nn; + struct listnode *node, *nnode; bgp_config_write_network (vty, bgp, afi, safi, &write); bgp_config_write_redistribute (vty, bgp, afi, safi, &write); - LIST_LOOP (bgp->group, group, nn) + for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) { if (group->conf->afc[afi][safi]) { @@ -4620,7 +4619,7 @@ bgp_config_write_family (struct vty *vty, struct bgp *bgp, afi_t afi, bgp_config_write_peer (vty, bgp, group->conf, afi, safi); } } - LIST_LOOP (bgp->peer, peer, nn) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (peer->afc[afi][safi]) { @@ -4644,7 +4643,8 @@ bgp_config_write (struct vty *vty) struct bgp *bgp; struct peer_group *group; struct peer *peer; - struct listnode *nn, *nm, *no; + struct listnode *node, *nnode; + struct listnode *mnode, *mnnode; /* BGP Multiple instance. */ if (bgp_option_check (BGP_OPT_MULTIPLE_INSTANCE)) @@ -4661,7 +4661,7 @@ bgp_config_write (struct vty *vty) } /* BGP configuration. */ - LIST_LOOP (bm->bgp, bgp, nn) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) { if (write) vty_out (vty, "!%s", VTY_NEWLINE); @@ -4789,13 +4789,13 @@ bgp_config_write (struct vty *vty) bgp->default_holdtime, VTY_NEWLINE); /* peer-group */ - LIST_LOOP (bgp->group, group, nm) + for (ALL_LIST_ELEMENTS (bgp->group, node, nnode, group)) { bgp_config_write_peer (vty, bgp, group->conf, AFI_IP, SAFI_UNICAST); } /* Normal neighbor configuration. */ - LIST_LOOP (bgp->peer, peer, no) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) { if (! CHECK_FLAG (peer->sflags, PEER_STATUS_ACCEPT_PEER)) bgp_config_write_peer (vty, bgp, peer, AFI_IP, SAFI_UNICAST); @@ -4887,15 +4887,15 @@ bgp_terminate () { struct bgp *bgp; struct peer *peer; - struct listnode *nn; - struct listnode *mm; + struct listnode *node, *nnode; + struct listnode *mnode, *mnnode; - LIST_LOOP (bm->bgp, bgp, nn) - LIST_LOOP (bgp->peer, peer, mm) + for (ALL_LIST_ELEMENTS (bm->bgp, mnode, mnnode, bgp)) + for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) if (peer->status == Established) bgp_notify_send (peer, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_PEER_UNCONFIG); - + bgp_cleanup_routes (); } diff --git a/configure.ac b/configure.ac index eba7d89d7..fb80ee6ac 100755 --- a/configure.ac +++ b/configure.ac @@ -5,7 +5,7 @@ ## Copyright (c) 1996, 97, 98, 99, 2000 Kunihiro Ishiguro <kunihiro@zebra.org> ## Portions Copyright (c) 2003 Paul Jakma <paul@dishone.st> ## -## $Id: configure.ac,v 1.98 2005/04/03 23:46:37 hasso Exp $ +## $Id: configure.ac,v 1.99 2005/04/07 07:30:20 paul Exp $ AC_PREREQ(2.53) AC_INIT(Quagga, 0.99.0, [http://bugzilla.quagga.net]) @@ -1252,6 +1252,14 @@ AC_DEFINE_UNQUOTED(OSPF6_VTYSH_PATH, "$quagga_statedir/ospf6d.vty",ospf6d vty so AC_DEFINE_UNQUOTED(ISIS_VTYSH_PATH, "$quagga_statedir/isisd.vty",isisd vty socket) AC_DEFINE_UNQUOTED(DAEMON_VTY_DIR, "$quagga_statedir",daemon vty directory) +dnl ------------------------------- +dnl Quagga sources should always be +dnl current wrt interfaces. Dont +dnl allow deprecated interfaces to +dnl be exposed. +dnl ------------------------------- +AC_DEFINE(QUAGGA_NO_DEPRECATED_INTERFACES, 1, Hide deprecated interfaces) + dnl --------------------------- dnl Check htonl works correctly dnl --------------------------- diff --git a/isisd/isis_adjacency.c b/isisd/isis_adjacency.c index 87609f641..0a48c070d 100644 --- a/isisd/isis_adjacency.c +++ b/isisd/isis_adjacency.c @@ -103,12 +103,9 @@ isis_adj_lookup (u_char * sysid, struct list *adjdb) struct isis_adjacency *adj; struct listnode *node; - for (node = listhead (adjdb); node; nextnode (node)) - { - adj = getdata (node); - if (memcmp (adj->sysid, sysid, ISIS_SYS_ID_LEN) == 0) - return adj; - } + for (ALL_LIST_ELEMENTS_RO (adjdb, node, adj)) + if (memcmp (adj->sysid, sysid, ISIS_SYS_ID_LEN) == 0) + return adj; return NULL; } @@ -120,12 +117,9 @@ isis_adj_lookup_snpa (u_char * ssnpa, struct list *adjdb) struct listnode *node; struct isis_adjacency *adj; - for (node = listhead (adjdb); node; nextnode (node)) - { - adj = getdata (node); - if (memcmp (adj->snpa, ssnpa, ETH_ALEN) == 0) - return adj; - } + for (ALL_LIST_ELEMENTS_RO (adjdb, node, adj)) + if (memcmp (adj->snpa, ssnpa, ETH_ALEN) == 0) + return adj; return NULL; } @@ -136,17 +130,15 @@ isis_adj_lookup_snpa (u_char * ssnpa, struct list *adjdb) void isis_delete_adj (struct isis_adjacency *adj, struct list *adjdb) { - struct isis_adjacency *adj2; + struct isis_adjacency *adj2 = NULL; struct listnode *node; if (adjdb) { - for (node = listhead (adjdb); node; nextnode (node)) - { - adj2 = getdata (node); - if (adj2 == adj) - break; - } + for (ALL_LIST_ELEMENTS_RO (adjdb, node, adj2)) + if (adj2 == adj) + break; + listnode_delete (adjdb, adj); } @@ -249,20 +241,16 @@ isis_adj_print (struct isis_adjacency *adj) { zlog_debug ("IPv4 Addresses:"); - for (node = listhead (adj->ipv4_addrs); node; nextnode (node)) - { - ipv4_addr = getdata (node); - zlog_debug ("%s", inet_ntoa (*ipv4_addr)); - } + for (ALL_LIST_ELEMENTS_RO (adj->ipv4_addrs, node, ipv4_addr)) + zlog_debug ("%s", inet_ntoa (*ipv4_addr)); } #ifdef HAVE_IPV6 if (adj->ipv6_addrs && listcount (adj->ipv6_addrs) > 0) { zlog_debug ("IPv6 Addresses:"); - for (node = listhead (adj->ipv6_addrs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (adj->ipv6_addrs, node, ipv6_addr)) { - ipv6_addr = getdata (node); inet_ntop (AF_INET6, ipv6_addr, (char *)ip6, INET6_ADDRSTRLEN); zlog_debug ("%s", ip6); } @@ -400,19 +388,15 @@ isis_adj_print_vty2 (struct isis_adjacency *adj, struct vty *vty, char detail) if (adj->ipv4_addrs && listcount (adj->ipv4_addrs) > 0) { vty_out (vty, " IPv4 Addresses:%s", VTY_NEWLINE); - for (node = listhead (adj->ipv4_addrs); node; nextnode (node)) - { - ip_addr = getdata (node); - vty_out (vty, " %s%s", inet_ntoa (*ip_addr), VTY_NEWLINE); - } + for (ALL_LIST_ELEMENTS_RO (adj->ipv4_addrs, node, ip_addr)) + vty_out (vty, " %s%s", inet_ntoa (*ip_addr), VTY_NEWLINE); } #ifdef HAVE_IPV6 if (adj->ipv6_addrs && listcount (adj->ipv6_addrs) > 0) { vty_out (vty, " IPv6 Addresses:%s", VTY_NEWLINE); - for (node = listhead (adj->ipv6_addrs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (adj->ipv4_addrs, node, ipv6_addr)) { - ipv6_addr = getdata (node); inet_ntop (AF_INET6, ipv6_addr, (char *)ip6, INET6_ADDRSTRLEN); vty_out (vty, " %s%s", ip6, VTY_NEWLINE); } @@ -463,13 +447,11 @@ void isis_adjdb_iterate (struct list *adjdb, void (*func) (struct isis_adjacency *, void *), void *arg) { - struct listnode *node; + struct listnode *node, *nnode; struct isis_adjacency *adj; - for (node = listhead (adjdb); node; nextnode (node)) - { - adj = getdata (node); - (*func) (adj, arg); - } + + for (ALL_LIST_ELEMENTS (adjdb, node, nnode, adj)) + (*func) (adj, arg); } void @@ -484,9 +466,8 @@ isis_adj_build_neigh_list (struct list *adjdb, struct list *list) return; } - for (node = listhead (adjdb); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (adjdb, node, adj)) { - adj = getdata (node); if (!adj) { zlog_warn ("isis_adj_build_neigh_list(): NULL adj"); @@ -512,10 +493,8 @@ isis_adj_build_up_list (struct list *adjdb, struct list *list) return; } - for (node = listhead (adjdb); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (adjdb, node, adj)) { - adj = getdata (node); - if (!adj) { zlog_warn ("isis_adj_build_up_list(): NULL adj"); diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 1a98a6337..b99fa5daf 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -150,13 +150,10 @@ circuit_lookup_by_ifp (struct interface *ifp, struct list *list) if (!list) return NULL; - for (node = listhead (list); node; nextnode (node)) - { - circuit = getdata (node); - if (circuit->interface == ifp) - return circuit; - } - + for (ALL_LIST_ELEMENTS_RO (list, node, circuit)) + if (circuit->interface == ifp) + return circuit; + return NULL; } @@ -170,9 +167,8 @@ circuit_scan_by_ifp (struct interface *ifp) if (!isis->area_list) return NULL; - for (node = listhead (isis->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area)) { - area = getdata (node); circuit = circuit_lookup_by_ifp (ifp, area->circuit_list); if (circuit) return circuit; @@ -295,12 +291,9 @@ isis_circuit_del_addr (struct isis_circuit *circuit, ipv4->prefixlen = connected->address->prefixlen; ipv4->prefix = connected->address->u.prefix4; - for (node = listhead (circuit->ip_addrs); node; nextnode (node)) - { - ip = getdata (node); - if (prefix_same ((struct prefix *) ip, (struct prefix *) &ipv4)) - break; - } + for (ALL_LIST_ELEMENTS_RO (circuit->ip_addrs, node, ip)) + if (prefix_same ((struct prefix *) ip, (struct prefix *) &ipv4)) + break; if (ip) { @@ -324,9 +317,8 @@ isis_circuit_del_addr (struct isis_circuit *circuit, if (IN6_IS_ADDR_LINKLOCAL (&ipv6->prefix)) { - for (node = listhead (circuit->ipv6_link); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_link, node, ip6)) { - ip6 = getdata (node); if (prefix_same ((struct prefix *) ip6, (struct prefix *) ipv6)) break; } @@ -338,9 +330,8 @@ isis_circuit_del_addr (struct isis_circuit *circuit, } else { - for (node = listhead (circuit->ipv6_non_link); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (circuit->ipv6_non_link, node, ip6)) { - ip6 = getdata (node); if (prefix_same ((struct prefix *) ip6, (struct prefix *) ipv6)) break; } @@ -368,7 +359,7 @@ isis_circuit_del_addr (struct isis_circuit *circuit, void isis_circuit_if_add (struct isis_circuit *circuit, struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct connected *conn; circuit->interface = ifp; @@ -416,12 +407,8 @@ isis_circuit_if_add (struct isis_circuit *circuit, struct interface *ifp) zlog_warn ("isis_circuit_if_add: unsupported media"); } - for (node = ifp->connected ? listhead (ifp->connected) : NULL; node; - nextnode (node)) - { - conn = getdata (node); - isis_circuit_add_addr (circuit, conn); - } + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, conn)) + isis_circuit_add_addr (circuit, conn); return; } @@ -631,14 +618,14 @@ isis_interface_config_write (struct vty *vty) { int write = 0; - struct listnode *node; - struct listnode *node2; + struct listnode *node, *nnode; + struct listnode *node2, *nnode2; struct interface *ifp; struct isis_area *area; struct isis_circuit *c; int i; - LIST_LOOP (iflist, ifp, node) + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) { /* IF name */ vty_out (vty, "interface %s%s", ifp->name, VTY_NEWLINE); @@ -650,7 +637,7 @@ isis_interface_config_write (struct vty *vty) write++; } /* ISIS Circuit */ - LIST_LOOP (isis->area_list, area, node2) + for (ALL_LIST_ELEMENTS (isis->area_list, node2, nnode2, area)) { c = circuit_lookup_by_ifp (ifp, area->circuit_list); if (c) @@ -901,7 +888,7 @@ DEFUN (no_ip_router_isis, struct isis_circuit *circuit = NULL; struct interface *ifp; struct isis_area *area; - struct listnode *node; + struct listnode *node, *nnode; ifp = (struct interface *) vty->index; assert (ifp); @@ -912,7 +899,7 @@ DEFUN (no_ip_router_isis, vty_out (vty, "Can't find ISIS instance %s", VTY_NEWLINE); return CMD_WARNING; } - LIST_LOOP (area->circuit_list, circuit, node) + for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit)) if (circuit->interface == ifp) break; if (!circuit) diff --git a/isisd/isis_dr.c b/isisd/isis_dr.c index 4eadc9c11..75713566b 100644 --- a/isisd/isis_dr.c +++ b/isisd/isis_dr.c @@ -130,7 +130,7 @@ int isis_dr_elect (struct isis_circuit *circuit, int level) { struct list *adjdb; - struct listnode *node; + struct listnode *node, *nnode; struct isis_adjacency *adj, *adj_dr = NULL; struct list *list = list_new (); u_char own_prio; @@ -152,9 +152,8 @@ isis_dr_elect (struct isis_circuit *circuit, int level) /* * Loop the adjacencies and find the one with the biggest priority */ - for (node = listhead (list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (list, node, nnode, adj)) { - adj = getdata (node); /* clear flag for show output */ adj->dis_record[level - 1].dis = ISIS_IS_NOT_DIS; adj->dis_record[level - 1].last_dis_change = time (NULL); @@ -215,11 +214,8 @@ isis_dr_elect (struct isis_circuit *circuit, int level) */ /* rotate the history log */ - for (node = listhead (list); node; nextnode (node)) - { - adj = getdata (node); - isis_check_dr_change (adj, level); - } + for (ALL_LIST_ELEMENTS (list, node, nnode, adj)) + isis_check_dr_change (adj, level); /* commence */ list_delete (list); @@ -238,11 +234,8 @@ isis_dr_elect (struct isis_circuit *circuit, int level) * if yes rotate the history log */ - for (node = listhead (list); node; nextnode (node)) - { - adj = getdata (node); - isis_check_dr_change (adj, level); - } + for (ALL_LIST_ELEMENTS (list, node, nnode, adj)) + isis_check_dr_change (adj, level); /* * We are not DR - if we were -> resign diff --git a/isisd/isis_dynhn.c b/isisd/isis_dynhn.c index 41c363714..68257ddce 100644 --- a/isisd/isis_dynhn.c +++ b/isisd/isis_dynhn.c @@ -60,12 +60,9 @@ dynhn_find_by_id (u_char * id) struct listnode *node = NULL; struct isis_dynhn *dyn = NULL; - for (node = listhead (dyn_cache); node; nextnode (node)) - { - dyn = getdata (node); - if (memcmp (dyn->id, id, ISIS_SYS_ID_LEN) == 0) - return dyn; - } + for (ALL_LIST_ELEMENTS_RO (dyn_cache, node, dyn)) + if (memcmp (dyn->id, id, ISIS_SYS_ID_LEN) == 0) + return dyn; return NULL; } @@ -114,9 +111,8 @@ dynhn_print_all (struct vty *vty) struct isis_dynhn *dyn; vty_out (vty, "Level System ID Dynamic Hostname%s", VTY_NEWLINE); - for (node = listhead (dyn_cache); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (dyn_cache, node, dyn)) { - dyn = getdata (node); vty_out (vty, "%-7d", dyn->level); vty_out (vty, "%-15s%-15s%s", sysid_print (dyn->id), dyn->name.name, VTY_NEWLINE); diff --git a/isisd/isis_events.c b/isisd/isis_events.c index 66d694f60..d54036a5f 100644 --- a/isisd/isis_events.c +++ b/isisd/isis_events.c @@ -88,7 +88,7 @@ isis_event_circuit_state_change (struct isis_circuit *circuit, int up) void isis_event_system_type_change (struct isis_area *area, int newtype) { - struct listnode *node; + struct listnode *node, *nnode; struct isis_circuit *circuit; if (isis->debugs & DEBUG_EVENTS) @@ -125,11 +125,8 @@ isis_event_system_type_change (struct isis_area *area, int newtype) } area->is_type = newtype; - for (node = listhead (area->circuit_list); node; nextnode (node)) - { - circuit = getdata (node); - isis_event_circuit_type_change (circuit, newtype); - } + for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit)) + isis_event_circuit_type_change (circuit, newtype); spftree_area_init (area); lsp_regenerate_schedule (area); diff --git a/isisd/isis_flags.c b/isisd/isis_flags.c index 0ef048e2c..9c861c945 100644 --- a/isisd/isis_flags.c +++ b/isisd/isis_flags.c @@ -43,7 +43,7 @@ flags_get_index (struct flags *flags) else { node = listhead (flags->free_idcs); - index = (int) getdata (node); + index = (int) listgetdata (node); listnode_delete (flags->free_idcs, (void *) index); } diff --git a/isisd/isis_lsp.c b/isisd/isis_lsp.c index 987a9b32b..88d4886bc 100644 --- a/isisd/isis_lsp.c +++ b/isisd/isis_lsp.c @@ -187,12 +187,11 @@ static void lsp_remove_frags (struct list *frags, dict_t * lspdb) { dnode_t *dnode; - struct listnode *lnode; + struct listnode *lnode, *lnnode; struct isis_lsp *lsp; - for (lnode = listhead (frags); lnode; nextnode (lnode)) + for (ALL_LIST_ELEMENTS (frags, lnode, lnnode, lsp)) { - lsp = getdata (lnode); dnode = dict_lookup (lspdb, lsp->lsp_header->lsp_id); lsp_destroy (lsp); dnode_destroy (dict_delete (lspdb, dnode)); @@ -325,18 +324,15 @@ static void lsp_seqnum_update (struct isis_lsp *lsp0) { struct isis_lsp *lsp; - struct listnode *node; + struct listnode *node, *nnode; lsp_inc_seqnum (lsp0, 0); if (!lsp0->lspu.frags) return; - for (node = listhead (lsp0->lspu.frags); node; nextnode (node)) - { - lsp = getdata (node); - lsp_inc_seqnum (lsp, 0); - } + for (ALL_LIST_ELEMENTS (lsp0->lspu.frags, node, nnode, lsp)) + lsp_inc_seqnum (lsp, 0); return; } @@ -717,7 +713,7 @@ lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) struct isis_lsp *lsp = dnode_get (node); struct area_addr *area_addr; int i; - struct listnode *lnode; + struct listnode *lnode, *lnnode; struct is_neigh *is_neigh; struct te_is_neigh *te_is_neigh; struct ipv4_reachability *ipv4_reach; @@ -739,15 +735,14 @@ lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) /* for all area address */ if (lsp->tlv_data.area_addrs) - { - LIST_LOOP (lsp->tlv_data.area_addrs, area_addr, lnode) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.area_addrs, lnode, + lnnode, area_addr)) { vty_out (vty, " Area Address: %s%s", isonet_print (area_addr->area_addr, area_addr->addr_len), VTY_NEWLINE); } - } - + /* for the nlpid tlv */ if (lsp->tlv_data.nlpids) { @@ -777,13 +772,12 @@ lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) } if (lsp->tlv_data.ipv4_addrs) - { - LIST_LOOP (lsp->tlv_data.ipv4_addrs, ipv4_addr, lnode) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_addrs, lnode, + lnnode, ipv4_addr)) { memcpy (ipv4_address, inet_ntoa (*ipv4_addr), sizeof (ipv4_address)); vty_out (vty, " IP: %s%s", ipv4_address, VTY_NEWLINE); } - } /* TE router id */ if (lsp->tlv_data.router_id) @@ -795,18 +789,17 @@ lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) /* for the IS neighbor tlv */ if (lsp->tlv_data.is_neighs) - { - LIST_LOOP (lsp->tlv_data.is_neighs, is_neigh, lnode) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.is_neighs, lnode, lnnode, is_neigh)) { lspid_print (is_neigh->neigh_id, LSPid, dynhost, 0); vty_out (vty, " Metric: %d IS %s%s", is_neigh->metrics.metric_default, LSPid, VTY_NEWLINE); } - } /* for the internal reachable tlv */ if (lsp->tlv_data.ipv4_int_reachs) - LIST_LOOP (lsp->tlv_data.ipv4_int_reachs, ipv4_reach, lnode) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_int_reachs, lnode, + lnnode, ipv4_reach)) { memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix), sizeof (ipv4_reach_prefix)); @@ -819,7 +812,8 @@ lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) /* for the external reachable tlv */ if (lsp->tlv_data.ipv4_ext_reachs) - LIST_LOOP (lsp->tlv_data.ipv4_ext_reachs, ipv4_reach, lnode) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv4_ext_reachs, lnode, + lnnode, ipv4_reach)) { memcpy (ipv4_reach_prefix, inet_ntoa (ipv4_reach->prefix), sizeof (ipv4_reach_prefix)); @@ -829,11 +823,12 @@ lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) ipv4_reach->metrics.metric_default, ipv4_reach_prefix, ipv4_reach_mask, VTY_NEWLINE); } - + /* IPv6 tlv */ #ifdef HAVE_IPV6 if (lsp->tlv_data.ipv6_reachs) - LIST_LOOP (lsp->tlv_data.ipv6_reachs, ipv6_reach, lnode) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.ipv6_reachs, lnode, + lnnode, ipv6_reach)) { memset (&in6, 0, sizeof (in6)); memcpy (in6.s6_addr, ipv6_reach->prefix, @@ -850,9 +845,11 @@ lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) buff, ipv6_reach->prefix_len, VTY_NEWLINE); } #endif + /* TE IS neighbor tlv */ if (lsp->tlv_data.te_is_neighs) - LIST_LOOP (lsp->tlv_data.te_is_neighs, te_is_neigh, lnode) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.te_is_neighs, lnode, + lnnode, te_is_neigh)) { /* FIXME: metric display is wrong. */ lspid_print (te_is_neigh->neigh_id, LSPid, dynhost, 0); @@ -862,7 +859,8 @@ lsp_print_detail (dnode_t * node, struct vty *vty, char dynhost) /* TE IPv4 tlv */ if (lsp->tlv_data.te_ipv4_reachs) - LIST_LOOP (lsp->tlv_data.te_ipv4_reachs, te_ipv4_reach, lnode) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.te_ipv4_reachs, lnode, + lnnode, te_ipv4_reach)) { /* FIXME: There should be better way to output this stuff. */ vty_out (vty, " Metric: %d extd-IP %s/%d%s", @@ -949,7 +947,7 @@ void lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) { struct is_neigh *is_neigh; - struct listnode *node, *ipnode; + struct listnode *node, *nnode, *ipnode, *ipnnode; int level = lsp->level; struct isis_circuit *circuit; struct prefix_ipv4 *ipv4; @@ -1027,9 +1025,8 @@ lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) /* * Then add tlvs related to circuits */ - for (node = listhead (area->circuit_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit)) { - circuit = getdata (node); if (circuit->state != C_STATE_UP) continue; @@ -1044,10 +1041,8 @@ lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) lsp->tlv_data.ipv4_int_reachs = list_new (); lsp->tlv_data.ipv4_int_reachs->del = free_tlv; } - for (ipnode = listhead (circuit->ip_addrs); ipnode; - nextnode (ipnode)) + for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4)) { - ipv4 = getdata (ipnode); ipreach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability)); ipreach->metrics = circuit->metrics[level - 1]; @@ -1068,10 +1063,9 @@ lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) lsp->tlv_data.ipv6_reachs = list_new (); lsp->tlv_data.ipv6_reachs->del = free_tlv; } - for (ipnode = listhead (circuit->ipv6_non_link); ipnode; - nextnode (ipnode)) + for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode, + ipnnode, ipv6)) { - ipv6 = getdata (ipnode); ip6reach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability)); memset (ip6reach, 0, sizeof (struct ipv6_reachability)); @@ -1192,8 +1186,8 @@ lsp_tlv_fit (struct isis_lsp *lsp, struct list **from, struct list **to, count = count / tlvsize; for (i = 0; i < count; i++) { - listnode_add (*to, getdata (listhead (*from))); - listnode_delete (*from, getdata (listhead (*from))); + listnode_add (*to, listgetdata (listhead (*from))); + listnode_delete (*from, listgetdata (listhead (*from))); } tlv_build_func (*to, lsp->pdu); } @@ -1256,7 +1250,7 @@ static void lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) { struct is_neigh *is_neigh; - struct listnode *node, *ipnode; + struct listnode *node, *nnode, *ipnode, *ipnnode; int level = lsp->level; struct isis_circuit *circuit; struct prefix_ipv4 *ipv4; @@ -1360,9 +1354,8 @@ lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) /* * Then build lists of tlvs related to circuits */ - for (node = listhead (area->circuit_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit)) { - circuit = getdata (node); if (circuit->state != C_STATE_UP) continue; @@ -1376,10 +1369,8 @@ lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) { tlv_data.ipv4_int_reachs = list_new (); } - for (ipnode = listhead (circuit->ip_addrs); ipnode; - nextnode (ipnode)) + for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4)) { - ipv4 = getdata (ipnode); ipreach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv4_reachability)); ipreach->metrics = circuit->metrics[level - 1]; @@ -1402,10 +1393,9 @@ lsp_build_nonpseudo (struct isis_lsp *lsp, struct isis_area *area) { tlv_data.ipv6_reachs = list_new (); } - for (ipnode = listhead (circuit->ipv6_non_link); ipnode; - nextnode (ipnode)) + for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, ipnode, ipnnode, + ipv6)) { - ipv6 = getdata (ipnode); ip6reach = XMALLOC (MTYPE_ISIS_TLV, sizeof (struct ipv6_reachability)); memset (ip6reach, 0, sizeof (struct ipv6_reachability)); @@ -1696,9 +1686,8 @@ lsp_non_pseudo_regenerate (struct isis_area *area, int level) lsp->last_generated = time (NULL); area->lsp_regenerate_pending[level - 1] = 0; ISIS_FLAGS_SET_ALL (lsp->SRMflags); - for (node = listhead (lsp->lspu.frags); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (lsp->lspu.frags, node, frag)) { - frag = getdata (node); frag->lsp_header->rem_lifetime = htons (isis_jitter (area-> max_lsp_lifetime[level - 1], @@ -1862,7 +1851,7 @@ lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit, struct is_neigh *is_neigh; struct es_neigh *es_neigh; struct list *adj_list; - struct listnode *node; + struct listnode *node, *nnode; struct isis_passwd *passwd; assert (circuit); @@ -1893,9 +1882,8 @@ lsp_build_pseudo (struct isis_lsp *lsp, struct isis_circuit *circuit, adj_list = list_new (); isis_adj_build_up_list (circuit->u.bc.adjdb[level - 1], adj_list); - for (node = listhead (adj_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (adj_list, node, nnode, adj)) { - adj = getdata (node); if (adj->circuit_t & level) { if ((level == 1 && adj->sys_type == ISIS_SYSTYPE_L1_IS) || @@ -2127,7 +2115,7 @@ lsp_tick (struct thread *thread) struct isis_circuit *circuit; struct isis_lsp *lsp; struct list *lsp_list; - struct listnode *lspnode, *cnode; + struct listnode *lspnode, *lspnnode, *cnode; dnode_t *dnode, *dnode_next; int level; @@ -2174,14 +2162,10 @@ lsp_tick (struct thread *thread) */ if (listcount (lsp_list) > 0) { - for (cnode = listhead (area->circuit_list); cnode; - nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (area->circuit_list, cnode, circuit)) { - circuit = getdata (cnode); - for (lspnode = listhead (lsp_list); lspnode; - nextnode (lspnode)) + for (ALL_LIST_ELEMENTS (lsp_list, lspnode, lspnnode, lsp)) { - lsp = getdata (lspnode); if (ISIS_CHECK_FLAG (lsp->SRMflags, circuit)) { /* FIXME: if same or elder lsp is already in lsp diff --git a/isisd/isis_pdu.c b/isisd/isis_pdu.c index 6dcc75e98..9d3b18adc 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -80,11 +80,12 @@ static int area_match (struct list *left, struct list *right) { struct area_addr *addr1, *addr2; - struct listnode *node1, *node2; + struct listnode *node1, *nnode1; + struct listnode *node2, *nnode2; - LIST_LOOP (left, addr1, node1) + for (ALL_LIST_ELEMENTS (left, node1, nnode1, addr1)) { - LIST_LOOP (right, addr2, node2) + for (ALL_LIST_ELEMENTS (right, node2, nnode2, addr2)) { if (addr1->addr_len == addr2->addr_len && !memcmp (addr1->area_addr, addr2->area_addr, (int) addr1->addr_len)) @@ -139,14 +140,15 @@ ip_match (struct list *left, struct list *right) { struct prefix_ipv4 *ip1; struct in_addr *ip2; - struct listnode *node1, *node2; + struct listnode *node1, *nnode1; + struct listnode *node2, *nnode2; if ((left == NULL) || (right == NULL)) return 0; - LIST_LOOP (left, ip1, node1) + for (ALL_LIST_ELEMENTS (left, node1, nnode1, ip1)) { - LIST_LOOP (right, ip2, node2) + for (ALL_LIST_ELEMENTS (right, node2, nnode2, ip2)) { if (ip_same_subnet (ip1, ip2)) { @@ -223,7 +225,7 @@ del_ip_addr (void *val) static void tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) { - struct listnode *node; + struct listnode *node, *nnode; struct in_addr *ipv4_addr, *malloced; if (adj->ipv4_addrs) @@ -234,7 +236,7 @@ tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) adj->ipv4_addrs = list_new (); if (tlvs->ipv4_addrs) { - LIST_LOOP (tlvs->ipv4_addrs, ipv4_addr, node) + for (ALL_LIST_ELEMENTS (tlvs->ipv4_addrs, node, nnode, ipv4_addr)) { malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in_addr)); memcpy (malloced, ipv4_addr, sizeof (struct in_addr)); @@ -247,7 +249,7 @@ tlvs_to_adj_ipv4_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) static void tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) { - struct listnode *node; + struct listnode *node, *nnode; struct in6_addr *ipv6_addr, *malloced; if (adj->ipv6_addrs) @@ -258,7 +260,7 @@ tlvs_to_adj_ipv6_addrs (struct tlvs *tlvs, struct isis_adjacency *adj) adj->ipv6_addrs = list_new (); if (tlvs->ipv6_addrs) { - LIST_LOOP (tlvs->ipv6_addrs, ipv6_addr, node) + for (ALL_LIST_ELEMENTS (tlvs->ipv6_addrs, node, nnode, ipv6_addr)) { malloced = XMALLOC (MTYPE_ISIS_TMP, sizeof (struct in6_addr)); memcpy (malloced, ipv6_addr, sizeof (struct in6_addr)); @@ -661,7 +663,7 @@ process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa) u_int32_t expected = 0, found; struct tlvs tlvs; u_char *snpa; - struct listnode *node; + struct listnode *node, *nnode; if ((stream_get_endp (circuit->rcv_stream) - stream_get_getp (circuit->rcv_stream)) < ISIS_LANHELLO_HDRLEN) @@ -884,7 +886,7 @@ process_lan_hello (int level, struct isis_circuit *circuit, u_char * ssnpa) { if (adj->adj_state != ISIS_ADJ_UP) { - LIST_LOOP (tlvs.lan_neighs, snpa, node) + for (ALL_LIST_ELEMENTS (tlvs.lan_neighs, node, nnode, snpa)) if (!memcmp (snpa, circuit->u.bc.snpa, ETH_ALEN)) { isis_adj_state_change (adj, ISIS_ADJ_UP, @@ -1267,7 +1269,8 @@ process_snp (int snp_type, int level, struct isis_circuit *circuit, uint32_t found = 0, expected = 0; struct isis_lsp *lsp; struct lsp_entry *entry; - struct listnode *node, *node2; + struct listnode *node, *nnode; + struct listnode *node2, *nnode2; struct tlvs tlvs; struct list *lsp_list = NULL; struct isis_passwd *passwd; @@ -1424,7 +1427,7 @@ process_snp (int snp_type, int level, struct isis_circuit *circuit, typechar, snpa_print (ssnpa), circuit->interface->name); if (tlvs.lsp_entries) { - LIST_LOOP (tlvs.lsp_entries, entry, node) + for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry)) { zlog_debug ("ISIS-Snp (%s): %cSNP entry %s, seq 0x%08x," " cksum 0x%04x, lifetime %us", @@ -1440,7 +1443,7 @@ process_snp (int snp_type, int level, struct isis_circuit *circuit, /* 7.3.15.2 b) Actions on LSP_ENTRIES reported */ if (tlvs.lsp_entries) { - LIST_LOOP (tlvs.lsp_entries, entry, node) + for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry)) { lsp = lsp_search (entry->lsp_id, circuit->area->lspdb[level - 1]); own_lsp = !memcmp (entry->lsp_id, isis->sysid, ISIS_SYS_ID_LEN); @@ -1507,9 +1510,9 @@ process_snp (int snp_type, int level, struct isis_circuit *circuit, /* Fixme: Find a better solution */ if (tlvs.lsp_entries) { - LIST_LOOP (tlvs.lsp_entries, entry, node) + for (ALL_LIST_ELEMENTS (tlvs.lsp_entries, node, nnode, entry)) { - LIST_LOOP (lsp_list, lsp, node2) + for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp)) { if (lsp_id_cmp (lsp->lsp_header->lsp_id, entry->lsp_id) == 0) { @@ -1520,7 +1523,7 @@ process_snp (int snp_type, int level, struct isis_circuit *circuit, } } /* on remaining LSPs we set SRM (neighbor knew not of) */ - LIST_LOOP (lsp_list, lsp, node2) + for (ALL_LIST_ELEMENTS (lsp_list, node2, nnode2, lsp)) { ISIS_SET_FLAG (lsp->SRMflags, circuit); } @@ -2178,7 +2181,7 @@ send_csnp (struct isis_circuit *circuit, int level) u_char start[ISIS_SYS_ID_LEN + 2]; u_char stop[ISIS_SYS_ID_LEN + 2]; struct list *list = NULL; - struct listnode *node; + struct listnode *node, *nnode; struct isis_lsp *lsp; memset (start, 0x00, ISIS_SYS_ID_LEN + 2); @@ -2200,9 +2203,9 @@ send_csnp (struct isis_circuit *circuit, int level) if (isis->debugs & DEBUG_SNP_PACKETS) { zlog_debug ("ISIS-Snp (%s): Sent L%d CSNP on %s, length %ld", - circuit->area->area_tag, level, circuit->interface->name, - STREAM_SIZE (circuit->snd_stream)); - LIST_LOOP (list, lsp, node) + circuit->area->area_tag, level, circuit->interface->name, + STREAM_SIZE (circuit->snd_stream)); + for (ALL_LIST_ELEMENTS (list, node, nnode, lsp)) { zlog_debug ("ISIS-Snp (%s): CSNP entry %s, seq 0x%08x," " cksum 0x%04x, lifetime %us", @@ -2275,7 +2278,7 @@ build_psnp (int level, struct isis_circuit *circuit, struct list *lsps) int retval = 0; struct isis_lsp *lsp; struct isis_passwd *passwd; - struct listnode *node; + struct listnode *node, *nnode; if (level == 1) fill_fixed_hdr_andstream (&fixed_hdr, L1_PARTIAL_SEQ_NUM, @@ -2313,7 +2316,7 @@ build_psnp (int level, struct isis_circuit *circuit, struct list *lsps) if (isis->debugs & DEBUG_SNP_PACKETS) { - LIST_LOOP (lsps, lsp, node) + for (ALL_LIST_ELEMENTS (lsps, node, nnode, lsp)) { zlog_debug ("ISIS-Snp (%s): PSNP entry %s, seq 0x%08x," " cksum 0x%04x, lifetime %us", @@ -2343,7 +2346,7 @@ send_psnp (int level, struct isis_circuit *circuit) int retval = ISIS_OK; struct isis_lsp *lsp; struct list *list = NULL; - struct listnode *node; + struct listnode *node, *nnode; if ((circuit->circ_type == CIRCUIT_T_BROADCAST && !circuit->u.bc.is_dr[level - 1]) || @@ -2380,11 +2383,8 @@ send_psnp (int level, struct isis_circuit *circuit) * sending succeeded, we can clear SSN flags of this circuit * for the LSPs in list */ - for (node = listhead (list); node; nextnode (node)) - { - lsp = getdata (node); - ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); - } + for (ALL_LIST_ELEMENTS (list, node, nnode, lsp)) + ISIS_CLEAR_FLAG (lsp->SSNflags, circuit); } } list_delete (list); @@ -2467,10 +2467,7 @@ send_lsp (struct thread *thread) if (circuit->state == C_STATE_UP) { - node = listhead (circuit->lsp_queue); - assert (node); - - lsp = getdata (node); + lsp = listgetdata ((node = listhead (circuit->lsp_queue))); /* * Do not send if levels do not match diff --git a/isisd/isis_route.c b/isisd/isis_route.c index 3ef903808..04346d4ac 100644 --- a/isisd/isis_route.c +++ b/isisd/isis_route.c @@ -59,9 +59,8 @@ isis_nexthop_create (struct in_addr *ip, unsigned int ifindex) struct listnode *node; struct isis_nexthop *nexthop; - for (node = listhead (isis->nexthops); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (isis->nexthops, node, nexthop)) { - nexthop = getdata (node); if (nexthop->ifindex != ifindex) continue; if (ip && memcmp (&nexthop->ip, ip, sizeof (struct in_addr)) != 0) @@ -106,9 +105,8 @@ nexthoplookup (struct list *nexthops, struct in_addr *ip, struct listnode *node; struct isis_nexthop *nh; - for (node = listhead (nexthops); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (nexthops, node, nh)) { - nh = getdata (node); if (!(memcmp (ip, &nh->ip, sizeof (struct in_addr))) && ifindex == nh->ifindex) return 1; @@ -133,8 +131,8 @@ nexthops_print (struct list *nhs) { struct listnode *node; - for (node = listhead (nhs); node; nextnode (node)) - nexthop_print (getdata (node)); + for (ALL_LIST_ELEMENTS_RO (nhs, node, nh)) + nexthop_print (nh); } #endif /* 0 */ @@ -165,9 +163,8 @@ isis_nexthop6_create (struct in6_addr *ip6, unsigned int ifindex) struct listnode *node; struct isis_nexthop6 *nexthop6; - for (node = listhead (isis->nexthops6); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (isis->nexthops6, node, nexthop6)) { - nexthop6 = getdata (node); if (nexthop6->ifindex != ifindex) continue; if (ip6 && memcmp (&nexthop6->ip6, ip6, sizeof (struct in6_addr)) != 0) @@ -203,9 +200,8 @@ nexthop6lookup (struct list *nexthops6, struct in6_addr *ip6, struct listnode *node; struct isis_nexthop6 *nh6; - for (node = listhead (nexthops6); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (nexthops6, node, nh6)) { - nh6 = getdata (node); if (!(memcmp (ip6, &nh6->ip6, sizeof (struct in6_addr))) && ifindex == nh6->ifindex) return 1; @@ -230,8 +226,8 @@ nexthops6_print (struct list *nhs6) { struct listnode *node; - for (node = listhead (nhs6); node; nextnode (node)) - nexthop6_print (getdata (node)); + for (ALL_LIST_ELEMENTS_RO (nhs6, node, nh6)) + nexthop6_print (nh6); } #endif /* EXTREME_DEBUG */ #endif /* HAVE_IPV6 */ @@ -240,14 +236,14 @@ static void adjinfo2nexthop (struct list *nexthops, struct isis_adjacency *adj) { struct isis_nexthop *nh; - struct listnode *node; + struct listnode *node, *nnode; struct in_addr *ipv4_addr; if (adj->ipv4_addrs == NULL) return; - for (node = listhead (adj->ipv4_addrs); node; nextnode (node)) + + for (ALL_LIST_ELEMENTS (adj->ipv4_addrs, node, nnode, ipv4_addr)) { - ipv4_addr = getdata (node); if (!nexthoplookup (nexthops, ipv4_addr, adj->circuit->interface->ifindex)) { @@ -262,16 +258,15 @@ adjinfo2nexthop (struct list *nexthops, struct isis_adjacency *adj) static void adjinfo2nexthop6 (struct list *nexthops6, struct isis_adjacency *adj) { - struct listnode *node; + struct listnode *node, *nnode; struct in6_addr *ipv6_addr; struct isis_nexthop6 *nh6; if (!adj->ipv6_addrs) return; - for (node = listhead (adj->ipv6_addrs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (adj->ipv6_addrs, node, nnode, ipv6_addr)) { - ipv6_addr = getdata (node); if (!nexthop6lookup (nexthops6, ipv6_addr, adj->circuit->interface->ifindex)) { @@ -289,7 +284,7 @@ isis_route_info_new (uint32_t cost, uint32_t depth, u_char family, { struct isis_route_info *rinfo; struct isis_adjacency *adj; - struct listnode *node; + struct listnode *node, *nnode; rinfo = XMALLOC (MTYPE_ISIS_ROUTE_INFO, sizeof (struct isis_route_info)); if (!rinfo) @@ -302,21 +297,15 @@ isis_route_info_new (uint32_t cost, uint32_t depth, u_char family, if (family == AF_INET) { rinfo->nexthops = list_new (); - for (node = listhead (adjacencies); node; nextnode (node)) - { - adj = getdata (node); - adjinfo2nexthop (rinfo->nexthops, adj); - } + for (ALL_LIST_ELEMENTS (adjacencies, node, nnode, adj)) + adjinfo2nexthop (rinfo->nexthops, adj); } #ifdef HAVE_IPV6 if (family == AF_INET6) { rinfo->nexthops6 = list_new (); - for (node = listhead (adjacencies); node; nextnode (node)) - { - adj = getdata (node); - adjinfo2nexthop6 (rinfo->nexthops6, adj); - } + for (ALL_LIST_ELEMENTS (adjacencies, node, nnode, adj)) + adjinfo2nexthop6 (rinfo->nexthops6, adj); } #endif /* HAVE_IPV6 */ @@ -363,7 +352,7 @@ static int isis_route_info_same (struct isis_route_info *new, struct isis_route_info *old, u_char family) { - struct listnode *node; + struct listnode *node, *nnode; struct isis_nexthop *nexthop; #ifdef HAVE_IPV6 struct isis_nexthop6 *nexthop6; @@ -373,40 +362,28 @@ isis_route_info_same (struct isis_route_info *new, if (family == AF_INET) { - for (node = listhead (new->nexthops); node; nextnode (node)) - { - nexthop = (struct isis_nexthop *) getdata (node); - if (nexthoplookup (old->nexthops, &nexthop->ip, nexthop->ifindex) == - 0) - return 0; - } - - for (node = listhead (old->nexthops); node; nextnode (node)) - { - nexthop = (struct isis_nexthop *) getdata (node); - if (nexthoplookup (new->nexthops, &nexthop->ip, nexthop->ifindex) == - 0) - return 0; - } + for (ALL_LIST_ELEMENTS (new->nexthops, node, nnode, nexthop)) + if (nexthoplookup (old->nexthops, &nexthop->ip, nexthop->ifindex) + == 0) + return 0; + + for (ALL_LIST_ELEMENTS (old->nexthops, node, nnode, nexthop)) + if (nexthoplookup (new->nexthops, &nexthop->ip, nexthop->ifindex) + == 0) + return 0; } #ifdef HAVE_IPV6 else if (family == AF_INET6) { - for (node = listhead (new->nexthops6); node; nextnode (node)) - { - nexthop6 = (struct isis_nexthop6 *) getdata (node); - if (nexthop6lookup (old->nexthops6, &nexthop6->ip6, - nexthop6->ifindex) == 0) - return 0; - } - - for (node = listhead (old->nexthops6); node; nextnode (node)) - { - nexthop6 = (struct isis_nexthop6 *) getdata (node); - if (nexthop6lookup (new->nexthops6, &nexthop6->ip6, - nexthop6->ifindex) == 0) - return 0; - } + for (ALL_LIST_ELEMENTS (new->nexthops6, node, nnode, nexthop6)) + if (nexthop6lookup (old->nexthops6, &nexthop6->ip6, + nexthop6->ifindex) == 0) + return 0; + + for (ALL_LIST_ELEMENTS (old->nexthops6, node, nnode, nexthop6)) + if (nexthop6lookup (new->nexthops6, &nexthop6->ip6, + nexthop6->ifindex) == 0) + return 0; } #endif /* HAVE_IPV6 */ @@ -416,12 +393,11 @@ isis_route_info_same (struct isis_route_info *new, static void isis_nexthops_merge (struct list *new, struct list *old) { - struct listnode *node; + struct listnode *node, *nnode; struct isis_nexthop *nexthop; - for (node = listhead (new); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (new, node, nnode, nexthop)) { - nexthop = (struct isis_nexthop *) getdata (node); if (nexthoplookup (old, &nexthop->ip, nexthop->ifindex)) continue; listnode_add (old, nexthop); @@ -433,12 +409,11 @@ isis_nexthops_merge (struct list *new, struct list *old) static void isis_nexthops6_merge (struct list *new, struct list *old) { - struct listnode *node; + struct listnode *node, *nnode; struct isis_nexthop6 *nexthop6; - for (node = listhead (new); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (new, node, nnode, nexthop6)) { - nexthop6 = (struct isis_nexthop6 *) getdata (node); if (nexthop6lookup (old, &nexthop6->ip6, nexthop6->ifindex)) continue; listnode_add (old, nexthop6); diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index 90a9ac582..dc5765a57 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -67,18 +67,13 @@ union_adjlist (struct list *target, struct list *source) struct listnode *node, *node2; zlog_debug ("Union adjlist!"); - for (node = listhead (source); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (source, node, adj)) { - adj = getdata (node); - /* lookup adjacency in the source list */ - for (node2 = listhead (target); node2; nextnode (node2)) - { - adj2 = getdata (node2); - if (adj == adj2) + for (ALL_LIST_ELEMENTS_RO (target, node2, adj2)) + if (adj == adj2) break; - } - + if (!node2) listnode_add (target, adj); } @@ -89,16 +84,16 @@ union_adjlist (struct list *target, struct list *source) static void remove_excess_adjs (struct list *adjs) { - struct listnode *node, *excess = NULL; + struct listnode *node, *nnode, *excess = NULL; struct isis_adjacency *adj, *candidate = NULL; int comp; - for (node = listhead (adjs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (adjs, node, nnode, adj)) { if (excess == NULL) excess = node; - candidate = getdata (excess); - adj = getdata (node); + candidate = listgetdata (excess); + if (candidate->sys_type < adj->sys_type) { excess = node; @@ -360,9 +355,8 @@ isis_find_vertex (struct list *list, void *id, enum vertextype vtype) struct isis_vertex *vertex; struct prefix *p1, *p2; - for (node = listhead (list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (list, node, vertex)) { - vertex = getdata (node); if (vertex->type != vtype) continue; switch (vtype) @@ -426,9 +420,11 @@ isis_spf_add2tent (struct isis_spftree *spftree, enum vertextype vtype, listnode_add (spftree->tents, vertex); return vertex; } - for (node = listhead (spftree->tents); node; nextnode (node)) + + /* XXX: This cant use the standard ALL_LIST_ELEMENT macro */ + for (node = listhead (spftree->tents); node; node = listnextnode (node)) { - v = getdata (node); + v = listgetdata (node); if (v->d_N > vertex->d_N) { list_add_node_prev (spftree->tents, node, vertex); @@ -443,8 +439,9 @@ isis_spf_add2tent (struct isis_spftree *spftree, enum vertextype vtype, { break; } - nextnode (node); - (node) ? (v = getdata (node)) : (v = NULL); + /* XXX: this seems dubious, node is the loop iterator */ + node = listnextnode (node); + (node) ? (v = listgetdata (node)) : (v = NULL); } list_add_node_prev (spftree->tents, node, vertex); break; @@ -586,10 +583,8 @@ lspfragloop: { if (lsp->tlv_data.is_neighs) { - for (node = listhead (lsp->tlv_data.is_neighs); node; - nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.is_neighs, node, is_neigh)) { - is_neigh = getdata (node); /* C.2.6 a) */ /* Two way connectivity */ if (!memcmp (is_neigh->neigh_id, isis->sysid, ISIS_SYS_ID_LEN)) @@ -604,10 +599,9 @@ lspfragloop: if (family == AF_INET && lsp->tlv_data.ipv4_int_reachs) { prefix.family = AF_INET; - for (node = listhead (lsp->tlv_data.ipv4_int_reachs); node; - nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_int_reachs, + node, ipreach)) { - ipreach = getdata (node); dist = cost + ipreach->metrics.metric_default; vtype = VTYPE_IPREACH_INTERNAL; prefix.u.prefix4 = ipreach->prefix; @@ -620,10 +614,9 @@ lspfragloop: if (family == AF_INET && lsp->tlv_data.ipv4_ext_reachs) { prefix.family = AF_INET; - for (node = listhead (lsp->tlv_data.ipv4_ext_reachs); node; - nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv4_ext_reachs, + node, ipreach)) { - ipreach = getdata (node); dist = cost + ipreach->metrics.metric_default; vtype = VTYPE_IPREACH_EXTERNAL; prefix.u.prefix4 = ipreach->prefix; @@ -636,10 +629,9 @@ lspfragloop: if (family == AF_INET6 && lsp->tlv_data.ipv6_reachs) { prefix.family = AF_INET6; - for (node = listhead (lsp->tlv_data.ipv6_reachs); node; - nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (lsp->tlv_data.ipv6_reachs, + node, ip6reach)) { - ip6reach = getdata (node); dist = cost + ip6reach->metric; vtype = (ip6reach->control_info & CTRL_INFO_DISTRIBUTION) ? VTYPE_IP6REACH_EXTERNAL : VTYPE_IP6REACH_INTERNAL; @@ -656,11 +648,11 @@ lspfragloop: if (fragnode == NULL) fragnode = listhead (lsp->lspu.frags); else - nextnode (fragnode); + fragnode = listnextnode (fragnode); if (fragnode) { - lsp = getdata (fragnode); + lsp = listgetdata (fragnode); goto lspfragloop; } @@ -672,7 +664,7 @@ isis_spf_process_pseudo_lsp (struct isis_spftree *spftree, struct isis_lsp *lsp, uint16_t cost, uint16_t depth, int family) { - struct listnode *node, *fragnode = NULL; + struct listnode *node, *nnode, *fragnode = NULL; struct is_neigh *is_neigh; enum vertextype vtype; @@ -685,11 +677,8 @@ pseudofragloop: return ISIS_WARNING; } - for (node = (lsp->tlv_data.is_neighs ? - listhead (lsp->tlv_data.is_neighs) : NULL); - node; nextnode (node)) + for (ALL_LIST_ELEMENTS (lsp->tlv_data.is_neighs, node, nnode, is_neigh)) { - is_neigh = getdata (node); vtype = LSP_PSEUDO_ID (is_neigh->neigh_id) ? VTYPE_PSEUDO_IS : VTYPE_NONPSEUDO_IS; /* Two way connectivity */ @@ -709,11 +698,11 @@ pseudofragloop: if (fragnode == NULL) fragnode = listhead (lsp->lspu.frags); else - nextnode (fragnode); + fragnode = listnextnode (fragnode); if (fragnode) { - lsp = getdata (fragnode); + lsp = listgetdata (fragnode); goto pseudofragloop; } @@ -726,7 +715,9 @@ isis_spf_preload_tent (struct isis_spftree *spftree, { struct isis_vertex *vertex; struct isis_circuit *circuit; - struct listnode *cnode, *anode, *ipnode; + struct listnode *cnode, *cnnode; + struct listnode *anode; + struct listnode *ipnode, *ipnnode; struct isis_adjacency *adj; struct isis_lsp *lsp; struct list *adj_list; @@ -739,9 +730,8 @@ isis_spf_preload_tent (struct isis_spftree *spftree, struct prefix_ipv6 *ipv6; #endif /* HAVE_IPV6 */ - for (cnode = listhead (area->circuit_list); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS (area->circuit_list, cnode, cnnode, circuit)) { - circuit = getdata (cnode); if (circuit->state != C_STATE_UP) continue; if (!(circuit->circuit_is_type & level)) @@ -758,11 +748,8 @@ isis_spf_preload_tent (struct isis_spftree *spftree, if (family == AF_INET) { prefix.family = AF_INET; - for (ipnode = - (circuit->ip_addrs ? listhead (circuit->ip_addrs) : NULL); - ipnode; nextnode (ipnode)) + for (ALL_LIST_ELEMENTS (circuit->ip_addrs, ipnode, ipnnode, ipv4)) { - ipv4 = getdata (ipnode); prefix.u.prefix4 = ipv4->prefix; prefix.prefixlen = ipv4->prefixlen; isis_spf_add_local (spftree, VTYPE_IPREACH_INTERNAL, &prefix, @@ -773,11 +760,9 @@ isis_spf_preload_tent (struct isis_spftree *spftree, if (family == AF_INET6) { prefix.family = AF_INET6; - for (ipnode = (circuit->ipv6_non_link ? listhead - (circuit->ipv6_non_link) : NULL); ipnode; - nextnode (ipnode)) + for (ALL_LIST_ELEMENTS (circuit->ipv6_non_link, + ipnode, ipnnode, ipv6)) { - ipv6 = getdata (ipnode); prefix.prefixlen = ipv6->prefixlen; prefix.u.prefix6 = ipv6->prefix; isis_spf_add_local (spftree, VTYPE_IP6REACH_INTERNAL, @@ -803,10 +788,10 @@ isis_spf_preload_tent (struct isis_spftree *spftree, anode = listhead (adj_list); while (anode) { - adj = getdata (anode); + adj = listgetdata (anode); if (!speaks (&adj->nlpids, family)) { - nextnode (anode); + anode = listnextnode (anode); continue; } switch (adj->sys_type) @@ -840,7 +825,7 @@ isis_spf_preload_tent (struct isis_spftree *spftree, default: zlog_warn ("isis_spf_preload_tent unknow adj type"); } - nextnode (anode); + anode = listnextnode (anode); } list_delete (adj_list); /* @@ -990,7 +975,7 @@ isis_run_spf (struct isis_area *area, int level, int family) while (listcount (spftree->tents) > 0) { node = listhead (spftree->tents); - vertex = getdata (node); + vertex = listgetdata (node); /* Remove from tent list */ list_delete_node (spftree->tents, node); if (isis_find_vertex (spftree->paths, vertex->N.id, vertex->type)) @@ -1262,7 +1247,7 @@ isis_spf_schedule6 (struct isis_area *area, int level) static void isis_print_paths (struct vty *vty, struct list *paths) { - struct listnode *node, *anode; + struct listnode *node; struct isis_vertex *vertex; struct isis_dynhn *dyn, *nh_dyn = NULL; struct isis_adjacency *adj; @@ -1272,9 +1257,9 @@ isis_print_paths (struct vty *vty, struct list *paths) vty_out (vty, "System Id Metric Next-Hop" " Interface SNPA%s", VTY_NEWLINE); - for (node = listhead (paths); node; nextnode (node)) + + for (ALL_LIST_ELEMENTS_RO (paths, node, vertex)) { - vertex = getdata (node); if (vertex->type != VTYPE_NONPSEUDO_IS) continue; if (memcmp (vertex->N.id, isis->sysid, ISIS_SYS_ID_LEN) == 0) @@ -1285,8 +1270,7 @@ isis_print_paths (struct vty *vty, struct list *paths) else { dyn = dynhn_find_by_id ((u_char *) vertex->N.id); - anode = listhead (vertex->Adj_N); - adj = getdata (anode); + adj = listgetdata (listhead (vertex->Adj_N)); if (adj) { nh_dyn = dynhn_find_by_id (adj->sysid); @@ -1326,10 +1310,8 @@ DEFUN (show_isis_topology, if (!isis->area_list || isis->area_list->count == 0) return CMD_SUCCESS; - for (node = listhead (isis->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area)) { - area = getdata (node); - vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", VTY_NEWLINE); @@ -1372,10 +1354,8 @@ DEFUN (show_isis_topology_l1, if (!isis->area_list || isis->area_list->count == 0) return CMD_SUCCESS; - for (node = listhead (isis->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area)) { - area = getdata (node); - vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", VTY_NEWLINE); @@ -1414,10 +1394,8 @@ DEFUN (show_isis_topology_l2, if (!isis->area_list || isis->area_list->count == 0) return CMD_SUCCESS; - for (node = listhead (isis->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (isis->area_list, node, area)) { - area = getdata (node); - vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", VTY_NEWLINE); diff --git a/isisd/isis_tlv.c b/isisd/isis_tlv.c index bc6536323..3dae5d89d 100644 --- a/isisd/isis_tlv.c +++ b/isisd/isis_tlv.c @@ -776,9 +776,8 @@ tlv_add_area_addrs (struct list *area_addrs, struct stream *stream) u_char value[255]; u_char *pos = value; - for (node = listhead (area_addrs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (area_addrs, node, area_addr)) { - area_addr = getdata (node); if (pos - value + area_addr->addr_len > 255) goto err; *pos = area_addr->addr_len; @@ -797,7 +796,7 @@ err: int tlv_add_is_neighs (struct list *is_neighs, struct stream *stream) { - struct listnode *node; + struct listnode *node, *nnode; struct is_neigh *is_neigh; u_char value[255]; u_char *pos = value; @@ -806,9 +805,8 @@ tlv_add_is_neighs (struct list *is_neighs, struct stream *stream) *pos = 0; /*is_neigh->virtual; */ pos++; - for (node = listhead (is_neighs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (is_neighs, node, nnode, is_neigh)) { - is_neigh = getdata (node); if (pos - value + IS_NEIGHBOURS_LEN > 255) { retval = add_tlv (IS_NEIGHBOURS, pos - value, value, stream); @@ -834,15 +832,14 @@ tlv_add_is_neighs (struct list *is_neighs, struct stream *stream) int tlv_add_lan_neighs (struct list *lan_neighs, struct stream *stream) { - struct listnode *node; + struct listnode *node, *nnode; u_char *snpa; u_char value[255]; u_char *pos = value; int retval; - for (node = listhead (lan_neighs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (lan_neighs, node, nnode, snpa)) { - snpa = getdata (node); if (pos - value + ETH_ALEN > 255) { retval = add_tlv (LAN_NEIGHBOURS, pos - value, value, stream); @@ -901,15 +898,14 @@ tlv_add_checksum (struct checksum *checksum, struct stream *stream) int tlv_add_ip_addrs (struct list *ip_addrs, struct stream *stream) { - struct listnode *node; + struct listnode *node, *nnode; struct prefix_ipv4 *ipv4; u_char value[255]; u_char *pos = value; int retval; - for (node = listhead (ip_addrs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (ip_addrs, node, nnode, ipv4)) { - ipv4 = getdata (node); if (pos - value + IPV4_MAX_BYTELEN > 255) { retval = add_tlv (IPV4_ADDR, pos - value, value, stream); @@ -934,15 +930,14 @@ tlv_add_dynamic_hostname (struct hostname *hostname, struct stream *stream) int tlv_add_lsp_entries (struct list *lsps, struct stream *stream) { - struct listnode *node; + struct listnode *node, *nnode; struct isis_lsp *lsp; u_char value[255]; u_char *pos = value; int retval; - for (node = listhead (lsps); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (lsps, node, nnode, lsp)) { - lsp = getdata (node); if (pos - value + LSP_ENTRIES_LEN > 255) { retval = add_tlv (LSP_ENTRIES, pos - value, value, stream); @@ -966,15 +961,14 @@ tlv_add_lsp_entries (struct list *lsps, struct stream *stream) int tlv_add_ipv4_reachs (struct list *ipv4_reachs, struct stream *stream) { - struct listnode *node; + struct listnode *node, *nnode; struct ipv4_reachability *reach; u_char value[255]; u_char *pos = value; int retval; - for (node = listhead (ipv4_reachs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (ipv4_reachs, node, nnode, reach)) { - reach = getdata (node); if (pos - value + IPV4_REACH_LEN > 255) { retval = @@ -1005,15 +999,14 @@ tlv_add_ipv4_reachs (struct list *ipv4_reachs, struct stream *stream) int tlv_add_ipv6_addrs (struct list *ipv6_addrs, struct stream *stream) { - struct listnode *node; + struct listnode *node, *nnode; struct prefix_ipv6 *ipv6; u_char value[255]; u_char *pos = value; int retval; - for (node = listhead (ipv6_addrs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (ipv6_addrs, node, nnode, ipv6)) { - ipv6 = getdata (node); if (pos - value + IPV6_MAX_BYTELEN > 255) { retval = add_tlv (IPV6_ADDR, pos - value, value, stream); @@ -1031,15 +1024,14 @@ tlv_add_ipv6_addrs (struct list *ipv6_addrs, struct stream *stream) int tlv_add_ipv6_reachs (struct list *ipv6_reachs, struct stream *stream) { - struct listnode *node; + struct listnode *node, *nnode; struct ipv6_reachability *ip6reach; u_char value[255]; u_char *pos = value; int retval, prefix_octets; - for (node = listhead (ipv6_reachs); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (ipv6_reachs, node, nnode, ip6reach)) { - ip6reach = getdata (node); if (pos - value + IPV6_MAX_BYTELEN + 6 > 255) { retval = add_tlv (IPV6_REACHABILITY, pos - value, value, stream); diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index 4690fe311..f45b9c138 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -280,9 +280,8 @@ isis_zebra_route_add_ipv4 (struct prefix *prefix, stream_putc (stream, listcount (route_info->nexthops)); /* Nexthop, ifindex, distance and metric information */ - for (node = listhead (route_info->nexthops); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (route_info->nexthops, node, nexthop)) { - nexthop = getdata (node); /* FIXME: can it be ? */ if (nexthop->ip.s_addr != INADDR_ANY) { @@ -379,10 +378,8 @@ isis_zebra_route_add_ipv6 (struct prefix *prefix, /* for each nexthop */ i = 0; - for (node = listhead (route_info->nexthops6); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6)) { - nexthop6 = getdata (node); - if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) { @@ -458,10 +455,8 @@ isis_zebra_route_del_ipv6 (struct prefix *prefix, /* for each nexthop */ i = 0; - for (node = listhead (route_info->nexthops6); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (route_info->nexthops6, node, nexthop6)) { - nexthop6 = getdata (node); - if (!IN6_IS_ADDR_LINKLOCAL (&nexthop6->ip6) && !IN6_IS_ADDR_UNSPECIFIED (&nexthop6->ip6)) { diff --git a/isisd/isisd.c b/isisd/isisd.c index 229f1356a..c2bb90644 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -144,9 +144,9 @@ struct isis_area * isis_area_lookup (const char *area_tag) { struct isis_area *area; - struct listnode *node; + struct listnode *node, *nnode; - LIST_LOOP (isis->area_list, area, node) + for (ALL_LIST_ELEMENTS (isis->area_list, node, nnode, area)) if ((area->area_tag == NULL && area_tag == NULL) || (area->area_tag && area_tag && strcmp (area->area_tag, area_tag) == 0)) @@ -185,7 +185,7 @@ int isis_area_destroy (struct vty *vty, const char *area_tag) { struct isis_area *area; - struct listnode *node; + struct listnode *node, *nnode; struct isis_circuit *circuit; area = isis_area_lookup (area_tag); @@ -198,13 +198,9 @@ isis_area_destroy (struct vty *vty, const char *area_tag) if (area->circuit_list) { - node = listhead (area->circuit_list); - while (node) - { - circuit = getdata (node); - nextnode (node); - isis_circuit_del (circuit); - } + for (ALL_LIST_ELEMENTS (area->circuit_list, node, nnode, circuit)) + isis_circuit_del (circuit); + list_delete (area->circuit_list); } listnode_delete (isis->area_list, area); @@ -225,7 +221,7 @@ area_net_title (struct vty *vty, u_char *net_title) struct isis_area *area; struct area_addr *addr; struct area_addr *addrp; - struct listnode *node; + struct listnode *node, *nnode; u_char buff[255]; area = vty->index; @@ -284,7 +280,7 @@ area_net_title (struct vty *vty, u_char *net_title) } /* now we see that we don't already have this address */ - LIST_LOOP (area->area_addrs, addrp, node) + for (ALL_LIST_ELEMENTS (area->area_addrs, node, nnode, addrp)) { if ((addrp->addr_len + ISIS_SYS_ID_LEN + 1) == (addr->addr_len)) { @@ -318,7 +314,7 @@ area_clear_net_title (struct vty *vty, u_char *net_title) { struct isis_area *area; struct area_addr addr, *addrp = NULL; - struct listnode *node; + struct listnode *node, *nnode; u_char buff[255]; area = vty->index; @@ -338,7 +334,7 @@ area_clear_net_title (struct vty *vty, u_char *net_title) memcpy (addr.area_addr, buff, (int) addr.addr_len); - LIST_LOOP (area->area_addrs, addrp, node) + for (ALL_LIST_ELEMENTS (area->area_addrs, node, nnode, addrp)) if (addrp->addr_len == addr.addr_len && !memcmp (addrp->area_addr, addr.area_addr, addr.addr_len)) break; @@ -362,7 +358,7 @@ area_clear_net_title (struct vty *vty, u_char *net_title) int show_clns_neigh (struct vty *vty, char detail) { - struct listnode *node_area, *node_circ; + struct listnode *anode, *annode, *cnode, *cnnode; struct isis_area *area; struct isis_circuit *circuit; struct list *db; @@ -374,20 +370,16 @@ show_clns_neigh (struct vty *vty, char detail) return CMD_SUCCESS; } - for (node_area = listhead (isis->area_list); node_area; - nextnode (node_area)) + for (ALL_LIST_ELEMENTS (isis->area_list, anode, annode, area)) { - area = getdata (node_area); vty_out (vty, "Area %s:%s", area->area_tag, VTY_NEWLINE); if (detail == ISIS_UI_LEVEL_BRIEF) vty_out (vty, " System Id Interface L State " "Holdtime SNPA%s", VTY_NEWLINE); - for (node_circ = listhead (area->circuit_list); node_circ; - nextnode (node_circ)) + for (ALL_LIST_ELEMENTS (area->circuit_list, cnode, cnnode, circuit)) { - circuit = getdata (node_circ); if (circuit->circ_type == CIRCUIT_T_BROADCAST) { for (i = 0; i < 2; i++) @@ -902,16 +894,15 @@ DEFUN (show_database, "show isis database", SHOW_STR "IS-IS information\n" "IS-IS link state database\n") { - struct listnode *node; + struct listnode *node, *nnode; struct isis_area *area; int level, lsp_count; if (isis->area_list->count == 0) return CMD_SUCCESS; - for (node = listhead (isis->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (isis->area_list, node, nnode, area)) { - area = getdata (node); vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", VTY_NEWLINE); for (level = 0; level < ISIS_LEVELS; level++) @@ -941,16 +932,15 @@ DEFUN (show_database_detail, "IS-IS information\n" "IS-IS link state database\n") { - struct listnode *node; + struct listnode *node, *nnode; struct isis_area *area; int level, lsp_count; if (isis->area_list->count == 0) return CMD_SUCCESS; - for (node = listhead (isis->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (isis->area_list, node, nnode, area)) { - area = getdata (node); vty_out (vty, "Area %s:%s", area->area_tag ? area->area_tag : "null", VTY_NEWLINE); for (level = 0; level < ISIS_LEVELS; level++) @@ -1222,7 +1212,7 @@ DEFUN (no_is_type, * Put the is-type back to default. Which is level-1-2 on first * circuit for the area level-1 for the rest */ - if (getdata (listhead (isis->area_list)) == area) + if (listgetdata (listhead (isis->area_list)) == area) type = IS_LEVEL_1_AND_2; else type = IS_LEVEL_1; @@ -1603,10 +1593,10 @@ DEFUN (show_isis_generated_topology, "CLNS neighbor adjacencies\n") { struct isis_area *area; - struct listnode *node; + struct listnode *node, *nnode; struct listnode *node2; struct arc *arc; - LIST_LOOP (isis->area_list, area, node) + for (ALL_LIST_ELEMENTS (isis->area_list, node, nnode, area)) { if (area->topology) { @@ -1852,10 +1842,10 @@ isis_config_write (struct vty *vty) if (isis != NULL) { struct isis_area *area; - struct listnode *node; - struct listnode *node2; + struct listnode *node, *nnode; + struct listnode *node2, *nnode2; - LIST_LOOP (isis->area_list, area, node) + for (ALL_LIST_ELEMENTS (isis->area_list, node, nnode, area)) { /* ISIS - Area name */ vty_out (vty, "router isis %s%s", area->area_tag, VTY_NEWLINE); @@ -1864,7 +1854,7 @@ isis_config_write (struct vty *vty) if (listcount (area->area_addrs) > 0) { struct area_addr *area_addr; - LIST_LOOP (area->area_addrs, area_addr, node2) + for (ALL_LIST_ELEMENTS (area->area_addrs, node2, nnode2, area_addr)) { vty_out (vty, " net %s%s", isonet_print (area_addr->area_addr, diff --git a/lib/ChangeLog b/lib/ChangeLog index ee20de847..3473257ad 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,25 @@ +2005-04-07 Paul Jakma <paul.jakma@sun.com> + + * 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.. + * linklist.c: fix up for linklist.h changes. + * *.c: fix up for new list loop macro, try audit other loop + usage at same time, to some degree. + 2004-04-05 Hasso Tepper <hasso at quagga.net> * lib/prefix.[hc]: inet6_ntoa utility function copied from @@ -183,9 +183,8 @@ if_lookup_by_index (unsigned int index) struct listnode *node; struct interface *ifp; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO(iflist, node, ifp)) { - ifp = getdata (node); if (ifp->ifindex == index) return ifp; } @@ -216,9 +215,8 @@ if_lookup_by_name (const char *name) struct listnode *node; struct interface *ifp; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); if (strcmp(name, ifp->name) == 0) return ifp; } @@ -229,15 +227,13 @@ struct interface * if_lookup_by_name_len(const char *name, size_t namelen) { struct listnode *node; + struct interface *ifp; if (namelen > INTERFACE_NAMSIZ) return NULL; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - struct interface *ifp; - - ifp = getdata (node); if (!memcmp(name, ifp->name, namelen) && (ifp->name[namelen] == '\0')) return ifp; } @@ -254,14 +250,10 @@ if_lookup_exact_address (struct in_addr src) struct prefix *p; struct connected *c; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); - - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c)) { - c = getdata (cnode); - p = c->address; if (p && p->family == AF_INET) @@ -293,14 +285,10 @@ if_lookup_address (struct in_addr src) match = NULL; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); - - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c)) { - c = getdata (cnode); - if (c->address && (c->address->family == AF_INET)) { if (CONNECTED_POINTOPOINT_HOST(c)) @@ -450,6 +438,7 @@ void if_dump (struct interface *ifp) { struct listnode *node; + struct connected *c; zlog_info ("Interface %s index %d metric %d mtu %d " #ifdef HAVE_IPV6 @@ -462,7 +451,7 @@ if_dump (struct interface *ifp) #endif /* HAVE_IPV6 */ if_flag_dump (ifp->flags)); - for (node = listhead (ifp->connected); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, c)) ; } @@ -471,9 +460,10 @@ void if_dump_all () { struct listnode *node; + void *p; - for (node = listhead (iflist); node; nextnode (node)) - if_dump (getdata (node)); + for (ALL_LIST_ELEMENTS_RO (iflist, node, p)) + if_dump (p); } DEFUN (interface_desc, @@ -581,13 +571,10 @@ DEFUN (show_address, struct connected *ifc; struct prefix *p; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); - - for (node2 = listhead (ifp->connected); node2; nextnode (node2)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc)) { - ifc = getdata (node2); p = ifc->address; if (p->family == AF_INET) @@ -677,7 +664,7 @@ connected_delete_by_prefix (struct interface *ifp, struct prefix *p) /* In case of same prefix come, replace it with new one. */ for (node = listhead (ifp->connected); node; node = next) { - ifc = getdata (node); + ifc = listgetdata (node); next = node->next; if (connected_same_prefix (ifc->address, p)) @@ -706,10 +693,8 @@ connected_lookup_address (struct interface *ifp, struct in_addr dst) match = NULL; - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c)) { - c = getdata (cnode); - if (c->address && (c->address->family == AF_INET)) { if (CONNECTED_POINTOPOINT_HOST(c)) @@ -838,7 +823,6 @@ ifaddr_ipv4_lookup (struct in_addr *addr, unsigned int ifindex) struct prefix_ipv4 p; struct route_node *rn; struct interface *ifp; - struct listnode *node; if (addr) { diff --git a/lib/keychain.c b/lib/keychain.c index a3219ef41..2b5b06840 100644 --- a/lib/keychain.c +++ b/lib/keychain.c @@ -61,13 +61,13 @@ key_free (struct key *key) struct keychain * keychain_lookup (const char *name) { - struct listnode *nn; + struct listnode *node; struct keychain *keychain; if (name == NULL) return NULL; - LIST_LOOP (keychain_list, keychain, nn) + for (ALL_LIST_ELEMENTS_RO (keychain_list, node, keychain)) { if (strcmp (keychain->name, name) == 0) return keychain; @@ -127,10 +127,10 @@ keychain_delete (struct keychain *keychain) struct key * key_lookup (const struct keychain *keychain, u_int32_t index) { - struct listnode *nn; + struct listnode *node; struct key *key; - LIST_LOOP (keychain->key, key, nn) + for (ALL_LIST_ELEMENTS_RO (keychain->key, node, key)) { if (key->index == index) return key; @@ -141,13 +141,13 @@ key_lookup (const struct keychain *keychain, u_int32_t index) struct key * key_lookup_for_accept (const struct keychain *keychain, u_int32_t index) { - struct listnode *nn; + struct listnode *node; struct key *key; time_t now; now = time (NULL); - LIST_LOOP (keychain->key, key, nn) + for (ALL_LIST_ELEMENTS_RO (keychain->key, node, key)) { if (key->index >= index) { @@ -165,13 +165,13 @@ key_lookup_for_accept (const struct keychain *keychain, u_int32_t index) struct key * key_match_for_accept (const struct keychain *keychain, const char *auth_str) { - struct listnode *nn; + struct listnode *node; struct key *key; time_t now; now = time (NULL); - LIST_LOOP (keychain->key, key, nn) + for (ALL_LIST_ELEMENTS_RO (keychain->key, node, key)) { if (key->accept.start == 0 || (key->accept.start <= now && @@ -185,13 +185,13 @@ key_match_for_accept (const struct keychain *keychain, const char *auth_str) struct key * key_lookup_for_send (const struct keychain *keychain) { - struct listnode *nn; + struct listnode *node; struct key *key; time_t now; now = time (NULL); - LIST_LOOP (keychain->key, key, nn) + for (ALL_LIST_ELEMENTS_RO (keychain->key, node, key)) { if (key->send.start == 0) return key; @@ -881,15 +881,15 @@ keychain_config_write (struct vty *vty) { struct keychain *keychain; struct key *key; - struct listnode *nn; - struct listnode *nm; + struct listnode *node; + struct listnode *knode; char buf[BUFSIZ]; - LIST_LOOP (keychain_list, keychain, nn) + for (ALL_LIST_ELEMENTS_RO (keychain_list, node, keychain)) { vty_out (vty, "key chain %s%s", keychain->name, VTY_NEWLINE); - LIST_LOOP (keychain->key, key, nm) + for (ALL_LIST_ELEMENTS_RO (keychain->key, knode, key)) { vty_out (vty, " key %d%s", key->index, VTY_NEWLINE); diff --git a/lib/linklist.c b/lib/linklist.c index 3970c24ff..4c4715332 100644 --- a/lib/linklist.c +++ b/lib/linklist.c @@ -247,8 +247,8 @@ listnode_lookup (struct list *list, void *data) struct listnode *node; assert(list); - for (node = list->head; node; nextnode (node)) - if (data == getdata (node)) + for (node = listhead(list); node; node = listnextnode (node)) + if (data == listgetdata (node)) return node; return NULL; } @@ -317,6 +317,6 @@ list_add_list (struct list *l, struct list *m) { struct listnode *n; - for (n = listhead (m); n; nextnode (n)) + for (n = listhead (m); n; n = listnextnode (n)) listnode_add (l, n->data); } diff --git a/lib/linklist.h b/lib/linklist.h index b766420fa..80b21f64a 100644 --- a/lib/linklist.h +++ b/lib/linklist.h @@ -22,10 +22,15 @@ #ifndef _ZEBRA_LINKLIST_H #define _ZEBRA_LINKLIST_H +/* listnodes must always contain data to be valid. Adding an empty node + * to a list is invalid + */ struct listnode { struct listnode *next; struct listnode *prev; + + /* private member, use getdata() to retrieve, do not access directly */ void *data; }; @@ -33,25 +38,31 @@ struct list { struct listnode *head; struct listnode *tail; + /* invariant: count is the number of listnodes in the list */ unsigned int count; + /* * Returns -1 if val1 < val2, 0 if equal?, 1 if val1 > val2. * Used as definition of sorted for listnode_add_sort */ int (*cmp) (void *val1, void *val2); + + /* callback to free user-owned data when listnode is deleted. supplying + * this callback is very much encouraged! + */ void (*del) (void *val); }; -#define nextnode(X) ((X) = (X)->next) +#define listnextnode(X) ((X)->next) #define listhead(X) ((X)->head) #define listtail(X) ((X)->tail) #define listcount(X) ((X)->count) #define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL) -#define getdata(X) ((X)->data) +#define listgetdata(X) (assert((X)->data != NULL), (X)->data) /* Prototypes. */ -struct list *list_new(); +struct list *list_new(); /* encouraged: set list.del callback on new lists */ void list_free (struct list *); void listnode_add (struct list *, void *); @@ -72,13 +83,33 @@ void list_add_node_prev (struct list *, struct listnode *, void *); void list_add_node_next (struct list *, struct listnode *, void *); void list_add_list (struct list *, struct list *); -/* List iteration macro. */ -#define LIST_LOOP(L,V,N) \ - for ((N) = (L)->head; (N); (N) = (N)->next) \ - if (((V) = (N)->data) != NULL) +/* List iteration macro. + * Usage: for (ALL_LIST_ELEMENTS (...) { ... } + * It is safe to delete the listnode using this macro. + */ +#define ALL_LIST_ELEMENTS(list,node,nextnode,data) \ + (node) = listhead(list); \ + (node) != NULL && \ + ((data) = listgetdata(node),(nextnode) = listnextnode(node), 1); \ + (node) = (nextnode) + +/* read-only list iteration macro. + * Usage: as per ALL_LIST_ELEMENTS, but not safe to delete the listnode Only + * use this macro when it is *immediately obvious* the listnode is not + * deleted in the body of the loop. Does not have forward-reference overhead + * of previous macro. + */ +#define ALL_LIST_ELEMENTS_RO(list,node,data) \ + (node) = listhead(list); \ + (node) != NULL && ((data) = listgetdata(node), 1); \ + (node) = listnextnode(node) -/* List node add macro. */ -#define LISTNODE_ADD(L,N) \ +/* these *do not* cleanup list nodes and referenced data, as the functions + * do - these macros simply {de,at}tach a listnode from/to a list. + */ + +/* List node attach macro. */ +#define LISTNODE_ATTACH(L,N) \ do { \ (N)->prev = (L)->tail; \ if ((L)->head == NULL) \ @@ -89,8 +120,8 @@ void list_add_list (struct list *, struct list *); (L)->count++; \ } while (0) -/* List node delete macro. */ -#define LISTNODE_DELETE(L,N) \ +/* List node detach macro. */ +#define LISTNODE_DETACH(L,N) \ do { \ if ((N)->prev) \ (N)->prev->next = (N)->next; \ @@ -103,4 +134,15 @@ void list_add_list (struct list *, struct list *); (L)->count--; \ } while (0) +/* Deprecated: 20050406 */ +#if !defined(QUAGGA_NO_DEPRECATED_INTERFACES) +#warning "Using deprecated libzebra interfaces" +#define LISTNODE_ADD(L,N) LISTNODE_ATTACH(L,N) +#define LISTNODE_DELETE(L,N) LISTNODE_DETACH(L,N) +#define nextnode(X) ((X) = (X)->next) +#define getdata(X) listgetdata(X) +#define LIST_LOOP(L,V,N) \ + for (ALL_LIST_ELEMENTS_RO (L,N,V)) +#endif /* QUAGGA_NO_DEPRECATED_INTERFACES */ + #endif /* _ZEBRA_LINKLIST_H */ diff --git a/lib/smux.c b/lib/smux.c index 0c2dba3ae..28f402d88 100644 --- a/lib/smux.c +++ b/lib/smux.c @@ -441,12 +441,11 @@ smux_set (oid *reqid, size_t *reqid_len, int result; u_char *statP = NULL; WriteMethod *write_method = NULL; - struct listnode *node; + struct listnode *node, *nnode; /* Check */ - for (node = treelist->head; node; node = node->next) + for (ALL_LIST_ELEMENTS (treelist, node, nnode, subtree)) { - subtree = node->data; subresult = oid_compare_part (reqid, *reqid_len, subtree->name, subtree->name_len); @@ -509,12 +508,11 @@ smux_get (oid *reqid, size_t *reqid_len, int exact, size_t suffix_len; int result; WriteMethod *write_method=NULL; - struct listnode *node; + struct listnode *node, *nnode; /* Check */ - for (node = treelist->head; node; node = node->next) + for (ALL_LIST_ELEMENTS (treelist, node, nnode,subtree)) { - subtree = node->data; subresult = oid_compare_part (reqid, *reqid_len, subtree->name, subtree->name_len); @@ -578,7 +576,7 @@ smux_getnext (oid *reqid, size_t *reqid_len, int exact, size_t suffix_len; int result; WriteMethod *write_method=NULL; - struct listnode *node; + struct listnode *node, *nnode; /* Save incoming request. */ @@ -586,9 +584,8 @@ smux_getnext (oid *reqid, size_t *reqid_len, int exact, savelen = *reqid_len; /* Check */ - for (node = treelist->head; node; node = node->next) + for (ALL_LIST_ELEMENTS (treelist, node, nnode, subtree)) { - subtree = node->data; subresult = oid_compare_part (reqid, *reqid_len, subtree->name, subtree->name_len); @@ -1108,17 +1105,15 @@ smux_register (int sock) long priority; long operation; struct subtree *subtree; - struct listnode *node; + struct listnode *node, *nnode; ret = 0; - for (node = treelist->head; node; node = node->next) + for (ALL_LIST_ELEMENTS (treelist, node, nnode, subtree)) { ptr = buf; len = BUFSIZ; - subtree = node->data; - /* SMUX RReq Header. */ ptr = asn_build_header (ptr, &len, (u_char) SMUX_RREQ, 0); diff --git a/ospf6d/ChangeLog b/ospf6d/ChangeLog index dc48ab7ba..bc04cc943 100644 --- a/ospf6d/ChangeLog +++ b/ospf6d/ChangeLog @@ -1,3 +1,13 @@ +2005-04-07 Paul Jakma <paul@dishone.st> + + * (global) Fix up list loops to match changes in lib/linklist, + and some basic auditing of usage. + * 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. + 2005-04-02 Andrew J. Schorr <ajschorr@alumni.princeton.edu> * ospf6_interface.[ch]: (ospf6_interface_lookup_by_name) Remove unused diff --git a/ospf6d/ospf6_abr.c b/ospf6d/ospf6_abr.c index 8bacfcd37..7eb8f09c1 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -56,12 +56,9 @@ ospf6_is_router_abr (struct ospf6 *o) struct ospf6_area *oa; int area_count = 0; - for (node = listhead (o->area_list); node; nextnode (node)) - { - oa = OSPF6_AREA (getdata (node)); - if (IS_AREA_ENABLED (oa)) - area_count++; - } + for (ALL_LIST_ELEMENTS_RO (o->area_list, node, oa)) + if (IS_AREA_ENABLED (oa)) + area_count++; if (area_count > 1) return 1; @@ -73,12 +70,10 @@ ospf6_abr_enable_area (struct ospf6_area *area) { struct ospf6_area *oa; struct ospf6_route *ro; - struct listnode *node; + struct listnode *node, *nnode; - for (node = listhead (area->ospf6->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (area->ospf6->area_list, node, nnode, oa)) { - oa = OSPF6_AREA (getdata (node)); - /* update B bit for each area */ OSPF6_ROUTER_LSA_SCHEDULE (oa); @@ -111,7 +106,7 @@ ospf6_abr_disable_area (struct ospf6_area *area) struct ospf6_area *oa; struct ospf6_route *ro; struct ospf6_lsa *old; - struct listnode *node; + struct listnode *node, *nnode; /* Withdraw all summary prefixes previously originated */ for (ro = ospf6_route_head (area->summary_prefix); ro; @@ -136,13 +131,9 @@ ospf6_abr_disable_area (struct ospf6_area *area) } /* Schedule Router-LSA for each area (ABR status may change) */ - for (node = listhead (area->ospf6->area_list); node; nextnode (node)) - { - oa = OSPF6_AREA (getdata (node)); - - /* update B bit for each area */ - OSPF6_ROUTER_LSA_SCHEDULE (oa); - } + for (ALL_LIST_ELEMENTS (area->ospf6->area_list, node, nnode, oa)) + /* update B bit for each area */ + OSPF6_ROUTER_LSA_SCHEDULE (oa); } /* RFC 2328 12.4.3. Summary-LSAs */ @@ -470,7 +461,7 @@ ospf6_abr_range_update (struct ospf6_route *range) void ospf6_abr_originate_summary (struct ospf6_route *route) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf6_area *oa; struct ospf6_route *range = NULL; @@ -482,11 +473,8 @@ ospf6_abr_originate_summary (struct ospf6_route *route) ospf6_abr_range_update (range); } - for (node = listhead (ospf6->area_list); node; nextnode (node)) - { - oa = (struct ospf6_area *) getdata (node); - ospf6_abr_originate_summary_to_area (route, oa); - } + for (ALL_LIST_ELEMENTS (ospf6->area_list, node, nnode, oa)) + ospf6_abr_originate_summary_to_area (route, oa); } /* RFC 2328 16.2. Calculating the inter-area routes */ @@ -656,22 +644,17 @@ ospf6_abr_examin_brouter (u_int32_t router_id) { struct ospf6_lsa *lsa; struct ospf6_area *oa; - struct listnode *node; + struct listnode *node, *nnode; u_int16_t type; - type = htons (OSPF6_LSTYPE_INTER_ROUTER); - for (node = listhead (ospf6->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (ospf6->area_list, node, nnode, oa)) { - oa = OSPF6_AREA (getdata (node)); + type = htons (OSPF6_LSTYPE_INTER_ROUTER); for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa; lsa = ospf6_lsdb_type_router_next (type, router_id, lsa)) ospf6_abr_examin_summary (lsa, oa); - } - type = htons (OSPF6_LSTYPE_INTER_PREFIX); - for (node = listhead (ospf6->area_list); node; nextnode (node)) - { - oa = OSPF6_AREA (getdata (node)); + type = htons (OSPF6_LSTYPE_INTER_PREFIX); for (lsa = ospf6_lsdb_type_router_head (type, router_id, oa->lsdb); lsa; lsa = ospf6_lsdb_type_router_next (type, router_id, lsa)) ospf6_abr_examin_summary (lsa, oa); diff --git a/ospf6d/ospf6_area.c b/ospf6d/ospf6_area.c index 2a738cb6d..57070e162 100644 --- a/ospf6d/ospf6_area.c +++ b/ospf6d/ospf6_area.c @@ -175,7 +175,7 @@ ospf6_area_create (u_int32_t area_id, struct ospf6 *o) void ospf6_area_delete (struct ospf6_area *oa) { - struct listnode *n; + struct listnode *n, *nnode; struct ospf6_interface *oi; ospf6_route_table_delete (oa->range_table); @@ -183,9 +183,8 @@ ospf6_area_delete (struct ospf6_area *oa) ospf6_route_table_delete (oa->summary_router); /* ospf6 interface list */ - for (n = listhead (oa->if_list); n; nextnode (n)) + for (ALL_LIST_ELEMENTS (oa->if_list, n, nnode, oi)) { - oi = (struct ospf6_interface *) getdata (n); ospf6_interface_delete (oi); } list_delete (oa->if_list); @@ -217,12 +216,9 @@ ospf6_area_lookup (u_int32_t area_id, struct ospf6 *ospf6) struct ospf6_area *oa; struct listnode *n; - for (n = listhead (ospf6->area_list); n; nextnode (n)) - { - oa = (struct ospf6_area *) getdata (n); - if (oa->area_id == area_id) - return oa; - } + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, n, oa)) + if (oa->area_id == area_id) + return oa; return (struct ospf6_area *) NULL; } @@ -240,31 +236,25 @@ ospf6_area_get (u_int32_t area_id, struct ospf6 *o) void ospf6_area_enable (struct ospf6_area *oa) { - struct listnode *i; + struct listnode *node, *nnode; struct ospf6_interface *oi; SET_FLAG (oa->flag, OSPF6_AREA_ENABLE); - for (i = listhead (oa->if_list); i; nextnode (i)) - { - oi = (struct ospf6_interface *) getdata (i); - ospf6_interface_enable (oi); - } + for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi)) + ospf6_interface_enable (oi); } void ospf6_area_disable (struct ospf6_area *oa) { - struct listnode *i; + struct listnode *node, *nnode; struct ospf6_interface *oi; UNSET_FLAG (oa->flag, OSPF6_AREA_ENABLE); - for (i = listhead (oa->if_list); i; nextnode (i)) - { - oi = (struct ospf6_interface *) getdata (i); - ospf6_interface_disable (oi); - } + for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi)) + ospf6_interface_disable (oi); } @@ -279,11 +269,9 @@ ospf6_area_show (struct vty *vty, struct ospf6_area *oa) oa->lsdb->count, VNL); vty_out (vty, " Interface attached to this area:"); - for (i = listhead (oa->if_list); i; nextnode (i)) - { - oi = (struct ospf6_interface *) getdata (i); - vty_out (vty, " %s", oi->interface->name); - } + for (ALL_LIST_ELEMENTS_RO (oa->if_list, i, oi)) + vty_out (vty, " %s", oi->interface->name); + vty_out (vty, "%s", VNL); } @@ -415,10 +403,8 @@ ospf6_area_config_write (struct vty *vty) struct ospf6_route *range; char buf[128]; - for (node = listhead (ospf6->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { - oa = OSPF6_AREA (getdata (node)); - for (range = ospf6_route_head (oa->range_table); range; range = ospf6_route_next (range)) { @@ -444,9 +430,9 @@ DEFUN (show_ipv6_ospf6_spf_tree, struct prefix prefix; ospf6_linkstate_prefix (ospf6->router_id, htonl (0), &prefix); - for (node = listhead (ospf6->area_list); node; nextnode (node)) + + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { - oa = (struct ospf6_area *) getdata (node); route = ospf6_route_lookup (&prefix, oa->spf_table); if (route == NULL) { diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index c9fc5c1c4..564efb225 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -444,7 +444,7 @@ ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix, struct prefix prefix_id; struct route_node *node; char pbuf[64], ibuf[16]; - struct listnode *lnode; + struct listnode *lnode, *lnnode; struct ospf6_area *oa; if (! ospf6_zebra_is_redistribute (type)) @@ -574,11 +574,8 @@ ospf6_asbr_redistribute_add (int type, int ifindex, struct prefix *prefix, ospf6_as_external_lsa_originate (route); /* Router-Bit (ASBR Flag) may have to be updated */ - for (lnode = listhead (ospf6->area_list); lnode; nextnode (lnode)) - { - oa = (struct ospf6_area *) getdata (lnode); - OSPF6_ROUTER_LSA_SCHEDULE (oa); - } + for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa)) + OSPF6_ROUTER_LSA_SCHEDULE (oa); } void @@ -590,7 +587,7 @@ ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix) struct ospf6_lsa *lsa; struct prefix prefix_id; char pbuf[64], ibuf[16]; - struct listnode *lnode; + struct listnode *lnode, *lnnode; struct ospf6_area *oa; match = ospf6_route_lookup (prefix, ospf6->external_table); @@ -642,11 +639,8 @@ ospf6_asbr_redistribute_remove (int type, int ifindex, struct prefix *prefix) XFREE (MTYPE_OSPF6_EXTERNAL_INFO, info); /* Router-Bit (ASBR Flag) may have to be updated */ - for (lnode = listhead (ospf6->area_list); lnode; nextnode (lnode)) - { - oa = (struct ospf6_area *) getdata (lnode); - OSPF6_ROUTER_LSA_SCHEDULE (oa); - } + for (ALL_LIST_ELEMENTS (ospf6->area_list, lnode, lnnode, oa)) + OSPF6_ROUTER_LSA_SCHEDULE (oa); } DEFUN (ospf6_redistribute, diff --git a/ospf6d/ospf6_flood.c b/ospf6d/ospf6_flood.c index 9971ef1c9..39b7c1f36 100644 --- a/ospf6d/ospf6_flood.c +++ b/ospf6d/ospf6_flood.c @@ -245,7 +245,7 @@ void 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 @@ ospf6_flood_interface (struct ospf6_neighbor *from, } /* (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 @@ ospf6_flood_interface (struct ospf6_neighbor *from, 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 @@ void 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 @@ void 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 @@ ospf6_flood (struct ospf6_neighbor *from, struct ospf6_lsa *lsa) 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 @@ ospf6_flood_clear_interface (struct ospf6_lsa *lsa, struct ospf6_interface *oi) 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 @@ ospf6_flood_clear_area (struct ospf6_lsa *lsa, struct ospf6_area *oa) 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 @@ ospf6_is_maxage_lsa_drop (struct ospf6_lsa *lsa, struct ospf6_neighbor *from) 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; diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index d4180d92e..0614e4409 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -151,14 +151,12 @@ ospf6_interface_create (struct interface *ifp) void ospf6_interface_delete (struct ospf6_interface *oi) { - struct listnode *n; + struct listnode *node, *nnode; struct ospf6_neighbor *on; - for (n = listhead (oi->neighbor_list); n; nextnode (n)) - { - on = (struct ospf6_neighbor *) getdata (n); + for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) ospf6_neighbor_delete (on); - } + list_delete (oi->neighbor_list); THREAD_OFF (oi->thread_send_hello); @@ -199,16 +197,14 @@ ospf6_interface_enable (struct ospf6_interface *oi) void ospf6_interface_disable (struct ospf6_interface *oi) { - struct listnode *i; + struct listnode *node, *nnode; struct ospf6_neighbor *on; SET_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE); - for (i = listhead (oi->neighbor_list); i; nextnode (i)) - { - on = (struct ospf6_neighbor *) getdata (i); + for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) ospf6_neighbor_delete (on); - } + list_delete_all_node (oi->neighbor_list); ospf6_lsdb_remove_all (oi->lsdb); @@ -228,10 +224,8 @@ ospf6_interface_get_linklocal_address (struct interface *ifp) struct in6_addr *l = (struct in6_addr *) NULL; /* for each connected address */ - for (n = listhead (ifp->connected); n; nextnode (n)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, n, c)) { - c = (struct connected *) getdata (n); - /* if family not AF_INET6, ignore */ if (c->address->family != AF_INET6) continue; @@ -318,7 +312,7 @@ ospf6_interface_connected_route_update (struct interface *ifp) struct ospf6_interface *oi; struct ospf6_route *route; struct connected *c; - struct listnode *i; + struct listnode *node, *nnode; oi = (struct ospf6_interface *) ifp->info; if (oi == NULL) @@ -333,10 +327,9 @@ ospf6_interface_connected_route_update (struct interface *ifp) /* update "route to advertise" interface route table */ ospf6_route_remove_all (oi->route_connected); - for (i = listhead (oi->interface->connected); i; nextnode (i)) - { - c = (struct connected *) getdata (i); + for (ALL_LIST_ELEMENTS (oi->interface->connected, node, nnode, c)) + { if (c->address->family != AF_INET6) continue; @@ -498,7 +491,7 @@ better_drouter (struct ospf6_neighbor *a, struct ospf6_neighbor *b) static u_char dr_election (struct ospf6_interface *oi) { - struct listnode *i; + struct listnode *node, *nnode; struct ospf6_neighbor *on, *drouter, *bdrouter, myself; struct ospf6_neighbor *best_drouter, *best_bdrouter; u_char next_state = 0; @@ -517,20 +510,16 @@ dr_election (struct ospf6_interface *oi) myself.router_id = oi->area->ospf6->router_id; /* Electing BDR (2) */ - for (i = listhead (oi->neighbor_list); i; nextnode (i)) - { - on = (struct ospf6_neighbor *) getdata (i); - bdrouter = better_bdrouter (bdrouter, on); - } + for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) + bdrouter = better_bdrouter (bdrouter, on); + best_bdrouter = bdrouter; bdrouter = better_bdrouter (best_bdrouter, &myself); /* Electing DR (3) */ - for (i = listhead (oi->neighbor_list); i; nextnode (i)) - { - on = (struct ospf6_neighbor *) getdata (i); - drouter = better_drouter (drouter, on); - } + for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) + drouter = better_drouter (drouter, on); + best_drouter = drouter; drouter = better_drouter (best_drouter, &myself); if (drouter == NULL) @@ -576,9 +565,8 @@ dr_election (struct ospf6_interface *oi) (drouter ? drouter->name : "0.0.0.0"), (bdrouter ? bdrouter->name : "0.0.0.0")); - for (i = listhead (oi->neighbor_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, node, on)) { - on = (struct ospf6_neighbor *) getdata (i); if (on->state < OSPF6_NEIGHBOR_TWOWAY) continue; /* Schedule AdjOK. */ @@ -724,7 +712,7 @@ int interface_down (struct thread *thread) { struct ospf6_interface *oi; - struct listnode *n; + struct listnode *node, *nnode; struct ospf6_neighbor *on; oi = (struct ospf6_interface *) THREAD_ARG (thread); @@ -740,11 +728,9 @@ interface_down (struct thread *thread) ospf6_interface_state_change (OSPF6_INTERFACE_DOWN, oi); - for (n = listhead (oi->neighbor_list); n; nextnode (n)) - { - on = (struct ospf6_neighbor *) getdata (n); - ospf6_neighbor_delete (on); - } + for (ALL_LIST_ELEMENTS (oi->neighbor_list, node, nnode, on)) + ospf6_neighbor_delete (on); + list_delete_all_node (oi->neighbor_list); return 0; @@ -790,9 +776,9 @@ ospf6_interface_show (struct vty *vty, struct interface *ifp) oi = (struct ospf6_interface *) ifp->info; vty_out (vty, " Internet Address:%s", VNL); - for (i = listhead (ifp->connected); i; nextnode (i)) + + for (ALL_LIST_ELEMENTS_RO (ifp->connected, i, c)) { - c = (struct connected *)getdata (i); p = c->address; prefix2str (p, strbuf, sizeof (strbuf)); switch (p->family) @@ -896,11 +882,8 @@ DEFUN (show_ipv6_ospf6_interface, } else { - for (i = listhead (iflist); i; nextnode (i)) - { - ifp = (struct interface *) getdata (i); - ospf6_interface_show (vty, ifp); - } + for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp)) + ospf6_interface_show (vty, ifp); } return CMD_SUCCESS; @@ -992,9 +975,8 @@ DEFUN (show_ipv6_ospf6_interface_prefix, struct ospf6_interface *oi; struct interface *ifp; - for (i = listhead (iflist); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp)) { - ifp = (struct interface *) getdata (i); oi = (struct ospf6_interface *) ifp->info; if (oi == NULL) continue; @@ -1045,7 +1027,7 @@ DEFUN (ipv6_ospf6_ifmtu, struct ospf6_interface *oi; struct interface *ifp; unsigned int ifmtu, iobuflen; - struct listnode *node; + struct listnode *node, *nnode; struct ospf6_neighbor *on; ifp = (struct interface *) vty->index; @@ -1084,9 +1066,8 @@ DEFUN (ipv6_ospf6_ifmtu, oi->ifmtu = ifmtu; /* re-establish adjacencies */ - 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->inactivity_timer); thread_execute (master, inactivity_timer, on, 0); } @@ -1106,7 +1087,7 @@ DEFUN (no_ipv6_ospf6_ifmtu, struct ospf6_interface *oi; struct interface *ifp; unsigned int iobuflen; - struct listnode *node; + struct listnode *node, *nnode; struct ospf6_neighbor *on; ifp = (struct interface *) vty->index; @@ -1133,9 +1114,8 @@ DEFUN (no_ipv6_ospf6_ifmtu, oi->ifmtu = ifp->mtu; /* re-establish adjacencies */ - 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->inactivity_timer); thread_execute (master, inactivity_timer, on, 0); } @@ -1355,7 +1335,7 @@ DEFUN (ipv6_ospf6_passive, { struct ospf6_interface *oi; struct interface *ifp; - struct listnode *node; + struct listnode *node, *nnode; struct ospf6_neighbor *on; ifp = (struct interface *) vty->index; @@ -1369,9 +1349,8 @@ DEFUN (ipv6_ospf6_passive, SET_FLAG (oi->flag, OSPF6_INTERFACE_PASSIVE); THREAD_OFF (oi->thread_send_hello); - 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->inactivity_timer); thread_execute (master, inactivity_timer, on, 0); } @@ -1490,9 +1469,8 @@ config_write_ospf6_interface (struct vty *vty) struct ospf6_interface *oi; struct interface *ifp; - for (i = listhead (iflist); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (iflist, i, ifp)) { - ifp = (struct interface *) getdata (i); oi = (struct ospf6_interface *) ifp->info; if (oi == NULL) continue; diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index e78441149..21693dbce 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -109,7 +109,8 @@ ospf6_router_lsa_originate (struct thread *thread) struct ospf6_lsa *lsa; u_int32_t link_state_id = 0; - struct listnode *i, *j; + struct listnode *node, *nnode; + struct listnode *j; struct ospf6_interface *oi; struct ospf6_neighbor *on, *drouter = NULL; struct ospf6_router_lsa *router_lsa; @@ -151,10 +152,8 @@ ospf6_router_lsa_originate (struct thread *thread) lsdesc = (struct ospf6_router_lsdesc *) ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa)); - for (i = listhead (oa->if_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi)) { - oi = (struct ospf6_interface *) getdata (i); - /* Interfaces in state Down or Loopback are not described */ if (oi->state == OSPF6_INTERFACE_DOWN || oi->state == OSPF6_INTERFACE_LOOPBACK) @@ -162,12 +161,10 @@ ospf6_router_lsa_originate (struct thread *thread) /* Nor are interfaces without any full adjacencies described */ count = 0; - for (j = listhead (oi->neighbor_list); j; nextnode (j)) - { - on = (struct ospf6_neighbor *) getdata (j); - if (on->state == OSPF6_NEIGHBOR_FULL) - count++; - } + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) + if (on->state == OSPF6_NEIGHBOR_FULL) + count++; + if (count == 0) continue; @@ -215,9 +212,8 @@ ospf6_router_lsa_originate (struct thread *thread) /* Point-to-Point interfaces */ if (if_is_pointopoint (oi->interface)) { - for (j = listhead (oi->neighbor_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) { - on = (struct ospf6_neighbor *) getdata (j); if (on->state != OSPF6_NEIGHBOR_FULL) continue; @@ -383,12 +379,11 @@ ospf6_network_lsa_originate (struct thread *thread) /* If none of neighbor is adjacent to us */ count = 0; - for (i = listhead (oi->neighbor_list); i; nextnode (i)) - { - on = (struct ospf6_neighbor *) getdata (i); - if (on->state == OSPF6_NEIGHBOR_FULL) - count++; - } + + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on)) + if (on->state == OSPF6_NEIGHBOR_FULL) + count++; + if (count == 0) { if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK)) @@ -425,10 +420,8 @@ ospf6_network_lsa_originate (struct thread *thread) lsdesc++; /* Walk through the neighbors */ - for (i = listhead (oi->neighbor_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on)) { - on = (struct ospf6_neighbor *) getdata (i); - if (on->state != OSPF6_NEIGHBOR_FULL) continue; @@ -725,10 +718,8 @@ ospf6_intra_prefix_lsa_originate_stub (struct thread *thread) route_advertise = ospf6_route_table_create (); - for (i = listhead (oa->if_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, i, oi)) { - oi = (struct ospf6_interface *) getdata (i); - if (oi->state == OSPF6_INTERFACE_DOWN) { if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) @@ -737,12 +728,11 @@ ospf6_intra_prefix_lsa_originate_stub (struct thread *thread) } full_count = 0; - for (j = listhead (oi->neighbor_list); j; nextnode (j)) - { - on = (struct ospf6_neighbor *) getdata (j); - if (on->state == OSPF6_NEIGHBOR_FULL) - full_count++; - } + + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) + if (on->state == OSPF6_NEIGHBOR_FULL) + full_count++; + if (oi->state != OSPF6_INTERFACE_LOOPBACK && oi->state != OSPF6_INTERFACE_POINTTOPOINT && full_count != 0) @@ -891,12 +881,10 @@ ospf6_intra_prefix_lsa_originate_transit (struct thread *thread) } full_count = 0; - for (i = listhead (oi->neighbor_list); i; nextnode (i)) - { - on = (struct ospf6_neighbor *) getdata (i); - if (on->state == OSPF6_NEIGHBOR_FULL) - full_count++; - } + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on)) + if (on->state == OSPF6_NEIGHBOR_FULL) + full_count++; + if (full_count == 0) { if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index 1486b6939..a4e5d6740 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -1388,7 +1388,7 @@ ospf6_hello_send (struct thread *thread) struct ospf6_header *oh; struct ospf6_hello *hello; u_char *p; - struct listnode *node; + struct listnode *node, *nnode; struct ospf6_neighbor *on; oi = (struct ospf6_interface *) THREAD_ARG (thread); @@ -1422,10 +1422,8 @@ ospf6_hello_send (struct thread *thread) p = (char *)((caddr_t) hello + sizeof (struct ospf6_hello)); - 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 (on->state < OSPF6_NEIGHBOR_INIT) continue; diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index 5e71c7b49..dd46ebc7d 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -61,12 +61,10 @@ ospf6_neighbor_lookup (u_int32_t router_id, struct listnode *n; struct ospf6_neighbor *on; - for (n = listhead (oi->neighbor_list); n; nextnode (n)) - { - on = (struct ospf6_neighbor *) getdata (n); - if (on->router_id == router_id) - return on; - } + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, n, on)) + if (on->router_id == router_id) + return on; + return (struct ospf6_neighbor *) NULL; } @@ -795,19 +793,11 @@ DEFUN (show_ipv6_ospf6_neighbor, "RouterID", "State", "Duration", "DR", "BDR", "I/F", "State", VNL); - for (i = listhead (ospf6->area_list); i; nextnode (i)) - { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) - { - oi = (struct ospf6_interface *) getdata (j); - for (k = listhead (oi->neighbor_list); k; nextnode (k)) - { - on = (struct ospf6_neighbor *) getdata (k); - (*showfunc) (vty, on); - } - } - } + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on)) + (*showfunc) (vty, on); + return CMD_SUCCESS; } @@ -849,20 +839,11 @@ DEFUN (show_ipv6_ospf6_neighbor_one, return CMD_SUCCESS; } - for (i = listhead (ospf6->area_list); i; nextnode (i)) - { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) - { - oi = (struct ospf6_interface *) getdata (j); - for (k = listhead (oi->neighbor_list); k; nextnode (k)) - { - on = (struct ospf6_neighbor *) getdata (k); - if (on->router_id == router_id) - (*showfunc) (vty, on); - } - } - } + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, i, oa)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on)) + (*showfunc) (vty, on); + return CMD_SUCCESS; } diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 3cc4f2dd6..09fa27ce7 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -318,9 +318,8 @@ ospfv3AreaEntry (struct variable *v, oid *name, size_t *length, inet_ntoa (* (struct in_addr *) &area_id), exact, len, *length); - for (node = listhead (ospf6->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { - oa = (struct ospf6_area *) getdata (node); if (area == NULL) { if (len == 0) /* return first area entry */ @@ -435,10 +434,8 @@ ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length, } else { - for (node = listhead (ospf6->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { - oa = (struct ospf6_area *) getdata (node); - if (lsa) continue; if (ntohl (oa->area_id) < ntohl (area_id.s_addr)) diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index d212c43a1..08c1eb73b 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -281,7 +281,7 @@ ospf6_spf_install (struct ospf6_vertex *v, struct ospf6_route *route; int i, j; struct ospf6_vertex *prev, *w; - struct listnode *node; + struct listnode *node, *nnode; if (IS_OSPF6_DEBUG_SPF (PROCESS)) zlog_debug ("SPF install %s hops %d cost %d", @@ -322,7 +322,7 @@ ospf6_spf_install (struct ospf6_vertex *v, prev = (struct ospf6_vertex *) route->route_option; if (prev->hops > v->hops) { - LIST_LOOP (prev->child_list, w, node) + for (ALL_LIST_ELEMENTS (prev->child_list, node, nnode, w)) { assert (w->parent == prev); w->parent = v; @@ -502,9 +502,8 @@ ospf6_spf_log_database (struct ospf6_area *oa) snprintf (p, end - p, " Area %s: %d", oa->name, oa->lsdb->count); p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end); - for (node = listhead (oa->if_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, node, oi)) { - oi = (struct ospf6_interface *) getdata (node); snprintf (p, end - p, " I/F %s: %d", oi->interface->name, oi->lsdb->count); p = (buffer + strlen (buffer) < end ? buffer + strlen (buffer) : end); @@ -556,7 +555,7 @@ void ospf6_spf_display_subtree (struct vty *vty, const char *prefix, int rest, struct ospf6_vertex *v) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf6_vertex *c; char *next_prefix; int len; @@ -575,7 +574,7 @@ ospf6_spf_display_subtree (struct vty *vty, const char *prefix, int rest, snprintf (next_prefix, len, "%s%s", prefix, (rest ? "| " : " ")); restnum = listcount (v->child_list); - LIST_LOOP (v->child_list, c, node) + for (ALL_LIST_ELEMENTS (v->child_list, node, nnode, c)) { restnum--; ospf6_spf_display_subtree (vty, next_prefix, restnum, c); diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index b0fe5ca7d..b3d45167b 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -143,14 +143,11 @@ ospf6_create () void ospf6_delete (struct ospf6 *o) { - struct listnode *i; + struct listnode *node, *nnode; struct ospf6_area *oa; - for (i = listhead (o->area_list); i; nextnode (i)) - { - oa = (struct ospf6_area *) getdata (i); - ospf6_area_delete (oa); - } + for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa)) + ospf6_area_delete (oa); ospf6_lsdb_delete (o->lsdb); ospf6_lsdb_delete (o->lsdb_self); @@ -167,34 +164,29 @@ ospf6_delete (struct ospf6 *o) void ospf6_enable (struct ospf6 *o) { - struct listnode *i; + struct listnode *node, *nnode; struct ospf6_area *oa; if (CHECK_FLAG (o->flag, OSPF6_DISABLED)) { UNSET_FLAG (o->flag, OSPF6_DISABLED); - for (i = listhead (o->area_list); i; nextnode (i)) - { - oa = (struct ospf6_area *) getdata (i); - ospf6_area_enable (oa); - } + for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa)) + ospf6_area_enable (oa); } } void ospf6_disable (struct ospf6 *o) { - struct listnode *i; + struct listnode *node, *nnode; struct ospf6_area *oa; if (! CHECK_FLAG (o->flag, OSPF6_DISABLED)) { SET_FLAG (o->flag, OSPF6_DISABLED); - for (i = listhead (o->area_list); i; nextnode (i)) - { - oa = (struct ospf6_area *) getdata (i); - ospf6_area_disable (oa); - } + + for (ALL_LIST_ELEMENTS (o->area_list, node, nnode, oa)) + ospf6_area_disable (oa); ospf6_lsdb_remove_all (o->lsdb); ospf6_route_remove_all (o->route_table); @@ -213,15 +205,12 @@ ospf6_maxage_remover (struct thread *thread) o->maxage_remover = (struct thread *) NULL; - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); - for (k = listhead (oi->neighbor_list); k; nextnode (k)) + for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, k, on)) { - on = (struct ospf6_neighbor *) getdata (k); if (on->state != OSPF6_NEIGHBOR_EXCHANGE && on->state != OSPF6_NEIGHBOR_LOADING) continue; @@ -231,14 +220,11 @@ ospf6_maxage_remover (struct thread *thread) } } - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) - { - oi = (struct ospf6_interface *) getdata (j); - OSPF6_LSDB_MAXAGE_REMOVER (oi->lsdb); - } + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) + OSPF6_LSDB_MAXAGE_REMOVER (oi->lsdb); + OSPF6_LSDB_MAXAGE_REMOVER (oa->lsdb); } OSPF6_LSDB_MAXAGE_REMOVER (o->lsdb); @@ -466,11 +452,9 @@ ospf6_show (struct vty *vty, struct ospf6 *o) /* Areas */ vty_out (vty, " Number of areas in this router is %u%s", listcount (o->area_list), VNL); - for (n = listhead (o->area_list); n; nextnode (n)) - { - oa = (struct ospf6_area *) getdata (n); - ospf6_area_show (vty, oa); - } + + for (ALL_LIST_ELEMENTS_RO (o->area_list, n, oa)) + ospf6_area_show (vty, oa); } /* show top level structures */ @@ -629,15 +613,11 @@ config_write_ospf6 (struct vty *vty) ospf6_redistribute_config_write (vty); ospf6_area_config_write (vty); - for (j = listhead (ospf6->area_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, j, oa)) { - oa = (struct ospf6_area *) getdata (j); - for (k = listhead (oa->if_list); k; nextnode (k)) - { - oi = (struct ospf6_interface *) getdata (k); - vty_out (vty, " interface %s area %s%s", - oi->interface->name, oa->name, VNL); - } + for (ALL_LIST_ELEMENTS_RO (oa->if_list, k, oi)) + vty_out (vty, " interface %s area %s%s", + oi->interface->name, oa->name, VNL); } vty_out (vty, "!%s", VNL); return 0; diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c index d10d1df67..e8fba97db 100644 --- a/ospf6d/ospf6d.c +++ b/ospf6d/ospf6d.c @@ -187,19 +187,16 @@ DEFUN (show_ipv6_ospf6_database, level = parse_show_level (argc, argv); - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, NULL, NULL, oa->lsdb); } - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, NULL, NULL, oi->lsdb); @@ -262,21 +259,18 @@ DEFUN (show_ipv6_ospf6_database_type, switch (OSPF6_LSA_SCOPE (type)) { case OSPF6_SCOPE_AREA: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, NULL, NULL, oa->lsdb); } break; case OSPF6_SCOPE_LINKLOCAL: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, NULL, NULL, oi->lsdb); @@ -353,19 +347,16 @@ DEFUN (show_ipv6_ospf6_database_id, argv++; level = parse_show_level (argc, argv); - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, &id, NULL, oa->lsdb); } - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, &id, NULL, oi->lsdb); @@ -452,19 +443,16 @@ DEFUN (show_ipv6_ospf6_database_router, argv++; level = parse_show_level (argc, argv); - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, NULL, &adv_router, oa->lsdb); } - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, NULL, &adv_router, oi->lsdb); @@ -569,21 +557,18 @@ DEFUN (show_ipv6_ospf6_database_type_id, switch (OSPF6_LSA_SCOPE (type)) { case OSPF6_SCOPE_AREA: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, NULL, oa->lsdb); } break; case OSPF6_SCOPE_LINKLOCAL: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, NULL, oi->lsdb); @@ -728,21 +713,18 @@ DEFUN (show_ipv6_ospf6_database_type_router, switch (OSPF6_LSA_SCOPE (type)) { case OSPF6_SCOPE_AREA: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, NULL, &adv_router, oa->lsdb); } break; case OSPF6_SCOPE_LINKLOCAL: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, NULL, &adv_router, oi->lsdb); @@ -881,19 +863,16 @@ DEFUN (show_ipv6_ospf6_database_id_router, argv++; level = parse_show_level (argc, argv); - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, &id, &adv_router, oa->lsdb); } - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, &id, &adv_router, oi->lsdb); @@ -967,19 +946,16 @@ DEFUN (show_ipv6_ospf6_database_adv_router_linkstate_id, argv++; level = parse_show_level (argc, argv); - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, &id, &adv_router, oa->lsdb); } - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, &id, &adv_router, oi->lsdb); @@ -1071,21 +1047,18 @@ DEFUN (show_ipv6_ospf6_database_type_id_router, switch (OSPF6_LSA_SCOPE (type)) { case OSPF6_SCOPE_AREA: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, &adv_router, oa->lsdb); } break; case OSPF6_SCOPE_LINKLOCAL: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, &adv_router, oi->lsdb); @@ -1196,21 +1169,18 @@ DEFUN (show_ipv6_ospf6_database_type_adv_router_linkstate_id, switch (OSPF6_LSA_SCOPE (type)) { case OSPF6_SCOPE_AREA: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, &adv_router, oa->lsdb); } break; case OSPF6_SCOPE_LINKLOCAL: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, &adv_router, oi->lsdb); @@ -1282,19 +1252,16 @@ DEFUN (show_ipv6_ospf6_database_self_originated, adv_router = o->router_id; - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, NULL, &adv_router, oa->lsdb); } - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, NULL, NULL, &adv_router, oi->lsdb); @@ -1362,21 +1329,18 @@ DEFUN (show_ipv6_ospf6_database_type_self_originated, switch (OSPF6_LSA_SCOPE (type)) { case OSPF6_SCOPE_AREA: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, NULL, &adv_router, oa->lsdb); } break; case OSPF6_SCOPE_LINKLOCAL: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, NULL, &adv_router, oi->lsdb); @@ -1478,21 +1442,18 @@ DEFUN (show_ipv6_ospf6_database_type_self_originated_linkstate_id, switch (OSPF6_LSA_SCOPE (type)) { case OSPF6_SCOPE_AREA: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, &adv_router, oa->lsdb); } break; case OSPF6_SCOPE_LINKLOCAL: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, &adv_router, oi->lsdb); @@ -1594,21 +1555,18 @@ DEFUN (show_ipv6_ospf6_database_type_id_self_originated, switch (OSPF6_LSA_SCOPE (type)) { case OSPF6_SCOPE_AREA: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); vty_out (vty, AREA_LSDB_TITLE_FORMAT, VNL, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, &adv_router, oa->lsdb); } break; case OSPF6_SCOPE_LINKLOCAL: - for (i = listhead (o->area_list); i; nextnode (i)) + for (ALL_LIST_ELEMENTS_RO (o->area_list, i, oa)) { - oa = (struct ospf6_area *) getdata (i); - for (j = listhead (oa->if_list); j; nextnode (j)) + for (ALL_LIST_ELEMENTS_RO (oa->if_list, j, oi)) { - oi = (struct ospf6_interface *) getdata (j); vty_out (vty, IF_LSDB_TITLE_FORMAT, VNL, oi->interface->name, oa->name, VNL, VNL); ospf6_lsdb_show (vty, level, &type, &id, &adv_router, oi->lsdb); @@ -1730,10 +1688,8 @@ DEFUN (show_ipv6_ospf6_linkstate, struct listnode *node; struct ospf6_area *oa; - for (node = listhead (ospf6->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { - oa = OSPF6_AREA (getdata (node)); - vty_out (vty, "%s SPF Result in Area %s%s%s", VNL, oa->name, VNL, VNL); ospf6_linkstate_table_show (vty, argc, argv, oa->spf_table); @@ -1787,10 +1743,8 @@ DEFUN (show_ipv6_ospf6_linkstate_detail, sargv[sargc++] = "detail"; sargv[sargc] = NULL; - for (node = listhead (ospf6->area_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa)) { - oa = OSPF6_AREA (getdata (node)); - vty_out (vty, "%s SPF Result in Area %s%s%s", VNL, oa->name, VNL, VNL); ospf6_linkstate_table_show (vty, sargc, sargv, oa->spf_table); diff --git a/ospf6d/ospf6d.h b/ospf6d/ospf6d.h index 6fcf200e2..4b718d7a6 100644 --- a/ospf6d/ospf6d.h +++ b/ospf6d/ospf6d.h @@ -50,7 +50,7 @@ extern struct thread_master *master; #endif /* IPV6_DROP_MEMBERSHIP */ #endif /* ! IPV6_LEAVE_GROUP */ -/* cast macro */ +/* cast macro: XXX - these *must* die, ick ick. */ #define OSPF6_PROCESS(x) ((struct ospf6 *) (x)) #define OSPF6_AREA(x) ((struct ospf6_area *) (x)) #define OSPF6_INTERFACE(x) ((struct ospf6_interface *) (x)) diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c index 416b3e794..90ed3920e 100644 --- a/ospfd/ospf_abr.c +++ b/ospfd/ospf_abr.c @@ -174,10 +174,11 @@ struct ospf_area_range * 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 @@ void 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 @@ void 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 @@ ospf_check_abr_status (struct ospf *ospf) 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 @@ int 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 @@ ospf_abr_announce_network (struct ospf *ospf, 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 @@ ospf_abr_process_nssa_translates (struct ospf *ospf) 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 @@ ospf_abr_announce_rtr (struct ospf *ospf, 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 @@ ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt) 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 @@ ospf_abr_process_router_rt (struct ospf *ospf, struct route_table *rt) 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 @@ ospf_abr_unapprove_summaries (struct ospf *ospf) 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 @@ ospf_abr_prepare_aggregates (struct ospf *ospf) 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 @@ ospf_abr_announce_aggregates (struct ospf *ospf) 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 @@ ospf_abr_announce_aggregates (struct ospf *ospf) 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 @@ ospf_abr_send_nssa_aggregates (struct ospf *ospf) /* temporarily turned off */ 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 @@ ospf_abr_announce_nssa_defaults (struct ospf *ospf) /* By ABR-Translator */ 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 @@ ospf_abr_announce_stub_defaults (struct ospf *ospf) 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 @@ ospf_abr_remove_unapproved_summaries (struct ospf *ospf) 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 @@ ospf_abr_remove_unapproved_summaries (struct ospf *ospf) 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 diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index 89af2a36e..59233c72c 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -83,15 +83,14 @@ struct list *apiserver_list; struct ospf_interface * ospf_apiserver_if_lookup_by_addr (struct in_addr address) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_interface *oi; struct ospf *ospf; if (!(ospf = ospf_lookup ())) return NULL; - for (node = listhead (ospf->oiflist); node; nextnode (node)) - LIST_LOOP (ospf->oiflist, oi, node) + for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) if (oi->type != OSPF_IFTYPE_VIRTUALLINK) if (IPV4_ADDR_SAME (&address, &oi->address->u.prefix4)) return oi; @@ -102,14 +101,14 @@ ospf_apiserver_if_lookup_by_addr (struct in_addr address) struct ospf_interface * ospf_apiserver_if_lookup_by_ifp (struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_interface *oi; struct ospf *ospf; if (!(ospf = ospf_lookup ())); return NULL; - LIST_LOOP (ospf->oiflist, oi, node) + for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) if (oi->ifp == ifp) return oi; @@ -190,7 +189,7 @@ ospf_apiserver_term (void) * Free all client instances. ospf_apiserver_free removes the node * from the list, so we examine the head of the list anew each time. */ - while ( (apiserv = getdata (listhead (apiserver_list))) != NULL) + while ( (apiserv = listgetdata (listhead (apiserver_list))) != NULL) ospf_apiserver_free (apiserv); /* Free client list itself */ @@ -208,20 +207,14 @@ lookup_apiserver (u_char lsa_type, u_char opaque_type) struct ospf_apiserver *apiserv, *found = NULL; /* XXX: this approaches O(n**2) */ - for (n1 = listhead (apiserver_list); n1; nextnode (n1)) + for (ALL_LIST_ELEMENTS_RO (apiserver_list, n1, apiserv)) { - apiserv = (struct ospf_apiserver *) getdata (n1); - - for (n2 = listhead (apiserv->opaque_types); n2; nextnode (n2)) - { - r = (struct registered_opaque_type *) getdata (n2); - - if (r->lsa_type == lsa_type && r->opaque_type == opaque_type) - { - found = apiserv; - goto out; - } - } + for (ALL_LIST_ELEMENTS_RO (apiserv->opaque_types, n2, r)) + if (r->lsa_type == lsa_type && r->opaque_type == opaque_type) + { + found = apiserv; + goto out; + } } out: return found; @@ -373,8 +366,7 @@ ospf_apiserver_free (struct ospf_apiserver *apiserv) while ((node = listhead (apiserv->opaque_types)) != NULL) { - - struct registered_opaque_type *regtype = node->data; + struct registered_opaque_type *regtype = listgetdata(node); ospf_apiserver_unregister_opaque_type (apiserv, regtype->lsa_type, regtype->opaque_type); @@ -964,15 +956,11 @@ int ospf_apiserver_unregister_opaque_type (struct ospf_apiserver *apiserv, u_char lsa_type, u_char opaque_type) { - struct listnode *n1, *n1_next; + struct listnode *node, *nnode; struct registered_opaque_type *regtype; - for (n1 = listhead (apiserv->opaque_types); n1; n1 = n1_next) + for (ALL_LIST_ELEMENTS (apiserv->opaque_types, node, nnode, regtype)) { - n1_next = n1->next; - - regtype = (struct registered_opaque_type *) getdata(n1); - /* Check if we really registered this opaque type */ if (regtype->lsa_type == lsa_type && regtype->opaque_type == opaque_type) @@ -1008,11 +996,11 @@ int apiserver_is_opaque_type_registered (struct ospf_apiserver *apiserv, u_char lsa_type, u_char opaque_type) { - struct listnode *node; + struct listnode *node, *nnode; struct registered_opaque_type *regtype; /* XXX: how many types are there? if few, why not just a bitmap? */ - LIST_LOOP (apiserv->opaque_types, regtype, node) + for (ALL_LIST_ELEMENTS (apiserv->opaque_types, node, nnode, regtype)) { /* Check if we really registered this opaque type */ if (regtype->lsa_type == lsa_type && @@ -1070,15 +1058,15 @@ out: void ospf_apiserver_notify_ready_type9 (struct ospf_apiserver *apiserv) { - struct listnode *node; - struct listnode *n2; + struct listnode *node, *nnode; + struct listnode *node2, *nnode2; struct ospf *ospf; struct ospf_interface *oi; struct registered_opaque_type *r; ospf = ospf_lookup (); - LIST_LOOP (ospf->oiflist, oi, node) + for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) { /* Check if this interface is indeed ready for type 9 */ if (!ospf_apiserver_is_ready_type9 (oi)) @@ -1086,7 +1074,7 @@ ospf_apiserver_notify_ready_type9 (struct ospf_apiserver *apiserv) /* Check for registered opaque type 9 types */ /* XXX: loop-de-loop - optimise me */ - LIST_LOOP (apiserv->opaque_types, r, n2) + for (ALL_LIST_ELEMENTS (apiserv->opaque_types, node2, nnode2, r)) { struct msg *msg; @@ -1121,14 +1109,14 @@ out: void ospf_apiserver_notify_ready_type10 (struct ospf_apiserver *apiserv) { - struct listnode *node; - struct listnode *n2; + struct listnode *node, *nnode; + struct listnode *node2, *nnode2; struct ospf *ospf; struct ospf_area *area; ospf = ospf_lookup (); - LIST_LOOP (ospf->areas, area, node) + for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) { struct registered_opaque_type *r; @@ -1139,7 +1127,7 @@ ospf_apiserver_notify_ready_type10 (struct ospf_apiserver *apiserv) /* Check for registered opaque type 10 types */ /* XXX: loop in loop - optimise me */ - LIST_LOOP (apiserv->opaque_types, r, n2) + for (ALL_LIST_ELEMENTS (apiserv->opaque_types, node2, nnode2, r)) { struct msg *msg; @@ -1172,7 +1160,7 @@ out: void ospf_apiserver_notify_ready_type11 (struct ospf_apiserver *apiserv) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf *ospf; struct registered_opaque_type *r; @@ -1183,7 +1171,7 @@ ospf_apiserver_notify_ready_type11 (struct ospf_apiserver *apiserv) goto out; /* Check for registered opaque type 11 types */ - LIST_LOOP (apiserv->opaque_types, r, node) + for (ALL_LIST_ELEMENTS (apiserv->opaque_types, node, nnode, r)) { struct msg *msg; struct in_addr noarea_id = { 0L }; @@ -1350,16 +1338,15 @@ int ospf_apiserver_handle_sync_lsdb (struct ospf_apiserver *apiserv, struct msg *msg) { - struct listnode *node; + struct listnode *node, *nnode; u_int32_t seqnum; int rc = 0; struct msg_sync_lsdb *smsg; - struct param_t + struct ospf_apiserver_param_t { struct ospf_apiserver *apiserv; struct lsa_filter_type *filter; - } - param; + } param; u_int16_t mask; struct route_node *rn; struct ospf_lsa *lsa; @@ -1381,7 +1368,7 @@ ospf_apiserver_handle_sync_lsdb (struct ospf_apiserver *apiserv, mask = ntohs (smsg->filter.typemask); /* Iterate over all areas. */ - LIST_LOOP (ospf->areas, area, node) + for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) { int i; u_int32_t *area_id = NULL; @@ -1563,10 +1550,10 @@ ospf_apiserver_is_ready_type10 (struct ospf_area *area) /* Type 10 opaque LSA can be originated if there is at least one interface belonging to the area that has an active opaque-capable neighbor. */ - struct listnode *node; + struct listnode *node, *nnode; struct ospf_interface *oi; - LIST_LOOP (area->oiflist, oi, node) + for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi)) /* Is there an active neighbor attached to this interface? */ if (ospf_apiserver_is_ready_type9 (oi)) return 1; @@ -1580,10 +1567,10 @@ ospf_apiserver_is_ready_type11 (struct ospf *ospf) { /* Type 11 opaque LSA can be originated if there is at least one interface that has an active opaque-capable neighbor. */ - struct listnode *node; + struct listnode *node, *nnode; struct ospf_interface *oi; - LIST_LOOP (ospf->oiflist, oi, node) + for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) /* Is there an active neighbor attached to this interface? */ if (ospf_apiserver_is_ready_type9 (oi)) return 1; @@ -2050,7 +2037,7 @@ ospf_apiserver_flush_opaque_lsa (struct ospf_apiserver *apiserv, u_char lsa_type; u_char opaque_type; } param; - struct listnode *node; + struct listnode *node, *nnode; struct ospf * ospf; struct ospf_area *area; @@ -2068,12 +2055,12 @@ ospf_apiserver_flush_opaque_lsa (struct ospf_apiserver *apiserv, struct ospf_lsa *lsa; case OSPF_OPAQUE_LINK_LSA: - LIST_LOOP (ospf->areas, area, node) + for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) LSDB_LOOP (OPAQUE_LINK_LSDB (area), rn, lsa) apiserver_flush_opaque_type_callback(lsa, (void *) ¶m, 0); break; case OSPF_OPAQUE_AREA_LSA: - LIST_LOOP (ospf->areas, area, node) + for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) LSDB_LOOP (OPAQUE_AREA_LSDB (area), rn, lsa) apiserver_flush_opaque_type_callback(lsa, (void *) ¶m, 0); break; @@ -2253,11 +2240,11 @@ ospf_apiserver_show_info (struct vty *vty, struct ospf_lsa *lsa) void ospf_apiserver_clients_notify_all (struct msg *msg) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_apiserver *apiserv; /* Send message to all clients */ - LIST_LOOP (apiserver_list, apiserv, node) + for (ALL_LIST_ELEMENTS (apiserver_list, node, nnode, apiserv)) ospf_apiserver_send_msg (apiserv, msg); } @@ -2266,7 +2253,7 @@ ospf_apiserver_clients_notify_all (struct msg *msg) void ospf_apiserver_clients_notify_ready_type9 (struct ospf_interface *oi) { - struct listnode *node; + struct listnode *node, *nnode; struct msg *msg; struct ospf_apiserver *apiserv; @@ -2283,12 +2270,12 @@ ospf_apiserver_clients_notify_ready_type9 (struct ospf_interface *oi) return; } - LIST_LOOP (apiserver_list, apiserv, node) + for (ALL_LIST_ELEMENTS (apiserver_list, node, nnode, apiserv)) { - struct listnode *n2; + struct listnode *node2, *nnode2; struct registered_opaque_type *r; - LIST_LOOP (apiserv->opaque_types, r, n2) + for (ALL_LIST_ELEMENTS (apiserv->opaque_types, node2, nnode2, r)) { if (r->lsa_type == OSPF_OPAQUE_LINK_LSA) { @@ -2319,7 +2306,7 @@ out: void ospf_apiserver_clients_notify_ready_type10 (struct ospf_area *area) { - struct listnode *node; + struct listnode *node, *nnode; struct msg *msg; struct ospf_apiserver *apiserv; @@ -2331,12 +2318,12 @@ ospf_apiserver_clients_notify_ready_type10 (struct ospf_area *area) return; } - LIST_LOOP (apiserver_list, apiserv, node) + for (ALL_LIST_ELEMENTS (apiserver_list, node, nnode, apiserv)) { - struct listnode *n2; + struct listnode *node2, *nnode2; struct registered_opaque_type *r; - LIST_LOOP (apiserv->opaque_types, r, n2) + for (ALL_LIST_ELEMENTS (apiserv->opaque_types, node2, nnode2, r)) { if (r->lsa_type == OSPF_OPAQUE_AREA_LSA) { @@ -2367,7 +2354,7 @@ out: void ospf_apiserver_clients_notify_ready_type11 (struct ospf *top) { - struct listnode *node; + struct listnode *node, *nnode; struct msg *msg; struct in_addr id_null = { 0L }; struct ospf_apiserver *apiserv; @@ -2380,12 +2367,12 @@ ospf_apiserver_clients_notify_ready_type11 (struct ospf *top) return; } - LIST_LOOP (apiserver_list, apiserv, node) + for (ALL_LIST_ELEMENTS (apiserver_list, node, nnode, apiserv)) { - struct listnode *n2; + struct listnode *node2, *nnode2; struct registered_opaque_type *r; - LIST_LOOP (apiserv->opaque_types, r, n2) + for (ALL_LIST_ELEMENTS (apiserv->opaque_types, node2, nnode2, r)) { if (r->lsa_type == OSPF_OPAQUE_AS_LSA) { @@ -2499,7 +2486,7 @@ void apiserver_clients_lsa_change_notify (u_char msgtype, struct ospf_lsa *lsa) { struct msg *msg; - struct listnode *node; + struct listnode *node, *nnode; struct ospf_apiserver *apiserv; /* Default area for AS-External and Opaque11 LSAs */ @@ -2530,7 +2517,7 @@ apiserver_clients_lsa_change_notify (u_char msgtype, struct ospf_lsa *lsa) } /* Now send message to all clients with a matching filter */ - LIST_LOOP (apiserver_list, apiserv, node) + for (ALL_LIST_ELEMENTS (apiserver_list, node, nnode, apiserv)) { struct lsa_filter_type *filter; u_int16_t mask; diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c index c4f4dd3db..f9f79e3c1 100644 --- a/ospfd/ospf_ase.c +++ b/ospfd/ospf_ase.c @@ -71,12 +71,11 @@ ospf_find_asbr_route (struct ospf *ospf, /* 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 @@ ospf_find_asbr_route (struct ospf *ospf, } /* 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 @@ ospf_find_asbr_route_through_area (struct route_table *rtrs, 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 @@ ospf_ase_complete_direct_routes (struct ospf_route *ro, struct in_addr nexthop) 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 @@ ospf_ase_forward_address_check (struct ospf *ospf, struct in_addr fwd_addr) 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 @@ ospf_ase_route_match_same (struct route_table *rt, struct prefix *prefix, /* 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 @@ ospf_ase_calculate_timer (struct thread *t) /* 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 @@ ospf_ase_external_lsas_finish (struct route_table *rt) 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 @@ ospf_ase_incremental_update (struct ospf *ospf, struct ospf_lsa *lsa) 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 (); diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c index 586c25fb8..06e0f1c7a 100644 --- a/ospfd/ospf_flood.c +++ b/ospfd/ospf_flood.c @@ -150,34 +150,33 @@ ospf_process_self_originated_lsa (struct ospf *ospf, /* Look through all interfaces, not just area, since interface could be moved from one area to another. */ - for (node = listhead (ospf->oiflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) /* These are sanity check. */ - if ((oi = getdata (node)) != NULL) - if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &new->data->id)) - { - if (oi->area != area || - oi->type != OSPF_IFTYPE_BROADCAST || - !IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))) - { - ospf_schedule_lsa_flush_area (area, new); - return; - } - + if (IPV4_ADDR_SAME (&oi->address->u.prefix4, &new->data->id)) + { + if (oi->area != area || + oi->type != OSPF_IFTYPE_BROADCAST || + !IPV4_ADDR_SAME (&oi->address->u.prefix4, &DR (oi))) + { + ospf_schedule_lsa_flush_area (area, new); + return; + } + #ifdef HAVE_OPAQUE_LSA - if (new->data->type == OSPF_OPAQUE_LINK_LSA) - { - ospf_opaque_lsa_refresh (new); - return; - } + if (new->data->type == OSPF_OPAQUE_LINK_LSA) + { + ospf_opaque_lsa_refresh (new); + return; + } #endif /* HAVE_OPAQUE_LSA */ - ospf_lsa_unlock (oi->network_lsa_self); - oi->network_lsa_self = ospf_lsa_lock (new); - - /* Schedule network-LSA origination. */ - ospf_network_lsa_timer_add (oi); - return; - } + ospf_lsa_unlock (oi->network_lsa_self); + oi->network_lsa_self = ospf_lsa_lock (new); + + /* Schedule network-LSA origination. */ + ospf_network_lsa_timer_add (oi); + return; + } break; case OSPF_SUMMARY_LSA: case OSPF_ASBR_SUMMARY_LSA: @@ -569,17 +568,16 @@ int ospf_flood_through_area (struct ospf_area *area, struct ospf_neighbor *inbr, struct ospf_lsa *lsa) { - struct listnode *node; + struct listnode *node, *nnode; + struct ospf_interface *oi; int lsa_ack_flag = 0; /* All other types are specific to a single area (Area A). The eligible interfaces are all those interfaces attaching to the Area A. If Area A is the backbone, this includes all the virtual links. */ - for (node = listhead (area->oiflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi)) { - struct ospf_interface *oi = getdata (node); - if (area->area_id.s_addr != OSPF_AREA_BACKBONE && oi->type == OSPF_IFTYPE_VIRTUALLINK) continue; @@ -609,6 +607,7 @@ ospf_flood_through_as (struct ospf *ospf, struct ospf_neighbor *inbr, struct ospf_lsa *lsa) { struct listnode *node; + struct ospf_area *area; int lsa_ack_flag; lsa_ack_flag = 0; @@ -628,11 +627,11 @@ ospf_flood_through_as (struct ospf *ospf, struct ospf_neighbor *inbr, if (IS_DEBUG_OSPF_NSSA) zlog_debug ("Flood/AS: NSSA TRANSLATED LSA"); - for (node = listhead (ospf->areas); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) { int continue_flag = 0; - struct ospf_area *area = getdata (node); struct listnode *if_node; + struct ospf_interface *oi; switch (area->external_routing) { @@ -671,10 +670,8 @@ ospf_flood_through_as (struct ospf *ospf, struct ospf_neighbor *inbr, /* send to every interface in this area */ - for (if_node = listhead (area->oiflist); if_node; nextnode (if_node)) + for (ALL_LIST_ELEMENTS_RO (area->oiflist, if_node, oi)) { - struct ospf_interface *oi = getdata (if_node); - /* Skip virtual links */ if (oi->type != OSPF_IFTYPE_VIRTUALLINK) if (ospf_flood_through_interface (oi, inbr, lsa)) /* lsa */ @@ -965,19 +962,21 @@ void ospf_ls_retransmit_delete_nbr_area (struct ospf_area *area, struct ospf_lsa *lsa) { - struct listnode *node; + struct listnode *node, *nnode; + struct ospf_interface *oi; - for (node = listhead (area->oiflist); node; nextnode (node)) - ospf_ls_retransmit_delete_nbr_if (getdata (node), lsa); + for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi)) + ospf_ls_retransmit_delete_nbr_if (oi, lsa); } void ospf_ls_retransmit_delete_nbr_as (struct ospf *ospf, struct ospf_lsa *lsa) { - struct listnode *node; + struct listnode *node, *nnode; + struct ospf_interface *oi; - for (node = listhead (ospf->oiflist); node; nextnode (node)) - ospf_ls_retransmit_delete_nbr_if (getdata (node), lsa); + for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) + ospf_ls_retransmit_delete_nbr_if (oi, lsa); } diff --git a/ospfd/ospf_ia.c b/ospfd/ospf_ia.c index 5bdcfba65..87613bf17 100644 --- a/ospfd/ospf_ia.c +++ b/ospfd/ospf_ia.c @@ -62,10 +62,10 @@ ospf_find_abr_route (struct route_table *rtrs, 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) && (or->u.std.flags & ROUTER_LSA_BORDER)) - 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) + && (or->u.std.flags & ROUTER_LSA_BORDER)) + return or; return NULL; } @@ -637,11 +637,10 @@ ospf_ia_routing (struct ospf *ospf, OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); - for (node = listhead (ospf->areas); node; nextnode (node)) - if ((area = getdata (node)) != NULL) - if (area != ospf->backbone) - if (ospf_area_is_transit (area)) - OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) + if (area != ospf->backbone) + if (ospf_area_is_transit (area)) + OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); } else if (IS_DEBUG_OSPF_EVENT) @@ -664,20 +663,18 @@ ospf_ia_routing (struct ospf *ospf, OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); - for (node = listhead (ospf->areas); node; nextnode (node)) - if ((area = getdata (node)) != NULL) - if (area != ospf->backbone) - if (ospf_area_is_transit (area)) - OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) + if (area != ospf->backbone) + if (ospf_area_is_transit (area)) + OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); } else { /* No active BB connection--consider all areas */ if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_ia_routing(): " "Active BB connection not found"); - for (node = listhead (ospf->areas); node; nextnode (node)) - if ((area = getdata (node)) != NULL) - OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) + OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); } break; case OSPF_ABR_SHORTCUT: @@ -696,15 +693,14 @@ ospf_ia_routing (struct ospf *ospf, OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); } - for (node = listhead (ospf->areas); node; nextnode (node)) - if ((area = getdata (node)) != NULL) - if (area != ospf->backbone) - if (ospf_area_is_transit (area) || - ((area->shortcut_configured != OSPF_SHORTCUT_DISABLE) && - ((ospf->backbone == NULL) || - ((area->shortcut_configured == OSPF_SHORTCUT_ENABLE) && - area->shortcut_capability)))) - OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) + if (area != ospf->backbone) + if (ospf_area_is_transit (area) || + ((area->shortcut_configured != OSPF_SHORTCUT_DISABLE) && + ((ospf->backbone == NULL) || + ((area->shortcut_configured == OSPF_SHORTCUT_ENABLE) && + area->shortcut_capability)))) + OSPF_EXAMINE_TRANSIT_SUMMARIES_ALL (area, rt, rtrs); break; default: break; @@ -717,8 +713,7 @@ ospf_ia_routing (struct ospf *ospf, if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_ia_routing():not ABR, considering all areas"); - for (node = listhead (ospf->areas); node; nextnode (node)) - if ((area = getdata (node)) != NULL) - OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) + OSPF_EXAMINE_SUMMARIES_ALL (area, rt, rtrs); } } diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 027dfb9dc..f8490f5ef 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -258,16 +258,15 @@ void 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_if_cleanup (struct ospf_interface *oi) 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 @@ ospf_if_free (struct ospf_interface *oi) 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 @@ ospf_if_is_configured (struct ospf *ospf, struct in_addr *address) 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_if_exists (struct ospf_interface *oic) 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 @@ ospf_if_lookup_by_local_addr (struct ospf *ospf, 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 @@ ospf_if_lookup_by_prefix (struct ospf *ospf, struct prefix_ipv4 *p) 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 @@ ospf_if_lookup_recv_if (struct ospf *ospf, struct in_addr src) 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 @@ ospf_vl_lookup (struct ospf_area *area, struct in_addr vl_peer) 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 @@ ospf_vl_set_params (struct ospf_vl_data *vl_data, struct vertex *v) 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; - - break; /* We take the first interface. */ - } + 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. */ + } rl = (struct router_lsa *)v->lsa; @@ -1093,11 +1087,8 @@ ospf_vl_up_check (struct ospf_area *area, struct in_addr rid, 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 @@ ospf_vl_unapprove (struct ospf *ospf) 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 @@ ospf_vls_in_area (struct ospf_area *area) 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 @@ ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id) 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 @@ ospf_crypt_key_lookup (struct list *auth_crypt, u_char key_id) 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); diff --git a/ospfd/ospf_ism.c b/ospfd/ospf_ism.c index dd0f06696..5d498d7dd 100644 --- a/ospfd/ospf_ism.c +++ b/ospfd/ospf_ism.c @@ -53,10 +53,8 @@ ospf_dr_election_sub (struct list *routers) /* Choose highest router priority. In case of tie, choose highest Router ID. */ - for (node = listhead (routers); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (routers, node, nbr)) { - nbr = getdata (node); - if (max == NULL) max = nbr; else @@ -82,10 +80,8 @@ ospf_elect_dr (struct ospf_interface *oi, struct list *el_list) dr_list = list_new (); /* Add neighbors to the list. */ - for (node = listhead (el_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (el_list, node, nbr)) { - nbr = getdata (node); - /* neighbor declared to be DR. */ if (NBR_IS_DR (nbr)) listnode_add (dr_list, nbr); @@ -126,10 +122,8 @@ ospf_elect_bdr (struct ospf_interface *oi, struct list *el_list) no_dr_list = list_new (); /* Add neighbors to the list. */ - for (node = listhead (el_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (el_list, node, nbr)) { - nbr = getdata (node); - /* neighbor declared to be DR. */ if (NBR_IS_DR (nbr)) continue; diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 203c4a5e6..e02d457ee 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); diff --git a/ospfd/ospf_neighbor.c b/ospfd/ospf_neighbor.c index 61366ed75..35906ec8a 100644 --- a/ospfd/ospf_neighbor.c +++ b/ospfd/ospf_neighbor.c @@ -304,9 +304,9 @@ ospf_renegotiate_optional_capabilities (struct ospf *top) ospf_flush_self_originated_lsas_now (top); /* Revert all neighbor status to ExStart. */ - for (node = listhead (top->oiflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (top->oiflist, node, oi)) { - if ((oi = getdata (node)) == NULL || (nbrs = oi->nbrs) == NULL) + if ((nbrs = oi->nbrs) == NULL) continue; for (rn = route_top (nbrs); rn; rn = route_next (rn)) @@ -355,11 +355,8 @@ ospf_nbr_add (struct ospf_interface *oi, struct ospf_header *ospfh, struct ospf_nbr_nbma *nbr_nbma; struct listnode *node; - for (node = listhead (oi->nbr_nbma); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, node, nbr_nbma)) { - nbr_nbma = getdata (node); - assert (nbr_nbma); - if (IPV4_ADDR_SAME(&nbr_nbma->addr, &nbr->src)) { nbr_nbma->nbr = nbr; diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c index 01a8e1ce1..d6b2f25bc 100644 --- a/ospfd/ospf_opaque.c +++ b/ospfd/ospf_opaque.c @@ -371,10 +371,10 @@ ospf_register_opaque_functab ( } else { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->opaque_type == opaque_type) { zlog_warn ("ospf_register_opaque_functab: Duplicated entry?:" @@ -418,14 +418,13 @@ void ospf_delete_opaque_functab (u_char lsa_type, u_char opaque_type) { struct list *funclist; - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; if ((funclist = ospf_get_opaque_funclist (lsa_type)) != NULL) - for (node = listhead (funclist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) { - if ((functab = getdata (node)) != NULL - && functab->opaque_type == opaque_type) + if (functab->opaque_type == opaque_type) { /* Cleanup internal control information, if it still remains. */ if (functab->oipt != NULL) @@ -455,7 +454,7 @@ ospf_opaque_functab_lookup (struct ospf_lsa *lsa) u_char key = GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr)); if ((funclist = ospf_get_opaque_funclist (lsa->data->type)) != NULL) - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS_RO (funclist, node, functab)) if (functab->opaque_type == key) return functab; @@ -588,13 +587,11 @@ free_opaque_info_per_type (void *val) struct opaque_info_per_type *oipt = (struct opaque_info_per_type *) val; struct opaque_info_per_id *oipi; struct ospf_lsa *lsa; - struct listnode *node; + struct listnode *node, *nnode; /* Control information per opaque-id may still exist. */ - for (node = listhead (oipt->id_list); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (oipt->id_list, node, nnode, oipi)) { - if ((oipi = getdata (node)) == NULL) - continue; if ((lsa = oipi->lsa) == NULL) continue; if (IS_LSA_MAXAGE (lsa)) @@ -641,7 +638,7 @@ lookup_opaque_info_by_type (struct ospf_lsa *lsa) struct ospf_area *area; struct ospf_interface *oi; struct list *listtop = NULL; - struct listnode *node; + struct listnode *node, *nnode; struct opaque_info_per_type *oipt = NULL; u_char key = GET_OPAQUE_TYPE (ntohl (lsa->data->id.s_addr)); @@ -674,7 +671,7 @@ lookup_opaque_info_by_type (struct ospf_lsa *lsa) } if (listtop != NULL) - LIST_LOOP (listtop, oipt, node) + for (ALL_LIST_ELEMENTS (listtop, node, nnode, oipt)) if (oipt->opaque_type == key) return oipt; @@ -720,11 +717,11 @@ static struct opaque_info_per_id * lookup_opaque_info_by_id (struct opaque_info_per_type *oipt, struct ospf_lsa *lsa) { - struct listnode *node; + struct listnode *node, *nnode; struct opaque_info_per_id *oipi; u_int32_t key = GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr)); - LIST_LOOP (oipt->id_list, oipi, node) + for (ALL_LIST_ELEMENTS (oipt->id_list, node, nnode, oipi)) if (oipi->opaque_id == key) return oipi; @@ -827,11 +824,11 @@ ospf_opaque_register_vty (void) static int opaque_lsa_new_if_callback (struct list *funclist, struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; int rc = -1; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->new_if_hook != NULL) if ((* functab->new_if_hook)(ifp) != 0) goto out; @@ -843,11 +840,11 @@ out: static int opaque_lsa_del_if_callback (struct list *funclist, struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; int rc = -1; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->del_if_hook != NULL) if ((* functab->del_if_hook)(ifp) != 0) goto out; @@ -860,10 +857,10 @@ static void opaque_lsa_ism_change_callback (struct list *funclist, struct ospf_interface *oi, int old_status) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->ism_change_hook != NULL) (* functab->ism_change_hook)(oi, old_status); @@ -874,10 +871,10 @@ static void opaque_lsa_nsm_change_callback (struct list *funclist, struct ospf_neighbor *nbr, int old_status) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->nsm_change_hook != NULL) (* functab->nsm_change_hook)(nbr, old_status); return; @@ -887,10 +884,10 @@ static void opaque_lsa_config_write_router_callback (struct list *funclist, struct vty *vty) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->config_write_router != NULL) (* functab->config_write_router)(vty); return; @@ -900,10 +897,10 @@ static void opaque_lsa_config_write_if_callback (struct list *funclist, struct vty *vty, struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->config_write_if != NULL) (* functab->config_write_if)(vty, ifp); return; @@ -912,10 +909,10 @@ opaque_lsa_config_write_if_callback (struct list *funclist, static void opaque_lsa_config_write_debug_callback (struct list *funclist, struct vty *vty) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->config_write_debug != NULL) (* functab->config_write_debug)(vty); return; @@ -924,11 +921,11 @@ opaque_lsa_config_write_debug_callback (struct list *funclist, struct vty *vty) static int opaque_lsa_originate_callback (struct list *funclist, void *lsa_type_dependent) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; int rc = -1; - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->lsa_originator != NULL) if ((* functab->lsa_originator)(lsa_type_dependent) != 0) goto out; @@ -940,12 +937,12 @@ out: static int new_lsa_callback (struct list *funclist, struct ospf_lsa *lsa) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; int rc = -1; /* This function handles ALL types of LSAs, not only opaque ones. */ - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->new_lsa_hook != NULL) if ((* functab->new_lsa_hook)(lsa) != 0) goto out; @@ -957,12 +954,12 @@ out: static int del_lsa_callback (struct list *funclist, struct ospf_lsa *lsa) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_opaque_functab *functab; int rc = -1; /* This function handles ALL types of LSAs, not only opaque ones. */ - LIST_LOOP (funclist, functab, node) + for (ALL_LIST_ELEMENTS (funclist, node, nnode, functab)) if (functab->del_lsa_hook != NULL) if ((* functab->del_lsa_hook)(lsa) != 0) goto out; @@ -1291,7 +1288,7 @@ ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi, int *delay0) { struct ospf *top; struct ospf_area *area; - struct listnode *node; + struct listnode *node, *nnode; struct opaque_info_per_type *oipt; int delay = 0; @@ -1381,7 +1378,7 @@ ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi, int *delay0) if (! list_isempty (ospf_opaque_type9_funclist) && ! list_isempty (oi->opaque_lsa_self)) { - for (node = listhead (oi->opaque_lsa_self); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (oi->opaque_lsa_self, node, nnode, oipt)) { /* * removed the test for @@ -1389,9 +1386,8 @@ ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi, int *delay0) * because opaque cababilities ON -> OFF -> ON result in list_isempty (oipt->id_list) * not being empty. */ - if ((oipt = getdata (node)) == NULL /* Something wrong? */ - || oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */ - || oipt->status == PROC_SUSPEND) /* Cannot originate now. */ + if (oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */ + || oipt->status == PROC_SUSPEND) /* Cannot originate now. */ continue; ospf_opaque_lsa_reoriginate_schedule ((void *) oi, @@ -1402,7 +1398,7 @@ ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi, int *delay0) if (! list_isempty (ospf_opaque_type10_funclist) && ! list_isempty (area->opaque_lsa_self)) { - for (node = listhead (area->opaque_lsa_self); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (area->opaque_lsa_self, node, nnode, oipt)) { /* * removed the test for @@ -1410,9 +1406,8 @@ ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi, int *delay0) * because opaque cababilities ON -> OFF -> ON result in list_isempty (oipt->id_list) * not being empty. */ - if ((oipt = getdata (node)) == NULL /* Something wrong? */ - || oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */ - || oipt->status == PROC_SUSPEND) /* Cannot originate now. */ + if (oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */ + || oipt->status == PROC_SUSPEND) /* Cannot originate now. */ continue; ospf_opaque_lsa_reoriginate_schedule ((void *) area, @@ -1423,7 +1418,7 @@ ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi, int *delay0) if (! list_isempty (ospf_opaque_type11_funclist) && ! list_isempty (top->opaque_lsa_self)) { - for (node = listhead (top->opaque_lsa_self); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (top->opaque_lsa_self, node, nnode, oipt)) { /* * removed the test for @@ -1431,9 +1426,8 @@ ospf_opaque_lsa_originate_schedule (struct ospf_interface *oi, int *delay0) * because opaque cababilities ON -> OFF -> ON result in list_isempty (oipt->id_list) * not being empty. */ - if ((oipt = getdata (node)) == NULL /* Something wrong? */ - || oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */ - || oipt->status == PROC_SUSPEND) /* Cannot originate now. */ + if (oipt->t_opaque_lsa_self != NULL /* Waiting for a thread call. */ + || oipt->status == PROC_SUSPEND) /* Cannot originate now. */ continue; ospf_opaque_lsa_reoriginate_schedule ((void *) top, @@ -1504,7 +1498,7 @@ ospf_opaque_type11_lsa_originate (struct thread *t) static void ospf_opaque_lsa_reoriginate_resume (struct list *listtop, void *arg) { - struct listnode *node; + struct listnode *node, *nnode; struct opaque_info_per_type *oipt; struct ospf_opaque_functab *functab; @@ -1515,7 +1509,7 @@ ospf_opaque_lsa_reoriginate_resume (struct list *listtop, void *arg) * Pickup oipt entries those which in SUSPEND status, and give * them a chance to start re-origination now. */ - LIST_LOOP (listtop, oipt, node) + for (ALL_LIST_ELEMENTS (listtop, node, nnode, oipt)) { if (oipt->status != PROC_SUSPEND) continue; @@ -1889,7 +1883,7 @@ ospf_opaque_type10_lsa_reoriginate_timer (struct thread *t) { struct opaque_info_per_type *oipt; struct ospf_opaque_functab *functab; - struct listnode *node; + struct listnode *node, *nnode; struct ospf *top; struct ospf_area *area; struct ospf_interface *oi; @@ -1914,7 +1908,7 @@ ospf_opaque_type10_lsa_reoriginate_timer (struct thread *t) /* There must be at least one "opaque-capable, full-state" neighbor. */ n = 0; - LIST_LOOP (area->oiflist, oi, node) + for (ALL_LIST_ELEMENTS (area->oiflist, node, nnode, oi)) { if ((n = ospf_nbr_count_opaque_capable (oi)) > 0) break; @@ -2144,7 +2138,8 @@ ospf_opaque_adjust_lsreq (struct ospf_neighbor *nbr, struct list *lsas) struct ospf *top; struct ospf_area *area; struct ospf_interface *oi; - struct listnode *node1, *node2; + struct listnode *node1, *nnode1; + struct listnode *node2, *nnode2; struct ospf_lsa *lsa; if ((top = oi_to_top (nbr->oi)) == NULL) @@ -2161,11 +2156,8 @@ ospf_opaque_adjust_lsreq (struct ospf_neighbor *nbr, struct list *lsas) * Obviously, the latter would trigger miserable situations that repeat * installation and removal of unwanted LSAs indefinitely. */ - for (node1 = listhead (lsas); node1; nextnode (node1)) + for (ALL_LIST_ELEMENTS (lsas, node1, nnode1, lsa)) { - if ((lsa = getdata (node1)) == NULL) - continue; - /* Filter out unwanted LSAs. */ if (! IS_OPAQUE_LSA (lsa->data->type)) continue; @@ -2198,20 +2190,12 @@ ospf_opaque_adjust_lsreq (struct ospf_neighbor *nbr, struct list *lsas) break; case OSPF_OPAQUE_AREA_LSA: area = nbr->oi->area; - for (node2 = listhead (area->oiflist); node2; nextnode (node2)) - { - if ((oi = getdata (node2)) == NULL) - continue; - ospf_opaque_exclude_lsa_from_lsreq (oi->nbrs, nbr, lsa); - } + for (ALL_LIST_ELEMENTS (area->oiflist, node2, nnode2, oi)) + ospf_opaque_exclude_lsa_from_lsreq (oi->nbrs, nbr, lsa); break; case OSPF_OPAQUE_AS_LSA: - for (node2 = listhead (top->oiflist); node2; nextnode (node2)) - { - if ((oi = getdata (node2)) == NULL) - continue; - ospf_opaque_exclude_lsa_from_lsreq (oi->nbrs, nbr, lsa); - } + for (ALL_LIST_ELEMENTS (top->oiflist, node2, nnode2, oi)) + ospf_opaque_exclude_lsa_from_lsreq (oi->nbrs, nbr, lsa); break; default: break; @@ -2264,13 +2248,8 @@ ospf_opaque_self_originated_lsa_received (struct ospf_neighbor *nbr, before = IS_OPAQUE_LSA_ORIGINATION_BLOCKED (top->opaque); - for (node = listhead (lsas); node; node = next) + for (ALL_LIST_ELEMENTS (lsas, node, next, lsa)) { - next = node->next; - - if ((lsa = getdata (node)) == NULL) - continue; - listnode_delete (lsas, lsa); /* @@ -2314,14 +2293,14 @@ void ospf_opaque_ls_ack_received (struct ospf_neighbor *nbr, struct list *acks) { struct ospf *top; - struct listnode *node; + struct listnode *node, *nnode; struct ospf_lsa *lsa; char type9_lsa_rcv = 0, type10_lsa_rcv = 0, type11_lsa_rcv = 0; if ((top = oi_to_top (nbr->oi)) == NULL) goto out; - LIST_LOOP (acks, lsa, node) + for (ALL_LIST_ELEMENTS (acks, node, nnode, lsa)) { switch (lsa->data->type) { @@ -2372,7 +2351,7 @@ ospf_opaque_ls_ack_received (struct ospf_neighbor *nbr, struct list *acks) /* Ok, let's start origination of Opaque-LSAs. */ delay = OSPF_MIN_LS_INTERVAL; - LIST_LOOP (top->oiflist, oi, node) + for (ALL_LIST_ELEMENTS (top->oiflist, node, nnode, oi)) { if (! ospf_if_is_enable (oi) || ospf_nbr_count_opaque_capable (oi) == 0) @@ -2409,13 +2388,10 @@ ospf_opaque_type10_lsa_rxmt_nbr_check (struct ospf_area *area) struct ospf_interface *oi; unsigned long n = 0; - for (node = listhead (area->oiflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi)) { - if ((oi = getdata (node)) == NULL) - continue; - if (area->area_id.s_addr != OSPF_AREA_BACKBONE - && oi->type == OSPF_IFTYPE_VIRTUALLINK) + && oi->type == OSPF_IFTYPE_VIRTUALLINK) continue; n = ospf_opaque_nrxmt_self (oi->nbrs, OSPF_OPAQUE_AREA_LSA); @@ -2441,11 +2417,8 @@ ospf_opaque_type11_lsa_rxmt_nbr_check (struct ospf *top) struct ospf_interface *oi; unsigned long n = 0; - for (node = listhead (top->oiflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (top->oiflist, node, oi)) { - if ((oi = getdata (node)) == NULL) - continue; - switch (oi->type) { case OSPF_IFTYPE_VIRTUALLINK: diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index 4f18c04d3..8892f0e59 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -350,7 +350,7 @@ ospf_make_md5_digest (struct ospf_interface *oi, struct ospf_packet *op) auth_key = (char *) ""; else { - ck = getdata (OSPF_IF_PARAM (oi, auth_crypt)->tail); + ck = listgetdata (listtail(OSPF_IF_PARAM (oi, auth_crypt))); auth_key = (char *) ck->auth_key; } @@ -588,7 +588,7 @@ ospf_write (struct thread *thread) node = listhead (ospf->oi_write_q); assert (node); - oi = getdata (node); + oi = listgetdata (node); assert (oi); #ifdef WANT_OSPF_WRITE_FRAGMENT @@ -1579,12 +1579,11 @@ ospf_ls_upd_list_lsa (struct ospf_neighbor *nbr, struct stream *s, void ospf_upd_list_clean (struct list *lsas) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_lsa *lsa; - for (node = listhead (lsas); node; nextnode (node)) - if ((lsa = getdata (node)) != NULL) - ospf_lsa_discard (lsa); + for (ALL_LIST_ELEMENTS (lsas, node, nnode, lsa)) + ospf_lsa_discard (lsa); list_delete (lsas); } @@ -1599,7 +1598,7 @@ ospf_ls_upd (struct ip *iph, struct ospf_header *ospfh, #ifdef HAVE_OPAQUE_LSA struct list *mylsa_acks, *mylsa_upds; #endif /* HAVE_OPAQUE_LSA */ - struct listnode *node, *next; + struct listnode *node, *nnode; struct ospf_lsa *lsa = NULL; /* unsigned long ls_req_found = 0; */ @@ -1659,15 +1658,11 @@ ospf_ls_upd (struct ip *iph, struct ospf_header *ospfh, continue; } /* Process each LSA received in the one packet. */ - for (node = listhead (lsas); node; node = next) + for (ALL_LIST_ELEMENTS (lsas, node, nnode, lsa)) { struct ospf_lsa *ls_ret, *current; int ret = 1; - next = node->next; - - lsa = getdata (node); - if (IS_DEBUG_OSPF_NSSA) { char buf1[INET_ADDRSTRLEN]; @@ -1794,12 +1789,12 @@ ospf_ls_upd (struct ip *iph, struct ospf_header *ospfh, if(lsa->data->type == OSPF_NETWORK_LSA) { - struct listnode *oi_node; + struct listnode *oinode, *oinnode; + struct ospf_interface *out_if; int Flag = 0; - for(oi_node = listhead(oi->ospf->oiflist); oi_node; oi_node = nextnode(oi_node)) + for (ALL_LIST_ELEMENTS (oi->ospf->oiflist, oinode, oinnode, out_if)) { - struct ospf_interface *out_if = getdata(oi_node); if(out_if == NULL) break; @@ -2126,11 +2121,8 @@ ospf_associate_packet_vl (struct ospf *ospf, struct interface *ifp, iph->ip_dst)) == NULL) return NULL; - 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; - vl_area = ospf_area_lookup_by_area_id (ospf, vl_data->vl_area_id); if (!vl_area) continue; @@ -2210,7 +2202,7 @@ ospf_check_auth (struct ospf_interface *oi, struct stream *ibuf, ret = 0; break; case OSPF_AUTH_CRYPTOGRAPHIC: - if ((ck = getdata (OSPF_IF_PARAM (oi,auth_crypt)->tail)) == NULL) + if ((ck = listgetdata (listtail(OSPF_IF_PARAM (oi,auth_crypt)))) == NULL) { ret = 0; break; @@ -2565,7 +2557,7 @@ ospf_make_auth (struct ospf_interface *oi, struct ospf_header *ospfh) } else { - ck = getdata (OSPF_IF_PARAM (oi, auth_crypt)->tail); + ck = listgetdata (listtail(OSPF_IF_PARAM (oi, auth_crypt))); ospfh->u.crypt.zero = 0; ospfh->u.crypt.key_id = ck->key_id; ospfh->u.crypt.auth_data_len = OSPF_AUTH_MD5_SIZE; @@ -2869,8 +2861,8 @@ ospf_make_ls_upd (struct ospf_interface *oi, struct list *update, struct stream if (IS_DEBUG_OSPF_EVENT) zlog_debug ("ospf_make_ls_upd: List Iteration"); - lsa = getdata (node); - assert (lsa); + lsa = listgetdata (node); + assert (lsa->data); /* Will it fit? */ @@ -2915,9 +2907,9 @@ ospf_make_ls_ack (struct ospf_interface *oi, struct list *ack, struct stream *s) rm_list = list_new (); - for (node = listhead (ack); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ack, node, lsa)) { - lsa = getdata (node); + lsa = listgetdata (node); assert (lsa); if (length + delta > ospf_packet_max (oi)) @@ -2930,10 +2922,11 @@ ospf_make_ls_ack (struct ospf_interface *oi, struct list *ack, struct stream *s) } /* Remove LSA from LS-Ack list. */ - for (node = listhead (rm_list); node; nextnode (node)) + /* XXX: this loop should be removed and the list move done in previous + * loop + */ + for (ALL_LIST_ELEMENTS_RO (rm_list, node, lsa)) { - lsa = (struct ospf_lsa *) getdata (node); - listnode_delete (ack, lsa); ospf_lsa_unlock (lsa); } @@ -3251,9 +3244,7 @@ ospf_ls_upd_packet_new (struct list *update, struct ospf_interface *oi) size_t size; static char warned = 0; - ln = listhead (update); - lsa = getdata (ln); - assert (lsa); + lsa = listgetdata((ln = listhead (update))); assert (lsa->data); if ((OSPF_LS_UPD_MIN_SIZE + ntohs (lsa->data->length)) @@ -3391,9 +3382,10 @@ void ospf_ls_upd_send (struct ospf_neighbor *nbr, struct list *update, int flag) { struct ospf_interface *oi; + struct ospf_lsa *lsa; struct prefix_ipv4 p; struct route_node *rn; - struct listnode *n; + struct listnode *node; oi = nbr->oi; @@ -3428,8 +3420,11 @@ ospf_ls_upd_send (struct ospf_neighbor *nbr, struct list *update, int flag) if (rn->info == NULL) rn->info = list_new (); - for (n = listhead (update); n; nextnode (n)) - listnode_add (rn->info, ospf_lsa_lock (getdata (n))); + for (ALL_LIST_ELEMENTS_RO (update, node, lsa)) + { + ospf_lsa_lock (lsa); + listnode_add (rn->info, lsa); + } if (oi->t_ls_upd_event == NULL) oi->t_ls_upd_event = diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c index cf55bf0e0..ca39d9b26 100644 --- a/ospfd/ospf_route.c +++ b/ospfd/ospf_route.c @@ -158,10 +158,10 @@ ospf_route_match_same (struct route_table *rt, struct prefix_ipv4 *prefix, /* 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; @@ -279,7 +279,7 @@ ospf_intra_route_add (struct route_table *rt, struct vertex *v, struct prefix_ipv4 p; struct ospf_path *path; struct vertex_nexthop *nexthop; - struct listnode *nnode; + struct listnode *node, *nnode; p.family = AF_INET; p.prefix = v->id; @@ -306,9 +306,8 @@ ospf_intra_route_add (struct route_table *rt, struct vertex *v, { or->type = OSPF_DESTINATION_NETWORK; - LIST_LOOP (v->nexthop, nexthop, nnode) + for (ALL_LIST_ELEMENTS (v->nexthop, node, nnode, nexthop)) { - nexthop = getdata (nnode); path = ospf_path_new (); path->nexthop = nexthop->router; listnode_add (or->paths, path); @@ -677,11 +676,8 @@ ospf_route_table_dump (struct route_table *rt) BUFSIZ), ospf_path_type_str[or->path_type], or->cost); - for (pnode = listhead (or->paths); pnode; nextnode (pnode)) - { - path = getdata (pnode); - zlog_debug (" -> %s", inet_ntoa (path->nexthop)); - } + for (ALL_LIST_ELEMENTS_RO (or->paths, pnode, path)) + zlog_debug (" -> %s", inet_ntoa (path->nexthop)); } else zlog_debug ("R %s\t%s\t%s\t%d", @@ -698,9 +694,9 @@ void ospf_terminate () { struct ospf *ospf; - struct listnode *node; + struct listnode *node, *nnode; - LIST_LOOP (om->ospf, ospf, node) + for (ALL_LIST_ELEMENTS (om->ospf, node, nnode, ospf)) { if (ospf->new_table) ospf_route_delete (ospf->new_table); @@ -786,16 +782,13 @@ int ospf_path_exist (struct list *plist, struct in_addr nexthop, struct ospf_interface *oi) { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_path *path; - for (node = listhead (plist); node; nextnode (node)) - { - path = node->data; + for (ALL_LIST_ELEMENTS (plist, node, nnode, path)) + if (IPV4_ADDR_SAME (&path->nexthop, &nexthop) && path->oi == oi) + return 1; - if (IPV4_ADDR_SAME (&path->nexthop, &nexthop) && path->oi == oi) - return 1; - } return 0; } @@ -803,16 +796,14 @@ void ospf_route_copy_nexthops_from_vertex (struct ospf_route *to, struct vertex *v) { - struct listnode *nnode; + struct listnode *node; struct ospf_path *path; struct vertex_nexthop *nexthop; assert (to->paths); - for (nnode = listhead (v->nexthop); nnode; nextnode (nnode)) + for (ALL_LIST_ELEMENTS_RO (v->nexthop, node, nexthop)) { - nexthop = getdata (nnode); - if (nexthop->oi != NULL) { if (! ospf_path_exist (to->paths, nexthop->router, nexthop->oi)) @@ -830,15 +821,12 @@ struct ospf_path * ospf_path_lookup (struct list *plist, struct ospf_path *path) { struct listnode *node; + struct ospf_path *op; - for (node = listhead (plist); node; nextnode (node)) - { - struct ospf_path *op = node->data; - - if (IPV4_ADDR_SAME (&op->nexthop, &path->nexthop) && - IPV4_ADDR_SAME (&op->adv_router, &path->adv_router)) - return op; - } + for (ALL_LIST_ELEMENTS_RO (plist, node, op)) + if (IPV4_ADDR_SAME (&op->nexthop, &path->nexthop) && + IPV4_ADDR_SAME (&op->adv_router, &path->adv_router)) + return op; return NULL; } @@ -846,14 +834,15 @@ ospf_path_lookup (struct list *plist, struct ospf_path *path) void ospf_route_copy_nexthops (struct ospf_route *to, struct list *from) { - struct listnode *node; + struct listnode *node, *nnode; + struct ospf_path *path; assert (to->paths); - for (node = listhead (from); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (from, node, nnode, path)) /* The same routes are just discarded. */ - if (!ospf_path_lookup (to->paths, node->data)) - listnode_add (to->paths, ospf_path_dup (node->data)); + if (!ospf_path_lookup (to->paths, path)) + listnode_add (to->paths, ospf_path_dup (path)); } void @@ -931,7 +920,7 @@ ospf_prune_unreachable_routers (struct route_table *rtrs) { struct route_node *rn, *next; struct ospf_route *or; - struct listnode *node, *nnext; + struct listnode *node, *nnode; struct list *paths; if (IS_DEBUG_OSPF_EVENT) @@ -943,12 +932,8 @@ ospf_prune_unreachable_routers (struct route_table *rtrs) if ((paths = rn->info) == NULL) continue; - for (node = listhead (paths); node; node = nnext) + for (ALL_LIST_ELEMENTS (paths, node, nnode, or)) { - nnext = node->next; - - or = getdata (node); - if (listcount (or->paths) == 0) { if (IS_DEBUG_OSPF_EVENT) diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c index c1994ab42..4ed1fab89 100644 --- a/ospfd/ospf_snmp.c +++ b/ospfd/ospf_snmp.c @@ -499,13 +499,10 @@ ospf_admin_stat (struct ospf *ospf) if (ospf == NULL) return 0; - for (node = listhead (ospf->oiflist); node; nextnode (node)) - { - oi = getdata (node); + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) + if (oi && oi->address) + return 1; - if (oi && oi->address) - return 1; - } return 0; } @@ -624,16 +621,14 @@ ospf_area_lookup_next (struct ospf *ospf, struct in_addr *area_id, int first) node = listhead (ospf->areas); if (node) { - area = getdata (node); + area = listgetdata (node); *area_id = area->area_id; return area; } return NULL; } - for (node = listhead (ospf->areas); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) { - area = getdata (node); - if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr)) { *area_id = area->area_id; @@ -757,10 +752,8 @@ ospf_stub_area_lookup_next (struct in_addr *area_id, int first) if (ospf == NULL) return NULL; - for (node = listhead (ospf->areas); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) { - area = getdata (node); - if (area->external_routing == OSPF_AREA_STUB) { if (first) @@ -1401,14 +1394,14 @@ ospf_snmp_if_free (struct ospf_snmp_if *osif) void ospf_snmp_if_delete (struct interface *ifp) { - struct listnode *nn; + struct listnode *node, *nnode; struct ospf_snmp_if *osif; - LIST_LOOP (ospf_snmp_iflist, osif, nn) + for (ALL_LIST_ELEMENTS (ospf_snmp_iflist, node, nnode, osif)) { if (osif->ifp == ifp) { - list_delete_node (ospf_snmp_iflist, nn); + list_delete_node (ospf_snmp_iflist, node); ospf_snmp_if_free (osif); return; } @@ -1418,7 +1411,7 @@ ospf_snmp_if_delete (struct interface *ifp) void ospf_snmp_if_update (struct interface *ifp) { - struct listnode *nn; + struct listnode *node; struct listnode *pn; struct connected *ifc; struct prefix *p; @@ -1433,7 +1426,7 @@ ospf_snmp_if_update (struct interface *ifp) ifindex = 0; /* Lookup first IPv4 address entry. */ - LIST_LOOP (ifp->connected, ifc, nn) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) { if (CONNECTED_POINTOPOINT_HOST(ifc)) p = ifc->destination; @@ -1451,7 +1444,7 @@ ospf_snmp_if_update (struct interface *ifp) /* Add interface to the list. */ pn = NULL; - LIST_LOOP (ospf_snmp_iflist, osif, nn) + for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif)) { if (addr) { @@ -1464,7 +1457,7 @@ ospf_snmp_if_update (struct interface *ifp) if (osif->addr.s_addr != 0 || osif->ifindex > ifindex) break; } - pn = nn; + pn = node; } osif = ospf_snmp_if_new (); @@ -1480,10 +1473,10 @@ ospf_snmp_if_update (struct interface *ifp) struct interface * ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex) { - struct listnode *nn; + struct listnode *node; struct ospf_snmp_if *osif; - LIST_LOOP (ospf_snmp_iflist, osif, nn) + for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif)) { if (ifaddr->s_addr) { @@ -1511,7 +1504,7 @@ ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex, nn = listhead (ospf_snmp_iflist); if (nn) { - osif = getdata (nn); + osif = listgetdata (nn); *ifaddr = osif->addr; *ifindex = osif->ifindex; return osif->ifp; @@ -1519,7 +1512,7 @@ ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex, return NULL; } - LIST_LOOP (ospf_snmp_iflist, osif, nn) + for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, nn, osif)) { if (ifaddr->s_addr) { @@ -2051,12 +2044,12 @@ struct ospf_neighbor * ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr, unsigned int *ifindex) { - struct listnode *nn; + struct listnode *node, *nnode; struct ospf_interface *oi; struct ospf_neighbor *nbr; struct route_node *rn; - LIST_LOOP (ospf->oiflist, oi, nn) + for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) { for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) if ((nbr = rn->info) != NULL @@ -2086,7 +2079,8 @@ ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex, struct ospf *ospf = ospf; ospf = ospf_lookup (); - LIST_LOOP (ospf->oiflist, oi, nn) + + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, nn, oi)) { for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) if ((nbr = rn->info) != NULL diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index 9a4e8ffa2..c69fc7f11 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -125,13 +125,14 @@ ospf_vertex_new (struct ospf_lsa *lsa) void ospf_vertex_free (struct vertex *v) { - struct listnode *node; + struct listnode *node, *nnode; + struct vertex_nexthop *nh; list_delete (v->child); if (listcount (v->nexthop) > 0) - for (node = listhead (v->nexthop); node; nextnode (node)) - vertex_nexthop_free (node->data); + for (ALL_LIST_ELEMENTS (v->nexthop, node, nnode, nh)) + vertex_nexthop_free (nh); list_delete (v->nexthop); @@ -155,14 +156,14 @@ ospf_vertex_dump(const char *msg, struct vertex *v, if (print_nexthops) { - struct listnode *nnode; - for (nnode = listhead (v->nexthop); nnode; nextnode (nnode)) + struct listnode *node; + struct vertex_nexthop *nexthop; + + for (ALL_LIST_ELEMENTS_RO (v->nexthop, node, nexthop)) { char buf1[BUFSIZ]; char buf2[BUFSIZ]; - struct vertex_nexthop *nexthop; - nexthop = getdata (nnode); if (nexthop) { zlog_debug (" nexthop %s interface %s parent %s", @@ -179,12 +180,10 @@ ospf_vertex_dump(const char *msg, struct vertex *v, if (print_children) { struct listnode *cnode; - for (cnode = listhead (v->child); cnode; nextnode (cnode)) - { - struct vertex *cv = getdata (cnode); - if (cv) - ospf_vertex_dump(" child:", cv, 0, 0); - } + struct vertex *cv; + + for (ALL_LIST_ELEMENTS_RO (v->child, cnode, cv)) + ospf_vertex_dump(" child:", cv, 0, 0); } } @@ -196,10 +195,8 @@ ospf_vertex_add_parent (struct vertex *v) struct vertex_nexthop *nh; struct listnode *node; - for (node = listhead (v->nexthop); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (v->nexthop, node, nh)) { - nh = (struct vertex_nexthop *) getdata (node); - /* No need to add two links from the same parent. */ if (listnode_lookup (nh->parent->child, v) == NULL) listnode_add (nh->parent->child, v); @@ -296,10 +293,9 @@ ospf_nexthop_add_unique (struct vertex_nexthop *new, struct list *nexthop) int match; match = 0; - for (node = listhead (nexthop); node; nextnode (node)) - { - nh = node->data; + for (ALL_LIST_ELEMENTS_RO (nexthop, node, nh)) + { /* Compare the two entries. */ /* XXX * Comparing the parent preserves the shortest path tree @@ -324,12 +320,11 @@ ospf_nexthop_add_unique (struct vertex_nexthop *new, struct list *nexthop) void ospf_nexthop_merge (struct list *a, struct list *b) { - struct listnode *n; + struct listnode *node, *nnode; + struct vertex_nexthop *nh; - for (n = listhead (b); n; nextnode (n)) - { - ospf_nexthop_add_unique (n->data, a); - } + for (ALL_LIST_ELEMENTS (b, node, nnode, nh)) + ospf_nexthop_add_unique (nh, a); } #define ROUTER_LSA_MIN_SIZE 12 @@ -407,17 +402,14 @@ ospf_spf_consider_nexthop (struct list *nexthops, */ if (nexthops->head != NULL) { - hop = getdata (nexthops->head); + hop = listgetdata (nexthops->head); /* weed out hops with higher cost than the newhop */ if (hop->oi->output_cost > newhop->oi->output_cost) { /* delete the existing nexthops */ - for (ln = nexthops->head; ln; ln = nn) + for (ALL_LIST_ELEMENTS (nexthops, ln, nn, hop)) { - nn = ln->next; - hop = getdata (ln); - listnode_delete (nexthops, hop); vertex_nexthop_free (hop); } @@ -439,7 +431,7 @@ void ospf_nexthop_calculation (struct ospf_area *area, struct vertex *v, struct vertex *w) { - struct listnode *node; + struct listnode *node, *nnode; struct vertex_nexthop *nh, *x; struct ospf_interface *oi = NULL; struct router_lsa_link *l = NULL; @@ -473,11 +465,13 @@ ospf_nexthop_calculation (struct ospf_area *area, if (IS_DEBUG_OSPF_EVENT) { char buf1[BUFSIZ]; + char buf2[BUFSIZ]; + zlog_debug("ospf_nexthop_calculation(): considering link " "type %d link_id %s link_data %s", l->m[0].type, inet_ntop (AF_INET, &l->link_id, buf1, BUFSIZ), - inet_ntop (AF_INET, &l->link_data, buf1, BUFSIZ)); + inet_ntop (AF_INET, &l->link_data, buf2, BUFSIZ)); } if (l->m[0].type == LSA_LINK_TYPE_POINTOPOINT) @@ -580,9 +574,8 @@ ospf_nexthop_calculation (struct ospf_area *area, else if (v->type == OSPF_VERTEX_NETWORK) { /* See if any of V's parents are the root. */ - for (node = listhead (v->nexthop); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (v->nexthop, node, nnode, x)) { - x = (struct vertex_nexthop *) getdata (node); if (x->parent == area->spf) /* connects to root? */ { /* 16.1.1 para 5. ...the parent vertex is a network that @@ -615,9 +608,8 @@ ospf_nexthop_calculation (struct ospf_area *area, * destination simply inherits the set of next hops from the * parent. */ - for (node = listhead (v->nexthop); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (v->nexthop, node, nnode, nh)) { - nh = vertex_nexthop_dup (node->data); nh->parent = v; ospf_nexthop_add_unique (nh, w->nexthop); } @@ -843,20 +835,14 @@ ospf_spf_dump (struct vertex *v, int i) ip_masklen (lsa->mask)); } - for (nnode = listhead (v->nexthop); nnode; nextnode (nnode)) - { - nexthop = getdata (nnode); - if (IS_DEBUG_OSPF_EVENT) - zlog_debug (" nexthop %s", inet_ntoa (nexthop->router)); - } + if (IS_DEBUG_OSPF_EVENT) + for (ALL_LIST_ELEMENTS_RO (v->nexthop, nnode, nexthop)) + zlog_debug (" nexthop %s", inet_ntoa (nexthop->router)); i++; - for (cnode = listhead (v->child); cnode; nextnode (cnode)) - { - v = getdata (cnode); - ospf_spf_dump (v, i); - } + for (ALL_LIST_ELEMENTS_RO (v->child, cnode, v)) + ospf_spf_dump (v, i); } /* Second stage of SPF calculation. */ @@ -864,7 +850,7 @@ void ospf_spf_process_stubs (struct ospf_area *area, struct vertex *v, struct route_table *rt) { - struct listnode *cnode; + struct listnode *cnode, *cnnode; struct vertex *child; if (IS_DEBUG_OSPF_EVENT) @@ -903,10 +889,8 @@ ospf_spf_process_stubs (struct ospf_area *area, struct vertex *v, ospf_vertex_dump("ospf_process_stubs(): after examining links: ", v, 1, 1); - for (cnode = listhead (v->child); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS (v->child, cnode, cnnode, child)) { - child = getdata (cnode); - if (CHECK_FLAG (child->flags, OSPF_VERTEX_PROCESSED)) continue; @@ -921,7 +905,8 @@ ospf_rtrs_free (struct route_table *rtrs) { struct route_node *rn; struct list *or_list; - struct listnode *node; + struct ospf_route *or; + struct listnode *node, *nnode; if (IS_DEBUG_OSPF_EVENT) zlog_debug ("Route: Router Routing Table free"); @@ -929,8 +914,8 @@ ospf_rtrs_free (struct route_table *rtrs) for (rn = route_top (rtrs); rn; rn = route_next (rn)) if ((or_list = rn->info) != NULL) { - for (node = listhead (or_list); node; nextnode (node)) - ospf_route_free (node->data); + for (ALL_LIST_ELEMENTS (or_list, node, nnode, or)) + ospf_route_free (or); list_delete (or_list); @@ -958,10 +943,8 @@ ospf_rtrs_print (struct route_table *rtrs) for (rn = route_top (rtrs); rn; rn = route_next (rn)) if ((or_list = rn->info) != NULL) - for (ln = listhead (or_list); ln; nextnode (ln)) + for (ALL_LIST_ELEMENTS_RO (or_list, ln, or)) { - or = getdata (ln); - switch (or->path_type) { case OSPF_PATH_INTRA_AREA: @@ -982,9 +965,8 @@ ospf_rtrs_print (struct route_table *rtrs) break; } - for (pnode = listhead (or->paths); pnode; nextnode (pnode)) + for (ALL_LIST_ELEMENTS_RO (or->paths, pnode, path)) { - path = getdata (pnode); if (path->nexthop.s_addr == 0) { if (IS_DEBUG_OSPF_EVENT) @@ -1118,7 +1100,8 @@ ospf_spf_calculate_timer (struct thread *thread) { struct ospf *ospf = THREAD_ARG (thread); struct route_table *new_table, *new_rtrs; - struct listnode *node; + struct ospf_area *area; + struct listnode *node, *nnode; if (IS_DEBUG_OSPF_EVENT) zlog_debug ("SPF: Timer (SPF calculation expire)"); @@ -1132,8 +1115,8 @@ ospf_spf_calculate_timer (struct thread *thread) ospf_vl_unapprove (ospf); /* Calculate SPF for each area. */ - for (node = listhead (ospf->areas); node; node = nextnode (node)) - ospf_spf_calculate (node->data, new_table, new_rtrs); + for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) + ospf_spf_calculate (area, new_table, new_rtrs); ospf_vl_shut_unapproved (ospf); diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 0b04c969b..582dc4332 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -252,10 +252,10 @@ out: static struct mpls_te_link * lookup_linkparams_by_ifp (struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct mpls_te_link *lp; - LIST_LOOP (OspfMplsTE.iflist, lp, node) + for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) if (lp->ifp == ifp) return lp; @@ -269,7 +269,7 @@ lookup_linkparams_by_instance (struct ospf_lsa *lsa) struct mpls_te_link *lp; unsigned int key = GET_OPAQUE_ID (ntohl (lsa->data->id.s_addr)); - LIST_LOOP (OspfMplsTE.iflist, lp, node) + for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp)) if (lp->instance == key) return lp; @@ -282,11 +282,12 @@ ospf_mpls_te_foreach_area ( void (*func)(struct mpls_te_link *lp, enum sched_opcode), enum sched_opcode sched_opcode) { - struct listnode *node, *node2; + struct listnode *node, *nnode; + struct listnode *node2; struct mpls_te_link *lp; struct ospf_area *area; - LIST_LOOP (OspfMplsTE.iflist, lp, node) + for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) { if ((area = lp->area) == NULL) continue; @@ -296,14 +297,14 @@ ospf_mpls_te_foreach_area ( if (func != NULL) (* func)(lp, sched_opcode); - for (node2 = nextnode (node); node2; nextnode (node2)) - if ((lp = getdata (node2)) != NULL) + for (node2 = listnextnode (node); node2; node2 = listnextnode (node2)) + if ((lp = listgetdata (node2)) != NULL) if (lp->area != NULL) if (IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id)) lp->flags |= LPFLG_LOOKUP_DONE; } - LIST_LOOP (OspfMplsTE.iflist, lp, node) + for (ALL_LIST_ELEMENTS_RO (OspfMplsTE.iflist, node, lp)) if (lp->area != NULL) lp->flags &= ~LPFLG_LOOKUP_DONE; @@ -965,7 +966,7 @@ static int ospf_mpls_te_lsa_originate (void *arg) { struct ospf_area *area = (struct ospf_area *) arg; - struct listnode *node; + struct listnode *node, *nnode; struct mpls_te_link *lp; int rc = -1; @@ -976,10 +977,8 @@ ospf_mpls_te_lsa_originate (void *arg) goto out; } - for (node = listhead (OspfMplsTE.iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) { - if ((lp = getdata (node)) == NULL) - continue; if (lp->area == NULL) continue; if (! IPV4_ADDR_SAME (&lp->area->area_id, &area->area_id)) @@ -1471,7 +1470,7 @@ DEFUN (mpls_te, "Configure MPLS-TE parameters\n" "Enable the MPLS-TE functionality\n") { - struct listnode *node; + struct listnode *node, *nnode; struct mpls_te_link *lp; if (OspfMplsTE.status == enabled) @@ -1488,9 +1487,8 @@ DEFUN (mpls_te, * 1) MPLS-TE was disabled at startup time, but now become enabled. * 2) MPLS-TE was once enabled then disabled, and now enabled again. */ - for (node = listhead (OspfMplsTE.iflist); node; nextnode (node)) - if ((lp = getdata (node)) != NULL) - initialize_linkparams (lp); + for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) + initialize_linkparams (lp); ospf_mpls_te_foreach_area (ospf_mpls_te_lsa_schedule, REORIGINATE_PER_AREA); @@ -1510,7 +1508,7 @@ DEFUN (no_mpls_te, "Configure MPLS-TE parameters\n" "Disable the MPLS-TE functionality\n") { - struct listnode *node; + struct listnode *node, *nnode; struct mpls_te_link *lp; if (OspfMplsTE.status == disabled) @@ -1521,11 +1519,10 @@ DEFUN (no_mpls_te, OspfMplsTE.status = disabled; - for (node = listhead (OspfMplsTE.iflist); node; nextnode (node)) - if ((lp = getdata (node)) != NULL) - if (lp->area != NULL) - if (lp->flags & LPFLG_LSA_ENGAGED) - ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA); + for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) + if (lp->area != NULL) + if (lp->flags & LPFLG_LSA_ENGAGED) + ospf_mpls_te_lsa_schedule (lp, FLUSH_THIS_LSA); return CMD_SUCCESS; } @@ -1549,7 +1546,7 @@ DEFUN (mpls_te_router_addr, if (ntohs (ra->header.type) == 0 || ntohl (ra->value.s_addr) != ntohl (value.s_addr)) { - struct listnode *node; + struct listnode *node, *nnode; struct mpls_te_link *lp; int need_to_reoriginate = 0; @@ -1558,7 +1555,7 @@ DEFUN (mpls_te_router_addr, if (OspfMplsTE.status == disabled) goto out; - LIST_LOOP (OspfMplsTE.iflist, lp, node) + for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) { if (lp->area == NULL) continue; @@ -1569,8 +1566,8 @@ DEFUN (mpls_te_router_addr, break; } } - for (node = listhead (OspfMplsTE.iflist); node; nextnode (node)) - LIST_LOOP (OspfMplsTE.iflist, lp, node) + + for (ALL_LIST_ELEMENTS (OspfMplsTE.iflist, node, nnode, lp)) { if (lp->area == NULL) continue; @@ -1868,13 +1865,13 @@ DEFUN (show_mpls_te_link, "Interface name\n") { struct interface *ifp; - struct listnode *node; + struct listnode *node, *nnode; /* Show All Interfaces. */ if (argc == 0) { - LIST_LOOP (iflist, ifp, node) - show_mpls_te_link_sub (vty, ifp); + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) + show_mpls_te_link_sub (vty, ifp); } /* Interface name is specified. */ else diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index c0e1f6cea..55b33150c 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -2319,6 +2319,7 @@ DEFUN (ospf_auto_cost_reference_bandwidth, struct ospf *ospf = vty->index; u_int32_t refbw; struct listnode *node; + struct interface *ifp; refbw = strtol (argv[0], NULL, 10); if (refbw < 1 || refbw > 4294967) @@ -2335,8 +2336,8 @@ DEFUN (ospf_auto_cost_reference_bandwidth, vty_out (vty, "%% OSPF: Reference bandwidth is changed.%s", VTY_NEWLINE); vty_out (vty, " Please ensure reference bandwidth is consistent across all routers%s", VTY_NEWLINE); - for (node = listhead (om->iflist); node; nextnode (node)) - ospf_if_recalculate_output_cost (getdata (node)); + for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp)) + ospf_if_recalculate_output_cost (ifp); return CMD_SUCCESS; } @@ -2349,7 +2350,8 @@ DEFUN (no_ospf_auto_cost_reference_bandwidth, "Use reference bandwidth method to assign OSPF cost\n") { struct ospf *ospf = vty->index; - struct listnode *node; + struct listnode *node, *nnode; + struct interface *ifp; if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) return CMD_SUCCESS; @@ -2358,8 +2360,8 @@ DEFUN (no_ospf_auto_cost_reference_bandwidth, vty_out (vty, "%% OSPF: Reference bandwidth is changed.%s", VTY_NEWLINE); vty_out (vty, " Please ensure reference bandwidth is consistent across all routers%s", VTY_NEWLINE); - for (node = listhead (om->iflist); node; nextnode (node)) - ospf_if_recalculate_output_cost (getdata (node)); + for (ALL_LIST_ELEMENTS (om->iflist, node, nnode, ifp)) + ospf_if_recalculate_output_cost (ifp); return CMD_SUCCESS; } @@ -2499,7 +2501,7 @@ DEFUN (show_ip_ospf, IP_STR "OSPF information\n") { - struct listnode *node; + struct listnode *node, *nnode; struct ospf_area * area; struct ospf *ospf; @@ -2562,9 +2564,8 @@ DEFUN (show_ip_ospf, listcount (ospf->areas), VTY_NEWLINE, VTY_NEWLINE); /* Show each area status. */ - for (node = listhead (ospf->areas); node; nextnode (node)) - if ((area = getdata (node)) != NULL) - show_ip_ospf_area (vty, area); + for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) + show_ip_ospf_area (vty, area); return CMD_SUCCESS; } @@ -2708,8 +2709,8 @@ DEFUN (show_ip_ospf_interface, /* Show All Interfaces. */ if (argc == 0) - for (node = listhead (iflist); node; nextnode (node)) - show_ip_ospf_interface_sub (vty, ospf, node->data); + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + show_ip_ospf_interface_sub (vty, ospf, ifp); /* Interface name is specified. */ else { @@ -2764,6 +2765,7 @@ DEFUN (show_ip_ospf_neighbor, "Neighbor list\n") { struct ospf *ospf; + struct ospf_interface *oi; struct listnode *node; ospf = ospf_lookup (); @@ -2778,8 +2780,8 @@ DEFUN (show_ip_ospf_neighbor, "Time Address Interface RXmtL " "RqstL DBsmL%s", VTY_NEWLINE, VTY_NEWLINE); - for (node = listhead (ospf->oiflist); node; nextnode (node)) - show_ip_ospf_neighbor_sub (vty, getdata (node)); + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) + show_ip_ospf_neighbor_sub (vty, oi); return CMD_SUCCESS; } @@ -2795,6 +2797,7 @@ DEFUN (show_ip_ospf_neighbor_all, { struct ospf *ospf = vty->index; struct listnode *node; + struct ospf_interface *oi; if (ospf == NULL) { @@ -2807,20 +2810,16 @@ DEFUN (show_ip_ospf_neighbor_all, "Time Address Interface RXmtL " "RqstL DBsmL%s", VTY_NEWLINE, VTY_NEWLINE); - for (node = listhead (ospf->oiflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) { - struct ospf_interface *oi = getdata (node); struct listnode *nbr_node; + struct ospf_nbr_nbma *nbr_nbma; show_ip_ospf_neighbor_sub (vty, oi); /* print Down neighbor status */ - for (nbr_node = listhead (oi->nbr_nbma); nbr_node; nextnode (nbr_node)) + for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, nbr_node, nbr_nbma)) { - struct ospf_nbr_nbma *nbr_nbma; - - nbr_nbma = getdata (nbr_node); - if (nbr_nbma->nbr == NULL || nbr_nbma->nbr->state == NSM_Down) { @@ -2980,6 +2979,7 @@ DEFUN (show_ip_ospf_neighbor_id, struct ospf *ospf; struct listnode *node; struct ospf_neighbor *nbr; + struct ospf_interface *oi; struct in_addr router_id; int ret; @@ -2997,16 +2997,12 @@ DEFUN (show_ip_ospf_neighbor_id, return CMD_SUCCESS; } - for (node = listhead (ospf->oiflist); node; nextnode (node)) - { - struct ospf_interface *oi = getdata (node); - - if ((nbr = ospf_nbr_lookup_by_routerid (oi->nbrs, &router_id))) - { - show_ip_ospf_neighbor_detail_sub (vty, oi, nbr); - return CMD_SUCCESS; - } - } + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) + if ((nbr = ospf_nbr_lookup_by_routerid (oi->nbrs, &router_id))) + { + show_ip_ospf_neighbor_detail_sub (vty, oi, nbr); + return CMD_SUCCESS; + } /* Nothing to show. */ return CMD_SUCCESS; @@ -3022,6 +3018,7 @@ DEFUN (show_ip_ospf_neighbor_detail, "detail of all neighbors\n") { struct ospf *ospf; + struct ospf_interface *oi; struct listnode *node; ospf = ospf_lookup (); @@ -3031,9 +3028,8 @@ DEFUN (show_ip_ospf_neighbor_detail, return CMD_SUCCESS; } - for (node = listhead (ospf->oiflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) { - struct ospf_interface *oi = getdata (node); struct route_node *rn; struct ospf_neighbor *nbr; @@ -3059,6 +3055,7 @@ DEFUN (show_ip_ospf_neighbor_detail_all, { struct ospf *ospf; struct listnode *node; + struct ospf_interface *oi; ospf = ospf_lookup (); if (ospf == NULL) @@ -3067,11 +3064,11 @@ DEFUN (show_ip_ospf_neighbor_detail_all, return CMD_SUCCESS; } - for (node = listhead (ospf->oiflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) { - struct ospf_interface *oi = getdata (node); struct route_node *rn; struct ospf_neighbor *nbr; + struct ospf_nbr_nbma *nbr_nbma; for (rn = route_top (oi->nbrs); rn; rn = route_next (rn)) if ((nbr = rn->info)) @@ -3083,13 +3080,10 @@ DEFUN (show_ip_ospf_neighbor_detail_all, { struct listnode *nd; - for (nd = listhead (oi->nbr_nbma); nd; nextnode (nd)) - { - struct ospf_nbr_nbma *nbr_nbma = getdata (nd); - if (nbr_nbma->nbr == NULL - || nbr_nbma->nbr->state == NSM_Down) - show_ip_ospf_nbr_nbma_detail_sub (vty, oi, nbr_nbma); - } + for (ALL_LIST_ELEMENTS_RO (oi->nbr_nbma, nd, nbr_nbma)) + if (nbr_nbma->nbr == NULL + || nbr_nbma->nbr->state == NSM_Down) + show_ip_ospf_nbr_nbma_detail_sub (vty, oi, nbr_nbma); } } @@ -3609,7 +3603,8 @@ show_lsa_detail (struct vty *vty, struct ospf *ospf, int type, struct in_addr *id, struct in_addr *adv_router) { struct listnode *node; - + struct ospf_area *area; + switch (type) { case OSPF_AS_EXTERNAL_LSA: @@ -3622,9 +3617,8 @@ show_lsa_detail (struct vty *vty, struct ospf *ospf, int type, show_lsa_detail_proc (vty, AS_LSDB (ospf, type), id, adv_router); break; default: - for (node = listhead (ospf->areas); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) { - struct ospf_area *area = node->data; vty_out (vty, "%s %s (Area %s)%s%s", VTY_NEWLINE, show_database_desc[type], ospf_area_desc_string (area), VTY_NEWLINE, VTY_NEWLINE); @@ -3658,6 +3652,7 @@ show_lsa_detail_adv_router (struct vty *vty, struct ospf *ospf, int type, struct in_addr *adv_router) { struct listnode *node; + struct ospf_area *area; switch (type) { @@ -3672,9 +3667,8 @@ show_lsa_detail_adv_router (struct vty *vty, struct ospf *ospf, int type, adv_router); break; default: - for (node = listhead (ospf->areas); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) { - struct ospf_area *area = node->data; vty_out (vty, "%s %s (Area %s)%s%s", VTY_NEWLINE, show_database_desc[type], ospf_area_desc_string (area), VTY_NEWLINE, VTY_NEWLINE); @@ -3690,12 +3684,12 @@ show_ip_ospf_database_summary (struct vty *vty, struct ospf *ospf, int self) { struct ospf_lsa *lsa; struct route_node *rn; + struct ospf_area *area; struct listnode *node; int type; - for (node = listhead (ospf->areas); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) { - struct ospf_area *area = node->data; for (type = OSPF_MIN_LSA; type < OSPF_MAX_LSA; type++) { switch (type) @@ -3765,17 +3759,16 @@ show_ip_ospf_database_maxage (struct vty *vty, struct ospf *ospf) vty_out (vty, "%s MaxAge Link States:%s%s", VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE); - for (node = listhead (ospf->maxage_lsa); node; nextnode (node)) - if ((lsa = node->data) != NULL) - { - vty_out (vty, "Link type: %d%s", lsa->data->type, VTY_NEWLINE); - vty_out (vty, "Link State ID: %s%s", - inet_ntoa (lsa->data->id), VTY_NEWLINE); - vty_out (vty, "Advertising Router: %s%s", - inet_ntoa (lsa->data->adv_router), VTY_NEWLINE); - vty_out (vty, "LSA lock count: %d%s", lsa->lock, VTY_NEWLINE); - vty_out (vty, "%s", VTY_NEWLINE); - } + for (ALL_LIST_ELEMENTS_RO (ospf->maxage_lsa, node, lsa)) + { + vty_out (vty, "Link type: %d%s", lsa->data->type, VTY_NEWLINE); + vty_out (vty, "Link State ID: %s%s", + inet_ntoa (lsa->data->id), VTY_NEWLINE); + vty_out (vty, "Advertising Router: %s%s", + inet_ntoa (lsa->data->adv_router), VTY_NEWLINE); + vty_out (vty, "LSA lock count: %d%s", lsa->lock, VTY_NEWLINE); + vty_out (vty, "%s", VTY_NEWLINE); + } } #define OSPF_LSA_TYPE_NSSA_DESC "NSSA external link state\n" @@ -6509,7 +6502,7 @@ show_ip_ospf_route_network (struct vty *vty, struct route_table *rt) { struct route_node *rn; struct ospf_route *or; - struct listnode *pnode; + struct listnode *pnode, *pnnode; struct ospf_path *path; vty_out (vty, "============ OSPF network routing table ============%s", @@ -6540,7 +6533,7 @@ show_ip_ospf_route_network (struct vty *vty, struct route_table *rt) } if (or->type == OSPF_DESTINATION_NETWORK) - LIST_LOOP (or->paths, path, pnode) + for (ALL_LIST_ELEMENTS (or->paths, pnode, pnnode, path)) { if (path->oi != NULL) { @@ -6562,7 +6555,8 @@ show_ip_ospf_route_router (struct vty *vty, struct route_table *rtrs) { struct route_node *rn; struct ospf_route *or; - struct listnode *pn, *nn; + struct listnode *pnode; + struct listnode *node; struct ospf_path *path; vty_out (vty, "============ OSPF router routing table =============%s", @@ -6574,33 +6568,32 @@ show_ip_ospf_route_router (struct vty *vty, struct route_table *rtrs) vty_out (vty, "R %-15s ", inet_ntoa (rn->p.u.prefix4)); - for (nn = listhead ((struct list *) rn->info); nn; nextnode (nn)) - if ((or = getdata (nn)) != NULL) - { - if (flag++) - vty_out (vty, "%24s", ""); - - /* Show path. */ - vty_out (vty, "%s [%d] area: %s", - (or->path_type == OSPF_PATH_INTER_AREA ? "IA" : " "), - or->cost, inet_ntoa (or->u.std.area_id)); - /* Show flags. */ - vty_out (vty, "%s%s%s", - (or->u.std.flags & ROUTER_LSA_BORDER ? ", ABR" : ""), - (or->u.std.flags & ROUTER_LSA_EXTERNAL ? ", ASBR" : ""), - VTY_NEWLINE); - - LIST_LOOP (or->paths, path, pn) - { - if (path->nexthop.s_addr == 0) - vty_out (vty, "%24s directly attached to %s%s", - "", path->oi->ifp->name, VTY_NEWLINE); - else - vty_out (vty, "%24s via %s, %s%s", "", - inet_ntoa (path->nexthop), path->oi->ifp->name, - VTY_NEWLINE); - } - } + for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, or)) + { + if (flag++) + vty_out (vty, "%24s", ""); + + /* Show path. */ + vty_out (vty, "%s [%d] area: %s", + (or->path_type == OSPF_PATH_INTER_AREA ? "IA" : " "), + or->cost, inet_ntoa (or->u.std.area_id)); + /* Show flags. */ + vty_out (vty, "%s%s%s", + (or->u.std.flags & ROUTER_LSA_BORDER ? ", ABR" : ""), + (or->u.std.flags & ROUTER_LSA_EXTERNAL ? ", ASBR" : ""), + VTY_NEWLINE); + + for (ALL_LIST_ELEMENTS_RO (or->paths, pnode, path)) + { + if (path->nexthop.s_addr == 0) + vty_out (vty, "%24s directly attached to %s%s", + "", path->oi->ifp->name, VTY_NEWLINE); + else + vty_out (vty, "%24s via %s, %s%s", "", + inet_ntoa (path->nexthop), path->oi->ifp->name, + VTY_NEWLINE); + } + } } vty_out (vty, "%s", VTY_NEWLINE); } @@ -6610,7 +6603,7 @@ show_ip_ospf_route_external (struct vty *vty, struct route_table *rt) { struct route_node *rn; struct ospf_route *er; - struct listnode *pnode; + struct listnode *pnode, *pnnode; struct ospf_path *path; vty_out (vty, "============ OSPF external routing table ===========%s", @@ -6634,7 +6627,7 @@ show_ip_ospf_route_external (struct vty *vty, struct route_table *rt) break; } - LIST_LOOP (er->paths, path, pnode) + for (ALL_LIST_ELEMENTS (er->paths, pnode, pnnode, path)) { if (path->oi != NULL) { @@ -6770,10 +6763,8 @@ config_write_interface (struct vty *vty) struct route_node *rn = NULL; struct ospf_if_params *params; - for (n1 = listhead (iflist); n1; nextnode (n1)) + for (ALL_LIST_ELEMENTS_RO (iflist, n1, ifp)) { - ifp = getdata (n1); - if (memcmp (ifp->name, "VLINK", 5) == 0) continue; @@ -6849,9 +6840,8 @@ config_write_interface (struct vty *vty) } /* Cryptographic Authentication Key print. */ - for (n2 = listhead (params->auth_crypt); n2; nextnode (n2)) + for (ALL_LIST_ELEMENTS_RO (params->auth_crypt, n2, ck)) { - ck = getdata (n2); vty_out (vty, " ip ospf message-digest-key %d md5 %s", ck->key_id, ck->auth_key); if (params != IF_DEF_PARAMS (ifp)) @@ -6977,12 +6967,12 @@ int config_write_ospf_area (struct vty *vty, struct ospf *ospf) { struct listnode *node; + struct ospf_area *area; u_char buf[INET_ADDRSTRLEN]; /* Area configuration print. */ - for (node = listhead (ospf->areas); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) { - struct ospf_area *area = getdata (node); struct route_node *rn1; area_id2str ((char *) buf, INET_ADDRSTRLEN, area); @@ -7103,14 +7093,14 @@ int config_write_virtual_link (struct vty *vty, struct ospf *ospf) { struct listnode *node; + struct ospf_vl_data *vl_data; u_char buf[INET_ADDRSTRLEN]; /* Virtual-Link print */ - for (node = listhead (ospf->vlinks); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl_data)) { struct listnode *n2; struct crypt_key *ck; - struct ospf_vl_data *vl_data = getdata (node); struct ospf_interface *oi; if (vl_data != NULL) @@ -7148,14 +7138,13 @@ config_write_virtual_link (struct vty *vty, struct ospf *ospf) IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_simple, VTY_NEWLINE); /* md5 keys */ - for (n2 = listhead (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_crypt); n2; nextnode (n2)) - { - ck = getdata (n2); - vty_out (vty, " area %s virtual-link %s message-digest-key %d md5 %s%s", - buf, - inet_ntoa (vl_data->vl_peer), - ck->key_id, ck->auth_key, VTY_NEWLINE); - } + for (ALL_LIST_ELEMENTS_RO (IF_DEF_PARAMS (vl_data->vl_oi->ifp)->auth_crypt, + n2, ck)) + vty_out (vty, " area %s virtual-link %s" + " message-digest-key %d md5 %s%s", + buf, + inet_ntoa (vl_data->vl_peer), + ck->key_id, ck->auth_key, VTY_NEWLINE); } } @@ -7281,6 +7270,8 @@ int ospf_config_write (struct vty *vty) { struct ospf *ospf; + struct interface *ifp; + struct ospf_interface *oi; struct listnode *node; int write = 0; @@ -7329,28 +7320,17 @@ ospf_config_write (struct vty *vty) config_write_ospf_redistribute (vty, ospf); /* passive-interface print. */ - for (node = listhead (om->iflist); node; nextnode (node)) - { - struct interface *ifp = getdata (node); - - if (!ifp) - continue; - if (IF_DEF_PARAMS (ifp)->passive_interface == OSPF_IF_PASSIVE) - vty_out (vty, " passive-interface %s%s", - ifp->name, VTY_NEWLINE); - } - - for (node = listhead (ospf->oiflist); node; nextnode (node)) - { - struct ospf_interface *oi = getdata (node); - - if (OSPF_IF_PARAM_CONFIGURED (oi->params, passive_interface) && - oi->params->passive_interface == OSPF_IF_PASSIVE) - vty_out (vty, " passive-interface %s %s%s", - oi->ifp->name, - inet_ntoa (oi->address->u.prefix4), VTY_NEWLINE); - } - + for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp)) + if (IF_DEF_PARAMS (ifp)->passive_interface == OSPF_IF_PASSIVE) + vty_out (vty, " passive-interface %s%s", + ifp->name, VTY_NEWLINE); + + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) + if (OSPF_IF_PARAM_CONFIGURED (oi->params, passive_interface) && + oi->params->passive_interface == OSPF_IF_PASSIVE) + vty_out (vty, " passive-interface %s %s%s", + oi->ifp->name, + inet_ntoa (oi->address->u.prefix4), VTY_NEWLINE); /* Network area print. */ config_write_network_area (vty, ospf); diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 27299c599..e8513b396 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -359,10 +359,8 @@ ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or) stream_putc (s, or->paths->count); /* Nexthop, ifindex, distance and metric information. */ - for (node = listhead (or->paths); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (or->paths, node, path)) { - path = getdata (node); - if (path->nexthop.s_addr != INADDR_ANY) { stream_putc (s, ZEBRA_NEXTHOP_IPV4); @@ -409,7 +407,7 @@ ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or) struct zapi_ipv4 api; struct ospf_path *path; struct in_addr *nexthop; - struct listnode *node; + struct listnode *node, *nnode; if (zclient->redist[ZEBRA_ROUTE_OSPF]) { @@ -419,10 +417,8 @@ ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or) api.ifindex_num = 0; api.nexthop_num = 0; - for (node = listhead (or->paths); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (or->paths, node, nnode, path)) { - path = getdata (node); - if (path->nexthop.s_addr != INADDR_ANY) { SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); @@ -1027,21 +1023,20 @@ ospf_filter_update (struct access_list *access) } /* Update Area access-list. */ - for (node = listhead (ospf->areas); node; nextnode (node)) - if ((area = getdata (node)) != NULL) - { - if (EXPORT_NAME (area)) - { - EXPORT_LIST (area) = NULL; - abr_inv++; - } + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) + { + if (EXPORT_NAME (area)) + { + EXPORT_LIST (area) = NULL; + abr_inv++; + } - if (IMPORT_NAME (area)) - { - IMPORT_LIST (area) = NULL; - abr_inv++; - } - } + if (IMPORT_NAME (area)) + { + IMPORT_LIST (area) = NULL; + abr_inv++; + } + } /* Schedule ABR tasks -- this will be changed -- takada. */ if (IS_OSPF_ABR (ospf) && abr_inv) @@ -1077,27 +1072,26 @@ ospf_prefix_list_update (struct prefix_list *plist) } /* Update area filter-lists. */ - for (node = listhead (ospf->areas); node; nextnode (node)) - if ((area = getdata (node)) != NULL) - { - /* Update filter-list in. */ - if (PREFIX_NAME_IN (area)) - if (strcmp (PREFIX_NAME_IN (area), plist->name) == 0) - { - PREFIX_LIST_IN (area) = - prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area)); - abr_inv++; - } + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) + { + /* Update filter-list in. */ + if (PREFIX_NAME_IN (area)) + if (strcmp (PREFIX_NAME_IN (area), plist->name) == 0) + { + PREFIX_LIST_IN (area) = + prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area)); + abr_inv++; + } - /* Update filter-list out. */ - if (PREFIX_NAME_OUT (area)) - if (strcmp (PREFIX_NAME_OUT (area), plist->name) == 0) - { - PREFIX_LIST_IN (area) = - prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area)); - abr_inv++; - } - } + /* Update filter-list out. */ + if (PREFIX_NAME_OUT (area)) + if (strcmp (PREFIX_NAME_OUT (area), plist->name) == 0) + { + PREFIX_LIST_IN (area) = + prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area)); + abr_inv++; + } + } /* Schedule ABR task. */ if (IS_OSPF_ABR (ospf) && abr_inv) diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index a77fb4b16..cbc3d13d6 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -75,6 +75,7 @@ void ospf_router_id_update (struct ospf *ospf) { struct in_addr router_id, router_id_old; + struct ospf_interface *oi; struct listnode *node; if (IS_DEBUG_OSPF_EVENT) @@ -94,13 +95,9 @@ ospf_router_id_update (struct ospf *ospf) if (!IPV4_ADDR_SAME (&router_id_old, &router_id)) { - for (node = listhead (ospf->oiflist); node; nextnode (node)) - { - struct ospf_interface *oi = getdata (node); - - /* Update self-neighbor's router_id. */ - oi->nbr_self->router_id = router_id; - } + for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi)) + /* Update self-neighbor's router_id. */ + oi->nbr_self->router_id = router_id; /* If AS-external-LSA is queued, then flush those LSAs. */ if (router_id_old.s_addr == 0 && ospf->external_origin) @@ -228,7 +225,7 @@ ospf_lookup () if (listcount (om->ospf) == 0) return NULL; - return getdata (listhead (om->ospf)); + return listgetdata (listhead (om->ospf)); } void @@ -271,7 +268,10 @@ ospf_finish (struct ospf *ospf) struct route_node *rn; struct ospf_nbr_nbma *nbr_nbma; struct ospf_lsa *lsa; - struct listnode *node; + struct ospf_interface *oi; + struct ospf_area *area; + struct ospf_vl_data *vl_data; + struct listnode *node, *nnode; int i; #ifdef HAVE_OPAQUE_LSA @@ -282,33 +282,17 @@ ospf_finish (struct ospf *ospf) for (i = 0; i < ZEBRA_ROUTE_MAX; i++) ospf_redistribute_unset (ospf, i); - for (node = listhead (ospf->areas); node;) - { - struct ospf_area *area = getdata (node); - nextnode (node); - - ospf_remove_vls_through_area (ospf, area); - } + for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) + ospf_remove_vls_through_area (ospf, area); - for (node = listhead (ospf->vlinks); node; ) - { - struct ospf_vl_data *vl_data = node->data; - nextnode (node); - - ospf_vl_delete (ospf, vl_data); - } + for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data)) + ospf_vl_delete (ospf, vl_data); list_delete (ospf->vlinks); /* Reset interface. */ - for (node = listhead (ospf->oiflist); node;) - { - struct ospf_interface *oi = getdata (node); - nextnode (node); - - if (oi) - ospf_if_free (oi); - } + for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) + ospf_if_free (oi); /* Clear static neighbors */ for (rn = route_top (ospf->nbr_nbma); rn; rn = route_next (rn)) @@ -346,11 +330,8 @@ ospf_finish (struct ospf *ospf) } } - for (node = listhead (ospf->areas); node;) + for (ALL_LIST_ELEMENTS (ospf->areas, node, nnode, area)) { - struct ospf_area *area = getdata (node); - nextnode (node); - listnode_delete (ospf->areas, area); ospf_area_free (area); } @@ -382,8 +363,8 @@ ospf_finish (struct ospf *ospf) ospf_lsdb_delete_all (ospf->lsdb); ospf_lsdb_free (ospf->lsdb); - for (node = listhead (ospf->maxage_lsa); node; nextnode (node)) - ospf_lsa_unlock (getdata (node)); + for (ALL_LIST_ELEMENTS (ospf->maxage_lsa, node, nnode, lsa)) + ospf_lsa_unlock (lsa); list_delete (ospf->maxage_lsa); @@ -565,13 +546,9 @@ ospf_area_lookup_by_area_id (struct ospf *ospf, struct in_addr area_id) struct ospf_area *area; struct listnode *node; - for (node = listhead (ospf->areas); node; nextnode (node)) - { - area = getdata (node); - - if (IPV4_ADDR_SAME (&area->area_id, &area_id)) - return area; - } + for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) + if (IPV4_ADDR_SAME (&area->area_id, &area_id)) + return area; return NULL; } @@ -728,6 +705,7 @@ void ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area) { struct interface *ifp; + struct connected *co; struct listnode *node; /* Schedule Router ID Update. */ @@ -739,21 +717,17 @@ ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area) } /* Get target interface. */ - for (node = listhead (om->iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (om->iflist, node, ifp)) { - struct listnode *cn; + struct listnode *cnode; - if ((ifp = getdata (node)) == NULL) - continue; - if (memcmp (ifp->name, "VLINK", 5) == 0) continue; /* if interface prefix is match specified prefix, then create socket and join multicast group. */ - for (cn = listhead (ifp->connected); cn; nextnode (cn)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, co)) { - struct connected *co = getdata (cn); struct prefix *addr; if (CHECK_FLAG(co->flags,ZEBRA_IFA_SECONDARY)) @@ -768,7 +742,7 @@ ospf_network_run (struct ospf *ospf, struct prefix *p, struct ospf_area *area) && ! ospf_if_is_configured (ospf, &(addr->u.prefix4)) && ospf_network_match_iface(co,p)) { - struct ospf_interface *oi; + struct ospf_interface *oi; oi = ospf_if_new (ospf, ifp, co->address); oi->connected = co; @@ -829,7 +803,7 @@ void ospf_ls_upd_queue_empty (struct ospf_interface *oi) { struct route_node *rn; - struct listnode *node; + struct listnode *node, *nnode; struct list *lst; struct ospf_lsa *lsa; @@ -838,9 +812,8 @@ ospf_ls_upd_queue_empty (struct ospf_interface *oi) rn = route_next (rn)) if ((lst = (struct list *) rn->info)) { - for (node = listhead (lst); node; nextnode (node)) - if ((lsa = getdata (node))) - ospf_lsa_unlock (lsa); + for (ALL_LIST_ELEMENTS (lst, node, nnode, lsa)) + ospf_lsa_unlock (lsa); list_free (lst); rn->info = NULL; } @@ -857,10 +830,10 @@ void ospf_if_update (struct ospf *ospf) { struct route_node *rn; - struct listnode *node; - struct listnode *next; + struct listnode *node, *nnode; struct ospf_network *network; struct ospf_area *area; + struct ospf_interface *oi; if (ospf != NULL) { @@ -874,14 +847,11 @@ ospf_if_update (struct ospf *ospf) } /* Find interfaces that not configured already. */ - for (node = listhead (ospf->oiflist); node; node = next) + for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi)) { int found = 0; - struct ospf_interface *oi = getdata (node); struct connected *co = oi->connected; - next = nextnode (node); - if (oi->type == OSPF_IFTYPE_VIRTUALLINK) continue; @@ -916,16 +886,12 @@ ospf_if_update (struct ospf *ospf) void ospf_remove_vls_through_area (struct ospf *ospf, struct ospf_area *area) { - struct listnode *node, *next; + struct listnode *node, *nnode; struct ospf_vl_data *vl_data; - for (node = listhead (ospf->vlinks); node; node = next) - { - next = node->next; - if ((vl_data = getdata (node)) != NULL) - if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) - ospf_vl_delete (ospf, vl_data); - } + for (ALL_LIST_ELEMENTS (ospf->vlinks, node, nnode, vl_data)) + if (IPV4_ADDR_SAME (&vl_data->vl_area_id, &area->area_id)) + ospf_vl_delete (ospf, vl_data); } @@ -960,40 +926,35 @@ ospf_area_type_set (struct ospf_area *area, int type) switch (area->external_routing) { case OSPF_AREA_DEFAULT: - for (node = listhead (area->oiflist); node; nextnode (node)) - if ((oi = getdata (node)) != NULL) - if (oi->nbr_self != NULL) - { - UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); - SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); - } + for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi)) + if (oi->nbr_self != NULL) + { + UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); + SET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); + } break; case OSPF_AREA_STUB: - for (node = listhead (area->oiflist); node; nextnode (node)) - if ((oi = getdata (node)) != NULL) - if (oi->nbr_self != NULL) - { - if (IS_DEBUG_OSPF_EVENT) - zlog_debug ("setting options on %s accordingly", IF_NAME (oi)); - UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); - UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); - if (IS_DEBUG_OSPF_EVENT) - zlog_debug ("options set on %s: %x", - IF_NAME (oi), OPTIONS (oi)); - } + for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi)) + if (oi->nbr_self != NULL) + { + if (IS_DEBUG_OSPF_EVENT) + zlog_debug ("setting options on %s accordingly", IF_NAME (oi)); + UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); + UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); + if (IS_DEBUG_OSPF_EVENT) + zlog_debug ("options set on %s: %x", + IF_NAME (oi), OPTIONS (oi)); + } break; case OSPF_AREA_NSSA: - for (node = listhead (area->oiflist); node; nextnode (node)) - if ((oi = getdata (node)) != NULL) - if (oi->nbr_self != NULL) - { - if (IS_DEBUG_OSPF_EVENT) - zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi)); - UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); - SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); - if (IS_DEBUG_OSPF_EVENT) - zlog_debug ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi)); - } + for (ALL_LIST_ELEMENTS_RO (area->oiflist, node, oi)) + if (oi->nbr_self != NULL) + { + zlog_debug ("setting nssa options on %s accordingly", IF_NAME (oi)); + UNSET_FLAG (oi->nbr_self->options, OSPF_OPTION_E); + SET_FLAG (oi->nbr_self->options, OSPF_OPTION_NP); + zlog_debug ("options set on %s: %x", IF_NAME (oi), OPTIONS (oi)); + } break; default: break; @@ -1036,12 +997,9 @@ ospf_area_vlink_count (struct ospf *ospf, struct ospf_area *area) struct listnode *node; int count = 0; - for (node = listhead (ospf->vlinks); node; nextnode (node)) - { - vl = getdata (node); - if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id)) - count++; - } + for (ALL_LIST_ELEMENTS_RO (ospf->vlinks, node, vl)) + if (IPV4_ADDR_SAME (&vl->vl_area_id, &area->area_id)) + count++; return count; } @@ -1474,10 +1432,8 @@ ospf_nbr_nbma_lookup_next (struct ospf *ospf, struct in_addr *addr, int first) return NULL; #if 0 - for (node = listhead (ospf->nbr_nbma); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ospf->nbr_nbma, node, nbr_nbma)) { - nbr_nbma = getdata (node); - if (first) { *addr = nbr_nbma->addr; @@ -1516,9 +1472,8 @@ ospf_nbr_nbma_set (struct ospf *ospf, struct in_addr nbr_addr) rn = route_node_get (ospf->nbr_nbma, (struct prefix *)&p); rn->info = nbr_nbma; - 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_NBMA) if (prefix_match (oi->address, (struct prefix *)&p)) { diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index f58fb3371..da73724a6 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -222,17 +222,14 @@ rip_request_interface_send (struct interface *ifp, u_char version) /* RIPv1 and non multicast interface. */ if (if_is_pointopoint (ifp) || if_is_broadcast (ifp)) { - struct listnode *cnode; + struct listnode *cnode, *cnnode; + struct connected *connected; if (IS_RIP_DEBUG_EVENT) zlog_debug ("broadcast request to %s", ifp->name); - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS (ifp->connected, cnode, cnnode, connected)) { - struct connected *connected; - - connected = getdata (cnode); - if (connected->address->family == AF_INET) { memset (&to, 0, sizeof (struct sockaddr_in)); @@ -321,20 +318,19 @@ int rip_multicast_join (struct interface *ifp, int sock) { struct listnode *cnode; + struct connected *ifc; if (if_is_operative (ifp) && if_is_multicast (ifp)) { if (IS_RIP_DEBUG_EVENT) zlog_debug ("multicast join at %s", ifp->name); - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, ifc)) { struct prefix_ipv4 *p; - struct connected *connected; struct in_addr group; - connected = getdata (cnode); - p = (struct prefix_ipv4 *) connected->address; + p = (struct prefix_ipv4 *) ifc->address; if (p->family != AF_INET) continue; @@ -354,21 +350,20 @@ void rip_multicast_leave (struct interface *ifp, int sock) { struct listnode *cnode; + struct connected *connected; if (if_is_up (ifp) && if_is_multicast (ifp)) { if (IS_RIP_DEBUG_EVENT) zlog_debug ("multicast leave from %s", ifp->name); - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { struct prefix_ipv4 *p; - struct connected *connected; struct in_addr group; - - connected = getdata (cnode); + p = (struct prefix_ipv4 *) connected->address; - + if (p->family != AF_INET) continue; @@ -387,18 +382,15 @@ rip_if_ipv4_address_check (struct interface *ifp) struct connected *connected; int count = 0; - for (nn = listhead (ifp->connected); nn; nextnode (nn)) - if ((connected = getdata (nn)) != NULL) - { - struct prefix *p; + for (ALL_LIST_ELEMENTS_RO (ifp->connected, nn, connected)) + { + struct prefix *p; - p = connected->address; + p = connected->address; - if (p->family == AF_INET) - { - count++; - } - } + if (p->family == AF_INET) + count++; + } return count; } @@ -411,20 +403,17 @@ int if_check_address (struct in_addr addr) { struct listnode *node; - - for (node = listhead (iflist); node; nextnode (node)) + struct interface *ifp; + + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { struct listnode *cnode; - struct interface *ifp; - - ifp = getdata (node); + struct connected *connected; - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { - struct connected *connected; struct prefix_ipv4 *p; - connected = getdata (cnode); p = (struct prefix_ipv4 *) connected->address; if (p->family != AF_INET) @@ -443,6 +432,7 @@ if_valid_neighbor (struct in_addr addr) { struct listnode *node; struct connected *connected = NULL; + struct interface *ifp; struct prefix_ipv4 *p; struct prefix_ipv4 pa; @@ -450,17 +440,12 @@ if_valid_neighbor (struct in_addr addr) pa.prefix = addr; pa.prefixlen = IPV4_MAX_PREFIXLEN; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { struct listnode *cnode; - struct interface *ifp; - - ifp = getdata (node); - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected)) { - connected = getdata (cnode); - if (if_is_pointopoint (ifp)) { p = (struct prefix_ipv4 *) connected->address; @@ -610,9 +595,8 @@ rip_interface_clean () struct interface *ifp; struct rip_interface *ri; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); ri = ifp->info; ri->enable_network = 0; @@ -634,9 +618,8 @@ rip_interface_reset () struct interface *ifp; struct rip_interface *ri; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); ri = ifp->info; ri->enable_network = 0; @@ -741,13 +724,10 @@ void rip_if_down_all () { struct interface *ifp; - struct listnode *node; + struct listnode *node, *nnode; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - rip_if_down (ifp); - } + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) + rip_if_down (ifp); } static void @@ -875,33 +855,32 @@ rip_interface_address_delete (int command, struct zclient *zclient, int rip_enable_network_lookup_if (struct interface *ifp) { - struct listnode *nn; + struct listnode *node, *nnode; struct connected *connected; struct prefix_ipv4 address; - for (nn = listhead (ifp->connected); nn; nextnode (nn)) - if ((connected = getdata (nn)) != NULL) - { - struct prefix *p; - struct route_node *node; + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected)) + { + struct prefix *p; + struct route_node *node; - p = connected->address; + p = connected->address; - if (p->family == AF_INET) - { - address.family = AF_INET; - address.prefix = p->u.prefix4; - address.prefixlen = IPV4_MAX_BITLEN; - - node = route_node_match (rip_enable_network, - (struct prefix *)&address); - if (node) - { - route_unlock_node (node); - return 1; - } - } - } + if (p->family == AF_INET) + { + address.family = AF_INET; + address.prefix = p->u.prefix4; + address.prefixlen = IPV4_MAX_BITLEN; + + node = route_node_match (rip_enable_network, + (struct prefix *)&address); + if (node) + { + route_unlock_node (node); + return 1; + } + } + } return -1; } @@ -1065,39 +1044,38 @@ int rip_redistribute_check (int); void rip_connect_set (struct interface *ifp, int set) { - struct listnode *nn; + struct listnode *node, *nnode; struct connected *connected; struct prefix_ipv4 address; - for (nn = listhead (ifp->connected); nn; nextnode (nn)) - if ((connected = getdata (nn)) != NULL) - { - struct prefix *p; - p = connected->address; - - if (p->family != AF_INET) - continue; - - address.family = AF_INET; - address.prefix = p->u.prefix4; - address.prefixlen = p->prefixlen; - apply_mask_ipv4 (&address); - - if (set) { - /* Check once more wether this prefix is within a "network IF_OR_PREF" one */ - if ((rip_enable_if_lookup(connected->ifp->name) >= 0) || - (rip_enable_network_lookup2(connected) >= 0)) - rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, - &address, connected->ifp->ifindex, NULL); - } else - { - rip_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, - &address, connected->ifp->ifindex); - if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT)) - rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_REDISTRIBUTE, - &address, connected->ifp->ifindex, NULL); - } - } + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected)) + { + struct prefix *p; + p = connected->address; + + if (p->family != AF_INET) + continue; + + address.family = AF_INET; + address.prefix = p->u.prefix4; + address.prefixlen = p->prefixlen; + apply_mask_ipv4 (&address); + + if (set) { + /* Check once more wether this prefix is within a "network IF_OR_PREF" one */ + if ((rip_enable_if_lookup(connected->ifp->name) >= 0) || + (rip_enable_network_lookup2(connected) >= 0)) + rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, + &address, connected->ifp->ifindex, NULL); + } else + { + rip_redistribute_delete (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_INTERFACE, + &address, connected->ifp->ifindex); + if (rip_redistribute_check (ZEBRA_ROUTE_CONNECT)) + rip_redistribute_add (ZEBRA_ROUTE_CONNECT, RIP_ROUTE_REDISTRIBUTE, + &address, connected->ifp->ifindex, NULL); + } + } } /* Update interface status. */ @@ -1169,14 +1147,11 @@ void rip_enable_apply_all () { struct interface *ifp; - struct listnode *node; + struct listnode *node, *nnode; /* Check each interface. */ - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - rip_enable_apply (ifp); - } + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) + rip_enable_apply (ifp); } int @@ -1294,13 +1269,10 @@ void rip_passive_interface_apply_all () { struct interface *ifp; - struct listnode *node; + struct listnode *node, *nnode; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - rip_passive_interface_apply (ifp); - } + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) + rip_passive_interface_apply (ifp); } /* Passive interface. */ @@ -2021,11 +1993,10 @@ rip_interface_config_write (struct vty *vty) struct listnode *node; struct interface *ifp; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { struct rip_interface *ri; - ifp = getdata (node); ri = ifp->info; /* Do not display the interface if there is no diff --git a/ripd/rip_offset.c b/ripd/rip_offset.c index 6899c4d17..61f137604 100644 --- a/ripd/rip_offset.c +++ b/ripd/rip_offset.c @@ -78,9 +78,9 @@ struct rip_offset_list * rip_offset_list_lookup (const char *ifname) { struct rip_offset_list *offset; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (rip_offset_list_master, offset, nn) + for (ALL_LIST_ELEMENTS (rip_offset_list_master, node, nnode, offset)) { if (strcmp_safe (offset->ifname, ifname) == 0) return offset; @@ -378,10 +378,10 @@ rip_offset_clean () int config_write_rip_offset_list (struct vty *vty) { - struct listnode *nn; + struct listnode *node, *nnode; struct rip_offset_list *offset; - LIST_LOOP (rip_offset_list_master, offset, nn) + for (ALL_LIST_ELEMENTS (rip_offset_list_master, node, nnode, offset)) { if (! offset->ifname) { diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c index 20c2da738..51df568ad 100644 --- a/ripd/rip_peer.c +++ b/ripd/rip_peer.c @@ -53,9 +53,9 @@ struct rip_peer * rip_peer_lookup (struct in_addr *addr) { struct rip_peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (peer_list, peer, nn) + for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) { if (IPV4_ADDR_SAME (&peer->addr, addr)) return peer; @@ -67,9 +67,9 @@ struct rip_peer * rip_peer_lookup_next (struct in_addr *addr) { struct rip_peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (peer_list, peer, nn) + for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) { if (htonl (peer->addr.s_addr) > htonl (addr->s_addr)) return peer; @@ -183,11 +183,11 @@ void rip_peer_display (struct vty *vty) { struct rip_peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; #define RIP_UPTIME_LEN 25 char timebuf[RIP_UPTIME_LEN]; - LIST_LOOP (peer_list, peer, nn) + for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) { vty_out (vty, " %-16s %9d %9d %9d %s%s", inet_ntoa (peer->addr), peer->recv_badpackets, peer->recv_badroutes, diff --git a/ripd/ripd.c b/ripd/ripd.c index afdcd8321..3dd91dae9 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -365,13 +365,10 @@ rip_nexthop_check (struct in_addr *addr) /* If nexthop address matches local configured address then it is invalid nexthop. */ - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); - - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, ifc)) { - ifc = getdata (cnode); p = ifc->address; if (p->family == AF_INET @@ -2440,7 +2437,8 @@ rip_update_interface (struct connected *ifc, u_char version, int route_type) void rip_update_process (int route_type) { - struct listnode *node, *ifnode; + struct listnode *node; + struct listnode *ifnode, *ifnnode; struct connected *connected; struct interface *ifp; struct rip_interface *ri; @@ -2449,10 +2447,8 @@ rip_update_process (int route_type) struct prefix_ipv4 *p; /* Send RIP update to each interface. */ - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); - if (if_is_loopback (ifp)) continue; @@ -2480,8 +2476,7 @@ rip_update_process (int route_type) } /* send update on each connected network */ - - LIST_LOOP(ifp->connected, connected, ifnode) + for (ALL_LIST_ELEMENTS (ifp->connected, ifnode, ifnnode, connected)) { struct prefix_ipv4 *ifaddr; int done = 0; @@ -2716,7 +2711,7 @@ rip_request_send (struct sockaddr_in *to, struct interface *ifp, { struct rte *rte; struct rip_packet rip_packet; - struct listnode *node; + struct listnode *node, *nnode; memset (&rip_packet, 0, sizeof (rip_packet)); @@ -2740,7 +2735,7 @@ rip_request_send (struct sockaddr_in *to, struct interface *ifp, } /* send request on each connected network */ - LIST_LOOP(ifp->connected, connected, node) + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected)) { struct prefix_ipv4 *p; @@ -3533,9 +3528,8 @@ DEFUN (show_ip_rip_status, vty_out (vty, " Interface Send Recv Key-chain%s", VTY_NEWLINE); - for (node = listhead (iflist); node; node = nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); ri = ifp->info; if (ri->enable_network || ri->enable_interface) @@ -3563,9 +3557,8 @@ DEFUN (show_ip_rip_status, { int found_passive = 0; - for (node = listhead (iflist); node; node = nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); ri = ifp->info; if ((ri->enable_network || ri->enable_interface) && ri->passive) @@ -3761,13 +3754,10 @@ void rip_distribute_update_all (struct prefix_list *notused) { struct interface *ifp; - struct listnode *node; + struct listnode *node, *nnode; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - rip_distribute_update_interface (ifp); - } + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) + rip_distribute_update_interface (ifp); } /* ARGSUSED */ void @@ -3955,13 +3945,10 @@ void rip_routemap_update (const char *notused) { struct interface *ifp; - struct listnode *node; + struct listnode *node, *nnode; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - rip_if_rmap_update_interface (ifp); - } + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) + rip_if_rmap_update_interface (ifp); rip_routemap_update_redistribute (); } diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 6d5d468c0..d2fa3d608 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -144,8 +144,8 @@ ripng_if_ipv6_lladdress_check (struct interface *ifp) struct connected *connected; int count = 0; - for (nn = listhead (ifp->connected); nn; nextnode (nn)) - if ((connected = getdata (nn)) != NULL) { + for (ALL_LIST_ELEMENTS_RO (ifp->connected, nn, connected)) + { struct prefix *p; p = connected->address; @@ -166,12 +166,10 @@ ripng_check_max_mtu () unsigned int mtu; mtu = 0; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - if (mtu < ifp->mtu6) - mtu = ifp->mtu6; - } + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + if (mtu < ifp->mtu6) + mtu = ifp->mtu6; + return mtu; } @@ -339,13 +337,12 @@ ripng_interface_delete (int command, struct zclient *zclient, void ripng_interface_clean () { - struct listnode *node; + struct listnode *node, *nnode; struct interface *ifp; struct ripng_interface *ri; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) { - ifp = getdata (node); ri = ifp->info; ri->enable_network = 0; @@ -366,9 +363,8 @@ ripng_interface_reset () { struct interface *ifp; struct ripng_interface *ri; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); ri = ifp->info; ri->enable_network = 0; @@ -535,33 +531,32 @@ struct route_table *ripng_enable_network; int ripng_enable_network_lookup_if (struct interface *ifp) { - struct listnode *listnode; + struct listnode *node; struct connected *connected; struct prefix_ipv6 address; - for (listnode = listhead (ifp->connected); listnode; nextnode (listnode)) - if ((connected = getdata (listnode)) != NULL) - { - struct prefix *p; - struct route_node *node; - - p = connected->address; + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) + { + struct prefix *p; + struct route_node *node; - if (p->family == AF_INET6) - { - address.family = AF_INET6; - address.prefix = p->u.prefix6; - address.prefixlen = IPV6_MAX_BITLEN; + p = connected->address; - node = route_node_match (ripng_enable_network, - (struct prefix *)&address); - if (node) - { - route_unlock_node (node); - return 1; - } - } - } + if (p->family == AF_INET6) + { + address.family = AF_INET6; + address.prefix = p->u.prefix6; + address.prefixlen = IPV6_MAX_BITLEN; + + node = route_node_match (ripng_enable_network, + (struct prefix *)&address); + if (node) + { + route_unlock_node (node); + return 1; + } + } + } return -1; } @@ -722,12 +717,12 @@ int ripng_redistribute_check (int); void ripng_connect_set (struct interface *ifp, int set) { - struct listnode *nn; + struct listnode *node, *nnode; struct connected *connected; struct prefix_ipv6 address; - for (nn = listhead (ifp->connected); nn; nextnode (nn)) - if ((connected = getdata (nn)) != NULL) { + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, connected)) + { struct prefix *p; p = connected->address; @@ -829,11 +824,8 @@ ripng_enable_apply_all () struct interface *ifp; struct listnode *node; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - ripng_enable_apply (ifp); - } + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + ripng_enable_apply (ifp); } /* Clear all network and neighbor configuration */ @@ -897,11 +889,8 @@ ripng_passive_interface_apply_all (void) struct interface *ifp; struct listnode *node; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - ripng_passive_interface_apply (ifp); - } + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + ripng_passive_interface_apply (ifp); } /* Passive interface. */ @@ -1171,9 +1160,8 @@ interface_config_write (struct vty *vty) struct ripng_interface *ri; int write = 0; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); ri = ifp->info; /* Do not display the interface if there is no diff --git a/ripngd/ripng_nexthop.c b/ripngd/ripng_nexthop.c index 1c1829d49..05f190e27 100644 --- a/ripngd/ripng_nexthop.c +++ b/ripngd/ripng_nexthop.c @@ -117,7 +117,7 @@ ripng_rte_send(struct list *ripng_rte_list, struct interface *ifp, struct sockaddr_in6 *to) { struct ripng_rte_data *data; - struct listnode * nn; + struct listnode *node, *nnode; struct in6_addr last_nexthop; struct in6_addr myself_nexthop; @@ -154,8 +154,7 @@ ripng_rte_send(struct list *ripng_rte_list, struct interface *ifp, sizeof (struct ripng_packet) + sizeof (struct rte)) / sizeof (struct rte); - LIST_LOOP(ripng_rte_list, data, nn) { - + for (ALL_LIST_ELEMENTS (ripng_rte_list, node, nnode, data)) { /* (2.1) Next hop support */ if (!IPV6_ADDR_SAME(&last_nexthop, NEXTHOP_OUT_PTR(data))) { diff --git a/ripngd/ripng_offset.c b/ripngd/ripng_offset.c index 46e23f0b6..31d78ba8e 100644 --- a/ripngd/ripng_offset.c +++ b/ripngd/ripng_offset.c @@ -81,9 +81,9 @@ struct ripng_offset_list * ripng_offset_list_lookup (const char *ifname) { struct ripng_offset_list *offset; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (ripng_offset_list_master, offset, nn) + for (ALL_LIST_ELEMENTS (ripng_offset_list_master, node, nnode, offset)) { if (strcmp_safe (offset->ifname, ifname) == 0) return offset; @@ -382,10 +382,10 @@ ripng_offset_clean () int config_write_ripng_offset_list (struct vty *vty) { - struct listnode *nn; + struct listnode *node, *nnode; struct ripng_offset_list *offset; - LIST_LOOP (ripng_offset_list_master, offset, nn) + for (ALL_LIST_ELEMENTS (ripng_offset_list_master, node, nnode, offset)) { if (! offset->ifname) { diff --git a/ripngd/ripng_peer.c b/ripngd/ripng_peer.c index 66282614a..bfbade50c 100644 --- a/ripngd/ripng_peer.c +++ b/ripngd/ripng_peer.c @@ -59,9 +59,9 @@ struct ripng_peer * ripng_peer_lookup (struct in6_addr *addr) { struct ripng_peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (peer_list, peer, nn) + for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) { if (IPV6_ADDR_SAME (&peer->addr, addr)) return peer; @@ -73,9 +73,9 @@ struct ripng_peer * ripng_peer_lookup_next (struct in6_addr *addr) { struct ripng_peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; - LIST_LOOP (peer_list, peer, nn) + for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) { if (addr6_cmp(&peer->addr, addr) > 0) return peer; @@ -191,11 +191,11 @@ void ripng_peer_display (struct vty *vty) { struct ripng_peer *peer; - struct listnode *nn; + struct listnode *node, *nnode; #define RIPNG_UPTIME_LEN 25 char timebuf[RIPNG_UPTIME_LEN]; - LIST_LOOP (peer_list, peer, nn) + for (ALL_LIST_ELEMENTS (peer_list, node, nnode, peer)) { vty_out (vty, " %s %s%14s %10d %10d %10d %s%s", inet6_ntoa (&peer->addr), VTY_NEWLINE, " ", diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index b6b5f5aef..ec6c4d04c 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -380,20 +380,19 @@ ripng_nexthop_rte (struct rte *rte, int ripng_lladdr_check (struct interface *ifp, struct in6_addr *addr) { - struct listnode *listnode; + struct listnode *node; struct connected *connected; struct prefix *p; - for (listnode = listhead (ifp->connected); listnode; nextnode (listnode)) - if ((connected = getdata (listnode)) != NULL) - { - p = connected->address; + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) + { + p = connected->address; - if (p->family == AF_INET6 && - IN6_IS_ADDR_LINKLOCAL (&p->u.prefix6) && - IN6_ARE_ADDR_EQUAL (&p->u.prefix6, addr)) - return 1; - } + if (p->family == AF_INET6 && + IN6_IS_ADDR_LINKLOCAL (&p->u.prefix6) && + IN6_ARE_ADDR_EQUAL (&p->u.prefix6, addr)) + return 1; + } return 0; } @@ -1439,9 +1438,8 @@ ripng_update (struct thread *t) zlog_debug ("RIPng update timer expired!"); /* Supply routes to each interface. */ - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); ri = ifp->info; if (if_is_loopback (ifp) || ! if_is_up (ifp)) @@ -1523,9 +1521,8 @@ ripng_triggered_update (struct thread *t) /* Split Horizon processing is done when generating triggered updates as well as normal updates (see section 2.6). */ - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { - ifp = getdata (node); ri = ifp->info; if (if_is_loopback (ifp) || ! if_is_up (ifp)) @@ -2137,6 +2134,7 @@ DEFUN (show_ipv6_ripng_status, "IPv6 routing protocol process parameters and statistics\n") { struct listnode *node; + struct interface *ifp; int ripng_network_write (struct vty *, int); void ripng_redistribute_write (struct vty *, int); @@ -2171,12 +2169,10 @@ DEFUN (show_ipv6_ripng_status, vty_out (vty, " Interface Send Recv%s", VTY_NEWLINE); - for (node = listhead (iflist); node; node = nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { struct ripng_interface *ri; - struct interface *ifp; - - ifp = getdata (node); + ri = ifp->info; if (ri->enable_network || ri->enable_interface) @@ -2808,11 +2804,8 @@ ripng_distribute_update_all (struct prefix_list *notused) struct interface *ifp; struct listnode *node; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - ripng_distribute_update_interface (ifp); - } + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + ripng_distribute_update_interface (ifp); } void @@ -2986,11 +2979,8 @@ ripng_routemap_update (const char *unused) struct interface *ifp; struct listnode *node; - for (node = listhead (iflist); node; nextnode (node)) - { - ifp = getdata (node); - ripng_if_rmap_update_interface (ifp); - } + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + ripng_if_rmap_update_interface (ifp); ripng_routemap_update_redistribute (); } diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index fe8d52fb7..70c37462f 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -88,7 +88,7 @@ config_get (int index, const char *line) struct config *config; struct config *config_loop; struct list *master; - struct listnode *nn; + struct listnode *node, *nnode; config = config_loop = NULL; @@ -102,7 +102,7 @@ config_get (int index, const char *line) vector_set_index (configvec, index, master); } - LIST_LOOP (master, config_loop, nn) + for (ALL_LIST_ELEMENTS (master, node, nnode, config_loop)) { if (strcmp (config_loop->name, line) == 0) config = config_loop; @@ -130,10 +130,10 @@ config_add_line (struct list *config, const char *line) void config_add_line_uniq (struct list *config, const char *line) { - struct listnode *nn; + struct listnode *node, *nnode; char *pnt; - LIST_LOOP (config, pnt, nn) + for (ALL_LIST_ELEMENTS (config, node, nnode, pnt)) { if (strcmp (pnt, line) == 0) return; @@ -294,14 +294,14 @@ vtysh_config_parse (char *line) void vtysh_config_dump (FILE *fp) { - struct listnode *nn; - struct listnode *nm; + struct listnode *node, *nnode; + struct listnode *mnode, *mnnode; struct config *config; struct list *master; char *line; unsigned int i; - LIST_LOOP (config_top, line, nn) + for (ALL_LIST_ELEMENTS (config_top, node, nnode, line)) { fprintf (fp, "%s\n", line); fflush (fp); @@ -312,12 +312,12 @@ vtysh_config_dump (FILE *fp) for (i = 0; i < vector_active (configvec); i++) if ((master = vector_slot (configvec, i)) != NULL) { - LIST_LOOP (master, config, nn) + for (ALL_LIST_ELEMENTS (master, node, nnode, config)) { fprintf (fp, "%s\n", config->name); fflush (fp); - LIST_LOOP (config->line, line, nm) + for (ALL_LIST_ELEMENTS (config->line, mnode, mnnode, line)) { fprintf (fp, "%s\n", line); fflush (fp); diff --git a/vtysh/vtysh_user.c b/vtysh/vtysh_user.c index f84cca83d..1ae2d8cba 100644 --- a/vtysh/vtysh_user.c +++ b/vtysh/vtysh_user.c @@ -116,10 +116,10 @@ user_free (struct user *user) struct user * user_lookup (const char *name) { - struct listnode *nn; + struct listnode *node, *nnode; struct user *user; - LIST_LOOP (userlist, user, nn) + for (ALL_LIST_ELEMENTS (userlist, node, nnode, user)) { if (strcmp (user->name, name) == 0) return user; @@ -130,10 +130,10 @@ user_lookup (const char *name) void user_config_write () { - struct listnode *nn; + struct listnode *node, *nnode; struct user *user; - LIST_LOOP (userlist, user, nn) + for (ALL_LIST_ELEMENTS (userlist, node, nnode, user)) { if (user->nopassword) printf (" username %s nopassword\n", user->name); diff --git a/zebra/connected.c b/zebra/connected.c index 5f581915b..3ce59530f 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -41,13 +41,10 @@ connected_check_ipv4 (struct interface *ifp, struct prefix *p) struct connected *ifc; struct listnode *node; - for (node = listhead (ifp->connected); node; node = nextnode (node)) - { - ifc = getdata (node); + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) + if (prefix_same (ifc->address, p)) + return ifc; - if (prefix_same (ifc->address, p)) - return ifc; - } return NULL; } @@ -267,13 +264,10 @@ connected_check_ipv6 (struct interface *ifp, struct prefix *p) struct connected *ifc; struct listnode *node; - for (node = listhead (ifp->connected); node; node = nextnode (node)) - { - ifc = getdata (node); + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) + if (prefix_same (ifc->address, p)) + return ifc; - if (prefix_same (ifc->address, p)) - return ifc; - } return 0; } diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index 0d7713db9..24c4cd746 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -409,13 +409,11 @@ if_get_addr (struct interface *ifp) static void interface_info_ioctl () { - struct listnode *node; + struct listnode *node, *nnode; struct interface *ifp; - LIST_LOOP (iflist, ifp, node) + for (ALL_LIST_ELEMENTS (iflist, ifp, node, nnode)) { - ifp = getdata (node); - if_get_index (ifp); #ifdef SIOCGIFHWADDR if_get_hwaddr (ifp); diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c index aa01b0733..ae6a94520 100644 --- a/zebra/if_ioctl_solaris.c +++ b/zebra/if_ioctl_solaris.c @@ -344,7 +344,7 @@ if_lookup_linklocal (struct interface *ifp) if (ifp == NULL) return NULL; - LIST_LOOP (ifp->connected, ifc, node) + for (ALL_LIST_ELEMENTS_RO(ifp->connected, ifc, node)) { if ((ifc->address->family == AF_INET6) && (IN6_IS_ADDR_LINKLOCAL (&ifc->address->u.prefix6))) diff --git a/zebra/interface.c b/zebra/interface.c index 0f294a56f..bd31fb40e 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -170,7 +170,7 @@ if_subnet_delete (struct interface *ifp, struct connected *ifc) /* If deleted address is primary, mark subsequent one as such and distribute. */ if (! CHECK_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY)) { - ifc = (struct connected *) addr_list->head->data; + ifc = listgetdata (listhead (addr_list)); zebra_interface_address_delete_update (ifp, ifc); UNSET_FLAG (ifc->flags, ZEBRA_IFA_SECONDARY); zebra_interface_address_add_update (ifp, ifc); @@ -192,14 +192,13 @@ if_subnet_delete (struct interface *ifp, struct connected *ifc) void if_addr_wakeup (struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct connected *ifc; struct prefix *p; int ret; - for (node = listhead (ifp->connected); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc)) { - ifc = getdata (node); p = ifc->address; if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED) @@ -334,7 +333,7 @@ if_delete_update (struct interface *ifp) last = NULL; while ((node = (last ? last->next : listhead (ifp->connected)))) { - ifc = getdata (node); + ifc = listgetdata (node); p = ifc->address; if (p->family == AF_INET) @@ -354,7 +353,7 @@ if_delete_update (struct interface *ifp) } next = node->next; - ifc = getdata (node); + ifc = listgetdata (node); p = ifc->address; connected_down_ipv4 (ifp, ifc); @@ -423,10 +422,8 @@ if_up (struct interface *ifp) /* Install connected routes to the kernel. */ if (ifp->connected) { - for (node = listhead (ifp->connected); node; node = next) + for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) { - next = node->next; - ifc = getdata (node); p = ifc->address; if (p->family == AF_INET) @@ -458,10 +455,8 @@ if_down (struct interface *ifp) /* Delete connected routes from the kernel. */ if (ifp->connected) { - for (node = listhead (ifp->connected); node; node = next) + for (ALL_LIST_ELEMENTS (ifp->connected, node, next, ifc)) { - next = node->next; - ifc = getdata (node); p = ifc->address; if (p->family == AF_INET) @@ -727,16 +722,12 @@ if_dump_vty (struct vty *vty, struct interface *ifp) if (! rn->info) continue; - for (node = listhead ((struct list *) rn->info); node; nextnode (node)) - { - connected = getdata (node); - connected_dump_vty (vty, connected); - } + for (ALL_LIST_ELEMENTS_RO ((struct list *)rn->info, node, connected)) + connected_dump_vty (vty, connected); } - for (node = listhead (ifp->connected); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, connected)) { - connected = getdata (node); if (CHECK_FLAG (connected->conf, ZEBRA_IFC_REAL) && (connected->address->family == AF_INET6)) connected_dump_vty (vty, connected); @@ -902,8 +893,8 @@ DEFUN (show_interface, show_interface_cmd, } /* All interface print. */ - for (node = listhead (iflist); node; nextnode (node)) - if_dump_vty (vty, getdata (node)); + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) + if_dump_vty (vty, ifp); return CMD_SUCCESS; } @@ -919,10 +910,9 @@ DEFUN (show_interface_desc, struct interface *ifp; vty_out (vty, "Interface Status Protocol Description%s", VTY_NEWLINE); - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { int len; - ifp = getdata (node); len = vty_out (vty, "%s", ifp->name); vty_out (vty, "%*s", (16 - len), " "); @@ -1514,14 +1504,13 @@ if_config_write (struct vty *vty) struct interface *ifp; char buf[BUFSIZ]; - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (iflist, node, ifp)) { struct zebra_if *if_data; struct listnode *addrnode; struct connected *ifc; struct prefix *p; - ifp = getdata (node); if_data = ifp->info; vty_out (vty, "interface %s%s", ifp->name, @@ -1539,9 +1528,8 @@ if_config_write (struct vty *vty) if (CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_LINKDETECTION)) vty_out(vty, " link-detect%s", VTY_NEWLINE); - for (addrnode = listhead (ifp->connected); addrnode; nextnode (addrnode)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, addrnode, ifc)) { - ifc = getdata (addrnode); if (CHECK_FLAG (ifc->conf, ZEBRA_IFC_CONFIGURED)) { p = ifc->address; diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c index 5f913856b..dd7734026 100644 --- a/zebra/irdp_interface.c +++ b/zebra/irdp_interface.c @@ -81,7 +81,7 @@ irdp_get_prefix(struct interface *ifp) struct connected *ifc; if (ifp->connected) - LIST_LOOP (ifp->connected, ifc, node) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) return ifc->address; return NULL; @@ -235,7 +235,7 @@ irdp_if_start(struct interface *ifp, int multicast, int set_defaults) seed = 0; if( ifp->connected) - LIST_LOOP (ifp->connected, ifc, node) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) { seed = ifc->address->u.prefix4.s_addr; break; @@ -355,7 +355,7 @@ void irdp_config_write (struct vty *vty, struct interface *ifp) vty_out (vty, " ip irdp preference %ld%s", irdp->Preference, VTY_NEWLINE); - LIST_LOOP (irdp->AdvPrefList, adv, node) + for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv)) vty_out (vty, " ip irdp address %s preference %d%s", inet_2a(adv->ip.s_addr, b1), adv->pref, @@ -610,7 +610,7 @@ DEFUN (ip_irdp_address_preference, pref = atoi(argv[1]); - LIST_LOOP (irdp->AdvPrefList, adv, node) + for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv)) if(adv->ip.s_addr == ip.s_addr) return CMD_SUCCESS; @@ -656,11 +656,8 @@ DEFUN (no_ip_irdp_address_preference, pref = atoi(argv[1]); - for (node = listhead (irdp->AdvPrefList); node; node = nnode) + for (ALL_LIST_ELEMENTS (irdp->AdvPrefList, node, nnode, adv)) { - nnode = node->next; - adv = getdata (node); - if(adv->ip.s_addr == ip.s_addr ) { listnode_delete(irdp->AdvPrefList, adv); diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index af6bb80b5..04f12f185 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -150,7 +150,7 @@ get_pref(struct irdp_interface *irdp, struct prefix *p) if( irdp->AdvPrefList == NULL ) return irdp->Preference; - LIST_LOOP (irdp->AdvPrefList, adv, node) + for (ALL_LIST_ELEMENTS_RO (irdp->AdvPrefList, node, adv)) if( p->u.prefix4.s_addr == adv->ip.s_addr ) return adv->pref; @@ -234,13 +234,13 @@ int irdp_send_thread(struct thread *t_advert) struct zebra_if *zi=ifp->info; struct irdp_interface *irdp=&zi->irdp; struct prefix *p; - struct listnode *node; + struct listnode *node, *nnode; struct connected *ifc; irdp->flags &= ~IF_SOLICIT; if(ifp->connected) - LIST_LOOP (ifp->connected, ifc, node) + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc)) { p = ifc->address; irdp_advertisement(ifp, p); @@ -266,7 +266,7 @@ void irdp_advert_off(struct interface *ifp) { struct zebra_if *zi=ifp->info; struct irdp_interface *irdp=&zi->irdp; - struct listnode *node; + struct listnode *node, *nnode; int i; struct connected *ifc; struct prefix *p; @@ -275,7 +275,7 @@ void irdp_advert_off(struct interface *ifp) irdp->t_advertise = NULL; if(ifp->connected) - LIST_LOOP (ifp->connected, ifc, node) + for (ALL_LIST_ELEMENTS (ifp->connected, node, nnode, ifc)) { p = ifc->address; @@ -319,16 +319,15 @@ void process_solicit (struct interface *ifp) void irdp_finish() { - struct listnode *node; + struct listnode *node, *nnode; struct interface *ifp; struct zebra_if *zi; struct irdp_interface *irdp; zlog_info("IRDP: Received shutdown notification."); - for (node = listhead (iflist); node; node = nextnode (node)) + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) { - ifp = getdata(node); zi = ifp->info; if (!zi) diff --git a/zebra/redistribute.c b/zebra/redistribute.c index 949159de8..dff6cb54e 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -169,71 +169,71 @@ zebra_redistribute (struct zserv *client, int type) void redistribute_add (struct prefix *p, struct rib *rib) { - struct listnode *node; + struct listnode *node, *nnode; struct zserv *client; - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - { - if (is_default (p)) - { - if (client->redist_default || client->redist[rib->type]) - { - if (p->family == AF_INET) - zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib); + for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) + { + if (is_default (p)) + { + if (client->redist_default || client->redist[rib->type]) + { + if (p->family == AF_INET) + zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib); #ifdef HAVE_IPV6 - if (p->family == AF_INET6) - zsend_route_multipath (ZEBRA_IPV6_ROUTE_ADD, client, p, rib); + if (p->family == AF_INET6) + zsend_route_multipath (ZEBRA_IPV6_ROUTE_ADD, client, p, rib); #endif /* HAVE_IPV6 */ - } - } - else if (client->redist[rib->type]) - { - if (p->family == AF_INET) - zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib); + } + } + else if (client->redist[rib->type]) + { + if (p->family == AF_INET) + zsend_route_multipath (ZEBRA_IPV4_ROUTE_ADD, client, p, rib); #ifdef HAVE_IPV6 - if (p->family == AF_INET6) - zsend_route_multipath (ZEBRA_IPV6_ROUTE_ADD, client, p, rib); + if (p->family == AF_INET6) + zsend_route_multipath (ZEBRA_IPV6_ROUTE_ADD, client, p, rib); #endif /* HAVE_IPV6 */ - } - } + } + } } void redistribute_delete (struct prefix *p, struct rib *rib) { - struct listnode *node; + struct listnode *node, *nnode; struct zserv *client; /* Add DISTANCE_INFINITY check. */ if (rib->distance == DISTANCE_INFINITY) return; - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - { - if (is_default (p)) - { - if (client->redist_default || client->redist[rib->type]) - { - if (p->family == AF_INET) - zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, rib); + for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) + { + if (is_default (p)) + { + if (client->redist_default || client->redist[rib->type]) + { + if (p->family == AF_INET) + zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, + rib); #ifdef HAVE_IPV6 - if (p->family == AF_INET6) - zsend_route_multipath (ZEBRA_IPV6_ROUTE_DELETE, client, p, rib); -#endif /* HAVE_IPV6 */ - } - } - else if (client->redist[rib->type]) - { - if (p->family == AF_INET) - zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, rib); + if (p->family == AF_INET6) + zsend_route_multipath (ZEBRA_IPV6_ROUTE_DELETE, client, p, + rib); +#endif /* HAVE_IPV6 */ + } + } + else if (client->redist[rib->type]) + { + if (p->family == AF_INET) + zsend_route_multipath (ZEBRA_IPV4_ROUTE_DELETE, client, p, rib); #ifdef HAVE_IPV6 - if (p->family == AF_INET6) - zsend_route_multipath (ZEBRA_IPV6_ROUTE_DELETE, client, p, rib); -#endif /* HAVE_IPV6 */ - } - } + if (p->family == AF_INET6) + zsend_route_multipath (ZEBRA_IPV6_ROUTE_DELETE, client, p, rib); +#endif /* HAVE_IPV6 */ + } + } } void @@ -306,46 +306,43 @@ zebra_redistribute_default_delete (int command, struct zserv *client, void zebra_interface_up_update (struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct zserv *client; if (IS_ZEBRA_DEBUG_EVENT) zlog_debug ("MESSAGE: ZEBRA_INTERFACE_UP %s", ifp->name); - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - zsend_interface_update (ZEBRA_INTERFACE_UP, client, ifp); + for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) + zsend_interface_update (ZEBRA_INTERFACE_UP, client, ifp); } /* Interface down information. */ void zebra_interface_down_update (struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct zserv *client; if (IS_ZEBRA_DEBUG_EVENT) zlog_debug ("MESSAGE: ZEBRA_INTERFACE_DOWN %s", ifp->name); - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - zsend_interface_update (ZEBRA_INTERFACE_DOWN, client, ifp); + for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) + zsend_interface_update (ZEBRA_INTERFACE_DOWN, client, ifp); } /* Interface information update. */ void zebra_interface_add_update (struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct zserv *client; if (IS_ZEBRA_DEBUG_EVENT) zlog_debug ("MESSAGE: ZEBRA_INTERFACE_ADD %s", ifp->name); - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - if (client->ifinfo) - zsend_interface_add (client, ifp); + for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) + if (client->ifinfo) + zsend_interface_add (client, ifp); } /* @@ -357,16 +354,15 @@ zebra_interface_add_update (struct interface *ifp) void zebra_interface_delete_update (struct interface *ifp) { - struct listnode *node; + struct listnode *node, *nnode; struct zserv *client; if (IS_ZEBRA_DEBUG_EVENT) zlog_debug ("MESSAGE: ZEBRA_INTERFACE_DELETE %s", ifp->name); - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - if (client->ifinfo) - zsend_interface_delete (client, ifp); + for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) + if (client->ifinfo) + zsend_interface_delete (client, ifp); } #endif /* defined(RTM_IFANNOUNCE) || defined(HAVE_NETLINK) */ @@ -375,7 +371,7 @@ void zebra_interface_address_add_update (struct interface *ifp, struct connected *ifc) { - struct listnode *node; + struct listnode *node, *nnode; struct zserv *client; struct prefix *p; char buf[BUFSIZ]; @@ -390,10 +386,9 @@ zebra_interface_address_add_update (struct interface *ifp, router_id_add_address(ifc); - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) - zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_ADD, client, ifp, ifc); + for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) + if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) + zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_ADD, client, ifp, ifc); } /* Interface address deletion. */ @@ -401,7 +396,7 @@ void zebra_interface_address_delete_update (struct interface *ifp, struct connected *ifc) { - struct listnode *node; + struct listnode *node, *nnode; struct zserv *client; struct prefix *p; char buf[BUFSIZ]; @@ -416,8 +411,7 @@ zebra_interface_address_delete_update (struct interface *ifp, router_id_del_address(ifc); - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) - zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_DELETE, client, ifp, ifc); + for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client)) + if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL)) + zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_DELETE, client, ifp, ifc); } diff --git a/zebra/router-id.c b/zebra/router-id.c index 3052e56a5..6194582e0 100644 --- a/zebra/router-id.c +++ b/zebra/router-id.c @@ -52,12 +52,10 @@ router_id_find_node (struct list *l, struct connected *ifc) struct listnode *node; struct connected *c; - for (node = l->head; node; node = node->next) - { - c = (struct connected *) getdata (node); - if (prefix_same (ifc->address, c->address)) - return c; - } + for (ALL_LIST_ELEMENTS_RO (l, node, c)) + if (prefix_same (ifc->address, c->address)) + return c; + return NULL; } @@ -94,13 +92,13 @@ router_id_get (struct prefix *p) else if (!list_isempty (&rid_lo_sorted_list)) { node = listtail (&rid_lo_sorted_list); - c = getdata (node); + c = listgetdata (node); p->u.prefix4.s_addr = c->address->u.prefix4.s_addr; } else if (!list_isempty (&rid_all_sorted_list)) { node = listtail (&rid_all_sorted_list); - c = getdata (node); + c = listgetdata (node); p->u.prefix4.s_addr = c->address->u.prefix4.s_addr; } } @@ -115,9 +113,9 @@ router_id_set (struct prefix *p) rid_user_assigned.u.prefix4.s_addr = p->u.prefix4.s_addr; router_id_get (&p2); - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - zsend_router_id_update (client, &p2); + + for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client)) + zsend_router_id_update (client, &p2); } void @@ -148,9 +146,8 @@ router_id_add_address (struct connected *ifc) if (prefix_same (&before, &after)) return; - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - zsend_router_id_update (client, &after); + for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client)) + zsend_router_id_update (client, &after); } void @@ -182,9 +179,8 @@ router_id_del_address (struct connected *ifc) if (prefix_same (&before, &after)) return; - for (node = listhead (zebrad.client_list); node; nextnode (node)) - if ((client = getdata (node)) != NULL) - zsend_router_id_update (client, &after); + for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client)) + zsend_router_id_update (client, &after); } void diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 725965630..3e2239857 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -166,6 +166,7 @@ rtadv_send_packet (int sock, struct interface *ifp) int ret; int len = 0; struct zebra_if *zif; + struct rtadv_prefix *rprefix; u_char all_nodes_addr[] = {0xff,0x02,0,0,0,0,0,0,0,0,0,0,0,0,0,1}; struct listnode *node; @@ -245,12 +246,9 @@ rtadv_send_packet (int sock, struct interface *ifp) } /* Fill in prefix. */ - for (node = listhead (zif->rtadv.AdvPrefixList); node; node = nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (zif->rtadv.AdvPrefixList, node, rprefix)) { struct nd_opt_prefix_info *pinfo; - struct rtadv_prefix *rprefix; - - rprefix = getdata (node); pinfo = (struct nd_opt_prefix_info *) (buf + len); @@ -338,7 +336,7 @@ rtadv_send_packet (int sock, struct interface *ifp) int rtadv_timer (struct thread *thread) { - struct listnode *node; + struct listnode *node, *nnode; struct interface *ifp; struct zebra_if *zif; int period; @@ -355,10 +353,8 @@ rtadv_timer (struct thread *thread) rtadv_event (RTADV_TIMER_MSEC, 10 /* 10 ms */); } - for (node = listhead (iflist); node; nextnode (node)) + for (ALL_LIST_ELEMENTS (iflist, node, nnode, ifp)) { - ifp = getdata (node); - if (if_is_loopback (ifp)) continue; @@ -553,12 +549,9 @@ rtadv_prefix_lookup (struct list *rplist, struct prefix *p) struct listnode *node; struct rtadv_prefix *rprefix; - for (node = listhead (rplist); node; node = nextnode (node)) - { - rprefix = getdata (node); - if (prefix_same (&rprefix->prefix, p)) - return rprefix; - } + for (ALL_LIST_ELEMENTS_RO (rplist, node, rprefix)) + if (prefix_same (&rprefix->prefix, p)) + return rprefix; return NULL; } @@ -1426,9 +1419,8 @@ rtadv_config_write (struct vty *vty, struct interface *ifp) if (zif->rtadv.AdvOtherConfigFlag) vty_out (vty, " ipv6 nd other-config-flag%s", VTY_NEWLINE); - for (node = listhead(zif->rtadv.AdvPrefixList); node; node = nextnode (node)) + for (ALL_LIST_ELEMENTS_RO (zif->rtadv.AdvPrefixList, node, rprefix)) { - rprefix = getdata (node); vty_out (vty, " ipv6 nd prefix %s/%d", inet_ntop (AF_INET6, &rprefix->prefix.u.prefix6, (char *) buf, INET6_ADDRSTRLEN), diff --git a/zebra/zserv.c b/zebra/zserv.c index a34e214af..4eaf6bd38 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -721,18 +721,16 @@ zsend_router_id_update (struct zserv *client, struct prefix *p) static int zread_interface_add (struct zserv *client, u_short length) { - struct listnode *ifnode; - struct listnode *cnode; + struct listnode *ifnode, *ifnnode; + struct listnode *cnode, *cnnode; struct interface *ifp; struct connected *c; /* Interface information is needed. */ client->ifinfo = 1; - for (ifnode = listhead (iflist); ifnode; ifnode = nextnode (ifnode)) + for (ALL_LIST_ELEMENTS (iflist, ifnode, ifnnode, ifp)) { - ifp = getdata (ifnode); - /* Skip pseudo interface. */ if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE)) continue; @@ -740,9 +738,8 @@ zread_interface_add (struct zserv *client, u_short length) if (zsend_interface_add (client, ifp) < 0) return -1; - for (cnode = listhead (ifp->connected); cnode; nextnode (cnode)) + for (ALL_LIST_ELEMENTS (ifp->connected, cnode, cnnode, c)) { - c = getdata (cnode); if (CHECK_FLAG (c->conf, ZEBRA_IFC_REAL) && (zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_ADD, client, ifp, c) < 0)) @@ -1566,11 +1563,9 @@ DEFUN (show_zebra_client, struct listnode *node; struct zserv *client; - for (node = listhead (zebrad.client_list); node; nextnode (node)) - { - client = getdata (node); - vty_out (vty, "Client fd %d%s", client->sock, VTY_NEWLINE); - } + for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client)) + vty_out (vty, "Client fd %d%s", client->sock, VTY_NEWLINE); + return CMD_SUCCESS; } |