diff options
author | paul <paul> | 2005-04-07 07:30:20 +0000 |
---|---|---|
committer | paul <paul> | 2005-04-07 07:30:20 +0000 |
commit | 1eb8ef2584833f18fb674e127d59cb5a7f771482 (patch) | |
tree | f5b09d4781de9a9b08839fefb6530e64d2d2ec31 /ripd | |
parent | 5920990fecba7e2430af3cfaa8bcbaed40d0ba1a (diff) |
2005-04-07 Paul Jakma <paul.jakma@sun.com>
* (global): Fix up list loops to match changes in lib/linklist,
and some basic auditing of usage.
* configure.ac: define QUAGGA_NO_DEPRECATED_INTERFACES
* HACKING: Add notes about deprecating interfaces and commands.
* lib/linklist.h: Add usage comments.
Rename getdata macro to listgetdata.
Rename nextnode to listnextnode and fix its odd behaviour to be
less dangerous.
Make listgetdata macro assert node is not null, NULL list entries
should be bug condition.
ALL_LIST_ELEMENTS, new macro, forward-referencing macro for use
with for loop, Suggested by Jim Carlson of Sun.
Add ALL_LIST_ELEMENTS_RO for cases which obviously do not need the
"safety" of previous macro.
LISTNODE_ADD and DELETE macros renamed to ATTACH, DETACH, to
distinguish from the similarly named functions, and reflect their
effect better.
Add a QUAGGA_NO_DEPRECATED_INTERFACES define guarded section
with the old defines which were modified above,
for backwards compatibility - guarded to prevent Quagga using it..
* lib/linklist.c: fix up for linklist.h changes.
* ospf6d/ospf6_abr.c: (ospf6_abr_examin_brouter) change to a single
scan of the area list, rather than scanning all areas first for
INTER_ROUTER and then again for INTER_NETWORK. According to
16.2, the scan should be area specific anyway, and further
ospf6d does not seem to implement 16.3 anyway.
Diffstat (limited to 'ripd')
-rw-r--r-- | ripd/rip_interface.c | 203 | ||||
-rw-r--r-- | ripd/rip_offset.c | 8 | ||||
-rw-r--r-- | ripd/rip_peer.c | 12 | ||||
-rw-r--r-- | ripd/ripd.c | 45 |
4 files changed, 113 insertions, 155 deletions
diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index f58fb337..da73724a 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 6899c4d1..61f13760 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 20c2da73..51df568a 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 afdcd832..3dd91dae 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 (); } |