diff options
61 files changed, 490 insertions, 574 deletions
diff --git a/.clang-format b/.clang-format index 2710d844e..21fe9d7c5 100644 --- a/.clang-format +++ b/.clang-format @@ -41,6 +41,8 @@ ForEachMacros: - RB_FOREACH_REVERSE - RB_FOREACH_REVERSE_SAFE - SPLAY_FOREACH + - FOR_ALL_INTERFACES + - FOR_ALL_INTERFACES_ADDRESSES # zebra - RE_DEST_FOREACH_ROUTE - RE_DEST_FOREACH_ROUTE_SAFE diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index 4419160cd..d4958ddf2 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -138,7 +138,7 @@ babel_interface_delete (int cmd, struct zclient *client, zebra_size_t length, vr /* To support pseudo interface do not free interface structure. */ /* if_delete(ifp); */ - ifp->ifindex = IFINDEX_INTERNAL; + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } @@ -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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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 501177e60..17d9bfb93 100644 --- a/babeld/babel_interface.h +++ b/babeld/babel_interface.h @@ -103,16 +103,6 @@ if_up(struct interface *ifp) (babel_get_if_nfo(ifp)->flags & BABEL_IF_IS_UP)); } -/* types: - struct interface _ifp, struct listnode node */ -#define FOR_ALL_INTERFACES(_ifp, _node) \ - for(ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), _node, _ifp)) - -/* types: - struct interface *ifp, struct connected *_connected, struct listnode *node */ -#define FOR_ALL_INTERFACES_ADDRESSES(ifp, _connected, _node) \ - for(ALL_LIST_ELEMENTS_RO(ifp->connected, _node, _connected)) - struct buffered_update { unsigned char id[8]; unsigned char prefix[16]; @@ -120,7 +110,6 @@ struct buffered_update { unsigned char pad[3]; }; - /* init function */ void babel_if_init(void); diff --git a/babeld/babeld.c b/babeld/babeld.c index 207c37d9b..00367612c 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)) + FOR_ALL_INTERFACES (vrf, ifp) babel_distribute_update_interface (ifp); } diff --git a/babeld/message.c b/babeld/message.c index 142770e86..1ff486790 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 f97945724..ddf461f1b 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -238,7 +238,7 @@ static int bgp_interface_delete(int command, struct zclient *zclient, bgp_update_interface_nbrs(bgp, ifp, NULL); - ifp->ifindex = IFINDEX_DELETED; + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } @@ -593,18 +593,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { cp = connected->address; @@ -618,13 +622,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; + + FOR_ALL_INTERFACES (vrf, ifp) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { cp = connected->address; @@ -639,18 +647,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { cp = connected->address; @@ -671,13 +683,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; + + FOR_ALL_INTERFACES (vrf, ifp) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { cp = connected->address; diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 308698e1c..d223cecc5 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { struct listnode *c_node, *c_nnode; struct connected *c; diff --git a/eigrpd/eigrp_filter.c b/eigrpd/eigrp_filter.c index b74127aa4..7a8fd027c 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)) + FOR_ALL_INTERFACES (vrf, ifp) eigrp_distribute_update_interface(ifp); } diff --git a/eigrpd/eigrp_network.c b/eigrpd/eigrp_network.c index 50e6b7b3b..56327f120 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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..d93abbb8b 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { ei = ifp->info; if (!ei) continue; diff --git a/eigrpd/eigrp_zebra.c b/eigrpd/eigrp_zebra.c index 66f03b776..28d2f2981 100644 --- a/eigrpd/eigrp_zebra.c +++ b/eigrpd/eigrp_zebra.c @@ -192,6 +192,7 @@ static int eigrp_interface_delete(int command, struct zclient *zclient, eigrp_if_free(ifp->info, INTERFACE_DOWN_BY_ZEBRA); + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } @@ -334,8 +335,7 @@ static struct interface *zebra_interface_if_lookup(struct stream *s) stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* And look it up. */ - return if_lookup_by_name_len( - ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), VRF_DEFAULT); + return if_lookup_by_name(ifname_tmp, VRF_DEFAULT); } void eigrp_zebra_route_add(struct prefix *p, struct list *successors) diff --git a/eigrpd/eigrpd.c b/eigrpd/eigrpd.c index c70e198bd..a8173f4ef 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)) + FOR_ALL_INTERFACES (vrf, ifp) eigrp_if_update(ifp); } } diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 4179de1c0..5e4090fac 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -932,17 +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)) { - if (ifp->ifindex == IFINDEX_DELETED) - continue; - + FOR_ALL_INTERFACES (vrf, ifp) { /* IF name */ vty_frame(vty, "interface %s\n", ifp->name); write++; @@ -952,7 +950,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..104a0fd4b 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)) + FOR_ALL_INTERFACES (vrf, ifp) show_mpls_te_sub(vty, ifp); } /* Interface name is specified. */ diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c index bc8131409..387f99938 100644 --- a/isisd/isis_zebra.c +++ b/isisd/isis_zebra.c @@ -128,7 +128,7 @@ static int isis_zebra_if_del(int command, struct zclient *zclient, in case there is configuration info attached to it. */ if_delete_retain(ifp); - ifp->ifindex = IFINDEX_DELETED; + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c index c50cc0fda..7f68f0b69 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { if (ifname && strcmp(ifname, ifp->name) != 0) continue; @@ -287,7 +288,7 @@ ldp_interface_delete(int command, struct zclient *zclient, zebra_size_t length, /* To support pseudo interface do not free interface structure. */ /* if_delete(ifp); */ - ifp->ifindex = IFINDEX_DELETED; + if_set_index(ifp, IFINDEX_INTERNAL); ifp2kif(ifp, &kif); main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif)); @@ -40,6 +40,12 @@ 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 *); +static int if_cmp_index_func(const struct interface *ifp1, + const struct interface *ifp2); +RB_GENERATE(if_name_head, interface, name_entry, if_cmp_func); +RB_GENERATE(if_index_head, interface, index_entry, if_cmp_index_func); + DEFINE_QOBJ_TYPE(interface) DEFINE_HOOK(if_add, (struct interface *ifp), (ifp)) @@ -85,6 +91,8 @@ int if_cmp_name_func(char *p1, char *p2) p1 += l1; p2 += l1; + if (!*p1 && !*p2) + return 0; if (!*p1) return -1; if (!*p2) @@ -109,32 +117,31 @@ 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((char *)ifp1->name, (char *)ifp2->name); +} + +static int if_cmp_index_func(const struct interface *ifp1, + const struct interface *ifp2) { - return if_cmp_name_func(ifp1->name, ifp2->name); + return ifp1->ifindex - ifp2->ifindex; } /* Create new interface structure. */ -struct interface *if_create(const char *name, int namelen, vrf_id_t vrf_id) +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; assert(name); - assert(namelen <= INTERFACE_NAMSIZ); /* Need space for '\0' at end. */ - strncpy(ifp->name, name, namelen); - ifp->name[namelen] = '\0'; + 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 - zlog_err( - "if_create(%s): corruption detected -- interface with this " - "name exists already in VRF %u!", - ifp->name, vrf_id); + IFNAME_RB_INSERT(vrf, ifp); ifp->connected = list_new(); ifp->connected->del = (void (*)(void *))connected_free; @@ -152,22 +159,22 @@ struct interface *if_create(const char *name, int namelen, 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) { + IFNAME_RB_REMOVE(vrf, ifp); + if (ifp->ifindex != IFINDEX_INTERNAL) + IFINDEX_RB_REMOVE(vrf, ifp); + } ifp->vrf_id = vrf_id; - if (if_lookup_by_name(ifp->name, vrf_id) == NULL) - listnode_add_sort(intf_list, ifp); - else - zlog_err( - "if_create(%s): corruption detected -- interface with this " - "name exists already in VRF %u!", - ifp->name, vrf_id); - - return; + vrf = vrf_get(ifp->vrf_id, NULL); + + IFNAME_RB_INSERT(vrf, ifp); + if (ifp->ifindex != IFINDEX_INTERNAL) + IFINDEX_RB_INSERT(vrf, ifp); } @@ -187,7 +194,11 @@ 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); + + IFNAME_RB_REMOVE(vrf, ifp); + if (ifp->ifindex != IFINDEX_INTERNAL) + IFINDEX_RB_REMOVE(vrf, ifp); if_delete_retain(ifp); @@ -202,14 +213,11 @@ 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 interface *ifp; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); + struct interface if_tmp; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { - if (ifp->ifindex == ifindex) - return ifp; - } - return NULL; + if_tmp.ifindex = ifindex; + return RB_FIND(if_index_head, &vrf->ifaces_by_index, &if_tmp); } const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id) @@ -233,15 +241,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) - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { - if (strcmp(name, ifp->name) == 0) - return ifp; - } - return NULL; + if (!name || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ) + 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) @@ -249,6 +256,9 @@ struct interface *if_lookup_by_name_all_vrf(const char *name) struct vrf *vrf; struct interface *ifp; + if (!name || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ) + return NULL; + RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { ifp = if_lookup_by_name(name, vrf->vrf_id); if (ifp) @@ -258,34 +268,17 @@ struct interface *if_lookup_by_name_all_vrf(const char *name) return NULL; } -struct interface *if_lookup_by_name_len(const char *name, size_t namelen, - vrf_id_t vrf_id) -{ - struct listnode *node; - struct interface *ifp; - - if (namelen > INTERFACE_NAMSIZ) - return NULL; - - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { - if (!memcmp(name, ifp->name, namelen) - && (ifp->name[namelen] == '\0')) - return ifp; - } - return NULL; -} - /* Lookup interface by IPv4 address. */ 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { p = c->address; @@ -311,7 +304,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; @@ -331,7 +324,7 @@ struct connected *if_lookup_address(void *matchaddr, int family, match = NULL; - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) { + FOR_ALL_INTERFACES (vrf, ifp) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { if (c->address && (c->address->family == AF_INET) && prefix_match(CONNECTED_PREFIX(c), &addr) @@ -347,12 +340,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) { if (prefix_cmp(c->address, prefix) == 0) { return ifp; @@ -364,53 +357,49 @@ struct interface *if_lookup_prefix(struct prefix *prefix, vrf_id_t vrf_id) /* Get interface by name if given name interface doesn't exist create one. */ -struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id) +struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id, int vty) { struct interface *ifp; - return ((ifp = if_lookup_by_name(name, vrf_id)) != NULL) - ? ifp - : if_create(name, strlen(name), vrf_id); + ifp = if_lookup_by_name_all_vrf(name); + if (ifp) { + if (ifp->vrf_id == vrf_id) + return ifp; + + /* Found a match on a different VRF. If the interface command + * was entered in vty without a VRF (passed as VRF_DEFAULT), + * accept the ifp we found. If a vrf was entered and there is + * a mismatch, reject it if from vty. If it came from the kernel + * or by way of zclient, believe it and update the ifp + * accordingly. + */ + if (vty) { + if (vrf_id == VRF_DEFAULT) + return ifp; + return NULL; + } else { + if_update_to_new_vrf(ifp, vrf_id); + return ifp; + } + } + + return if_create(name, vrf_id); } -struct interface *if_get_by_name_len(const char *name, size_t namelen, - vrf_id_t vrf_id, int vty) +void if_set_index(struct interface *ifp, ifindex_t ifindex) { - struct interface *ifp; - struct vrf *vrf; - struct listnode *node; + struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); - ifp = if_lookup_by_name_len(name, namelen, vrf_id); - if (ifp) - return ifp; + if (ifp->ifindex == ifindex) + return; - /* Didn't find the interface on that vrf. Defined on a different one? */ - RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf->vrf_id), node, ifp)) { - if (!memcmp(name, ifp->name, namelen) - && (ifp->name[namelen] == '\0')) { - /* Found a match. If the interface command was - * entered in vty without a - * VRF (passed as VRF_DEFAULT), accept the ifp - * we found. If a vrf was - * entered and there is a mismatch, reject it if - * from vty. If it came - * from the kernel by way of zclient, believe - * it and update - * the ifp accordingly. - */ - if (vty) { - if (vrf_id == VRF_DEFAULT) - return ifp; - return NULL; - } else { - if_update_to_new_vrf(ifp, vrf_id); - return ifp; - } - } - } - } - return (if_create(name, namelen, vrf_id)); + if (ifp->ifindex != IFINDEX_INTERNAL) + IFINDEX_RB_REMOVE(vrf, ifp) + + ifp->ifindex = ifindex; + + if (ifp->ifindex != IFINDEX_INTERNAL) + IFINDEX_RB_INSERT(vrf, ifp) } /* Does interface up ? */ @@ -536,13 +525,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); + FOR_ALL_INTERFACES (vrf, ifp) + if_dump(ifp); } DEFUN (interface_desc, @@ -597,24 +584,20 @@ DEFUN (no_interface_desc, * if not: * - no idea, just get the name in its entirety. */ -static struct interface *if_sunwzebra_get(const char *name, size_t nlen, - vrf_id_t vrf_id) +static struct interface *if_sunwzebra_get(char *name, vrf_id_t vrf_id) { struct interface *ifp; - size_t seppos = 0; + char *cp; - if ((ifp = if_lookup_by_name_len(name, nlen, vrf_id)) != NULL) + if ((ifp = if_lookup_by_name(name, vrf_id)) != NULL) return ifp; /* hunt the primary interface name... */ - while (seppos < nlen && name[seppos] != ':') - seppos++; - - /* Wont catch seperator as last char, e.g. 'foo0:' but thats invalid */ - if (seppos < nlen) - return if_get_by_name_len(name, seppos, vrf_id, 1); - else - return if_get_by_name_len(name, nlen, vrf_id, 1); + cp = strchr(name, ':'); + if (cp) + *cp = '\0'; + + return if_get_by_name(name, vrf_id, 1); } #endif /* SUNOS_5 */ @@ -631,10 +614,9 @@ DEFUN (interface, const char *vrfname = (argc > 2) ? argv[idx_vrf]->arg : NULL; struct interface *ifp; - size_t sl; vrf_id_t vrf_id = VRF_DEFAULT; - if ((sl = strlen(ifname)) > INTERFACE_NAMSIZ) { + if (strlen(ifname) > INTERFACE_NAMSIZ) { vty_out(vty, "%% Interface name %s is invalid: length exceeds " "%d characters\n", @@ -648,9 +630,9 @@ DEFUN (interface, VRF_GET_ID(vrf_id, vrfname); #ifdef SUNOS_5 - ifp = if_sunwzebra_get(ifname, sl, vrf_id); + ifp = if_sunwzebra_get(ifname, vrf_id); #else - ifp = if_get_by_name_len(ifname, sl, vrf_id, 1); + ifp = if_get_by_name(ifname, vrf_id, 1); #endif /* SUNOS_5 */ if (!ifp) { @@ -697,8 +679,30 @@ DEFUN_NOSH (no_interface, return CMD_SUCCESS; } +static void if_autocomplete(vector comps, struct cmd_token *token) +{ + struct interface *ifp; + struct vrf *vrf = NULL; + + RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { + FOR_ALL_INTERFACES (vrf, ifp) { + vector_set(comps, XSTRDUP(MTYPE_COMPLETION, ifp->name)); + } + } +} + +static const struct cmd_variable_handler if_var_handlers[] = { + {/* "interface NAME" */ + .varname = "interface", + .completions = if_autocomplete}, + {.tokenname = "IFNAME", .completions = if_autocomplete}, + {.tokenname = "INTERFACE", .completions = if_autocomplete}, + {.completions = NULL}}; + void if_cmd_init(void) { + cmd_variable_handler_register(if_var_handlers); + install_element(CONFIG_NODE, &interface_cmd); install_element(CONFIG_NODE, &no_interface_cmd); @@ -718,7 +722,6 @@ DEFUN (show_address, { int idx_vrf = 3; struct listnode *node; - struct listnode *node2; struct interface *ifp; struct connected *ifc; struct prefix *p; @@ -727,9 +730,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)) + FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) { p = ifc->address; @@ -749,21 +752,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)) + FOR_ALL_INTERFACES (vrf, ifp) { - for (ALL_LIST_ELEMENTS_RO (ifp->connected, node2, ifc)) + for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc)) { p = ifc->address; @@ -1045,57 +1047,17 @@ ifaddr_ipv4_lookup (struct in_addr *addr, ifindex_t ifindex) } #endif /* ifaddr_ipv4_table */ -static void if_autocomplete(vector comps, struct cmd_token *token) +void if_terminate(struct vrf *vrf) { struct interface *ifp; - struct listnode *ln; - struct vrf *vrf = NULL; - - RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { - for (ALL_LIST_ELEMENTS_RO(vrf->iflist, ln, ifp)) - vector_set(comps, XSTRDUP(MTYPE_COMPLETION, ifp->name)); - } -} - -static const struct cmd_variable_handler if_var_handlers[] = { - {/* "interface NAME" */ - .varname = "interface", - .completions = if_autocomplete}, - {.tokenname = "IFNAME", .completions = if_autocomplete}, - {.tokenname = "INTERFACE", .completions = if_autocomplete}, - {.completions = NULL}}; - -/* 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; - - cmd_variable_handler_register(if_var_handlers); -} - -void if_terminate(struct list **intf_list) -{ - for (;;) { - struct interface *ifp; - - ifp = listnode_head(*intf_list); - if (ifp == NULL) - break; + 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, index_entry; + /* Interface name. This should probably never be changed after the interface is created, because the configuration info for this interface @@ -209,13 +211,17 @@ struct interface { To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the interface does not exist in the kernel. */ - char name[INTERFACE_NAMSIZ + 1]; + char name[INTERFACE_NAMSIZ]; /* Interface index (should be IFINDEX_INTERNAL for non-kernel or - deleted interfaces). */ + deleted interfaces). + WARNING: the ifindex needs to be changed using the if_set_index() + function. Failure to respect this will cause corruption in the data + structure used to store the interfaces and if_lookup_by_index() will + not work as expected. + */ ifindex_t ifindex; #define IFINDEX_INTERNAL 0 -#define IFINDEX_DELETED INT_MAX /* Zebra internal interface status */ u_char status; @@ -282,8 +288,47 @@ struct interface { QOBJ_FIELDS }; +RB_HEAD(if_name_head, interface); +RB_PROTOTYPE(if_name_head, interface, name_entry, if_cmp_func); +RB_HEAD(if_index_head, interface); +RB_PROTOTYPE(if_index_head, interface, index_entry, if_cmp_func); DECLARE_QOBJ_TYPE(interface) +#define IFNAME_RB_INSERT(vrf, ifp) \ + 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, (ifp)->vrf_id); + +#define IFNAME_RB_REMOVE(vrf, ifp) \ + if (RB_REMOVE(if_name_head, &vrf->ifaces_by_name, (ifp)) == NULL) \ + zlog_err( \ + "%s(%s): corruption detected -- interface with this " \ + "name doesn't exist in VRF %u!", \ + __func__, (ifp)->name, (ifp)->vrf_id); + +#define IFINDEX_RB_INSERT(vrf, ifp) \ + if (RB_INSERT(if_index_head, &vrf->ifaces_by_index, (ifp))) \ + zlog_err( \ + "%s(%u): corruption detected -- interface with this " \ + "ifindex exists already in VRF %u!", \ + __func__, (ifp)->ifindex, (ifp)->vrf_id); + +#define IFINDEX_RB_REMOVE(vrf, ifp) \ + if (RB_REMOVE(if_index_head, &vrf->ifaces_by_index, (ifp)) == NULL) \ + zlog_err( \ + "%s(%u): corruption detected -- interface with this " \ + "ifindex doesn't exist in VRF %u!", \ + __func__, (ifp)->ifindex, (ifp)->vrf_id); + +#define FOR_ALL_INTERFACES(vrf, ifp) \ + if (vrf) \ + RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) + +#define FOR_ALL_INTERFACES_ADDRESSES(ifp, connected, node) \ + for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) + /* called from the library code whenever interfaces are created/deleted * note: interfaces may not be fully realized at that point; also they * may not exist in the system (ifindex = IFINDEX_INTERNAL) @@ -408,8 +453,7 @@ struct nbr_connected { extern int if_cmp_name_func(char *, char *); extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id); -extern struct interface *if_create(const char *name, int namelen, - vrf_id_t vrf_id); +extern struct interface *if_create(const char *name, vrf_id_t vrf_id); extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id); extern struct interface *if_lookup_exact_address(void *matchaddr, int family, vrf_id_t vrf_id); @@ -422,16 +466,9 @@ extern struct interface *if_lookup_prefix(struct prefix *prefix, by a '\0' character: */ extern struct interface *if_lookup_by_name_all_vrf(const char *ifname); extern struct interface *if_lookup_by_name(const char *ifname, vrf_id_t vrf_id); -extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id); - -/* For these 2 functions, the namelen argument should be the precise length - of the ifname string (not counting any optional trailing '\0' character). - In most cases, strnlen should be used to calculate the namelen value. */ -extern struct interface *if_lookup_by_name_len(const char *ifname, - size_t namelen, vrf_id_t vrf_id); -extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen, - vrf_id_t vrf_id, int vty); - +extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id, + int vty); +extern void if_set_index(struct interface *ifp, ifindex_t ifindex); /* Delete the interface, but do not free the structure, and leave it in the interface list. It is often advisable to leave the pseudo interface @@ -450,9 +487,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,8 @@ 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); + RB_INIT(if_index_head, &vrf->ifaces_by_index); QOBJ_REG(vrf, vrf); new = 1; @@ -153,7 +154,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 +252,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,9 @@ 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; + struct if_index_head ifaces_by_index; /* User data */ void *info; @@ -127,15 +128,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/lib/zclient.c b/lib/zclient.c index 43d46a180..ad5c30584 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1230,8 +1230,7 @@ struct interface *zebra_interface_add_read(struct stream *s, vrf_id_t vrf_id) stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* Lookup/create interface by name. */ - ifp = if_get_by_name_len( - ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), vrf_id, 0); + ifp = if_get_by_name(ifname_tmp, vrf_id, 0); zebra_interface_if_set_value(s, ifp); @@ -1254,8 +1253,7 @@ struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id) stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* Lookup this by interface index. */ - ifp = if_lookup_by_name_len( - ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), vrf_id); + ifp = if_lookup_by_name(ifname_tmp, vrf_id); if (ifp == NULL) { zlog_warn("INTERFACE_STATE: Cannot find IF %s in VRF %d", ifname_tmp, vrf_id); @@ -1333,7 +1331,7 @@ void zebra_interface_if_set_value(struct stream *s, struct interface *ifp) u_char link_params_status = 0; /* Read interface's index. */ - ifp->ifindex = stream_getl(s); + if_set_index(ifp, stream_getl(s)); ifp->status = stream_getc(s); /* Read interface's value. */ diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index a46962c91..67e3f41b3 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -299,7 +299,7 @@ int nhrp_interface_delete(int cmd, struct zclient *client, return 0; debugf(NHRP_DEBUG_IF, "if-delete: %s", ifp->name); - ifp->ifindex = IFINDEX_INTERNAL; + if_set_index(ifp, ifp->ifindex); nhrp_interface_update(ifp); /* if_delete(ifp); */ return 0; diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index 0bada3350..6fbd6ca22 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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..ab052ac04 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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..e28af9d06 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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..f237e4bef 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) + FOR_ALL_INTERFACES (vrf, ifp) ospf6_interface_clear(vty, ifp); } else /* Interface name is specified. */ { diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index e582737f9..4641f41c3 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)) + FOR_ALL_INTERFACES (vrf, ifp) if (ifp->info != NULL) ospf6_interface_delete(ifp->info); diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 0b399bad1..c14810744 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)) + FOR_ALL_INTERFACES (vrf, iif) listnode_add_sort(ifslist, iif); for (ALL_LIST_ELEMENTS_RO(ifslist, node, iif)) { @@ -1042,6 +1042,7 @@ static u_char *ospfv3IfEntry(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); ifindex_t ifindex = 0; unsigned int instid = 0; struct ospf6_interface *oi = NULL; @@ -1092,7 +1093,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)) + FOR_ALL_INTERFACES (vrf, iif) listnode_add_sort(ifslist, iif); for (ALL_LIST_ELEMENTS_RO(ifslist, i, iif)) { @@ -1194,6 +1195,7 @@ static u_char *ospfv3NbrEntry(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); ifindex_t ifindex = 0; unsigned int instid, rtrid; struct ospf6_interface *oi = NULL; @@ -1253,7 +1255,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)) + FOR_ALL_INTERFACES (vrf, iif) listnode_add_sort(ifslist, iif); for (ALL_LIST_ELEMENTS_RO(ifslist, i, iif)) { diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index b0281b9e0..e0844765d 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -595,7 +595,7 @@ DEFUN (ospf6_interface_area, u_int32_t area_id; /* find/create ospf6 interface */ - ifp = if_get_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); + ifp = if_get_by_name(argv[idx_ifname]->arg, VRF_DEFAULT, 0); oi = (struct ospf6_interface *)ifp->info; if (oi == NULL) oi = ospf6_interface_create(ifp); diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 30bb4393c..b032bd7a7 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -126,7 +126,7 @@ static int ospf6_zebra_if_del(int command, struct zclient *zclient, ospf6_interface_if_del (ifp); #endif /*0*/ - ifp->ifindex = IFINDEX_DELETED; + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 67ce6f171..34a1e6f6d 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -798,7 +798,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf, { struct ospf_interface *voi; struct interface *vi; - char ifname[INTERFACE_NAMSIZ + 1]; + char ifname[INTERFACE_NAMSIZ]; struct ospf_area *area; struct in_addr area_id; struct connected *co; @@ -819,7 +819,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf, ospf->vrf_id); snprintf(ifname, sizeof(ifname), "VLINK%d", vlink_count); - vi = if_create(ifname, strnlen(ifname, sizeof(ifname)), ospf->vrf_id); + vi = if_create(ifname, ospf->vrf_id); /* * if_create sets ZEBRA_INTERFACE_LINKDETECTION * virtual links don't need this. diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 392df5fb4..b13e833af 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -2535,9 +2535,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; @@ -2552,11 +2553,11 @@ 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); + FOR_ALL_INTERFACES (vrf, ifp) show_mpls_te_link_sub(vty, ifp); } return CMD_SUCCESS; @@ -2564,18 +2565,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); + FOR_ALL_INTERFACES (vrf, ifp) 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); + FOR_ALL_INTERFACES (vrf, ifp) show_mpls_te_link_sub(vty, ifp); } } diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 7b7a53baa..f53efa435 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -345,13 +345,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { if (ifp && OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), passive_interface)) UNSET_IF_PARAM(IF_DEF_PARAMS(ifp), passive_interface); @@ -425,7 +426,7 @@ DEFUN (ospf_passive_interface, return CMD_SUCCESS; } - ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id); + ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, 0); if (ifp == NULL) { vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); @@ -497,7 +498,7 @@ DEFUN (no_ospf_passive_interface, return CMD_SUCCESS; } - ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id); + ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, 0); if (ifp == NULL) { vty_out(vty, "interface %s not found.\n", (char *)argv[1]->arg); @@ -2469,9 +2470,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); @@ -2485,7 +2486,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)) + FOR_ALL_INTERFACES (vrf, ifp) ospf_if_recalculate_output_cost(ifp); return CMD_SUCCESS; @@ -2500,7 +2501,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) @@ -2511,7 +2512,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)) + FOR_ALL_INTERFACES (vrf, ifp) ospf_if_recalculate_output_cost(ifp); return CMD_SUCCESS; @@ -3569,7 +3570,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; @@ -3587,8 +3588,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { if (ospf_oi_count(ifp)) { if (use_json) json_interface_sub = @@ -8665,22 +8665,20 @@ 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { struct vrf *vrf = NULL; if (memcmp(ifp->name, "VLINK", 5) == 0) continue; - if (ifp->ifindex == IFINDEX_DELETED) - continue; - vrf = vrf_lookup_by_id(ifp->vrf_id); vty_frame(vty, "!\n"); @@ -8761,7 +8759,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); @@ -9266,6 +9264,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; @@ -9360,7 +9359,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)) + FOR_ALL_INTERFACES (vrf, ifp) if (OSPF_IF_PARAM_CONFIGURED(IF_DEF_PARAMS(ifp), passive_interface) && IF_DEF_PARAMS(ifp)->passive_interface @@ -9623,14 +9622,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); + FOR_ALL_INTERFACES (vrf, ifp) ospf_interface_clear(ifp); } } else { diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index 16f87735b..7e6146e0d 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -166,7 +166,7 @@ static int ospf_interface_delete(int command, struct zclient *zclient, if (rn->info) ospf_if_free((struct ospf_interface *)rn->info); - ifp->ifindex = IFINDEX_DELETED; + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } @@ -179,8 +179,7 @@ static struct interface *zebra_interface_if_lookup(struct stream *s, stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* And look it up. */ - return if_lookup_by_name_len( - ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), vrf_id); + return if_lookup_by_name(ifname_tmp, vrf_id); } static int ospf_interface_state_up(int command, struct zclient *zclient, diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 88833e64d..9e1cf8116 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { struct ospf_if_params *params; params = IF_DEF_PARAMS(ifp); @@ -1254,15 +1255,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)) + FOR_ALL_INTERFACES (vrf, ifp) ospf_network_run_interface(area->ospf, ifp, p, area); } diff --git a/pimd/pim_bfd.c b/pimd/pim_bfd.c index 314162c78..f8903d71e 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index ed1d6a819..a9239c283 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) @@ -1324,7 +1315,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; @@ -1337,7 +1327,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) @@ -1419,7 +1409,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; @@ -1437,7 +1426,7 @@ static void pim_show_interface_traffic(struct pim_instance *pim, "---------------------------------------------------------------------------------------------------------------\n"); } - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(pim->vrf_id), node, ifp)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) @@ -1500,7 +1489,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; @@ -1519,7 +1507,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { if (strcmp(ifname, ifp->name)) continue; @@ -1664,7 +1652,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; @@ -1679,7 +1666,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -1699,7 +1686,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; @@ -1725,7 +1711,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) @@ -2111,7 +2097,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; @@ -2133,7 +2118,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) @@ -2194,13 +2179,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { struct pim_interface *pim_ifp; struct in_addr ifaddr; struct listnode *neighnode; @@ -2517,7 +2501,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; @@ -2531,7 +2514,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) continue; @@ -2812,7 +2795,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; @@ -2828,7 +2810,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; @@ -2934,14 +2916,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; @@ -2999,7 +2980,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; @@ -3009,7 +2989,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; @@ -3076,14 +3056,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { struct pim_interface *pim_ifp = ifp->info; struct listnode *sock_node; struct igmp_sock *igmp; @@ -3135,29 +3114,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) pim_if_addr_del_all_igmp(ifp); - } - for (ALL_LIST_ELEMENTS(vrf_iflist(pim->vrf_id), ifnode, ifnextnode, - ifp)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { if (ifp->info) { pim_neighbor_delete_all(ifp, "interface cleared"); } @@ -3311,16 +3281,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { pim_ifp = ifp->info; if (!pim_ifp) @@ -4330,7 +4297,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"); @@ -4338,7 +4304,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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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 878714502..5dc64a1b3 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { if (ifp->info) { struct pim_interface *pim_ifp; pim_ifp = ifp->info; @@ -1480,17 +1479,16 @@ void pim_if_update_assert_tracking_desired(struct interface *ifp) */ void pim_if_create_pimreg(struct pim_instance *pim) { - char pimreg_name[100]; + char pimreg_name[INTERFACE_NAMSIZ]; if (!pim->regiface) { if (pim->vrf_id == VRF_DEFAULT) - strcpy(pimreg_name, "pimreg"); + strlcpy(pimreg_name, "pimreg", sizeof(pimreg_name)); else - sprintf(pimreg_name, "pimreg%d", - pim->vrf->data.l.table_id); + snprintf(pimreg_name, sizeof(pimreg_name), "pimreg%u", + pim->vrf->data.l.table_id); - pim->regiface = if_create(pimreg_name, strlen(pimreg_name), - pim->vrf_id); + pim->regiface = if_create(pimreg_name, pim->vrf_id); pim->regiface->ifindex = PIM_OIF_PIM_REGISTER_VIF; pim_if_new(pim->regiface, 0, 0); diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 6aa5105c5..5f597b17b 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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..e87dfbca9 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { pim_ifp = ifp->info; struct listnode *nnode; diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index a1de4837d..8f9058d99 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)) + FOR_ALL_INTERFACES (pim->vrf, ifp) 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..d961aa4c4 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { struct pim_interface *pim_ifp = ifp->info; if (!pim_ifp) diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index ed5d1ecaa..fdd37f2b9 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { if (!ifp->info) continue; diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index fc377b5a5..450faf75b 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)) { - + FOR_ALL_INTERFACES (pim->vrf, ifp) { /* 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..db11e5f17 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) + FOR_ALL_INTERFACES (pim->vrf, ifp) 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)) { + FOR_ALL_INTERFACES (pim->vrf, ifp) { 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..9282896c2 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { struct listnode *cnode; struct connected *connected; @@ -471,7 +471,7 @@ int rip_interface_delete(int command, struct zclient *zclient, /* To support pseudo interface do not free interface structure. */ /* if_delete(ifp); */ - ifp->ifindex = IFINDEX_DELETED; + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } @@ -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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) rip_passive_interface_apply(ifp); } @@ -1728,15 +1728,12 @@ 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { struct rip_interface *ri; - if (ifp->ifindex == IFINDEX_DELETED) - continue; - ri = ifp->info; /* Do not display the interface if there is no diff --git a/ripd/ripd.c b/ripd/ripd.c index bededba7f..a4b56d9fb 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) rip_if_rmap_update_interface(ifp); rip_routemap_update_redistribute(); diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 5c65f522e..d450d5a7f 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -299,18 +299,18 @@ int ripng_interface_delete(int command, struct zclient *zclient, /* To support pseudo interface do not free interface structure. */ /* if_delete(ifp); */ - ifp->ifindex = IFINDEX_DELETED; + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { ri = ifp->info; /* Do not display the interface if there is no diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 7524061ad..df3af2a17 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -1379,7 +1379,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; @@ -1391,7 +1391,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { ri = ifp->info; if (if_is_loopback(ifp) || !if_is_up(ifp)) @@ -1447,7 +1447,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; @@ -1467,7 +1467,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { ri = ifp->info; if (if_is_loopback(ifp) || !if_is_up(ifp)) @@ -2060,7 +2060,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) @@ -2093,7 +2093,7 @@ DEFUN (show_ipv6_ripng_status, vty_out(vty, " Interface Send Recv\n"); - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node, ifp)) { + FOR_ALL_INTERFACES (vrf, ifp) { struct ripng_interface *ri; ri = ifp->info; @@ -2793,10 +2793,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)) + FOR_ALL_INTERFACES (vrf, ifp) ripng_distribute_update_interface(ifp); } @@ -2970,10 +2970,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)) + FOR_ALL_INTERFACES (vrf, ifp) ripng_if_rmap_update_interface(ifp); ripng_routemap_update_redistribute(); diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index 6396911e1..1d108886d 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -105,10 +105,7 @@ static int interface_list_ioctl(void) unsigned int size; ifreq = (struct ifreq *)((caddr_t)ifconf.ifc_req + n); - ifp = if_get_by_name_len( - ifreq->ifr_name, - strnlen(ifreq->ifr_name, sizeof(ifreq->ifr_name)), - VRF_DEFAULT, 0); + ifp = if_get_by_name(ifreq->ifr_name, VRF_DEFAULT, 0); if_add_update(ifp); size = ifreq->ifr_addr.sa_len; if (size < sizeof(ifreq->ifr_addr)) @@ -118,10 +115,7 @@ static int interface_list_ioctl(void) } #else for (n = 0; n < ifconf.ifc_len; n += sizeof(struct ifreq)) { - ifp = if_get_by_name_len( - ifreq->ifr_name, - strnlen(ifreq->ifr_name, sizeof(ifreq->ifr_name)), - VRF_DEFAULT, 0); + ifp = if_get_by_name(ifreq->ifr_name, VRF_DEFAULT, 0); if_add_update(ifp); ifreq++; } @@ -137,7 +131,7 @@ end: /* Get interface's index by ioctl. */ static int if_get_index(struct interface *ifp) { - ifp->ifindex = if_nametoindex(ifp->name); + if_set_index(ifp, if_nametoindex(ifp->name)); return ifp->ifindex; } @@ -268,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { if_get_index(ifp); #ifdef SIOCGIFHWADDR if_get_hwaddr(ifp); diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c index 9ec575b5b..94738664b 100644 --- a/zebra/if_ioctl_solaris.c +++ b/zebra/if_ioctl_solaris.c @@ -170,8 +170,7 @@ calculate_lifc_len: /* must hold privileges to enter here */ && (*(lifreq->lifr_name + normallen) != ':')) normallen++; - ifp = if_get_by_name_len(lifreq->lifr_name, normallen, - VRF_DEFAULT, 0); + ifp = if_get_by_name(lifreq->lifr_name, VRF_DEFAULT, 0); if (lifreq->lifr_addr.ss_family == AF_INET) ifp->flags |= IFF_IPV4; @@ -228,9 +227,9 @@ static int if_get_index(struct interface *ifp) /* OK we got interface index. */ #ifdef ifr_ifindex - ifp->ifindex = lifreq.lifr_ifindex; + if_set_index(ifp, lifreq.lifr_ifindex); #else - ifp->ifindex = lifreq.lifr_index; + if_set_index(ifp, lifreq.lifr_index); #endif return ifp->ifindex; } diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 5a42e0c8f..a2235904c 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -93,7 +93,7 @@ static void set_ifindex(struct interface *ifp, ifindex_t ifi_index, if_delete_update(oifp); } } - ifp->ifindex = ifi_index; + if_set_index(ifp, ifi_index); } /* Utility function to parse hardware link-layer address and update ifp */ @@ -666,7 +666,7 @@ static int netlink_interface(struct sockaddr_nl *snl, struct nlmsghdr *h, link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]); /* Add interface. */ - ifp = if_get_by_name(name, vrf_id); + ifp = if_get_by_name(name, vrf_id, 0); set_ifindex(ifp, ifi->ifi_index, zns); ifp->flags = ifi->ifi_flags & 0x0000fffff; if (IS_ZEBRA_IF_VRF(ifp)) @@ -1121,7 +1121,7 @@ int netlink_link_change(struct sockaddr_nl *snl, struct nlmsghdr *h, if (ifp == NULL) { /* unknown interface */ - ifp = if_get_by_name(name, vrf_id); + ifp = if_get_by_name(name, vrf_id, 0); } else { /* pre-configured interface, learnt now */ if (ifp->vrf_id != vrf_id) diff --git a/zebra/interface.c b/zebra/interface.c index a65dd21f6..e912b2dcf 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -685,7 +685,7 @@ void if_delete_update(struct interface *ifp) while processing the deletion. Each client daemon is responsible for setting ifindex to IFINDEX_INTERNAL after processing the interface deletion message. */ - ifp->ifindex = IFINDEX_INTERNAL; + if_set_index(ifp, IFINDEX_INTERNAL); ifp->node = NULL; /* if the ifp is in a vrf, move it to default so vrf can be deleted if @@ -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); + FOR_ALL_INTERFACES (vrf, ifp) 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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..5567d53c3 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { zi = ifp->info; if (!zi) diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 9907ef5b7..89c933f90 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -323,11 +323,8 @@ static int ifan_read(struct if_announcemsghdr *ifan) __func__, ifan->ifan_index, ifan->ifan_name); /* Create Interface */ - ifp = if_get_by_name_len( - ifan->ifan_name, - strnlen(ifan->ifan_name, sizeof(ifan->ifan_name)), - VRF_DEFAULT, 0); - ifp->ifindex = ifan->ifan_index; + ifp = if_get_by_name(ifan->ifan_name, VRF_DEFAULT, 0); + if_set_index(ifp, ifan->ifan_index); if_get_metric(ifp); if_add_update(ifp); @@ -517,7 +514,7 @@ int ifm_read(struct if_msghdr *ifm) if (ifp == NULL) { /* Interface that zebra was not previously aware of, so * create. */ - ifp = if_create(ifname, ifnlen, VRF_DEFAULT); + ifp = if_create(ifname, VRF_DEFAULT); if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("%s: creating ifp for ifindex %d", __func__, ifm->ifm_index); @@ -531,7 +528,7 @@ int ifm_read(struct if_msghdr *ifm) * Fill in newly created interface structure, or larval * structure with ifindex IFINDEX_INTERNAL. */ - ifp->ifindex = ifm->ifm_index; + if_set_index(ifp, ifm->ifm_index); #ifdef HAVE_BSD_IFI_LINK_STATE /* translate BSD kernel msg for link-state */ bsd_linkdetect_translate(ifm); diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 633604120..6a8e2ac59 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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..529fc48ed 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { struct zebra_if *zif; struct zebra_l2info_brslave *br_slave; diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index a42e6680e..93b0723d8 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)) + FOR_ALL_INTERFACES (vrf, ifp) 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)) { + FOR_ALL_INTERFACES (vrf, ifp) { 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..0d0a8dd74 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)) + FOR_ALL_INTERFACES (vrf, ifp) if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp); } diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index bd7b3cb8d..c0b5f9d10 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)) { + FOR_ALL_INTERFACES (zvrf->vrf, tmp_if) { zif = tmp_if->info; if (!zif) continue; diff --git a/zebra/zserv.c b/zebra/zserv.c index f88820781..cbc9f2bed 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -1000,14 +1000,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)) { + FOR_ALL_INTERFACES (vrf, ifp) { /* Skip pseudo interface. */ if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) continue; |