diff options
author | Renato Westphal <renato@opensourcerouting.org> | 2017-10-03 03:06:01 +0200 |
---|---|---|
committer | Renato Westphal <renato@opensourcerouting.org> | 2017-10-10 14:05:02 +0200 |
commit | f4e14fdba7de19ca660278a0b8c750140db5868b (patch) | |
tree | 58eb2d22e84b24672ddff1dd786f18e5bc555b15 | |
parent | lib: register 'if_var_handlers' only once (diff) | |
download | frr-f4e14fdba7de19ca660278a0b8c750140db5868b.tar.xz frr-f4e14fdba7de19ca660278a0b8c750140db5868b.zip |
*: use rb-trees to store interfaces instead of sorted linked-lists
This is an important optimization for users running FRR on systems with
a large number of interfaces (e.g. thousands of tunnels). Red-black
trees scale much better than sorted linked-lists and also store the
elements in an ordered way (contrary to hash tables).
This is a big patch but the interesting bits are all in lib/if.[ch].
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
49 files changed, 308 insertions, 382 deletions
diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index 4419160cd..49c848d49 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -809,10 +809,10 @@ interface_reset(struct interface *ifp) void babel_interface_close_all(void) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp = NULL; - struct listnode *linklist_node = NULL; - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { if(!if_up(ifp)) continue; send_wildcard_retraction(ifp); @@ -823,7 +823,7 @@ babel_interface_close_all(void) usleep(roughly(1000)); gettime(&babel_now); } - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { if(!if_up(ifp)) continue; /* Make sure they got it. */ @@ -896,12 +896,12 @@ DEFUN (show_babel_interface, "Interface information\n" "Interface\n") { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node; if (argc == 3) { - for (ALL_LIST_ELEMENTS_RO (vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) show_babel_interface_sub (vty, ifp); return CMD_SUCCESS; } @@ -1316,11 +1316,11 @@ babeld-specific statement lines where appropriate. */ static int interface_config_write (struct vty *vty) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; int write = 0; - for (ALL_LIST_ELEMENTS_RO (vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { vty_frame (vty, "interface %s\n",ifp->name); if (ifp->desc) vty_out (vty, " description %s\n",ifp->desc); diff --git a/babeld/babel_interface.h b/babeld/babel_interface.h index 64509afa1..ce14e5906 100644 --- a/babeld/babel_interface.h +++ b/babeld/babel_interface.h @@ -104,9 +104,9 @@ if_up(struct interface *ifp) } /* types: - struct interface _ifp, struct listnode node */ -#define FOR_ALL_INTERFACES(_ifp, _node) \ - for(ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), _node, _ifp)) + struct vrf _vrf, struct interface _ifp */ +#define FOR_ALL_INTERFACES(_vrf, _ifp) \ + RB_FOREACH(_ifp, if_name_head, &_vrf->ifaces_by_name) /* types: struct interface *ifp, struct connected *_connected, struct listnode *node */ diff --git a/babeld/babeld.c b/babeld/babeld.c index 207c37d9b..b66844465 100644 --- a/babeld/babeld.c +++ b/babeld/babeld.c @@ -164,9 +164,9 @@ static int babel_read_protocol (struct thread *thread) { int rc; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp = NULL; struct sockaddr_in6 sin6; - struct listnode *linklist_node = NULL; assert(babel_routing_process != NULL); assert(protocol_socket >= 0); @@ -179,7 +179,7 @@ babel_read_protocol (struct thread *thread) zlog_err("recv: %s", safe_strerror(errno)); } } else { - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { if(!if_up(ifp)) continue; if(ifp->ifindex == (ifindex_t)sin6.sin6_scope_id) { @@ -214,8 +214,8 @@ babel_init_routing_process(struct thread *thread) static void babel_get_myid(void) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp = NULL; - struct listnode *linklist_node = NULL; int rc; int i; @@ -224,7 +224,7 @@ babel_get_myid(void) return; } - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { /* ifp->ifindex is not necessarily valid at this point */ int ifindex = if_nametoindex(ifp->name); if(ifindex > 0) { @@ -268,10 +268,10 @@ babel_get_myid(void) static void babel_initial_noise(void) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp = NULL; - struct listnode *linklist_node = NULL; - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { if(!if_up(ifp)) continue; /* Apply jitter before we send the first message. */ @@ -281,7 +281,7 @@ babel_initial_noise(void) send_wildcard_retraction(ifp); } - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { if(!if_up(ifp)) continue; usleep(roughly(10000)); @@ -319,8 +319,8 @@ static int babel_main_loop(struct thread *thread) { struct timeval tv; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp = NULL; - struct listnode *linklist_node = NULL; while(1) { gettime(&babel_now); @@ -361,7 +361,7 @@ babel_main_loop(struct thread *thread) source_expiry_time = babel_now.tv_sec + roughly(300); } - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { babel_interface_nfo *babel_ifp = NULL; if(!if_up(ifp)) continue; @@ -385,7 +385,7 @@ babel_main_loop(struct thread *thread) flush_unicast(1); } - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { babel_interface_nfo *babel_ifp = NULL; if(!if_up(ifp)) continue; @@ -449,8 +449,8 @@ babel_fill_with_next_timeout(struct timeval *tv) #define printIfMin(a,b,c,d) \ if (UNLIKELY(debug & BABEL_DEBUG_TIMEOUT)) {printIfMin(a,b,c,d);} + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp = NULL; - struct listnode *linklist_node = NULL; *tv = check_neighbours_timeout; printIfMin(tv, 0, "check_neighbours_timeout", NULL); @@ -460,7 +460,7 @@ babel_fill_with_next_timeout(struct timeval *tv) printIfMin(tv, 1, "source_expiry_time", NULL); timeval_min(tv, &resend_time); printIfMin(tv, 1, "resend_time", NULL); - FOR_ALL_INTERFACES(ifp, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp) { babel_interface_nfo *babel_ifp = NULL; if(!if_up(ifp)) continue; @@ -578,10 +578,10 @@ babel_distribute_update_interface (struct interface *ifp) static void babel_distribute_update_all (struct prefix_list *notused) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node; - for (ALL_LIST_ELEMENTS_RO (vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) babel_distribute_update_interface (ifp); } diff --git a/babeld/message.c b/babeld/message.c index e31d5de5d..ea378240b 100644 --- a/babeld/message.c +++ b/babeld/message.c @@ -1154,9 +1154,9 @@ flushupdates(struct interface *ifp) int i; if(ifp == NULL) { - struct interface *ifp_aux; - struct listnode *linklist_node = NULL; - FOR_ALL_INTERFACES(ifp_aux, linklist_node) + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct interface *ifp_aux; + FOR_ALL_INTERFACES(vrf, ifp_aux) flushupdates(ifp_aux); return; } @@ -1326,10 +1326,10 @@ send_update(struct interface *ifp, int urgent, babel_interface_nfo *babel_ifp = NULL; if(ifp == NULL) { - struct interface *ifp_aux; - struct listnode *linklist_node = NULL; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct interface *ifp_aux; struct babel_route *route; - FOR_ALL_INTERFACES(ifp_aux, linklist_node) + FOR_ALL_INTERFACES(vrf, ifp_aux) send_update(ifp_aux, urgent, prefix, plen); if(prefix) { /* Since flushupdates only deals with non-wildcard interfaces, we @@ -1387,9 +1387,9 @@ send_wildcard_retraction(struct interface *ifp) { babel_interface_nfo *babel_ifp = NULL; if(ifp == NULL) { - struct interface *ifp_aux; - struct listnode *linklist_node = NULL; - FOR_ALL_INTERFACES(ifp_aux, linklist_node) + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct interface *ifp_aux; + FOR_ALL_INTERFACES(vrf, ifp_aux) send_wildcard_retraction(ifp_aux); return; } @@ -1422,9 +1422,9 @@ send_self_update(struct interface *ifp) { struct xroute_stream *xroutes; if(ifp == NULL) { - struct interface *ifp_aux; - struct listnode *linklist_node = NULL; - FOR_ALL_INTERFACES(ifp_aux, linklist_node) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct interface *ifp_aux; + FOR_ALL_INTERFACES(vrf, ifp_aux) { if(!if_up(ifp_aux)) continue; send_self_update(ifp_aux); @@ -1456,9 +1456,9 @@ send_ihu(struct neighbour *neigh, struct interface *ifp) int msglen; if(neigh == NULL && ifp == NULL) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp_aux; - struct listnode *linklist_node = NULL; - FOR_ALL_INTERFACES(ifp_aux, linklist_node) { + FOR_ALL_INTERFACES(vrf, ifp_aux) { if(if_up(ifp_aux)) continue; send_ihu(NULL, ifp_aux); @@ -1573,9 +1573,9 @@ send_request(struct interface *ifp, int v4, pb, len; if(ifp == NULL) { - struct interface *ifp_aux; - struct listnode *linklist_node = NULL; - FOR_ALL_INTERFACES(ifp_aux, linklist_node) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct interface *ifp_aux; + FOR_ALL_INTERFACES(vrf, ifp_aux) { if(if_up(ifp_aux)) continue; send_request(ifp_aux, prefix, plen); @@ -1648,9 +1648,9 @@ send_multihop_request(struct interface *ifp, flushupdates(ifp); if(ifp == NULL) { - struct interface *ifp_aux; - struct listnode *linklist_node = NULL; - FOR_ALL_INTERFACES(ifp_aux, linklist_node) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct interface *ifp_aux; + FOR_ALL_INTERFACES(vrf, ifp_aux) { if(!if_up(ifp_aux)) continue; send_multihop_request(ifp_aux, prefix, plen, seqno, id, hop_count); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index c90257d65..9c8f56636 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -591,18 +591,22 @@ static int zebra_read_route(int command, struct zclient *zclient, struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id) { - struct listnode *ifnode; + struct vrf *vrf; struct listnode *cnode; struct interface *ifp; struct connected *connected; struct prefix_ipv4 p; struct prefix *cp; + vrf = vrf_lookup_by_id(vrf_id); + if (!vrf) + return NULL; + p.family = AF_INET; p.prefix = *addr; p.prefixlen = IPV4_MAX_BITLEN; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { cp = connected->address; @@ -616,13 +620,17 @@ struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id) struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id) { - struct listnode *ifnode; + struct vrf *vrf; struct listnode *cnode; struct interface *ifp; struct connected *connected; struct prefix *cp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) { + vrf = vrf_lookup_by_id(vrf_id); + if (!vrf) + return NULL; + + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { cp = connected->address; @@ -637,18 +645,22 @@ struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id) struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex, vrf_id_t vrf_id) { - struct listnode *ifnode; + struct vrf *vrf; struct listnode *cnode; struct interface *ifp; struct connected *connected; struct prefix_ipv6 p; struct prefix *cp; + vrf = vrf_lookup_by_id(vrf_id); + if (!vrf) + return NULL; + p.family = AF_INET6; p.prefix = *addr; p.prefixlen = IPV6_MAX_BITLEN; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { cp = connected->address; @@ -669,13 +681,17 @@ struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex, struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr, ifindex_t ifindex, vrf_id_t vrf_id) { - struct listnode *ifnode; + struct vrf *vrf; struct listnode *cnode; struct interface *ifp; struct connected *connected; struct prefix *cp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) { + vrf = vrf_lookup_by_id(vrf_id); + if (!vrf) + return NULL; + + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { cp = connected->address; diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 308698e1c..d8a4852ff 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -7342,13 +7342,13 @@ void bgp_master_init(struct thread_master *master) */ static void bgp_if_finish(struct bgp *bgp) { - struct listnode *ifnode, *ifnnode; + struct vrf *vrf = vrf_lookup_by_id(bgp->vrf_id); struct interface *ifp; - if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) + if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW || !vrf) return; - for (ALL_LIST_ELEMENTS(vrf_iflist(bgp->vrf_id), ifnode, ifnnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { struct listnode *c_node, *c_nnode; struct connected *c; diff --git a/eigrpd/eigrp_filter.c b/eigrpd/eigrp_filter.c index b74127aa4..fd2e71466 100644 --- a/eigrpd/eigrp_filter.c +++ b/eigrpd/eigrp_filter.c @@ -295,10 +295,10 @@ void eigrp_distribute_update_interface(struct interface *ifp) */ void eigrp_distribute_update_all(struct prefix_list *notused) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node, *nnode; - for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) eigrp_distribute_update_interface(ifp); } diff --git a/eigrpd/eigrp_network.c b/eigrpd/eigrp_network.c index 50e6b7b3b..56b63597e 100644 --- a/eigrpd/eigrp_network.c +++ b/eigrpd/eigrp_network.c @@ -231,9 +231,9 @@ int eigrp_if_drop_allspfrouters(struct eigrp *top, struct prefix *p, int eigrp_network_set(struct eigrp *eigrp, struct prefix *p) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct route_node *rn; struct interface *ifp; - struct listnode *node; rn = route_node_get(eigrp->networks, (struct prefix *)p); if (rn->info) { @@ -251,7 +251,7 @@ int eigrp_network_set(struct eigrp *eigrp, struct prefix *p) eigrp_router_id_update(eigrp); /* Run network config now. */ /* Get target interface. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { zlog_debug("Setting up %s", ifp->name); eigrp_network_run_interface(eigrp, p, ifp); } diff --git a/eigrpd/eigrp_vty.c b/eigrpd/eigrp_vty.c index 59ec57168..5ca3a3bef 100644 --- a/eigrpd/eigrp_vty.c +++ b/eigrpd/eigrp_vty.c @@ -132,11 +132,11 @@ static int config_write_interfaces(struct vty *vty, struct eigrp *eigrp) static int eigrp_write_interface(struct vty *vty) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct eigrp_interface *ei; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { ei = ifp->info; if (!ei) continue; diff --git a/eigrpd/eigrpd.c b/eigrpd/eigrpd.c index c70e198bd..1f2c59271 100644 --- a/eigrpd/eigrpd.c +++ b/eigrpd/eigrpd.c @@ -94,8 +94,8 @@ extern struct in_addr router_id_zebra; */ void eigrp_router_id_update(struct eigrp *eigrp) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node; u_int32_t router_id, router_id_old; router_id_old = eigrp->router_id; @@ -116,7 +116,7 @@ void eigrp_router_id_update(struct eigrp *eigrp) // inet_ntoa(eigrp->router_id)); /* update eigrp_interface's */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) eigrp_if_update(ifp); } } diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 4179de1c0..761e73aa8 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -932,14 +932,15 @@ void isis_circuit_print_vty(struct isis_circuit *circuit, struct vty *vty, int isis_interface_config_write(struct vty *vty) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); int write = 0; - struct listnode *node, *node2; + struct listnode *node; struct interface *ifp; struct isis_area *area; struct isis_circuit *circuit; int i; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { if (ifp->ifindex == IFINDEX_DELETED) continue; @@ -952,7 +953,7 @@ int isis_interface_config_write(struct vty *vty) write++; } /* ISIS Circuit */ - for (ALL_LIST_ELEMENTS_RO(isis->area_list, node2, area)) { + for (ALL_LIST_ELEMENTS_RO(isis->area_list, node, area)) { circuit = circuit_lookup_by_ifp(ifp, area->circuit_list); if (circuit == NULL) diff --git a/isisd/isis_te.c b/isisd/isis_te.c index 5a4fe82c9..dda5781c2 100644 --- a/isisd/isis_te.c +++ b/isisd/isis_te.c @@ -1245,13 +1245,13 @@ DEFUN (show_isis_mpls_te_interface, "Interface information\n" "Interface name\n") { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); int idx_interface = 4; struct interface *ifp; - struct listnode *node; /* Show All Interfaces. */ if (argc == 4) { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) show_mpls_te_sub(vty, ifp); } /* Interface name is specified. */ diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c index c50cc0fda..2dda5f57b 100644 --- a/ldpd/ldp_zebra.c +++ b/ldpd/ldp_zebra.c @@ -212,13 +212,14 @@ kmpw_unset(struct zapi_pw *zpw) void kif_redistribute(const char *ifname) { - struct listnode *node, *cnode; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct listnode *cnode; struct interface *ifp; struct connected *ifc; struct kif kif; struct kaddr ka; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { if (ifname && strcmp(ifname, ifp->name) != 0) continue; @@ -40,6 +40,9 @@ DEFINE_MTYPE_STATIC(LIB, NBR_CONNECTED, "Neighbor Connected") DEFINE_MTYPE(LIB, CONNECTED_LABEL, "Connected interface label") DEFINE_MTYPE_STATIC(LIB, IF_LINK_PARAMS, "Informational Link Parameters") +static int if_cmp_func(const struct interface *, const struct interface *); +RB_GENERATE(if_name_head, interface, name_entry, if_cmp_func); + DEFINE_QOBJ_TYPE(interface) DEFINE_HOOK(if_add, (struct interface *ifp), (ifp)) @@ -109,16 +112,17 @@ int if_cmp_name_func(char *p1, char *p2) return 0; } -static int if_cmp_func(struct interface *ifp1, struct interface *ifp2) +static int if_cmp_func(const struct interface *ifp1, + const struct interface *ifp2) { - return if_cmp_name_func(ifp1->name, ifp2->name); + return if_cmp_name_func((char *)ifp1->name, (char *)ifp2->name); } /* Create new interface structure. */ struct interface *if_create(const char *name, vrf_id_t vrf_id) { + struct vrf *vrf = vrf_get(vrf_id, NULL); struct interface *ifp; - struct list *intf_list = vrf_iflist_get(vrf_id); ifp = XCALLOC(MTYPE_IF, sizeof(struct interface)); ifp->ifindex = IFINDEX_INTERNAL; @@ -126,9 +130,7 @@ struct interface *if_create(const char *name, vrf_id_t vrf_id) assert(name); strlcpy(ifp->name, name, sizeof(ifp->name)); ifp->vrf_id = vrf_id; - if (if_lookup_by_name(ifp->name, vrf_id) == NULL) - listnode_add_sort(intf_list, ifp); - else + if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, ifp)) zlog_err( "if_create(%s): corruption detected -- interface with this " "name exists already in VRF %u!", @@ -150,22 +152,20 @@ struct interface *if_create(const char *name, vrf_id_t vrf_id) /* Create new interface structure. */ void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id) { - struct list *intf_list = vrf_iflist_get(vrf_id); + struct vrf *vrf; /* remove interface from old master vrf list */ - if (vrf_iflist(ifp->vrf_id)) - listnode_delete(vrf_iflist(ifp->vrf_id), ifp); + vrf = vrf_lookup_by_id(ifp->vrf_id); + if (vrf) + RB_REMOVE(if_name_head, &vrf->ifaces_by_name, ifp); ifp->vrf_id = vrf_id; - if (if_lookup_by_name(ifp->name, vrf_id) == NULL) - listnode_add_sort(intf_list, ifp); - else + vrf = vrf_get(ifp->vrf_id, NULL); + if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, ifp)) zlog_err( "%s(%s): corruption detected -- interface with this " - "name exists already in VRF %u!", __func__, - ifp->name, vrf_id); - - return; + "name exists already in VRF %u!", + __func__, ifp->name, vrf_id); } @@ -185,7 +185,9 @@ void if_delete_retain(struct interface *ifp) /* Delete and free interface structure. */ void if_delete(struct interface *ifp) { - listnode_delete(vrf_iflist(ifp->vrf_id), ifp); + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + + RB_REMOVE(if_name_head, &vrf->ifaces_by_name, ifp); if_delete_retain(ifp); @@ -200,13 +202,13 @@ void if_delete(struct interface *ifp) /* Interface existance check by index. */ struct interface *if_lookup_by_index(ifindex_t ifindex, vrf_id_t vrf_id) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) if (ifp->ifindex == ifindex) return ifp; - } + return NULL; } @@ -231,18 +233,14 @@ ifindex_t ifname2ifindex(const char *name, vrf_id_t vrf_id) /* Interface existance check by interface name. */ struct interface *if_lookup_by_name(const char *name, vrf_id_t vrf_id) { - struct listnode *node; - struct interface *ifp; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); + struct interface if_tmp; if (!name || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ) return NULL; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { - if (strcmp(name, ifp->name) == 0) - return ifp; - } - - return NULL; + strlcpy(if_tmp.name, name, sizeof(if_tmp.name)); + return RB_FIND(if_name_head, &vrf->ifaces_by_name, &if_tmp); } struct interface *if_lookup_by_name_all_vrf(const char *name) @@ -266,13 +264,13 @@ struct interface *if_lookup_by_name_all_vrf(const char *name) struct interface *if_lookup_exact_address(void *src, int family, vrf_id_t vrf_id) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct listnode *cnode; struct interface *ifp; struct prefix *p; struct connected *c; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { p = c->address; @@ -298,7 +296,7 @@ struct interface *if_lookup_exact_address(void *src, int family, struct connected *if_lookup_address(void *matchaddr, int family, vrf_id_t vrf_id) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct prefix addr; int bestlen = 0; struct listnode *cnode; @@ -318,7 +316,7 @@ struct connected *if_lookup_address(void *matchaddr, int family, match = NULL; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { if (c->address && (c->address->family == AF_INET) && prefix_match(CONNECTED_PREFIX(c), &addr) @@ -334,12 +332,12 @@ struct connected *if_lookup_address(void *matchaddr, int family, /* Lookup interface by prefix */ struct interface *if_lookup_prefix(struct prefix *prefix, vrf_id_t vrf_id) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct listnode *cnode; struct interface *ifp; struct connected *c; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { if (prefix_cmp(c->address, prefix) == 0) { return ifp; @@ -503,13 +501,11 @@ static void if_dump(const struct interface *ifp) void if_dump_all(void) { struct vrf *vrf; - struct listnode *node; - void *p; + void *ifp; RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) - if (vrf->iflist != NULL) - for (ALL_LIST_ELEMENTS_RO(vrf->iflist, node, p)) - if_dump(p); + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) + if_dump(ifp); } DEFUN (interface_desc, @@ -702,7 +698,6 @@ DEFUN (show_address, { int idx_vrf = 3; struct listnode *node; - struct listnode *node2; struct interface *ifp; struct connected *ifc; struct prefix *p; @@ -711,9 +706,9 @@ DEFUN (show_address, if (argc > 2) VRF_GET_ID (vrf_id, argv[idx_vrf]->arg); - for (ALL_LIST_ELEMENTS_RO (vrf_iflist (vrf_id), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { - for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) { p = ifc->address; @@ -733,21 +728,20 @@ DEFUN (show_address_vrf_all, { struct vrf *vrf; struct listnode *node; - struct listnode *node2; struct interface *ifp; struct connected *ifc; struct prefix *p; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - if (!vrf->iflist || !listcount (vrf->iflist)) + if (RB_EMPTY (if_name_head, &vrf->ifaces_by_name)) continue; vty_out (vty, "\nVRF %u\n\n", vrf->vrf_id); - for (ALL_LIST_ELEMENTS_RO (vrf->iflist, node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { - for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) { p = ifc->address; @@ -1029,35 +1023,17 @@ ifaddr_ipv4_lookup (struct in_addr *addr, ifindex_t ifindex) } #endif /* ifaddr_ipv4_table */ -/* Initialize interface list. */ -void if_init(struct list **intf_list) -{ - *intf_list = list_new(); -#if 0 - ifaddr_ipv4_table = route_table_init (); -#endif /* ifaddr_ipv4_table */ - - (*intf_list)->cmp = (int (*)(void *, void *))if_cmp_func; -} - -void if_terminate(struct list **intf_list) +void if_terminate(struct vrf *vrf) { - for (;;) { - struct interface *ifp; - - ifp = listnode_head(*intf_list); - if (ifp == NULL) - break; + struct interface *ifp; + while ((ifp = RB_ROOT(if_name_head, &vrf->ifaces_by_name)) != NULL) { if (ifp->node) { ifp->node->info = NULL; route_unlock_node(ifp->node); } - if_delete(ifp); } - - list_delete_and_null(intf_list); } const char *if_link_type_str(enum zebra_link_type llt) @@ -201,6 +201,8 @@ struct if_link_params { /* Interface structure */ struct interface { + RB_ENTRY(interface) name_entry; + /* Interface name. This should probably never be changed after the interface is created, because the configuration info for this interface @@ -282,6 +284,8 @@ struct interface { QOBJ_FIELDS }; +RB_HEAD(if_name_head, interface); +RB_PROTOTYPE(if_name_head, interface, name_entry, if_cmp_func); DECLARE_QOBJ_TYPE(interface) /* called from the library code whenever interfaces are created/deleted @@ -441,9 +445,9 @@ extern int if_is_loopback(struct interface *); extern int if_is_broadcast(struct interface *); extern int if_is_pointopoint(struct interface *); extern int if_is_multicast(struct interface *); -extern void if_init(struct list **); extern void if_cmd_init(void); -extern void if_terminate(struct list **); +struct vrf; +extern void if_terminate(struct vrf *vrf); extern void if_dump_all(void); extern const char *if_flag_dump(unsigned long); extern const char *if_link_type_str(enum zebra_link_type); @@ -109,7 +109,7 @@ struct vrf *vrf_get(vrf_id_t vrf_id, const char *name) if (vrf == NULL) { vrf = XCALLOC(MTYPE_VRF, sizeof(struct vrf)); vrf->vrf_id = VRF_UNKNOWN; - if_init(&vrf->iflist); + RB_INIT(if_name_head, &vrf->ifaces_by_name); QOBJ_REG(vrf, vrf); new = 1; @@ -153,7 +153,7 @@ void vrf_delete(struct vrf *vrf) (*vrf_master.vrf_delete_hook)(vrf); QOBJ_UNREG(vrf); - if_terminate(&vrf->iflist); + if_terminate(vrf); if (vrf->vrf_id != VRF_UNKNOWN) RB_REMOVE(vrf_id_head, &vrfs_by_id, vrf); @@ -251,20 +251,6 @@ void *vrf_info_lookup(vrf_id_t vrf_id) return vrf ? vrf->info : NULL; } -/* Look up the interface list in a VRF. */ -struct list *vrf_iflist(vrf_id_t vrf_id) -{ - struct vrf *vrf = vrf_lookup_by_id(vrf_id); - return vrf ? vrf->iflist : NULL; -} - -/* Get the interface list of the specified VRF. Create one if not find. */ -struct list *vrf_iflist_get(vrf_id_t vrf_id) -{ - struct vrf *vrf = vrf_get(vrf_id, NULL); - return vrf->iflist; -} - /* * VRF bit-map */ @@ -77,8 +77,8 @@ struct vrf { u_char status; #define VRF_ACTIVE (1 << 0) - /* Master list of interfaces belonging to this VRF */ - struct list *iflist; + /* Interfaces belonging to this VRF */ + struct if_name_head ifaces_by_name; /* User data */ void *info; @@ -127,15 +127,6 @@ extern void *vrf_info_get(vrf_id_t); extern void *vrf_info_lookup(vrf_id_t); /* - * Utilities to obtain the interface list - */ - -/* Look up the interface list of the specified VRF. */ -extern struct list *vrf_iflist(vrf_id_t); -/* Get the interface list of the specified VRF. Create one if not find. */ -extern struct list *vrf_iflist_get(vrf_id_t); - -/* * VRF bit-map: maintaining flags, one bit per VRF ID */ diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index 0bada3350..3a4135a53 100644 --- a/nhrpd/nhrp_nhs.c +++ b/nhrpd/nhrp_nhs.c @@ -352,13 +352,13 @@ int nhrp_nhs_free(struct nhrp_nhs *nhs) void nhrp_nhs_terminate(void) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct nhrp_interface *nifp; struct nhrp_nhs *nhs, *tmp; - struct listnode *node; afi_t afi; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist (VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { nifp = ifp->info; for (afi = 0; afi < AFI_MAX; afi++) { list_for_each_entry_safe(nhs, tmp, &nifp->afi[afi].nhslist_head, nhslist_entry) diff --git a/nhrpd/nhrp_vty.c b/nhrpd/nhrp_vty.c index bd5b1aa6f..48386c350 100644 --- a/nhrpd/nhrp_vty.c +++ b/nhrpd/nhrp_vty.c @@ -712,7 +712,7 @@ DEFUN(show_ip_nhrp, show_ip_nhrp_cmd, "Shortcut information\n" "opennhrpctl style cache dump\n") { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct info_ctx ctx = { .vty = vty, @@ -720,17 +720,17 @@ DEFUN(show_ip_nhrp, show_ip_nhrp_cmd, }; if (argc <= 3 || argv[3]->text[0] == 'c') { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) nhrp_cache_foreach(ifp, show_ip_nhrp_cache, &ctx); } else if (argv[3]->text[0] == 'n') { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) nhrp_nhs_foreach(ifp, ctx.afi, show_ip_nhrp_nhs, &ctx); } else if (argv[3]->text[0] == 's') { nhrp_shortcut_foreach(ctx.afi, show_ip_nhrp_shortcut, &ctx); } else { vty_out (vty, "Status: ok\n\n"); ctx.count++; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) nhrp_cache_foreach(ifp, show_ip_opennhrp_cache, &ctx); } @@ -796,7 +796,7 @@ DEFUN(clear_nhrp, clear_nhrp_cmd, "Dynamic cache entries\n" "Shortcut entries\n") { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct info_ctx ctx = { .vty = vty, @@ -805,7 +805,7 @@ DEFUN(clear_nhrp, clear_nhrp_cmd, }; if (argc <= 3 || argv[3]->text[0] == 'c') { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) nhrp_cache_foreach(ifp, clear_nhrp_cache, &ctx); } else { nhrp_shortcut_foreach(ctx.afi, clear_nhrp_shortcut, &ctx); @@ -843,8 +843,8 @@ static void interface_config_write_nhrp_map(struct nhrp_cache *c, void *data) static int interface_config_write(struct vty *vty) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct write_map_ctx mapctx; - struct listnode *node; struct interface *ifp; struct nhrp_interface *nifp; struct nhrp_nhs *nhs; @@ -853,7 +853,7 @@ static int interface_config_write(struct vty *vty) char buf[SU_ADDRSTRLEN]; int i; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { vty_frame(vty, "interface %s\n", ifp->name); if (ifp->desc) vty_out (vty, " description %s\n", ifp->desc); diff --git a/ospf6d/ospf6_bfd.c b/ospf6d/ospf6_bfd.c index fa0030b6d..9f5d9fbd8 100644 --- a/ospf6d/ospf6_bfd.c +++ b/ospf6d/ospf6_bfd.c @@ -141,7 +141,8 @@ static void ospf6_bfd_reg_dereg_all_nbr(struct ospf6_interface *oi, int command) static int ospf6_bfd_nbr_replay(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id) { - struct listnode *inode, *nnode; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); + struct listnode *node; struct interface *ifp; struct ospf6_interface *oi; struct ospf6_neighbor *on; @@ -154,13 +155,13 @@ static int ospf6_bfd_nbr_replay(int command, struct zclient *zclient, bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); /* Replay the neighbor, if BFD is enabled on the interface*/ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), inode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { oi = (struct ospf6_interface *)ifp->info; if (!oi || !oi->bfd_info) continue; - for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, nnode, on)) { + for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, node, on)) { if (on->state < OSPF6_NEIGHBOR_TWOWAY) continue; diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index 7286b3242..f8cefbf9e 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -983,9 +983,9 @@ DEFUN (show_ipv6_ospf6_interface, INTERFACE_STR IFNAME_STR) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); int idx_ifname = 4; struct interface *ifp; - struct listnode *i; if (argc == 5) { ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); @@ -996,7 +996,7 @@ DEFUN (show_ipv6_ospf6_interface, } ospf6_interface_show(vty, ifp); } else { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), i, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ospf6_interface_show(vty, ifp); } @@ -1054,12 +1054,12 @@ DEFUN (show_ipv6_ospf6_interface_prefix, OSPF6_ROUTE_MATCH_STR "Display details of the prefixes\n") { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); int idx_prefix = 5; - struct listnode *i; struct ospf6_interface *oi; struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), i, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { oi = (struct ospf6_interface *)ifp->info; if (oi == NULL) continue; @@ -1755,11 +1755,11 @@ DEFUN (no_ipv6_ospf6_network, static int config_write_ospf6_interface(struct vty *vty) { - struct listnode *i; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct ospf6_interface *oi; struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), i, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { oi = (struct ospf6_interface *)ifp->info; if (oi == NULL) continue; @@ -1905,13 +1905,13 @@ DEFUN (clear_ipv6_ospf6_interface, IFNAME_STR ) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); int idx_ifname = 4; struct interface *ifp; - struct listnode *node; if (argc == 4) /* Clear all the ospfv3 interfaces. */ { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ospf6_interface_clear(vty, ifp); } else /* Interface name is specified. */ { diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index e582737f9..2a6e56deb 100644 --- a/ospf6d/ospf6_main.c +++ b/ospf6d/ospf6_main.c @@ -79,7 +79,7 @@ struct thread_master *master; static void __attribute__((noreturn)) ospf6_exit(int status) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; frr_early_fini(); @@ -89,7 +89,7 @@ static void __attribute__((noreturn)) ospf6_exit(int status) bfd_gbl_exit(); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) if (ifp->info != NULL) ospf6_interface_delete(ifp->info); diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 0b399bad1..fb3b146e3 100644 --- a/ospf6d/ospf6_snmp.c +++ b/ospf6d/ospf6_snmp.c @@ -837,6 +837,7 @@ static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct ospf6_lsa *lsa = NULL; ifindex_t ifindex; uint32_t area_id, id, instid, adv_router; @@ -955,8 +956,7 @@ static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length, if (!ifslist) return NULL; ifslist->cmp = (int (*)(void *, void *))if_icmp_func; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, - iif)) + RB_FOREACH (iif, if_name_head, &vrf->ifaces_by_name) listnode_add_sort(ifslist, iif); for (ALL_LIST_ELEMENTS_RO(ifslist, node, iif)) { @@ -1092,7 +1092,7 @@ static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length, if (!ifslist) return NULL; ifslist->cmp = (int (*)(void *, void *))if_icmp_func; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), i, iif)) + RB_FOREACH (iif, if_name_head, &vrf->ifaces_by_name) listnode_add_sort(ifslist, iif); for (ALL_LIST_ELEMENTS_RO(ifslist, i, iif)) { @@ -1253,7 +1253,7 @@ static u_char *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length, if (!ifslist) return NULL; ifslist->cmp = (int (*)(void *, void *))if_icmp_func; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), i, iif)) + RB_FOREACH (iif, if_name_head, &vrf->ifaces_by_name) listnode_add_sort(ifslist, iif); for (ALL_LIST_ELEMENTS_RO(ifslist, i, iif)) { diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 5f300daba..95610e4c7 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -2533,9 +2533,10 @@ DEFUN (show_ip_ospf_mpls_te_link, "Interface information\n" "Interface name\n") { + struct vrf *vrf; int idx_interface = 5; struct interface *ifp; - struct listnode *node, *nnode, *n1; + struct listnode *node; char *vrf_name = NULL; bool all_vrf; int inst = 0; @@ -2550,11 +2551,12 @@ DEFUN (show_ip_ospf_mpls_te_link, /* vrf input is provided could be all or specific vrf*/ if (vrf_name) { if (all_vrf) { - for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { + for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; - for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), - node, nnode, ifp)) + vrf = vrf_lookup_by_id(ospf->vrf_id); + RB_FOREACH (ifp, if_name_head, + &vrf->ifaces_by_name) show_mpls_te_link_sub(vty, ifp); } return CMD_SUCCESS; @@ -2562,18 +2564,18 @@ DEFUN (show_ip_ospf_mpls_te_link, ospf = ospf_lookup_by_inst_name (inst, vrf_name); if (ospf == NULL || !ospf->oi_running) return CMD_SUCCESS; - for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), node, - nnode, ifp)) + vrf = vrf_lookup_by_id(ospf->vrf_id); + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) show_mpls_te_link_sub(vty, ifp); return CMD_SUCCESS; } /* Show All Interfaces. */ if (argc == 5) { - for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { + for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { if (!ospf->oi_running) continue; - for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), node, - nnode, ifp)) + vrf = vrf_lookup_by_id(ospf->vrf_id); + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) show_mpls_te_link_sub(vty, ifp); } } diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index c12e7e035..3c709df38 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -333,13 +333,14 @@ DEFPY (no_ospf_router_id, static void ospf_passive_interface_default(struct ospf *ospf, u_char newval) { + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); struct listnode *ln; struct interface *ifp; struct ospf_interface *oi; ospf->passive_interface_default = newval; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), ln, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), passive_interface)) UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); @@ -2457,9 +2458,9 @@ DEFUN (ospf_auto_cost_reference_bandwidth, "The reference bandwidth in terms of Mbits per second\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); int idx_number = 2; u_int32_t refbw; - struct listnode *node; struct interface *ifp; refbw = strtol(argv[idx_number]->arg, NULL, 10); @@ -2473,7 +2474,7 @@ DEFUN (ospf_auto_cost_reference_bandwidth, return CMD_SUCCESS; ospf->ref_bandwidth = refbw; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ospf_if_recalculate_output_cost(ifp); return CMD_SUCCESS; @@ -2488,7 +2489,7 @@ DEFUN (no_ospf_auto_cost_reference_bandwidth, "The reference bandwidth in terms of Mbits per second\n") { VTY_DECLVAR_INSTANCE_CONTEXT(ospf, ospf); - struct listnode *node, *nnode; + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); struct interface *ifp; if (ospf->ref_bandwidth == OSPF_DEFAULT_REF_BANDWIDTH) @@ -2499,7 +2500,7 @@ DEFUN (no_ospf_auto_cost_reference_bandwidth, vty_out(vty, " Please ensure reference bandwidth is consistent across all routers\n"); - for (ALL_LIST_ELEMENTS(vrf_iflist(ospf->vrf_id), node, nnode, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ospf_if_recalculate_output_cost(ifp); return CMD_SUCCESS; @@ -3555,7 +3556,7 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, int iface_argv, u_char use_json) { struct interface *ifp; - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); json_object *json = NULL; json_object *json_interface_sub = NULL; @@ -3573,8 +3574,7 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, if (argc == iface_argv) { /* Show All Interfaces.*/ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), - node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { if (ospf_oi_count(ifp)) { if (use_json) json_interface_sub = @@ -8633,14 +8633,15 @@ const char *ospf_int_type_str[] = {"unknown", /* should never be used. */ static int config_write_interface_one(struct vty *vty, struct ospf *ospf) { - struct listnode *n1, *n2; + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); + struct listnode *node; struct interface *ifp; struct crypt_key *ck; struct route_node *rn = NULL; struct ospf_if_params *params; int write = 0; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), n1, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { struct vrf *vrf = NULL; if (memcmp(ifp->name, "VLINK", 5) == 0) @@ -8729,7 +8730,7 @@ static int config_write_interface_one(struct vty *vty, struct ospf *ospf) /* Cryptographic Authentication Key print. */ if (params && params->auth_crypt) { for (ALL_LIST_ELEMENTS_RO(params->auth_crypt, - n2, ck)) { + node, ck)) { vty_out(vty, " ip ospf message-digest-key %d md5 %s", ck->key_id, ck->auth_key); @@ -9234,6 +9235,7 @@ static int config_write_ospf_distance(struct vty *vty, struct ospf *ospf) static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) { + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); struct interface *ifp; struct ospf_interface *oi; struct listnode *node = NULL; @@ -9328,7 +9330,7 @@ static int ospf_config_write_one(struct vty *vty, struct ospf *ospf) if (ospf->passive_interface_default == OSPF_IF_PASSIVE) vty_out(vty, " passive-interface default\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), passive_interface) && IF_DEF_PARAMS(ifp)->passive_interface @@ -9591,14 +9593,14 @@ DEFUN (clear_ip_ospf_interface, { int idx_ifname = 4; struct interface *ifp; - struct listnode *node, *n1; + struct listnode *node; struct ospf *ospf = NULL; if (argc == 4) /* Clear all the ospfv2 interfaces. */ { - for (ALL_LIST_ELEMENTS_RO(om->ospf, n1, ospf)) { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), - node, ifp)) + for (ALL_LIST_ELEMENTS_RO(om->ospf, node, ospf)) { + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ospf_interface_clear(ifp); } } else { diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 24d3abf2a..e6d58d7a3 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -86,6 +86,7 @@ static void ospf_finish_final(struct ospf *); void ospf_router_id_update(struct ospf *ospf) { + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); struct in_addr router_id, router_id_old; struct ospf_interface *oi; struct interface *ifp; @@ -209,7 +210,7 @@ void ospf_router_id_update(struct ospf *ospf) ospf_router_lsa_update(ospf); /* update ospf_interface's */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ospf_if_update(ospf, ifp); } } @@ -581,6 +582,7 @@ void ospf_finish(struct ospf *ospf) /* Final cleanup of ospf instance */ static void ospf_finish_final(struct ospf *ospf) { + struct vrf *vrf = vrf_lookup_by_id(ospf->vrf_id); struct route_node *rn; struct ospf_nbr_nbma *nbr_nbma; struct ospf_lsa *lsa; @@ -591,7 +593,6 @@ static void ospf_finish_final(struct ospf *ospf) struct listnode *node, *nnode; int i; u_short instance = 0; - struct vrf *vrf = NULL; QOBJ_UNREG(ospf); @@ -623,7 +624,7 @@ static void ospf_finish_final(struct ospf *ospf) list_delete_and_null(&ospf->vlinks); /* Remove any ospf interface config params */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(ospf->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { struct ospf_if_params *params; params = IF_DEF_PARAMS(ifp); @@ -1252,15 +1253,15 @@ static void ospf_network_run_interface(struct ospf *ospf, struct interface *ifp, static void ospf_network_run(struct prefix *p, struct ospf_area *area) { + struct vrf *vrf = vrf_lookup_by_id(area->ospf->vrf_id); struct interface *ifp; - struct listnode *node; /* Schedule Router ID Update. */ if (area->ospf->router_id.s_addr == 0) ospf_router_id_update(area->ospf); /* Get target interface. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(area->ospf->vrf_id), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ospf_network_run_interface(area->ospf, ifp, p, area); } diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c index 314162c78..c8d111387 100644 --- a/pimd/pim_bfd.c +++ b/pimd/pim_bfd.c @@ -292,7 +292,6 @@ static int pim_bfd_nbr_replay(int command, struct zclient *zclient, struct interface *ifp = NULL; struct pim_interface *pim_ifp = NULL; struct pim_neighbor *neigh = NULL; - struct listnode *node; struct listnode *neigh_node; struct listnode *neigh_nextnode; struct vrf *vrf = NULL; @@ -301,7 +300,7 @@ static int pim_bfd_nbr_replay(int command, struct zclient *zclient, bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 7ce345d8e..cd55e0fa1 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -214,7 +214,6 @@ static void pim_show_assert(struct pim_instance *pim, struct vty *vty) { struct pim_interface *pim_ifp; struct pim_ifchannel *ch; - struct listnode *if_node; struct interface *ifp; time_t now; @@ -223,7 +222,7 @@ static void pim_show_assert(struct pim_instance *pim, struct vty *vty) vty_out(vty, "Interface Address Source Group State Winner Uptime Timer\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), if_node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -263,7 +262,6 @@ static void pim_show_assert_internal_helper(struct vty *vty, static void pim_show_assert_internal(struct pim_instance *pim, struct vty *vty) { struct pim_interface *pim_ifp; - struct listnode *if_node; struct pim_ifchannel *ch; struct interface *ifp; @@ -275,7 +273,7 @@ static void pim_show_assert_internal(struct pim_instance *pim, struct vty *vty) vty_out(vty, "Interface Address Source Group CA eCA ATD eATD\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), if_node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -317,14 +315,13 @@ static void pim_show_assert_metric_helper(struct vty *vty, static void pim_show_assert_metric(struct pim_instance *pim, struct vty *vty) { struct pim_interface *pim_ifp; - struct listnode *if_node; struct pim_ifchannel *ch; struct interface *ifp; vty_out(vty, "Interface Address Source Group RPT Pref Metric Address \n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), if_node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -379,7 +376,6 @@ static void pim_show_assert_winner_metric_helper(struct vty *vty, static void pim_show_assert_winner_metric(struct pim_instance *pim, struct vty *vty) { - struct listnode *if_node; struct pim_interface *pim_ifp; struct pim_ifchannel *ch; struct interface *ifp; @@ -387,7 +383,7 @@ static void pim_show_assert_winner_metric(struct pim_instance *pim, vty_out(vty, "Interface Address Source Group RPT Pref Metric Address \n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), if_node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -467,7 +463,6 @@ static void pim_show_membership_helper(struct vty *vty, static void pim_show_membership(struct pim_instance *pim, struct vty *vty, u_char uj) { - struct listnode *if_node; struct pim_interface *pim_ifp; struct pim_ifchannel *ch; struct interface *ifp; @@ -477,7 +472,7 @@ static void pim_show_membership(struct pim_instance *pim, struct vty *vty, json = json_object_new_object(); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), if_node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -585,7 +580,6 @@ static void pim_print_ifp_flags(struct vty *vty, struct interface *ifp, static void igmp_show_interfaces(struct pim_instance *pim, struct vty *vty, u_char uj) { - struct listnode *node; struct interface *ifp; time_t now; json_object *json = NULL; @@ -599,7 +593,7 @@ static void igmp_show_interfaces(struct pim_instance *pim, struct vty *vty, vty_out(vty, "Interface State Address V Querier Query Timer Uptime\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp; struct listnode *sock_node; struct igmp_sock *igmp; @@ -666,7 +660,6 @@ static void igmp_show_interfaces_single(struct pim_instance *pim, { struct igmp_sock *igmp; struct interface *ifp; - struct listnode *node; struct listnode *sock_node; struct pim_interface *pim_ifp; char uptime[10]; @@ -690,7 +683,7 @@ static void igmp_show_interfaces_single(struct pim_instance *pim, now = pim_time_monotonic_sec(); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) @@ -866,7 +859,6 @@ static void igmp_show_interfaces_single(struct pim_instance *pim, static void igmp_show_interface_join(struct pim_instance *pim, struct vty *vty) { - struct listnode *node; struct interface *ifp; time_t now; @@ -875,7 +867,7 @@ static void igmp_show_interface_join(struct pim_instance *pim, struct vty *vty) vty_out(vty, "Interface Address Source Group Socket Uptime \n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp; struct listnode *join_node; struct igmp_join *ij; @@ -922,7 +914,6 @@ static void pim_show_interfaces_single(struct pim_instance *pim, struct in_addr ifaddr; struct interface *ifp; struct listnode *neighnode; - struct listnode *node; struct listnode *upnode; struct pim_interface *pim_ifp; struct pim_neighbor *neigh; @@ -956,7 +947,7 @@ static void pim_show_interfaces_single(struct pim_instance *pim, if (uj) json = json_object_new_object(); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) @@ -1338,7 +1329,6 @@ static void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, u_char uj) { struct interface *ifp; - struct listnode *node; struct listnode *upnode; struct pim_interface *pim_ifp; struct pim_upstream *up; @@ -1351,7 +1341,7 @@ static void pim_show_interfaces(struct pim_instance *pim, struct vty *vty, json = json_object_new_object(); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) @@ -1433,7 +1423,6 @@ static void pim_show_interface_traffic(struct pim_instance *pim, { struct interface *ifp = NULL; struct pim_interface *pim_ifp = NULL; - struct listnode *node = NULL; json_object *json = NULL; json_object *json_row = NULL; @@ -1451,7 +1440,7 @@ static void pim_show_interface_traffic(struct pim_instance *pim, "---------------------------------------------------------------------------------------------------------------\n"); } - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) @@ -1514,7 +1503,6 @@ static void pim_show_interface_traffic_single(struct pim_instance *pim, { struct interface *ifp = NULL; struct pim_interface *pim_ifp = NULL; - struct listnode *node = NULL; json_object *json = NULL; json_object *json_row = NULL; uint8_t found_ifname = 0; @@ -1533,7 +1521,7 @@ static void pim_show_interface_traffic_single(struct pim_instance *pim, "---------------------------------------------------------------------------------------------------------------\n"); } - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { if (strcmp(ifname, ifp->name)) continue; @@ -1678,7 +1666,6 @@ static void pim_show_join_helper(struct vty *vty, static void pim_show_join(struct pim_instance *pim, struct vty *vty, u_char uj) { - struct listnode *if_node; struct pim_interface *pim_ifp; struct pim_ifchannel *ch; struct interface *ifp; @@ -1693,7 +1680,7 @@ static void pim_show_join(struct pim_instance *pim, struct vty *vty, u_char uj) vty_out(vty, "Interface Address Source Group State Uptime Expire Prune\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), if_node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -1713,7 +1700,6 @@ static void pim_show_join(struct pim_instance *pim, struct vty *vty, u_char uj) static void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty, const char *neighbor, u_char uj) { - struct listnode *node; struct listnode *neighnode; struct interface *ifp; struct pim_interface *pim_ifp; @@ -1739,7 +1725,7 @@ static void pim_show_neighbors_single(struct pim_instance *pim, struct vty *vty, if (uj) json = json_object_new_object(); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) @@ -2125,7 +2111,6 @@ static void pim_show_state(struct pim_instance *pim, struct vty *vty, static void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, u_char uj) { - struct listnode *node; struct listnode *neighnode; struct interface *ifp; struct pim_interface *pim_ifp; @@ -2147,7 +2132,7 @@ static void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, "Interface Neighbor Uptime Holdtime DR Pri\n"); } - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) @@ -2208,13 +2193,12 @@ static void pim_show_neighbors(struct pim_instance *pim, struct vty *vty, static void pim_show_neighbors_secondary(struct pim_instance *pim, struct vty *vty) { - struct listnode *node; struct interface *ifp; vty_out(vty, "Interface Address Neighbor Secondary \n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp; struct in_addr ifaddr; struct listnode *neighnode; @@ -2507,7 +2491,6 @@ static void pim_show_join_desired_helper(struct pim_instance *pim, static void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, u_char uj) { - struct listnode *if_node; struct pim_interface *pim_ifp; struct pim_ifchannel *ch; struct interface *ifp; @@ -2521,7 +2504,7 @@ static void pim_show_join_desired(struct pim_instance *pim, struct vty *vty, "Interface Source Group LostAssert Joins PimInclude JoinDesired EvalJD\n"); /* scan per-interface (S,G) state */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), if_node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -2802,7 +2785,6 @@ static void pim_show_nexthop(struct pim_instance *pim, struct vty *vty) static void igmp_show_groups(struct pim_instance *pim, struct vty *vty, u_char uj) { - struct listnode *ifnode; struct interface *ifp; time_t now; json_object *json = NULL; @@ -2818,7 +2800,7 @@ static void igmp_show_groups(struct pim_instance *pim, struct vty *vty, "Interface Address Group Mode Timer Srcs V Uptime \n"); /* scan interfaces */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; @@ -2924,14 +2906,13 @@ static void igmp_show_groups(struct pim_instance *pim, struct vty *vty, static void igmp_show_group_retransmission(struct pim_instance *pim, struct vty *vty) { - struct listnode *ifnode; struct interface *ifp; vty_out(vty, "Interface Address Group RetTimer Counter RetSrcs\n"); /* scan interfaces */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; @@ -2989,7 +2970,6 @@ static void igmp_show_group_retransmission(struct pim_instance *pim, static void igmp_show_sources(struct pim_instance *pim, struct vty *vty) { - struct listnode *ifnode; struct interface *ifp; time_t now; @@ -2999,7 +2979,7 @@ static void igmp_show_sources(struct pim_instance *pim, struct vty *vty) "Interface Address Group Source Timer Fwd Uptime \n"); /* scan interfaces */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; @@ -3066,14 +3046,13 @@ static void igmp_show_sources(struct pim_instance *pim, struct vty *vty) static void igmp_show_source_retransmission(struct pim_instance *pim, struct vty *vty) { - struct listnode *ifnode; struct interface *ifp; vty_out(vty, "Interface Address Group Source Counter\n"); /* scan interfaces */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; @@ -3125,29 +3104,20 @@ static void igmp_show_source_retransmission(struct pim_instance *pim, static void clear_igmp_interfaces(struct pim_instance *pim) { - struct listnode *ifnode; - struct listnode *ifnextnode; struct interface *ifp; - for (ALL_LIST_ELEMENTS(vrf_iflist(pim->vrf_id), ifnode, ifnextnode, - ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) pim_if_addr_del_all_igmp(ifp); - } - for (ALL_LIST_ELEMENTS(vrf_iflist(pim->vrf_id), ifnode, ifnextnode, - ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) pim_if_addr_add_all(ifp); - } } static void clear_pim_interfaces(struct pim_instance *pim) { - struct listnode *ifnode; - struct listnode *ifnextnode; struct interface *ifp; - for (ALL_LIST_ELEMENTS(vrf_iflist(pim->vrf_id), ifnode, ifnextnode, - ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { if (ifp->info) { pim_neighbor_delete_all(ifp, "interface cleared"); } @@ -3301,16 +3271,13 @@ DEFUN (clear_ip_pim_interface_traffic, { int idx = 2; struct vrf *vrf = pim_cmd_lookup_vrf(vty, argv, argc, &idx); - struct listnode *ifnode = NULL; - struct listnode *ifnextnode = NULL; struct interface *ifp = NULL; struct pim_interface *pim_ifp = NULL; if (!vrf) return CMD_WARNING; - for (ALL_LIST_ELEMENTS(vrf_iflist(vrf->vrf_id), ifnode, ifnextnode, - ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { pim_ifp = ifp->info; if (!pim_ifp) @@ -4320,7 +4287,6 @@ DEFUN (show_ip_pim_interface_traffic, static void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty) { - struct listnode *node; struct interface *ifp; vty_out(vty, "\n"); @@ -4328,7 +4294,7 @@ static void show_multicast_interfaces(struct pim_instance *pim, struct vty *vty) vty_out(vty, "Interface Address ifi Vif PktsIn PktsOut BytesIn BytesOut\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp; struct in_addr ifaddr; struct sioc_vif_req vreq; diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 01e14bec0..09b5fe2bf 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -1023,10 +1023,9 @@ int pim_if_del_vif(struct interface *ifp) struct interface *pim_if_find_by_vif_index(struct pim_instance *pim, ifindex_t vif_index) { - struct listnode *ifnode; struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { if (ifp->info) { struct pim_interface *pim_ifp; pim_ifp = ifp->info; diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 6aa5105c5..71897afce 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -1291,10 +1291,9 @@ void pim_ifchannel_scan_forward_start(struct interface *new_ifp) { struct pim_interface *new_pim_ifp = new_ifp->info; struct pim_instance *pim = new_pim_ifp->pim; - struct listnode *ifnode; struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *loop_pim_ifp = ifp->info; struct pim_ifchannel *ch; diff --git a/pimd/pim_jp_agg.c b/pimd/pim_jp_agg.c index 7de3e4ca6..3ec0a620f 100644 --- a/pimd/pim_jp_agg.c +++ b/pimd/pim_jp_agg.c @@ -212,12 +212,11 @@ int pim_jp_agg_is_in_list(struct list *group, struct pim_upstream *up) void pim_jp_agg_upstream_verification(struct pim_upstream *up, bool ignore) { #ifdef PIM_JP_AGG_DEBUG - struct listnode *node; struct interface *ifp; struct pim_interface *pim_ifp = up->rpf.source_nexthop.interface->info; struct pim_instance *pim = pim_ifp->pim; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { pim_ifp = ifp->info; struct listnode *nnode; diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index a1de4837d..78b160f6a 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -410,12 +410,12 @@ static int pim_update_upstream_nh_helper(struct hash_backet *backet, void *arg) static int pim_update_upstream_nh(struct pim_instance *pim, struct pim_nexthop_cache *pnc) { - struct listnode *node, *ifnode; + struct listnode *node; struct interface *ifp; hash_walk(pnc->upstream_hash, pim_update_upstream_nh_helper, pim); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) if (ifp->info) { struct pim_interface *pim_ifp = ifp->info; struct pim_iface_upstream_switch *us; diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index cb722c17b..c1ecf6870 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -332,11 +332,10 @@ static int pim_rp_check_interface_addrs(struct rp_info *rp_info, static void pim_rp_check_interfaces(struct pim_instance *pim, struct rp_info *rp_info) { - struct listnode *node; struct interface *ifp; rp_info->i_am_rp = 0; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp = ifp->info; if (!pim_ifp) diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index ed5d1ecaa..47a70eb09 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -864,12 +864,11 @@ int pim_upstream_evaluate_join_desired(struct pim_instance *pim, struct pim_upstream *up) { struct interface *ifp; - struct listnode *node; struct pim_ifchannel *ch, *starch; struct pim_upstream *starup = up->parent; int ret = 0; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { if (!ifp->info) continue; @@ -1426,7 +1425,6 @@ int pim_upstream_inherited_olist_decide(struct pim_instance *pim, struct interface *ifp; struct pim_interface *pim_ifp = NULL; struct pim_ifchannel *ch, *starch; - struct listnode *node; struct pim_upstream *starup = up->parent; int output_intf = 0; @@ -1441,7 +1439,7 @@ int pim_upstream_inherited_olist_decide(struct pim_instance *pim, up->channel_oil = pim_channel_oil_add( pim, &up->sg, pim_ifp->mroute_vif_index); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { if (!ifp->info) continue; diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index fc377b5a5..9b60e284e 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -240,7 +240,6 @@ int pim_global_config_write(struct vty *vty) int pim_interface_config_write(struct vty *vty) { struct pim_instance *pim; - struct listnode *node; struct interface *ifp; struct vrf *vrf; int writes = 0; @@ -250,8 +249,7 @@ int pim_interface_config_write(struct vty *vty) if (!pim) continue; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { - + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { /* IF name */ if (vrf->vrf_id == VRF_DEFAULT) vty_frame(vty, "interface %s\n", ifp->name); diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index df70e9dd5..3424eded9 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -330,10 +330,10 @@ static int pim_zebra_if_address_add(int command, struct zclient *zclient, pim_rp_check_on_if_add(pim_ifp); if (if_is_loopback(c->ifp)) { - struct listnode *ifnode; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), ifnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { if (!if_is_loopback(ifp) && if_is_operative(ifp)) pim_if_addr_add_all(ifp); } @@ -392,7 +392,6 @@ static int pim_zebra_if_address_del(int command, struct zclient *client, static void scan_upstream_rpf_cache() { struct listnode *up_node; - struct listnode *ifnode; struct listnode *up_nextnode; struct listnode *node; struct pim_upstream *up; @@ -501,7 +500,7 @@ static void scan_upstream_rpf_cache() if (!pim) continue; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, ifp)) + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) if (ifp->info) { struct pim_interface *pim_ifp = ifp->info; struct pim_iface_upstream_switch *us; @@ -861,7 +860,6 @@ static void igmp_source_forward_reevaluate_one(struct pim_instance *pim, void igmp_source_forward_reevaluate_all(void) { - struct listnode *ifnode; struct interface *ifp; struct vrf *vrf; struct pim_instance *pim; @@ -871,8 +869,7 @@ void igmp_source_forward_reevaluate_all(void) if (!pim) continue; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), ifnode, - ifp)) { + RB_FOREACH (ifp, if_name_head, &pim->vrf->ifaces_by_name) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index 1b2cbb61c..fe72de229 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -336,10 +336,10 @@ static int rip_if_ipv4_address_check(struct interface *ifp) /* Does this address belongs to me ? */ int if_check_address(struct in_addr addr) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { struct listnode *cnode; struct connected *connected; @@ -490,10 +490,10 @@ static void rip_interface_clean(struct rip_interface *ri) void rip_interfaces_clean(void) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) rip_interface_clean(ifp->info); } @@ -542,10 +542,10 @@ static void rip_interface_reset(struct rip_interface *ri) void rip_interfaces_reset(void) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) rip_interface_reset(ifp->info); } @@ -583,10 +583,10 @@ int rip_if_down(struct interface *ifp) /* Needed for stop RIP process. */ void rip_if_down_all() { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node, *nnode; - for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) rip_if_down(ifp); } @@ -977,11 +977,11 @@ void rip_enable_apply(struct interface *ifp) /* Apply network configuration to all interface. */ void rip_enable_apply_all() { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node, *nnode; /* Check each interface. */ - for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) rip_enable_apply(ifp); } @@ -1091,10 +1091,10 @@ void rip_passive_interface_apply(struct interface *ifp) static void rip_passive_interface_apply_all(void) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node, *nnode; - for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) rip_passive_interface_apply(ifp); } @@ -1728,10 +1728,10 @@ DEFUN (no_rip_passive_interface, /* Write rip configuration of each interface. */ static int rip_interface_config_write(struct vty *vty) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { struct rip_interface *ri; if (ifp->ifindex == IFINDEX_DELETED) diff --git a/ripd/ripd.c b/ripd/ripd.c index bededba7f..fb628001a 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -372,16 +372,16 @@ static int rip_filter(int rip_distribute, struct prefix_ipv4 *p, /* Check nexthop address validity. */ static int rip_nexthop_check(struct in_addr *addr) { - struct listnode *node; - struct listnode *cnode; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; + struct listnode *cnode; struct connected *ifc; struct prefix *p; /* If nexthop address matches local configured address then it is invalid nexthop. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) { p = ifc->address; @@ -2445,7 +2445,7 @@ static void rip_update_interface(struct connected *ifc, u_char version, /* Update send to all interface and neighbor. */ static void rip_update_process(int route_type) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct listnode *ifnode, *ifnnode; struct connected *connected; struct interface *ifp; @@ -2455,7 +2455,7 @@ static void rip_update_process(int route_type) struct prefix *p; /* Send RIP update to each interface. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { if (if_is_loopback(ifp)) continue; @@ -3512,7 +3512,7 @@ DEFUN (show_ip_rip_status, "Show RIP routes\n" "IP routing protocol process parameters and statistics\n") { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct rip_interface *ri; extern const struct message ri_version_msg[]; @@ -3552,7 +3552,7 @@ DEFUN (show_ip_rip_status, vty_out(vty, " Interface Send Recv Key-chain\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { ri = ifp->info; if (!ri->running) @@ -3586,7 +3586,7 @@ DEFUN (show_ip_rip_status, { int found_passive = 0; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { ri = ifp->info; if ((ri->enable_network || ri->enable_interface) @@ -3771,10 +3771,10 @@ void rip_distribute_update_interface(struct interface *ifp) /* ARGSUSED */ static void rip_distribute_update_all(struct prefix_list *notused) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node, *nnode; - for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) rip_distribute_update_interface(ifp); } /* ARGSUSED */ @@ -3947,10 +3947,10 @@ static void rip_routemap_update_redistribute(void) /* ARGSUSED */ static void rip_routemap_update(const char *notused) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node, *nnode; - for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) rip_if_rmap_update_interface(ifp); rip_routemap_update_redistribute(); diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 5c65f522e..aab2b2324 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -306,11 +306,11 @@ int ripng_interface_delete(int command, struct zclient *zclient, void ripng_interface_clean(void) { - struct listnode *node, *nnode; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct ripng_interface *ri; - for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { ri = ifp->info; ri->enable_network = 0; @@ -326,11 +326,11 @@ void ripng_interface_clean(void) void ripng_interface_reset(void) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct ripng_interface *ri; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { ri = ifp->info; ri->enable_network = 0; @@ -760,10 +760,10 @@ void ripng_enable_apply(struct interface *ifp) /* Set distribute list to all interfaces. */ static void ripng_enable_apply_all(void) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ripng_enable_apply(ifp); } @@ -821,10 +821,10 @@ void ripng_passive_interface_apply(struct interface *ifp) static void ripng_passive_interface_apply_all(void) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ripng_passive_interface_apply(ifp); } @@ -1069,12 +1069,12 @@ static int ripng_if_delete_hook(struct interface *ifp) /* Configuration write function for ripngd. */ static int interface_config_write(struct vty *vty) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct ripng_interface *ri; int write = 0; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { ri = ifp->info; /* Do not display the interface if there is no diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 4df1aafe5..902b5d986 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -1377,7 +1377,7 @@ static void ripng_clear_changed_flag(void) enabled interface. */ static int ripng_update(struct thread *t) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct ripng_interface *ri; @@ -1389,7 +1389,7 @@ static int ripng_update(struct thread *t) zlog_debug("RIPng update timer expired!"); /* Supply routes to each interface. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { ri = ifp->info; if (if_is_loopback(ifp) || !if_is_up(ifp)) @@ -1445,7 +1445,7 @@ static int ripng_triggered_interval(struct thread *t) /* Execute triggered update. */ int ripng_triggered_update(struct thread *t) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct ripng_interface *ri; int interval; @@ -1465,7 +1465,7 @@ int 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 (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { ri = ifp->info; if (if_is_loopback(ifp) || !if_is_up(ifp)) @@ -2058,7 +2058,7 @@ DEFUN (show_ipv6_ripng_status, "Show RIPng routes\n" "IPv6 routing protocol process parameters and statistics\n") { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; if (!ripng) @@ -2091,7 +2091,7 @@ DEFUN (show_ipv6_ripng_status, vty_out(vty, " Interface Send Recv\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { struct ripng_interface *ri; ri = ifp->info; @@ -2791,10 +2791,10 @@ void ripng_distribute_update_interface(struct interface *ifp) /* Update all interface's distribute list. */ static void ripng_distribute_update_all(struct prefix_list *notused) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ripng_distribute_update_interface(ifp); } @@ -2968,10 +2968,10 @@ static void ripng_routemap_update_redistribute(void) static void ripng_routemap_update(const char *unused) { + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - struct listnode *node; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) ripng_if_rmap_update_interface(ifp); ripng_routemap_update_redistribute(); diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index f31c24ada..54dbb555d 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -262,10 +262,10 @@ static int if_getaddrs(void) /* Fetch interface information via ioctl(). */ static void interface_info_ioctl() { - struct listnode *node, *nnode; + struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; - for (ALL_LIST_ELEMENTS(vrf_iflist(VRF_DEFAULT), node, nnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { if_get_index(ifp); #ifdef SIOCGIFHWADDR if_get_hwaddr(ifp); diff --git a/zebra/interface.c b/zebra/interface.c index a65dd21f6..1b11357a8 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1317,7 +1317,7 @@ DEFUN (show_interface, "Interface status and configuration\n" VRF_CMD_HELP_STR) { - struct listnode *node; + struct vrf *vrf; struct interface *ifp; vrf_id_t vrf_id = VRF_DEFAULT; @@ -1327,7 +1327,8 @@ DEFUN (show_interface, VRF_GET_ID(vrf_id, argv[3]->arg); /* All interface print. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) + vrf = vrf_lookup_by_id(vrf_id); + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) if_dump_vty(vty, ifp); return CMD_SUCCESS; @@ -1343,14 +1344,13 @@ DEFUN (show_interface_vrf_all, VRF_ALL_CMD_HELP_STR) { struct vrf *vrf; - struct listnode *node; struct interface *ifp; interface_update_stats(); /* All interface print. */ RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - for (ALL_LIST_ELEMENTS_RO(vrf->iflist, node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) if_dump_vty(vty, ifp); return CMD_SUCCESS; @@ -1425,11 +1425,11 @@ DEFUN (show_interface_name_vrf_all, static void if_show_description(struct vty *vty, vrf_id_t vrf_id) { - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct interface *ifp; vty_out(vty, "Interface Status Protocol Description\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { int len; len = vty_out(vty, "%s", ifp->name); @@ -1486,7 +1486,7 @@ DEFUN (show_interface_desc_vrf_all, struct vrf *vrf; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - if (!list_isempty(vrf->iflist)) { + if (!RB_EMPTY (if_name_head, &vrf->ifaces_by_name)) { vty_out(vty, "\n\tVRF %u\n\n", vrf->vrf_id); if_show_description(vty, vrf->vrf_id); } @@ -2830,13 +2830,12 @@ static int link_params_config_write(struct vty *vty, struct interface *ifp) static int if_config_write(struct vty *vty) { struct vrf *vrf; - struct listnode *node; struct interface *ifp; zebra_ptm_write(vty); RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - for (ALL_LIST_ELEMENTS_RO(vrf->iflist, node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { struct zebra_if *if_data; struct listnode *addrnode; struct connected *ifc; diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c index bc85e983e..816bc85ce 100644 --- a/zebra/irdp_main.c +++ b/zebra/irdp_main.c @@ -315,7 +315,6 @@ void process_solicit(struct interface *ifp) static int irdp_finish(void) { struct vrf *vrf; - struct listnode *node, *nnode; struct interface *ifp; struct zebra_if *zi; struct irdp_interface *irdp; @@ -323,7 +322,7 @@ static int irdp_finish(void) zlog_info("IRDP: Received shutdown notification."); RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) - for (ALL_LIST_ELEMENTS(vrf->iflist, node, nnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { zi = ifp->info; if (!zi) diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 633604120..c870e2916 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -383,7 +383,6 @@ static int rtadv_timer(struct thread *thread) { struct zebra_ns *zns = THREAD_ARG(thread); struct vrf *vrf; - struct listnode *node, *nnode; struct interface *ifp; struct zebra_if *zif; int period; @@ -398,7 +397,7 @@ static int rtadv_timer(struct thread *thread) } RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) - for (ALL_LIST_ELEMENTS(vrf->iflist, node, nnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { if (if_is_loopback(ifp) || CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_VRF_LOOPBACK) diff --git a/zebra/zebra_l2.c b/zebra/zebra_l2.c index 345637c04..2ee711e1c 100644 --- a/zebra/zebra_l2.c +++ b/zebra/zebra_l2.c @@ -52,11 +52,10 @@ static void map_slaves_to_bridge(struct interface *br_if, int link) { struct vrf *vrf; - struct listnode *node; struct interface *ifp; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - for (ALL_LIST_ELEMENTS_RO(vrf->iflist, node, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { struct zebra_if *zif; struct zebra_l2info_brslave *br_slave; diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index a42e6680e..46d16e46c 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -257,14 +257,13 @@ DEFUN (zebra_ptm_enable, "Enable neighbor check with specified topology\n") { struct vrf *vrf; - struct listnode *i; struct interface *ifp; struct zebra_if *if_data; ptm_cb.ptm_enable = ZEBRA_IF_PTM_ENABLE_ON; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) - for (ALL_LIST_ELEMENTS_RO(vrf->iflist, i, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) if (!ifp->ptm_enable) { if_data = (struct zebra_if *)ifp->info; if (if_data @@ -1088,12 +1087,11 @@ void zebra_ptm_send_status_req(void) void zebra_ptm_reset_status(int ptm_disable) { struct vrf *vrf; - struct listnode *i; struct interface *ifp; int send_linkup; RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) - for (ALL_LIST_ELEMENTS_RO(vrf->iflist, i, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { send_linkup = 0; if (ifp->ptm_enable) { if (!if_is_operative(ifp)) diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index bf8a17c3e..44a682957 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -179,7 +179,6 @@ static int zebra_vrf_delete(struct vrf *vrf) /* uninstall everything */ if (!CHECK_FLAG(zvrf->flags, ZEBRA_VRF_RETAIN)) { - struct listnode *node; struct interface *ifp; for (afi = AFI_IP; afi <= AFI_IP6; afi++) { @@ -204,7 +203,7 @@ static int zebra_vrf_delete(struct vrf *vrf) zebra_mpls_close_tables(zvrf); zebra_pw_exit(zvrf); - for (ALL_LIST_ELEMENTS_RO(vrf->iflist, node, ifp)) + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp); } diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index bd7b3cb8d..6066980b2 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -1211,12 +1211,11 @@ struct interface *zebra_get_vrr_intf_for_svi(struct interface *ifp) struct zebra_vrf *zvrf = NULL; struct interface *tmp_if = NULL; struct zebra_if *zif = NULL; - struct listnode *node; zvrf = vrf_info_lookup(ifp->vrf_id); assert(zvrf); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(zvrf_id(zvrf)), node, tmp_if)) { + RB_FOREACH (tmp_if, if_name_head, &zvrf->vrf->ifaces_by_name) { zif = tmp_if->info; if (!zif) continue; diff --git a/zebra/zserv.c b/zebra/zserv.c index fd2c5dd97..2a08a556d 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -998,14 +998,13 @@ static int zread_interface_add(struct zserv *client, u_short length, struct zebra_vrf *zvrf) { struct vrf *vrf; - struct listnode *ifnode, *ifnnode; struct interface *ifp; /* Interface information is needed. */ vrf_bitmap_set(client->ifinfo, zvrf_id(zvrf)); RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { - for (ALL_LIST_ELEMENTS(vrf->iflist, ifnode, ifnnode, ifp)) { + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) { /* Skip pseudo interface. */ if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) continue; |