diff options
110 files changed, 1541 insertions, 1493 deletions
diff --git a/.clang-format b/.clang-format index 2710d844e9..21fe9d7c5e 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 4419160cd7..d4958ddf24 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 64509afa17..17d9bfb936 100644 --- a/babeld/babel_interface.h +++ b/babeld/babel_interface.h @@ -50,7 +50,7 @@ struct babel_interface { char have_buffered_id; char have_buffered_nh; char have_buffered_prefix; - unsigned char buffered_id[16]; + unsigned char buffered_id[8]; unsigned char buffered_nh[4]; unsigned char buffered_prefix[16]; unsigned char *sendbuf; @@ -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 207c37d9b1..00367612c6 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 e31d5de5df..1ff4867908 100644 --- a/babeld/message.c +++ b/babeld/message.c @@ -1080,7 +1080,7 @@ really_send_update(struct interface *ifp, accumulate_bytes(ifp, id, 8); end_message(ifp, MESSAGE_ROUTER_ID, 10); } - memcpy(babel_ifp->buffered_id, id, 16); + memcpy(babel_ifp->buffered_id, id, sizeof(babel_ifp->buffered_id)); babel_ifp->have_buffered_id = 1; } @@ -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_aspath.c b/bgpd/bgp_aspath.c index 2b776d2182..6c03ba3059 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -1914,7 +1914,8 @@ static const char *aspath_gettoken(const char *buf, enum as_token *token, /* There is no match then return unknown token. */ *token = as_token_unknown; - return p++; + p++; + return p; } struct aspath *aspath_str2aspath(const char *str) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 97b6273cb4..c178089af7 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1849,7 +1849,6 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ u_char *startp) { bgp_size_t total; - struct bgp_attr_encap_subtlv *stlv_last = NULL; uint16_t tunneltype = 0; total = length + (CHECK_FLAG(flag, BGP_ATTR_FLAG_EXTLEN) ? 4 : 3); @@ -1926,6 +1925,7 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ /* attach tlv to encap chain */ if (BGP_ATTR_ENCAP == type) { + struct bgp_attr_encap_subtlv *stlv_last; for (stlv_last = attr->encap_subtlvs; stlv_last && stlv_last->next; stlv_last = stlv_last->next) @@ -1937,6 +1937,7 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ } #if ENABLE_BGP_VNC } else { + struct bgp_attr_encap_subtlv *stlv_last; for (stlv_last = attr->vnc_subtlvs; stlv_last && stlv_last->next; stlv_last = stlv_last->next) @@ -1948,7 +1949,6 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ } #endif } - stlv_last = tlv; } if (BGP_ATTR_ENCAP == type) { diff --git a/bgpd/bgp_filter.c b/bgpd/bgp_filter.c index 6e1a1b6d62..ae9d805b05 100644 --- a/bgpd/bgp_filter.c +++ b/bgpd/bgp_filter.c @@ -410,8 +410,8 @@ DEFUN (ip_as_path, char *regstr; /* Retrieve access list name */ - char *alname = - argv_find(argv, argc, "WORD", &idx) ? argv[idx]->arg : NULL; + argv_find(argv, argc, "WORD", &idx); + char *alname = argv[idx]->arg; /* Check the filter type. */ type = argv_find(argv, argc, "deny", &idx) ? AS_FILTER_DENY diff --git a/bgpd/bgp_label.c b/bgpd/bgp_label.c index ad7411990e..06c314de03 100644 --- a/bgpd/bgp_label.c +++ b/bgpd/bgp_label.c @@ -225,7 +225,6 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr, for (; pnt < lim; pnt += psize) { /* Clear prefix structure. */ memset(&p, 0, sizeof(struct prefix)); - llen = 0; if (addpath_encoded) { diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 762519715c..0c2a2f6fe9 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11464,12 +11464,6 @@ void bgp_route_init(void) install_element(BGP_IPV6M_NODE, &ipv6_bgp_network_cmd); install_element(BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd); - install_element(BGP_IPV6L_NODE, &bgp_table_map_cmd); - install_element(BGP_IPV6L_NODE, &ipv6_bgp_network_cmd); - install_element(BGP_IPV6L_NODE, &ipv6_bgp_network_route_map_cmd); - install_element(BGP_IPV6L_NODE, &no_bgp_table_map_cmd); - install_element(BGP_IPV6L_NODE, &no_ipv6_bgp_network_cmd); - install_element(BGP_NODE, &bgp_distance_cmd); install_element(BGP_NODE, &no_bgp_distance_cmd); install_element(BGP_NODE, &bgp_distance_source_cmd); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 355d1037b8..c41039e7c1 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -6045,7 +6045,13 @@ DEFUN_NOSH (address_family_ipv4_safi, { if (argc == 3) { + VTY_DECLVAR_CONTEXT(bgp, bgp); safi_t safi = bgp_vty_safi_from_str(argv[2]->text); + if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT && + safi != SAFI_UNICAST && safi != SAFI_MULTICAST) { + vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n"); + return CMD_WARNING_CONFIG_FAILED; + } vty->node = bgp_node_type(AFI_IP, safi); } else vty->node = BGP_IPV4_NODE; @@ -6061,7 +6067,13 @@ DEFUN_NOSH (address_family_ipv6_safi, BGP_SAFI_WITH_LABEL_HELP_STR) { if (argc == 3) { + VTY_DECLVAR_CONTEXT(bgp, bgp); safi_t safi = bgp_vty_safi_from_str(argv[2]->text); + if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT && + safi != SAFI_UNICAST && safi != SAFI_MULTICAST) { + vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n"); + return CMD_WARNING_CONFIG_FAILED; + } vty->node = bgp_node_type(AFI_IP6, safi); } else vty->node = BGP_IPV6_NODE; @@ -6100,6 +6112,11 @@ DEFUN_NOSH (address_family_evpn, "Address Family\n" "Address Family modifier\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); + if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT) { + vty_out(vty, "Only Unicast and Multicast SAFIs supported in non-core instances.\n"); + return CMD_WARNING_CONFIG_FAILED; + } vty->node = BGP_EVPN_NODE; return CMD_SUCCESS; } @@ -6652,6 +6669,48 @@ DEFUN (show_bgp_memory, return CMD_SUCCESS; } +static void bgp_show_bestpath_json(struct bgp *bgp, json_object *json) +{ + json_object *bestpath = json_object_new_object(); + + if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_IGNORE)) + json_object_string_add(bestpath, "asPath", "ignore"); + + if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_CONFED)) + json_object_string_add(bestpath, "asPath", "confed"); + + if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX)) { + if (bgp_flag_check(bgp, + BGP_FLAG_MULTIPATH_RELAX_AS_SET)) + json_object_string_add(bestpath, + "multiPathRelax", + "as-set"); + else + json_object_string_add(bestpath, + "multiPathRelax", + "true"); + } else + json_object_string_add(bestpath, + "multiPathRelax", + "false"); + + if (bgp_flag_check(bgp, BGP_FLAG_COMPARE_ROUTER_ID)) + json_object_string_add(bestpath, "compareRouterId", "true"); + if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED) + || bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) { + if (bgp_flag_check(bgp, BGP_FLAG_MED_CONFED)) + json_object_string_add(bestpath, "med", + "confed"); + if (bgp_flag_check(bgp, BGP_FLAG_MED_MISSING_AS_WORST)) + json_object_string_add(bestpath, "med", + "missing-as-worst"); + else + json_object_string_add(bestpath, "med", "true"); + } + + json_object_object_add(json, "bestPath", bestpath); +} + /* Show BGP peer's summary information. */ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, u_char use_json, json_object *json) @@ -7048,6 +7107,8 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, json_object_int_add(json, "totalPeers", count); json_object_int_add(json, "dynamicPeers", dn_count); + bgp_show_bestpath_json(bgp, json); + vty_out(vty, "%s\n", json_object_to_json_string_ext( json, JSON_C_TO_STRING_PRETTY)); json_object_free(json); @@ -9745,6 +9806,7 @@ static int bgp_show_neighbor(struct vty *vty, struct bgp *bgp, } if (use_json) { + bgp_show_bestpath_json(bgp, json); vty_out(vty, "%s\n", json_object_to_json_string_ext( json, JSON_C_TO_STRING_PRETTY)); json_object_free(json); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index c90257d659..ddf461f1b1 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -224,6 +224,10 @@ static int bgp_interface_delete(int command, struct zclient *zclient, struct interface *ifp; struct bgp *bgp; + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; + s = zclient->ibuf; ifp = zebra_interface_state_read(s, vrf_id); if (!ifp) /* This may happen if we've just unregistered for a VRF. */ @@ -232,13 +236,9 @@ static int bgp_interface_delete(int command, struct zclient *zclient, if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("Rx Intf del VRF %u IF %s", vrf_id, ifp->name); - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - bgp_update_interface_nbrs(bgp, ifp, NULL); - ifp->ifindex = IFINDEX_DELETED; + if_set_index(ifp, IFINDEX_INTERNAL); return 0; } @@ -252,6 +252,10 @@ static int bgp_interface_up(int command, struct zclient *zclient, struct listnode *node, *nnode; struct bgp *bgp; + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; + s = zclient->ibuf; ifp = zebra_interface_state_read(s, vrf_id); @@ -261,10 +265,6 @@ static int bgp_interface_up(int command, struct zclient *zclient, if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("Rx Intf up VRF %u IF %s", vrf_id, ifp->name); - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) bgp_connected_add(bgp, c); @@ -284,6 +284,10 @@ static int bgp_interface_down(int command, struct zclient *zclient, struct listnode *node, *nnode; struct bgp *bgp; + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; + s = zclient->ibuf; ifp = zebra_interface_state_read(s, vrf_id); if (!ifp) @@ -292,10 +296,6 @@ static int bgp_interface_down(int command, struct zclient *zclient, if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("Rx Intf down VRF %u IF %s", vrf_id, ifp->name); - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) bgp_connected_delete(bgp, c); @@ -338,6 +338,11 @@ static int bgp_interface_address_add(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id) { struct connected *ifc; + struct bgp *bgp; + + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; ifc = zebra_interface_address_read(command, zclient->ibuf, vrf_id); @@ -352,13 +357,8 @@ static int bgp_interface_address_add(int command, struct zclient *zclient, } if (if_is_operative(ifc->ifp)) { - struct bgp *bgp; - - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (!bgp) - return 0; - bgp_connected_add(bgp, ifc); + /* If we have learnt of any neighbors on this interface, * check to kick off any BGP interface-based neighbors, * but only if this is a link-local address. @@ -377,6 +377,10 @@ static int bgp_interface_address_delete(int command, struct zclient *zclient, struct connected *ifc; struct bgp *bgp; + bgp = bgp_lookup_by_vrf_id(vrf_id); + if (!bgp) + return 0; + ifc = zebra_interface_address_read(command, zclient->ibuf, vrf_id); if (ifc == NULL) @@ -390,9 +394,7 @@ static int bgp_interface_address_delete(int command, struct zclient *zclient, } if (if_is_operative(ifc->ifp)) { - bgp = bgp_lookup_by_vrf_id(vrf_id); - if (bgp) - bgp_connected_delete(bgp, ifc); + bgp_connected_delete(bgp, ifc); } connected_free(ifc); @@ -591,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; @@ -616,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; @@ -637,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; @@ -669,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 308698e1c5..d223cecc59 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/bgpd/rfapi/bgp_rfapi_cfg.c b/bgpd/rfapi/bgp_rfapi_cfg.c index 5ae27a2878..e82ca3bbbe 100644 --- a/bgpd/rfapi/bgp_rfapi_cfg.c +++ b/bgpd/rfapi/bgp_rfapi_cfg.c @@ -231,7 +231,7 @@ void *rfapi_get_rfp_start_val(void *bgpv) /*------------------------------------------ * bgp_rfapi_is_vnc_configured * - * Returns if VNC (BGP VPN messaging /VPN & encap SAFIs) are configured + * Returns if VNC is configured * * input: * bgp NULL (=use default instance) @@ -240,6 +240,7 @@ void *rfapi_get_rfp_start_val(void *bgpv) * * return value: If VNC is configured for the bgpd instance * 0 Success + * EPERM Not Default instance (VNC operations not allowed) * ENXIO VNC not configured --------------------------------------------*/ int bgp_rfapi_is_vnc_configured(struct bgp *bgp) @@ -247,29 +248,32 @@ int bgp_rfapi_is_vnc_configured(struct bgp *bgp) if (bgp == NULL) bgp = bgp_get_default(); - if (bgp && bgp->rfapi_cfg) { - struct peer *peer; - struct peer_group *group; - struct listnode *node, *nnode; - /* if have configured VPN neighbors, assume running VNC */ - for (ALL_LIST_ELEMENTS(bgp->group, node, nnode, group)) { - if (group->conf->afc[AFI_IP][SAFI_MPLS_VPN] - || group->conf->afc[AFI_IP6][SAFI_MPLS_VPN]) - return 0; - } - for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { - if (peer->afc[AFI_IP][SAFI_MPLS_VPN] - || peer->afc[AFI_IP6][SAFI_MPLS_VPN]) - return 0; - } - } + if (bgp && bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT) + return EPERM; + + if (bgp && bgp->rfapi_cfg) + return 0; return ENXIO; } /*********************************************************************** * VNC Configuration/CLI ***********************************************************************/ - +#define VNC_VTY_CONFIG_CHECK(bgp) \ + { \ + switch (bgp_rfapi_is_vnc_configured(bgp)) { \ + case EPERM: \ + vty_out(vty, "VNC operations only permitted on default BGP instance.\n"); \ + return CMD_WARNING_CONFIG_FAILED; \ + break; \ + case ENXIO: \ + vty_out(vty, "VNC not configured.\n"); \ + return CMD_WARNING_CONFIG_FAILED; \ + break; \ + default: \ + break; \ + } \ + } DEFUN (vnc_advertise_un_method, vnc_advertise_un_method_cmd, @@ -279,12 +283,7 @@ DEFUN (vnc_advertise_un_method, "Via Tunnel Encap attribute (in VPN SAFI)\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); - - if (!bgp->rfapi_cfg) { - vty_out(vty, "VNC not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } - + VNC_VTY_CONFIG_CHECK(bgp); if (!strncmp(argv[2]->arg, "encap-safi", 7)) { bgp->rfapi_cfg->flags |= BGP_VNC_CONFIG_ADV_UN_METHOD_ENCAP; @@ -301,9 +300,15 @@ DEFUN (vnc_advertise_un_method, DEFUN_NOSH (vnc_defaults, - vnc_defaults_cmd, - "vnc defaults", VNC_CONFIG_STR "Configure default NVE group\n") + vnc_defaults_cmd, + "vnc defaults", VNC_CONFIG_STR "Configure default NVE group\n") { + VTY_DECLVAR_CONTEXT(bgp, bgp); + VNC_VTY_CONFIG_CHECK(bgp); + if (bgp->inst_type != BGP_INSTANCE_TYPE_DEFAULT) { + vty_out(vty, "Malformed community-list value\n"); + return CMD_WARNING_CONFIG_FAILED; + } vty->node = BGP_VNC_DEFAULTS_NODE; return CMD_SUCCESS; } @@ -736,10 +741,7 @@ DEFUN (vnc_redistribute_rh_roo_localadmin, uint32_t localadmin; char *endptr; - if (!bgp->rfapi_cfg) { - vty_out(vty, "RFAPI not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); localadmin = strtoul(argv[4]->arg, &endptr, 0); if (!argv[4]->arg[0] || *endptr) { @@ -787,11 +789,7 @@ DEFUN (vnc_redistribute_mode, VTY_DECLVAR_CONTEXT(bgp, bgp); vnc_redist_mode_t newmode; - if (!bgp->rfapi_cfg) { - vty_out(vty, "RFAPI not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } - + VNC_VTY_CONFIG_CHECK(bgp); switch (argv[3]->arg[0]) { case 'n': @@ -839,10 +837,7 @@ DEFUN (vnc_redistribute_protocol, int type = ZEBRA_ROUTE_MAX; /* init to bogus value */ afi_t afi; - if (!bgp->rfapi_cfg) { - vty_out(vty, "RFAPI not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); if (rfapi_str2route_type(argv[2]->arg, argv[3]->arg, &afi, &type)) { vty_out(vty, "%% Invalid route type\n"); @@ -884,10 +879,7 @@ DEFUN (vnc_no_redistribute_protocol, int type; afi_t afi; - if (!bgp->rfapi_cfg) { - vty_out(vty, "RFAPI not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); if (rfapi_str2route_type(argv[3]->arg, argv[4]->arg, &afi, &type)) { vty_out(vty, "%% Invalid route type\n"); @@ -921,10 +913,7 @@ DEFUN (vnc_redistribute_bgp_exterior, int type; afi_t afi; - if (!bgp->rfapi_cfg) { - vty_out(vty, "RFAPI not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); if (rfapi_str2route_type(argv[2]->arg, "bgp-direct-to-nve-groups", &afi, &type)) { @@ -952,11 +941,7 @@ DEFUN (vnc_redistribute_nvegroup, "NVE group\n" "Group name\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); - - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); vnc_redistribute_prechange(bgp); @@ -985,10 +970,7 @@ DEFUN (vnc_redistribute_no_nvegroup, { VTY_DECLVAR_CONTEXT(bgp, bgp); - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); vnc_redistribute_prechange(bgp); @@ -1013,11 +995,7 @@ DEFUN (vnc_redistribute_lifetime, "Allow lifetime to never expire\n") { VTY_DECLVAR_CONTEXT(bgp, bgp); - - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); vnc_redistribute_prechange(bgp); @@ -1051,10 +1029,8 @@ DEFUN (vnc_redist_bgpdirect_no_prefixlist, struct rfapi_cfg *hc; uint8_t route_type = 0; - if (!(hc = bgp->rfapi_cfg)) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); + hc = bgp->rfapi_cfg; if (strmatch(argv[3]->text, "bgp-direct")) { route_type = ZEBRA_ROUTE_BGP_DIRECT; @@ -1097,10 +1073,8 @@ DEFUN (vnc_redist_bgpdirect_prefixlist, afi_t afi; uint8_t route_type = 0; - if (!(hc = bgp->rfapi_cfg)) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); + hc = bgp->rfapi_cfg; if (strmatch(argv[2]->text, "bgp-direct")) { route_type = ZEBRA_ROUTE_BGP_DIRECT; @@ -1141,10 +1115,8 @@ DEFUN (vnc_redist_bgpdirect_no_routemap, struct rfapi_cfg *hc; uint8_t route_type = 0; - if (!(hc = bgp->rfapi_cfg)) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); + hc = bgp->rfapi_cfg; if (strmatch(argv[3]->text, "bgp-direct")) { route_type = ZEBRA_ROUTE_BGP_DIRECT; @@ -1177,10 +1149,8 @@ DEFUN (vnc_redist_bgpdirect_routemap, struct rfapi_cfg *hc; uint8_t route_type = 0; - if (!(hc = bgp->rfapi_cfg)) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); + hc = bgp->rfapi_cfg; if (strmatch(argv[2]->text, "bgp-direct")) { route_type = ZEBRA_ROUTE_BGP_DIRECT; @@ -1219,10 +1189,7 @@ DEFUN (vnc_nve_group_redist_bgpdirect_no_prefixlist, VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg) afi_t afi; - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); /* make sure it's still in list */ if (!listnode_lookup(bgp->rfapi_cfg->nve_groups_sequential, rfg)) { @@ -1263,10 +1230,7 @@ DEFUN (vnc_nve_group_redist_bgpdirect_prefixlist, VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); afi_t afi; - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); /* make sure it's still in list */ if (!listnode_lookup(bgp->rfapi_cfg->nve_groups_sequential, rfg)) { @@ -1306,10 +1270,7 @@ DEFUN (vnc_nve_group_redist_bgpdirect_no_routemap, VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); /* make sure it's still in list */ if (!listnode_lookup(bgp->rfapi_cfg->nve_groups_sequential, rfg)) { @@ -1340,10 +1301,7 @@ DEFUN (vnc_nve_group_redist_bgpdirect_routemap, VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); /* make sure it's still in list */ if (!listnode_lookup(bgp->rfapi_cfg->nve_groups_sequential, rfg)) { @@ -1388,10 +1346,7 @@ DEFUN (vnc_export_mode, uint32_t oldmode = 0; uint32_t newmode = 0; - if (!bgp->rfapi_cfg) { - vty_out(vty, "VNC not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); if (argv[2]->arg[0] == 'b') { oldmode = bgp->rfapi_cfg->flags @@ -1499,10 +1454,7 @@ DEFUN (vnc_export_nvegroup, VTY_DECLVAR_CONTEXT(bgp, bgp); struct rfapi_nve_group_cfg *rfg_new; - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); rfg_new = bgp_rfapi_cfg_match_byname(bgp, argv[5]->arg, RFAPI_GROUP_CFG_NVE); @@ -1596,10 +1548,7 @@ DEFUN (vnc_no_export_nvegroup, struct listnode *node, *nnode; struct rfapi_rfg_name *rfgn; - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); if (argv[2]->arg[0] == 'b') { for (ALL_LIST_ELEMENTS(bgp->rfapi_cfg->rfg_export_direct_bgp_l, @@ -1655,10 +1604,7 @@ DEFUN (vnc_nve_group_export_no_prefixlist, VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); afi_t afi; - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); /* make sure it's still in list */ if (!listnode_lookup(bgp->rfapi_cfg->nve_groups_sequential, rfg)) { @@ -1714,10 +1660,7 @@ DEFUN (vnc_nve_group_export_prefixlist, VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); afi_t afi; - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); /* make sure it's still in list */ if (!listnode_lookup(bgp->rfapi_cfg->nve_groups_sequential, rfg)) { @@ -1765,10 +1708,7 @@ DEFUN (vnc_nve_group_export_no_routemap, VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); /* make sure it's still in list */ if (!listnode_lookup(bgp->rfapi_cfg->nve_groups_sequential, rfg)) { @@ -1817,10 +1757,7 @@ DEFUN (vnc_nve_group_export_routemap, VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); - if (!bgp->rfapi_cfg) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); /* make sure it's still in list */ if (!listnode_lookup(bgp->rfapi_cfg->nve_groups_sequential, rfg)) { @@ -1865,10 +1802,8 @@ DEFUN (vnc_nve_export_no_prefixlist, struct rfapi_cfg *hc; afi_t afi; - if (!(hc = bgp->rfapi_cfg)) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); + hc = bgp->rfapi_cfg; if (strmatch(argv[4]->text, "ipv4")) { afi = AFI_IP; @@ -1916,10 +1851,8 @@ DEFUN (vnc_nve_export_prefixlist, struct rfapi_cfg *hc; afi_t afi; - if (!(hc = bgp->rfapi_cfg)) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); + hc = bgp->rfapi_cfg; if (strmatch(argv[3]->text, "ipv4")) { afi = AFI_IP; @@ -1958,10 +1891,8 @@ DEFUN (vnc_nve_export_no_routemap, VTY_DECLVAR_CONTEXT(bgp, bgp); struct rfapi_cfg *hc; - if (!(hc = bgp->rfapi_cfg)) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); + hc = bgp->rfapi_cfg; if (argv[3]->arg[0] == 'b') { if (((argc > 5) && hc->routemap_export_bgp_name @@ -2001,10 +1932,8 @@ DEFUN (vnc_nve_export_routemap, VTY_DECLVAR_CONTEXT(bgp, bgp); struct rfapi_cfg *hc; - if (!(hc = bgp->rfapi_cfg)) { - vty_out(vty, "rfapi not configured\n"); - return CMD_WARNING_CONFIG_FAILED; - } + VNC_VTY_CONFIG_CHECK(bgp); + hc = bgp->rfapi_cfg; if (argv[2]->arg[0] == 'b') { if (hc->routemap_export_bgp_name) @@ -2219,6 +2148,8 @@ DEFUN_NOSH (vnc_nve_group, struct listnode *node, *nnode; struct rfapi_rfg_name *rfgn; + VNC_VTY_CONFIG_CHECK(bgp); + /* Search for name */ rfg = bgp_rfapi_cfg_match_byname(bgp, argv[2]->arg, RFAPI_GROUP_CFG_NVE); @@ -3384,6 +3315,7 @@ DEFUN_NOSH (vnc_l2_group, { struct rfapi_l2_group_cfg *rfg; VTY_DECLVAR_CONTEXT(bgp, bgp); + VNC_VTY_CONFIG_CHECK(bgp); /* Search for name */ rfg = rfapi_l2_group_lookup_byname(bgp, argv[2]->arg); diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index 6e31b63451..b093265ffb 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -122,7 +122,7 @@ int rfapi_get_response_lifetime_default(void *rfp_start_val) /*------------------------------------------ * rfapi_is_vnc_configured * - * Returns if VNC (BGP VPN messaging /VPN & encap SAFIs) are configured + * Returns if VNC is configured * * input: * rfp_start_val value returned by rfp_start or @@ -137,7 +137,9 @@ int rfapi_get_response_lifetime_default(void *rfp_start_val) int rfapi_is_vnc_configured(void *rfp_start_val) { struct bgp *bgp = rfapi_bgp_lookup_by_rfp(rfp_start_val); - return bgp_rfapi_is_vnc_configured(bgp); + if (bgp_rfapi_is_vnc_configured(bgp) == 0) + return 0; + return ENXIO; } diff --git a/bgpd/rfapi/rfapi.h b/bgpd/rfapi/rfapi.h index 8eb0d717df..6af2ebeeb8 100644 --- a/bgpd/rfapi/rfapi.h +++ b/bgpd/rfapi/rfapi.h @@ -862,7 +862,7 @@ extern int rfapi_get_response_lifetime_default(void *rfp_start_val); /*------------------------------------------ * rfapi_is_vnc_configured * - * Returns if VNC (BGP VPN messaging /VPN & encap SAFIs) are configured + * Returns if VNC is configured * * input: * rfp_start_val value returned by rfp_start or diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index d963a759ac..894bdad767 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -3530,7 +3530,10 @@ void rfapiBgpInfoFilteredImportVPN( * Compare types. Doing so prevents a RFP-originated * route from matching an imported route, for example. */ - assert(bi->type == type); + if (VNC_DEBUG(VERBOSE) && bi->type != type) + /* should be handled by RDs, but warn for now */ + zlog_warn("%s: type mismatch! (bi=%d, arg=%d)", + __func__, bi->type, type); vnc_zlog_debug_verbose("%s: found matching bi", __func__); @@ -3861,6 +3864,20 @@ void rfapiBgpInfoFilteredImportVPN( VNC_ITRCCK; } +static void rfapiBgpInfoFilteredImportBadSafi( + struct rfapi_import_table *import_table, int action, struct peer *peer, + void *rfd, /* set for looped back routes */ + struct prefix *p, + struct prefix *aux_prefix, /* AFI_L2VPN: optional IP */ + afi_t afi, struct prefix_rd *prd, + struct attr *attr, /* part of bgp_info */ + u_char type, /* part of bgp_info */ + u_char sub_type, /* part of bgp_info */ + uint32_t *label) /* part of bgp_info */ +{ + vnc_zlog_debug_verbose("%s: Error, bad safi", __func__); +} + static rfapi_bi_filtered_import_f * rfapiBgpInfoFilteredImportFunction(safi_t safi) { @@ -3874,7 +3891,7 @@ rfapiBgpInfoFilteredImportFunction(safi_t safi) default: /* not expected */ zlog_err("%s: bad safi %d", __func__, safi); - return NULL; + return rfapiBgpInfoFilteredImportBadSafi; } } diff --git a/bgpd/rfapi/rfapi_monitor.c b/bgpd/rfapi/rfapi_monitor.c index 6a7595443a..47a72d75fd 100644 --- a/bgpd/rfapi/rfapi_monitor.c +++ b/bgpd/rfapi/rfapi_monitor.c @@ -1378,6 +1378,8 @@ struct route_node *rfapiMonitorEthAdd(struct bgp *bgp, #if DEBUG_L2_EXTRA vnc_zlog_debug_verbose("%s: inserted rfd=%p mon_eth=%p, rc=%d", __func__, rfd, val, rc); +#else + (void)rc; #endif /* diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 7bfc8882e2..f678e78825 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -4074,12 +4074,11 @@ DEFUN (clear_vnc_mac_all_prefix, /* copied from rfp_vty.c */ static int check_and_display_is_vnc_running(struct vty *vty) { - if (!bgp_rfapi_is_vnc_configured(NULL)) + if (bgp_rfapi_is_vnc_configured(NULL) == 0) return 1; /* is running */ if (vty) { - vty_out(vty, - "VNC is not configured. (There are no configured BGP VPN SAFI peers.)\n"); + vty_out(vty, "VNC is not configured.\n"); } return 0; /* not running */ } @@ -4089,7 +4088,7 @@ static int rfapi_vty_show_nve_summary(struct vty *vty, { struct bgp *bgp_default = bgp_get_default(); struct rfapi *h; - int is_vnc_running = !bgp_rfapi_is_vnc_configured(bgp_default); + int is_vnc_running = (bgp_rfapi_is_vnc_configured(bgp_default) == 0); int active_local_routes; int active_remote_routes; diff --git a/configure.ac b/configure.ac index 2faaa7fc8e..cae5061122 100755 --- a/configure.ac +++ b/configure.ac @@ -185,6 +185,23 @@ CC="${CC% -std=c99}" AC_C_FLAG([-std=gnu11], [CC="$ac_cc"], [CC="$CC -std=gnu11"]) +dnl if the user has specified any CFLAGS, override our settings +if test "x${enable_dev_build}" = "xyes"; then + AC_DEFINE(DEV_BUILD,,Build for development) + if test "z$orig_cflags" = "z"; then + AC_C_FLAG([-g3]) + AC_C_FLAG([-O0]) + fi +else + if test "z$orig_cflags" = "z"; then + AC_C_FLAG([-g]) + AC_C_FLAG([-Os], [ + AC_C_FLAG([-O2]) + ]) + fi +fi +AM_CONDITIONAL([DEV_BUILD], [test "x$enable_dev_build" = "xyes"]) + dnl always want these CFLAGS AC_C_FLAG([-fno-omit-frame-pointer]) AC_C_FLAG([-funwind-tables]) @@ -428,21 +445,6 @@ fi AM_CONDITIONAL([FPM], [test "x$enable_fpm" = "xyes"]) -if test "x${enable_dev_build}" = "xyes"; then - AC_DEFINE(DEV_BUILD,,Build for development) - AC_C_FLAG([-g]) - AC_C_FLAG([-O0]) -else - dnl if the user specified any CFLAGS, we don't add "-g -Os/-O2" here - if test "z$orig_cflags" = "z"; then - AC_C_FLAG([-g]) - AC_C_FLAG([-Os], [ - AC_C_FLAG([-O2]) - ]) - fi -fi -AM_CONDITIONAL([DEV_BUILD], [test "x$enable_dev_build" = "xyes"]) - # # Python for clippy # diff --git a/doc/install.texi b/doc/install.texi index 9a98f46733..1930af95e6 100644 --- a/doc/install.texi +++ b/doc/install.texi @@ -97,6 +97,10 @@ Controls backtrace support for the crash handlers. This is autodetected by default. Using the switch will enforce the requested behaviour, failing with an error if support is requested but not available. On BSD systems, this needs libexecinfo, while on glibc support for this is part of libc itself. +@item --enable-dev-build +Turn on some options for compiling FRR within a development environment in +mind. Specifically turn on -g3 -O0 for compiling options and add inclusion +of grammar sandbox. @end table You may specify any combination of the above options to the configure diff --git a/eigrpd/eigrp_filter.c b/eigrpd/eigrp_filter.c index 7b9e0de525..7a8fd027ca 100644 --- a/eigrpd/eigrp_filter.c +++ b/eigrpd/eigrp_filter.c @@ -187,6 +187,7 @@ void eigrp_distribute_update(struct distribute *dist) break; } } + assert(ei != NULL); /* Access-list for interface in */ if (dist->list[DISTRIBUTE_V4_IN]) { @@ -294,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 50e6b7b3be..56327f1205 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_packet.c b/eigrpd/eigrp_packet.c index f7bbcba328..83ff194729 100644 --- a/eigrpd/eigrp_packet.c +++ b/eigrpd/eigrp_packet.c @@ -169,7 +169,7 @@ int eigrp_check_md5_digest(struct stream *s, struct TLV_MD5_Authentication_Type *auth_TLV; struct eigrp_header *eigrph; - if (nbr && ntohl(nbr->crypt_seqnum) > ntohl(authTLV->key_sequence)) { + if (ntohl(nbr->crypt_seqnum) > ntohl(authTLV->key_sequence)) { zlog_warn( "interface %s: eigrp_check_md5 bad sequence %d (expect %d)", IF_NAME(nbr->ei), ntohl(authTLV->key_sequence), @@ -317,7 +317,6 @@ int eigrp_write(struct thread *thread) struct ip iph; struct msghdr msg; struct iovec iov[2]; - u_int16_t opcode = 0; u_int32_t seqno, ack; int ret; @@ -363,7 +362,6 @@ int eigrp_write(struct thread *thread) * this outgoing packet. */ eigrph = (struct eigrp_header *)STREAM_DATA(ep->s); - opcode = eigrph->opcode; seqno = ntohl(eigrph->sequence); ack = ntohl(eigrph->ack); if (ep->nbr && (ack != ep->nbr->recv_sequence_number)) { @@ -427,9 +425,8 @@ int eigrp_write(struct thread *thread) if (IS_DEBUG_EIGRP_TRANSMIT(0, SEND)) { eigrph = (struct eigrp_header *)STREAM_DATA(ep->s); - opcode = eigrph->opcode; zlog_debug("Sending [%s][%d/%d] to [%s] via [%s] ret [%d].", - lookup_msg(eigrp_packet_type_str, opcode, NULL), + lookup_msg(eigrp_packet_type_str, eigrph->opcode, NULL), seqno, ack, inet_ntoa(ep->dst), IF_NAME(ei), ret); } diff --git a/eigrpd/eigrp_vty.c b/eigrpd/eigrp_vty.c index 59ec571684..d93abbb8b7 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 66f03b776e..28d2f29811 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 c70e198bdb..a8173f4efd 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 4179de1c01..5e4090facc 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_pdu.c b/isisd/isis_pdu.c index be989cbabb..9c68fe5966 100644 --- a/isisd/isis_pdu.c +++ b/isisd/isis_pdu.c @@ -1546,8 +1546,11 @@ int send_hello(struct isis_circuit *circuit, int level) isis_tlvs_add_auth(tlvs, &circuit->passwd); - if (!listcount(circuit->area->area_addrs)) + if (!listcount(circuit->area->area_addrs)) { + isis_free_tlvs(tlvs); return ISIS_WARNING; + } + isis_tlvs_add_area_addresses(tlvs, circuit->area->area_addrs); if (circuit->circ_type == CIRCUIT_T_BROADCAST) diff --git a/isisd/isis_te.c b/isisd/isis_te.c index 70afef1a86..104a0fd4bf 100644 --- a/isisd/isis_te.c +++ b/isisd/isis_te.c @@ -223,6 +223,9 @@ uint8_t add_te_subtlvs(uint8_t *buf, struct mpls_te_circuit *mtc) tlvs += size; } + /* Add before this line any other parsing of TLV */ + (void)tlvs; + /* Update SubTLVs length */ mtc->length = subtlvs_len(mtc); @@ -1242,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 bc81314097..387f99938e 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/address.c b/ldpd/address.c index 18ab037760..9c1564a31f 100644 --- a/ldpd/address.c +++ b/ldpd/address.c @@ -88,6 +88,7 @@ send_address(struct nbr *nbr, int af, struct if_addr_head *addr_list, err |= gen_msg_hdr(buf, msg_type, size); size -= LDP_MSG_SIZE; err |= gen_address_list_tlv(buf, af, addr_list, tlv_addr_count); + (void)size; if (err) { address_list_clr(addr_list); ibuf_free(buf); @@ -98,6 +99,7 @@ send_address(struct nbr *nbr, int af, struct if_addr_head *addr_list, log_msg_address(1, msg_type, nbr, af, &if_addr->addr); LIST_REMOVE(if_addr, entry); + assert(if_addr != LIST_FIRST(addr_list)); free(if_addr); if (--tlv_addr_count == 0) break; @@ -168,7 +170,6 @@ send_mac_withdrawal(struct nbr *nbr, struct map *fec, uint8_t *mac) err = gen_ldp_hdr(buf, size); size -= LDP_HDR_SIZE; err |= gen_msg_hdr(buf, MSG_TYPE_ADDRWITHDRAW, size); - size -= LDP_MSG_SIZE; err |= gen_address_list_tlv(buf, AF_INET, NULL, 0); err |= gen_fec_tlv(buf, fec); err |= gen_mac_list_tlv(buf, mac); @@ -400,6 +401,7 @@ address_list_clr(struct if_addr_head *addr_list) while ((if_addr = LIST_FIRST(addr_list)) != NULL) { LIST_REMOVE(if_addr, entry); + assert(if_addr != LIST_FIRST(addr_list)); free(if_addr); } } diff --git a/ldpd/interface.c b/ldpd/interface.c index a18019c0c1..bbcea9f553 100644 --- a/ldpd/interface.c +++ b/ldpd/interface.c @@ -103,6 +103,7 @@ ldpe_if_exit(struct iface *iface) while ((if_addr = LIST_FIRST(&iface->addr_list)) != NULL) { LIST_REMOVE(if_addr, entry); + assert(if_addr != LIST_FIRST(&iface->addr_list)); free(if_addr); } } diff --git a/ldpd/labelmapping.c b/ldpd/labelmapping.c index f53bc8333d..5662038a58 100644 --- a/ldpd/labelmapping.c +++ b/ldpd/labelmapping.c @@ -130,6 +130,7 @@ send_labelmessage(struct nbr *nbr, uint16_t type, struct mapping_head *mh) } TAILQ_REMOVE(mh, me, entry); + assert(me != TAILQ_FIRST(mh)); free(me); } @@ -459,6 +460,7 @@ recv_labelmessage(struct nbr *nbr, char *buf, uint16_t len, uint16_t type) next: TAILQ_REMOVE(&mh, me, entry); + assert(me != TAILQ_FIRST(&mh)); free(me); } diff --git a/ldpd/lde.c b/ldpd/lde.c index 3482f3d722..a7f933bbe5 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -185,11 +185,14 @@ lde_shutdown(void) if (iev_ldpe) { msgbuf_clear(&iev_ldpe->ibuf.w); close(iev_ldpe->ibuf.fd); + iev_ldpe->ibuf.fd = -1; } msgbuf_clear(&iev_main->ibuf.w); close(iev_main->ibuf.fd); + iev_main->ibuf.fd = -1; msgbuf_clear(&iev_main_sync->ibuf.w); close(iev_main_sync->ibuf.fd); + iev_main_sync->ibuf.fd = -1; lde_gc_stop_timer(); lde_nbr_clear(); @@ -210,12 +213,16 @@ lde_shutdown(void) int lde_imsg_compose_parent(int type, pid_t pid, void *data, uint16_t datalen) { + if (iev_main->ibuf.fd == -1) + return (0); return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen)); } void lde_imsg_compose_parent_sync(int type, pid_t pid, void *data, uint16_t datalen) { + if (iev_main_sync->ibuf.fd == -1) + return; imsg_compose_event(iev_main_sync, type, 0, pid, -1, data, datalen); imsg_flush(&iev_main_sync->ibuf); } @@ -224,6 +231,8 @@ int lde_imsg_compose_ldpe(int type, uint32_t peerid, pid_t pid, void *data, uint16_t datalen) { + if (iev_ldpe->ibuf.fd == -1) + return (0); return (imsg_compose_event(iev_ldpe, type, peerid, pid, -1, data, datalen)); } @@ -429,7 +438,7 @@ lde_dispatch_parent(struct thread *thread) struct imsg imsg; struct kif *kif; struct kroute *kr; - int fd = THREAD_FD(thread); + int fd; struct imsgev *iev = THREAD_ARG(thread); struct imsgbuf *ibuf = &iev->ibuf; ssize_t n; diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c index c56b7e33d0..18c8c0a122 100644 --- a/ldpd/lde_lib.c +++ b/ldpd/lde_lib.c @@ -229,8 +229,10 @@ fec_free(void *arg) struct fec_node *fn = arg; struct fec_nh *fnh; - while ((fnh = LIST_FIRST(&fn->nexthops))) + while ((fnh = LIST_FIRST(&fn->nexthops))) { fec_nh_del(fnh); + assert(fnh != LIST_FIRST(&fn->nexthops)); + } if (!RB_EMPTY(lde_map_head, &fn->downstream)) log_warnx("%s: fec %s downstream list not empty", __func__, log_fec(&fn->fec)); diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c index c50cc0fda2..7f68f0b694 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)); diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 843d160d62..12aeb1fff3 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -260,7 +260,6 @@ main(int argc, char *argv[]) sizeof(init.zclient_serv_path)); argc -= optind; - argv += optind; if (argc > 0 || (lflag && eflag)) frr_help_exit(1); diff --git a/ldpd/ldpe.c b/ldpd/ldpe.c index 1c0a8bdc84..9d00bcd2b6 100644 --- a/ldpd/ldpe.c +++ b/ldpd/ldpe.c @@ -190,15 +190,16 @@ ldpe_shutdown(void) /* close pipes */ if (iev_lde) { - msgbuf_write(&iev_lde->ibuf.w); msgbuf_clear(&iev_lde->ibuf.w); close(iev_lde->ibuf.fd); + iev_lde->ibuf.fd = -1; } - msgbuf_write(&iev_main->ibuf.w); msgbuf_clear(&iev_main->ibuf.w); close(iev_main->ibuf.fd); + iev_main->ibuf.fd = -1; msgbuf_clear(&iev_main_sync->ibuf.w); close(iev_main_sync->ibuf.fd); + iev_main_sync->ibuf.fd = -1; control_cleanup(ctl_sock_path); config_clear(leconf); @@ -215,6 +216,7 @@ ldpe_shutdown(void) /* remove addresses from global list */ while ((if_addr = LIST_FIRST(&global.addr_list)) != NULL) { LIST_REMOVE(if_addr, entry); + assert(if_addr != LIST_FIRST(&global.addr_list)); free(if_addr); } while ((adj = RB_ROOT(global_adj_head, &global.adj_tree)) != NULL) @@ -235,12 +237,16 @@ ldpe_shutdown(void) int ldpe_imsg_compose_parent(int type, pid_t pid, void *data, uint16_t datalen) { + if (iev_main->ibuf.fd == -1) + return (0); return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen)); } void ldpe_imsg_compose_parent_sync(int type, pid_t pid, void *data, uint16_t datalen) { + if (iev_main_sync->ibuf.fd == -1) + return; imsg_compose_event(iev_main_sync, type, 0, pid, -1, data, datalen); imsg_flush(&iev_main_sync->ibuf); } @@ -249,6 +255,8 @@ int ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data, uint16_t datalen) { + if (iev_lde->ibuf.fd == -1) + return (0); return (imsg_compose_event(iev_lde, type, peerid, pid, -1, data, datalen)); } @@ -265,7 +273,7 @@ ldpe_dispatch_main(struct thread *thread) struct l2vpn_if *lif, *nlif; struct l2vpn_pw *pw, *npw; struct imsg imsg; - int fd = THREAD_FD(thread); + int fd; struct imsgev *iev = THREAD_ARG(thread); struct imsgbuf *ibuf = &iev->ibuf; struct iface *iface = NULL; @@ -964,6 +972,7 @@ mapping_list_clr(struct mapping_head *mh) while ((me = TAILQ_FIRST(mh)) != NULL) { TAILQ_REMOVE(mh, me, entry); + assert(me != TAILQ_FIRST(mh)); free(me); } } diff --git a/ldpd/packet.c b/ldpd/packet.c index be7f2ba649..4a4b258b91 100644 --- a/ldpd/packet.c +++ b/ldpd/packet.c @@ -494,7 +494,7 @@ session_read(struct thread *thread) msg_len = ntohs(msg->length); if (msg_len < LDP_MSG_LEN || (msg_len + LDP_MSG_DEAD_LEN) > pdu_len) { - session_shutdown(nbr, S_BAD_TLV_LEN, msg->id, + session_shutdown(nbr, S_BAD_MSG_LEN, msg->id, msg->type); free(buf); return (0); diff --git a/lib/command.h b/lib/command.h index 8cccb62de3..e2d31decd4 100644 --- a/lib/command.h +++ b/lib/command.h @@ -380,6 +380,13 @@ extern void uninstall_element(enum node_type, struct cmd_element *); string with a space between each element (allocated using XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */ extern char *argv_concat(struct cmd_token **argv, int argc, int shift); + +/* + * It is preferred that you set the index initial value + * to a 0. This way in the future if you modify the + * cli then there is no need to modify the initial + * value of the index + */ extern int argv_find(struct cmd_token **argv, int argc, const char *text, int *index); @@ -284,6 +284,11 @@ csv_record_t *csv_encode_record(csv_t *csv, csv_record_t *rec, int count, ...) va_start(list, count); str = csv_field_iter(rec, &fld); + if (!fld) { + va_end(list); + return NULL; + } + for (tempc = 0; tempc < count; tempc++) { col = va_arg(list, char *); for (i = 0; i < fld->field_len; i++) { @@ -652,18 +657,15 @@ int main() { char buf[10000]; csv_t csv; - int p; - int i, j; + int i; csv_record_t *rec; - csv_field_t *fld; - char *str; char hdr1[32], hdr2[32]; - log_verbose("Mem: %ld\n", get_memory_usage(getpid())); + log_verbose("Mem: %d\n", get_memory_usage(getpid())); csv_init(&csv, buf, 256); sprintf(hdr1, "%4u", 0); sprintf(hdr2, "%4u", 1); - log_verbose("(%d/%d/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), + log_verbose("(%zu/%zu/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), atoi(hdr2)); rec = csv_encode(&csv, 2, hdr1, hdr2); csv_encode(&csv, 4, "name", "age", "sex", "hei"); @@ -676,19 +678,19 @@ int main() log_verbose("%s\n", buf); sprintf(hdr1, "%4u", csv.csv_len); sprintf(hdr2, "%4u", 1); - log_verbose("(%d/%d/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), + log_verbose("(%zu/%zu/%d/%d)\n", strlen(hdr1), strlen(hdr2), atoi(hdr1), atoi(hdr2)); rec = csv_encode_record(&csv, rec, 2, hdr1, hdr2); log_verbose("(%d/%d)\n%s\n", rec->rec_len, csv.csv_len, buf); - log_verbose("Mem: %ld\n", get_memory_usage(getpid())); + log_verbose("Mem: %d\n", get_memory_usage(getpid())); csv_clean(&csv); - log_verbose("Mem: %ld\n", get_memory_usage(getpid())); + log_verbose("Mem: %d\n", get_memory_usage(getpid())); csv_init(&csv, buf, 256); csv_decode(&csv, NULL); - log_verbose("AFTER DECODE\n"); + log_verbose("%s", "AFTER DECODE\n"); csv_dump(&csv); csv_clean(&csv); - log_verbose("Mem: %ld\n", get_memory_usage(getpid())); + log_verbose("Mem: %d\n", get_memory_usage(getpid())); } #endif diff --git a/lib/ferr.c b/lib/ferr.c index 2a039d2089..69aeb3db40 100644 --- a/lib/ferr.c +++ b/lib/ferr.c @@ -74,6 +74,7 @@ static ferr_r ferr_set_va(const char *file, int line, const char *func, /* we're screwed */ zlog_err("out of memory while allocating error info"); raise(SIGSEGV); + abort(); /* raise() can return, but raise(SIGSEGV) shall not */ } pthread_setspecific(errkey, error); @@ -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); diff --git a/lib/linklist.h b/lib/linklist.h index 4a65fead86..8a43fbe64b 100644 --- a/lib/linklist.h +++ b/lib/linklist.h @@ -56,7 +56,8 @@ struct list { #define listtail(X) ((X) ? ((X)->tail) : NULL) #define listcount(X) ((X)->count) #define list_isempty(X) ((X)->head == NULL && (X)->tail == NULL) -#define listgetdata(X) (assert((X)->data != NULL), (X)->data) +/* return X->data only if X and X->data are not NULL */ +#define listgetdata(X) (assert(X), assert((X)->data != NULL), (X)->data) /* Prototypes. */ extern struct list * diff --git a/lib/nexthop.c b/lib/nexthop.c index ea6a310a4a..f6b2c9788d 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -128,7 +128,7 @@ int nexthop_labels_match(struct nexthop *nh1, struct nexthop *nh2) nhl1 = nh1->nh_label; nhl2 = nh2->nh_label; - if ((nhl1 && !nhl2) || (!nhl1 && nhl2)) + if (!nhl1 || !nhl2) return 0; if (nhl1->num_labels != nhl2->num_labels) diff --git a/lib/ptm_lib.c b/lib/ptm_lib.c index f50d1e2989..e881d49225 100644 --- a/lib/ptm_lib.c +++ b/lib/ptm_lib.c @@ -330,7 +330,7 @@ int ptm_lib_process_msg(ptm_lib_handle_t *hdl, int fd, char *inbuf, int inlen, char client_name[32]; int cmd_id, type, ver, msglen; csv_t *csv; - ptm_lib_msg_ctxt_t *p_ctxt; + ptm_lib_msg_ctxt_t *p_ctxt = NULL; len = _ptm_lib_read_ptm_socket(fd, inbuf, PTMLIB_MSG_HDR_LEN); if (len <= 0) @@ -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/workqueue.c b/lib/workqueue.c index 643ed2d2b8..952012a006 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -57,6 +57,22 @@ static void work_queue_item_free(struct work_queue_item *item) return; } +static void work_queue_item_remove(struct work_queue *wq, + struct work_queue_item *item) +{ + assert(item && item->data); + + /* call private data deletion callback if needed */ + if (wq->spec.del_item_data) + wq->spec.del_item_data(wq, item->data); + + work_queue_item_dequeue(wq, item); + + work_queue_item_free(item); + + return; +} + /* create new work queue */ struct work_queue *work_queue_new(struct thread_master *m, const char *queue_name) @@ -90,6 +106,12 @@ void work_queue_free(struct work_queue *wq) if (wq->thread != NULL) thread_cancel(wq->thread); + while (!work_queue_empty(wq)) { + struct work_queue_item *item = work_queue_last_item(wq); + + work_queue_item_remove(wq, item); + } + listnode_delete(work_queues, wq); XFREE(MTYPE_WORK_QUEUE_NAME, wq->name); @@ -137,22 +159,6 @@ void work_queue_add(struct work_queue *wq, void *data) return; } -static void work_queue_item_remove(struct work_queue *wq, - struct work_queue_item *item) -{ - assert(item && item->data); - - /* call private data deletion callback if needed */ - if (wq->spec.del_item_data) - wq->spec.del_item_data(wq, item->data); - - work_queue_item_dequeue(wq, item); - - work_queue_item_free(item); - - return; -} - static void work_queue_item_requeue(struct work_queue *wq, struct work_queue_item *item) { work_queue_item_dequeue(wq, item); diff --git a/lib/zclient.c b/lib/zclient.c index 43d46a1801..ad5c30584c 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 a46962c91a..67e3f41b3d 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 0bada33502..6fbd6ca224 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 bd5b1aa6f1..ab052ac04a 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_abr.c b/ospf6d/ospf6_abr.c index 36528d063c..d270b9547e 100644 --- a/ospf6d/ospf6_abr.c +++ b/ospf6d/ospf6_abr.c @@ -1110,19 +1110,21 @@ void install_element_ospf6_debug_abr(void) } struct ospf6_lsa_handler inter_prefix_handler = { - OSPF6_LSTYPE_INTER_PREFIX, - "Inter-Prefix", - "IAP", - ospf6_inter_area_prefix_lsa_show, - ospf6_inter_area_prefix_lsa_get_prefix_str, + .lh_type = OSPF6_LSTYPE_INTER_PREFIX, + .lh_name = "Inter-Prefix", + .lh_short_name = "IAP", + .lh_show = ospf6_inter_area_prefix_lsa_show, + .lh_get_prefix_str = ospf6_inter_area_prefix_lsa_get_prefix_str, + .lh_debug = 0 }; struct ospf6_lsa_handler inter_router_handler = { - OSPF6_LSTYPE_INTER_ROUTER, - "Inter-Router", - "IAR", - ospf6_inter_area_router_lsa_show, - ospf6_inter_area_router_lsa_get_prefix_str, + .lh_type = OSPF6_LSTYPE_INTER_ROUTER, + .lh_name = "Inter-Router", + .lh_short_name = "IAR", + .lh_show = ospf6_inter_area_router_lsa_show, + .lh_get_prefix_str = ospf6_inter_area_router_lsa_get_prefix_str, + .lh_debug = 0 }; void ospf6_abr_init(void) diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index de20fbc3ab..c65578c11e 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -438,6 +438,9 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, if (!ospf6_zebra_is_redistribute(type)) return; + memset(&troute, 0, sizeof(troute)); + memset(&tinfo, 0, sizeof(tinfo)); + if (IS_OSPF6_DEBUG_ASBR) { prefix2str(prefix, pbuf, sizeof(pbuf)); zlog_debug("Redistribute %s (%s)", pbuf, ZROUTE_NAME(type)); @@ -457,8 +460,6 @@ void ospf6_asbr_redistribute_add(int type, ifindex_t ifindex, /* apply route-map */ if (ospf6->rmap[type].map) { - memset(&troute, 0, sizeof(troute)); - memset(&tinfo, 0, sizeof(tinfo)); troute.route_option = &tinfo; tinfo.ifindex = ifindex; tinfo.tag = tag; @@ -1234,8 +1235,13 @@ DEFUN (show_ipv6_ospf6_redistribute, } struct ospf6_lsa_handler as_external_handler = { - OSPF6_LSTYPE_AS_EXTERNAL, "AS-External", "ASE", - ospf6_as_external_lsa_show, ospf6_as_external_lsa_get_prefix_str}; + .lh_type = OSPF6_LSTYPE_AS_EXTERNAL, + .lh_name = "AS-External", + .lh_short_name = "ASE", + .lh_show = ospf6_as_external_lsa_show, + .lh_get_prefix_str = ospf6_as_external_lsa_get_prefix_str, + .lh_debug = 0 +}; void ospf6_asbr_init(void) { diff --git a/ospf6d/ospf6_bfd.c b/ospf6d/ospf6_bfd.c index fa0030b6d9..e28af9d06d 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 7286b3242d..f237e4bef3 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_intra.c b/ospf6d/ospf6_intra.c index e4644bb09f..a2caeccb86 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -1630,21 +1630,41 @@ void ospf6_intra_brouter_calculation(struct ospf6_area *oa) oa->name); } -struct ospf6_lsa_handler router_handler = {OSPF6_LSTYPE_ROUTER, "Router", "Rtr", - ospf6_router_lsa_show, - ospf6_router_lsa_get_nbr_id}; - -struct ospf6_lsa_handler network_handler = {OSPF6_LSTYPE_NETWORK, "Network", - "Net", ospf6_network_lsa_show, - ospf6_network_lsa_get_ar_id}; - -struct ospf6_lsa_handler link_handler = {OSPF6_LSTYPE_LINK, "Link", "Lnk", - ospf6_link_lsa_show, - ospf6_link_lsa_get_prefix_str}; +struct ospf6_lsa_handler router_handler = { + .lh_type = OSPF6_LSTYPE_ROUTER, + .lh_name = "Router", + .lh_short_name = "Rtr", + .lh_show = ospf6_router_lsa_show, + .lh_get_prefix_str = ospf6_router_lsa_get_nbr_id, + .lh_debug = 0 +}; + +struct ospf6_lsa_handler network_handler = { + .lh_type = OSPF6_LSTYPE_NETWORK, + .lh_name = "Network", + .lh_short_name = "Net", + .lh_show = ospf6_network_lsa_show, + .lh_get_prefix_str = ospf6_network_lsa_get_ar_id, + .lh_debug = 0 +}; + +struct ospf6_lsa_handler link_handler = { + .lh_type = OSPF6_LSTYPE_LINK, + .lh_name = "Link", + .lh_short_name = "Lnk", + .lh_show = ospf6_link_lsa_show, + .lh_get_prefix_str = ospf6_link_lsa_get_prefix_str, + .lh_debug = 0 +}; struct ospf6_lsa_handler intra_prefix_handler = { - OSPF6_LSTYPE_INTRA_PREFIX, "Intra-Prefix", "INP", - ospf6_intra_prefix_lsa_show, ospf6_intra_prefix_lsa_get_prefix_str}; + .lh_type = OSPF6_LSTYPE_INTRA_PREFIX, + .lh_name = "Intra-Prefix", + .lh_short_name = "INP", + .lh_show = ospf6_intra_prefix_lsa_show, + .lh_get_prefix_str = ospf6_intra_prefix_lsa_get_prefix_str, + .lh_debug = 0 +}; void ospf6_intra_init(void) { diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index a0dad9344a..82f75b153e 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -68,19 +68,25 @@ static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) return 0; } -struct ospf6_lsa_handler unknown_handler = { - OSPF6_LSTYPE_UNKNOWN, "Unknown", "Unk", ospf6_unknown_lsa_show, NULL}; +static struct ospf6_lsa_handler unknown_handler = { + .lh_type = OSPF6_LSTYPE_UNKNOWN, + .lh_name = "Unknown", + .lh_short_name = "Unk", + .lh_show = ospf6_unknown_lsa_show, + .lh_get_prefix_str = NULL, + .lh_debug = 0 /* No default debug */ +}; -void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler) +void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler) { /* type in handler is host byte order */ - int index = handler->type & OSPF6_LSTYPE_FCODE_MASK; - vector_set_index(ospf6_lsa_handler_vector, index, handler); + int index = handler->lh_type & OSPF6_LSTYPE_FCODE_MASK; + vector_set_index(ospf6_lsa_handler_vector, index, (void *)handler); } -struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type) +const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type) { - struct ospf6_lsa_handler *handler = NULL; + const struct ospf6_lsa_handler *handler = NULL; unsigned int index = ntohs(type) & OSPF6_LSTYPE_FCODE_MASK; if (index >= vector_active(ospf6_lsa_handler_vector)) @@ -97,11 +103,11 @@ struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type) const char *ospf6_lstype_name(u_int16_t type) { static char buf[8]; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; handler = ospf6_get_lsa_handler(type); if (handler && handler != &unknown_handler) - return handler->name; + return handler->lh_name; snprintf(buf, sizeof(buf), "0x%04hx", ntohs(type)); return buf; @@ -110,11 +116,11 @@ const char *ospf6_lstype_name(u_int16_t type) const char *ospf6_lstype_short_name(u_int16_t type) { static char buf[8]; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; handler = ospf6_get_lsa_handler(type); if (handler && handler != &unknown_handler) - return handler->short_name; + return handler->lh_short_name; snprintf(buf, sizeof(buf), "0x%04hx", ntohs(type)); return buf; @@ -122,7 +128,7 @@ const char *ospf6_lstype_short_name(u_int16_t type) u_char ospf6_lstype_debug(u_int16_t type) { - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; handler = ospf6_get_lsa_handler(type); return handler->debug; } @@ -369,7 +375,7 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa) { char adv_router[16], id[16]; int type; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; char buf[64], tmpbuf[80]; int cnt = 0; @@ -389,14 +395,14 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa) ospf6_lstype_short_name(lsa->header->type), id, adv_router, ospf6_lsa_age_current(lsa), (u_long)ntohl(lsa->header->seqnum), - handler->get_prefix_str(lsa, buf, sizeof(buf), 0)); + handler->lh_get_prefix_str(lsa, buf, sizeof(buf), 0)); } else if (type != OSPF6_LSTYPE_UNKNOWN) { sprintf(tmpbuf, "%-4s %-15s%-15s%4hu %8lx", ospf6_lstype_short_name(lsa->header->type), id, adv_router, ospf6_lsa_age_current(lsa), (u_long)ntohl(lsa->header->seqnum)); - while (handler->get_prefix_str(lsa, buf, sizeof(buf), cnt) + while (handler->lh_get_prefix_str(lsa, buf, sizeof(buf), cnt) != NULL) { vty_out(vty, "%s %30s\n", tmpbuf, buf); cnt++; @@ -465,7 +471,7 @@ void ospf6_lsa_show_internal(struct vty *vty, struct ospf6_lsa *lsa) void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) { char adv_router[64], id[64]; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; struct timeval now, res; char duration[64]; @@ -490,9 +496,13 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) vty_out(vty, "Duration: %s\n", duration); handler = ospf6_get_lsa_handler(lsa->header->type); - if (handler->show == NULL) - handler = &unknown_handler; - (*handler->show)(vty, lsa); + + if (handler->lh_show != NULL) + handler->lh_show(vty, lsa); + else { + assert(unknown_handler.lh_show != NULL); + unknown_handler.lh_show(vty, lsa); + } vty_out(vty, "\n"); } @@ -739,22 +749,22 @@ void ospf6_lsa_terminate(void) vector_free(ospf6_lsa_handler_vector); } -static char *ospf6_lsa_handler_name(struct ospf6_lsa_handler *h) +static char *ospf6_lsa_handler_name(const struct ospf6_lsa_handler *h) { static char buf[64]; unsigned int i; - unsigned int size = strlen(h->name); + unsigned int size = strlen(h->lh_name); - if (!strcmp(h->name, "unknown") && h->type != OSPF6_LSTYPE_UNKNOWN) { - snprintf(buf, sizeof(buf), "%#04hx", h->type); + if (!strcmp(h->lh_name, "unknown") && h->lh_type != OSPF6_LSTYPE_UNKNOWN) { + snprintf(buf, sizeof(buf), "%#04hx", h->lh_type); return buf; } for (i = 0; i < MIN(size, sizeof(buf)); i++) { - if (!islower((unsigned char)h->name[i])) - buf[i] = tolower((unsigned char)h->name[i]); + if (!islower((unsigned char)h->lh_name[i])) + buf[i] = tolower((unsigned char)h->lh_name[i]); else - buf[i] = h->name[i]; + buf[i] = h->lh_name[i]; } buf[size] = '\0'; return buf; @@ -791,7 +801,7 @@ DEFUN (debug_ospf6_lsa_type, strlen(argv[idx_lsa]->arg)) == 0) break; - if (!strcasecmp(argv[idx_lsa]->arg, handler->name)) + if (!strcasecmp(argv[idx_lsa]->arg, handler->lh_name)) break; handler = NULL; } @@ -844,7 +854,7 @@ DEFUN (no_debug_ospf6_lsa_type, strlen(argv[idx_lsa]->arg)) == 0) break; - if (!strcasecmp(argv[idx_lsa]->arg, handler->name)) + if (!strcasecmp(argv[idx_lsa]->arg, handler->lh_name)) break; } @@ -875,7 +885,7 @@ void install_element_ospf6_debug_lsa(void) int config_write_ospf6_debug_lsa(struct vty *vty) { u_int i; - struct ospf6_lsa_handler *handler; + const struct ospf6_lsa_handler *handler; for (i = 0; i < vector_active(ospf6_lsa_handler_vector); i++) { handler = vector_slot(ospf6_lsa_handler_vector, i); diff --git a/ospf6d/ospf6_lsa.h b/ospf6d/ospf6_lsa.h index ef63429fdf..3536d33d19 100644 --- a/ospf6d/ospf6_lsa.h +++ b/ospf6d/ospf6_lsa.h @@ -137,18 +137,25 @@ struct ospf6_lsa { #define OSPF6_LSA_SEQWRAPPED 0x20 struct ospf6_lsa_handler { - u_int16_t type; /* host byte order */ - const char *name; - const char *short_name; - int (*show)(struct vty *, struct ospf6_lsa *); - char *(*get_prefix_str)(struct ospf6_lsa *, char *buf, int buflen, - int pos); + const struct { + u_int16_t type; /* host byte order */ + const char *name; + const char *short_name; + int (*show)(struct vty *, struct ospf6_lsa *); + char *(*get_prefix_str)(struct ospf6_lsa *, char *buf, int buflen, + int pos); + } s; +#define lh_type s.type +#define lh_name s.name +#define lh_short_name s.short_name +#define lh_show s.show +#define lh_get_prefix_str s.get_prefix_str u_char debug; +#define lh_debug debug }; -extern struct ospf6_lsa_handler unknown_handler; -#define OSPF6_LSA_IS_KNOWN(type) \ - (ospf6_get_lsa_handler(type) != &unknown_handler ? 1 : 0) +#define OSPF6_LSA_IS_KNOWN(t) \ + (ospf6_get_lsa_handler(t)->lh_type != OSPF6_LSTYPE_UNKNOWN ? 1 : 0) extern vector ospf6_lsa_handler_vector; @@ -237,8 +244,8 @@ extern int ospf6_lsa_checksum_valid(struct ospf6_lsa_header *); extern int ospf6_lsa_prohibited_duration(u_int16_t type, u_int32_t id, u_int32_t adv_router, void *scope); -extern void ospf6_install_lsa_handler(struct ospf6_lsa_handler *handler); -extern struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type); +extern void ospf6_install_lsa_handler(const struct ospf6_lsa_handler *handler); +extern const struct ospf6_lsa_handler *ospf6_get_lsa_handler(u_int16_t type); extern void ospf6_lsa_init(void); extern void ospf6_lsa_terminate(void); diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c index 76c20fa81f..9a6729ee2a 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_proto.h b/ospf6d/ospf6_proto.h index 174b5a4f0f..5919190854 100644 --- a/ospf6d/ospf6_proto.h +++ b/ospf6d/ospf6_proto.h @@ -62,6 +62,7 @@ struct ospf6_prefix { #define prefix_metric u._prefix_metric #define prefix_refer_lstype u._prefix_referenced_lstype /* followed by one address_prefix */ + struct in6_addr addr[]; }; #define OSPF6_PREFIX_OPTION_NU (1 << 0) /* No Unicast */ diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c index 0b399bad10..c148107449 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 b0281b9e0a..e0844765d3 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 30bb4393c7..b032bd7a79 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_apiserver.c b/ospfd/ospf_apiserver.c index c1485abb81..8c1ad5ff0c 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -2322,7 +2322,7 @@ void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor *nbr) { struct msg *msg; struct in_addr ifaddr = {.s_addr = 0L}; - struct in_addr nbraddr = {.s_addr = 0L}; + struct in_addr nbraddr; assert(nbr); diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c index eca0f85f57..5933f5abfe 100644 --- a/ospfd/ospf_dump.c +++ b/ospfd/ospf_dump.c @@ -169,6 +169,7 @@ const char *ospf_timeval_dump(struct timeval *t, char *buf, size_t size) if (us >= 1000) { ms = us / 1000; us %= 1000; + (void)us; /* unused */ } if (ms >= 1000) { diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 67ce6f1713..34a1e6f6d6 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_lsa.c b/ospfd/ospf_lsa.c index 1795225ca7..74d5178f55 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -1702,7 +1702,7 @@ static void ospf_install_flood_nssa(struct ospf *ospf, struct ospf_lsa *lsa, not adversited into OSPF as an internal OSPF route and the type-7 LSA's P-bit is set a forwarding address should be - selected from one of the router's active OSPF inteface + selected from one of the router's active OSPF interface addresses which belong to the NSSA. If no such addresses exist, then diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c index d1c1429054..699f2341d5 100644 --- a/ospfd/ospf_network.c +++ b/ospfd/ospf_network.c @@ -220,8 +220,10 @@ int ospf_sock_init(struct ospf *ospf) } ret = ospf_bind_vrfdevice(ospf, ospf_sock); - if (ret < 0) + if (ret < 0) { + close(ospf_sock); goto out; + } #ifdef IP_HDRINCL /* we will include IP header with packet */ @@ -232,6 +234,7 @@ int ospf_sock_init(struct ospf *ospf) zlog_warn("Can't set IP_HDRINCL option for fd %d: %s", ospf_sock, safe_strerror(save_errno)); + close(ospf_sock); goto out; } #elif defined(IPTOS_PREC_INTERNETCONTROL) diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index d5769c866e..69f6883186 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -659,6 +659,7 @@ static int ospf_router_info_lsa_originate1(void *arg) if (top == NULL) { zlog_debug("%s: ospf instance not found for vrf id %u", __PRETTY_FUNCTION__, vrf_id); + ospf_lsa_unlock(&new); return rc; } diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 5f300dabae..b13e833afd 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -1167,8 +1167,10 @@ static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf *ospf, tmp = SET_OPAQUE_LSID(OPAQUE_TYPE_INTER_AS_LSA, lp->instance); lsa_id.s_addr = htonl(tmp); - if (!ospf) + if (!ospf) { + stream_free(s); return NULL; + } lsa_header_set(s, options, lsa_type, lsa_id, ospf->router_id); } else { @@ -2533,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; @@ -2550,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; @@ -2562,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 3840bc4170..f53efa4355 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -171,6 +171,18 @@ static struct ospf *ospf_cmd_lookup_ospf(struct vty *vty, return ospf; } +static void ospf_show_vrf_name(struct ospf *ospf, struct vty *vty, + json_object *json) +{ + if (ospf->name) { + if (json) + json_object_string_add(json, "vrfName", ospf->name); + else + vty_out(vty, "VRF Name: %s\n", ospf->name); + } + +} + #ifndef VTYSH_EXTRACT_PL #include "ospf_vty_clippy.c" #endif @@ -333,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); @@ -413,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); @@ -485,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); @@ -2457,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); @@ -2473,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; @@ -2488,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) @@ -2499,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; @@ -2890,6 +2903,8 @@ static int show_ip_ospf_common(struct vty *vty, struct ospf *ospf, } } + ospf_show_vrf_name(ospf, vty, json); + /* Show Router ID. */ if (use_json) { json_object_string_add(json, "routerId", @@ -3555,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; @@ -3573,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 = @@ -3857,6 +3871,8 @@ static int show_ip_ospf_neighbor_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } + ospf_show_vrf_name(ospf, vty, json); + for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) show_ip_ospf_neighbor_sub(vty, oi, json, use_json); @@ -4146,6 +4162,8 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } + ospf_show_vrf_name(ospf, vty, json); + /*ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id);*/ ifp = if_lookup_by_name_all_vrf(argv[arg_base]->arg); if (!ifp) { @@ -4558,6 +4576,8 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } + ospf_show_vrf_name(ospf, vty, json); + ret = inet_aton(argv[arg_base]->arg, &router_id); if (!ret) { if (!use_json) @@ -4657,6 +4677,8 @@ static int show_ip_ospf_neighbor_detail_common(struct vty *vty, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } + ospf_show_vrf_name(ospf, vty, json); + for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { struct route_node *rn; struct ospf_neighbor *nbr; @@ -4781,6 +4803,8 @@ static int show_ip_ospf_neighbor_detail_all_common(struct vty *vty, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } + ospf_show_vrf_name(ospf, vty, json); + for (ALL_LIST_ELEMENTS_RO(ospf->oiflist, node, oi)) { struct route_node *rn; struct ospf_neighbor *nbr; @@ -5591,6 +5615,8 @@ static int show_ip_ospf_database_common(struct vty *vty, struct ospf *ospf, if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); + ospf_show_vrf_name(ospf, vty, NULL); + vty_out(vty, "\n OSPF Router with ID (%s)\n\n", inet_ntoa(ospf->router_id)); @@ -5812,6 +5838,8 @@ static int show_ip_ospf_database_type_adv_router_common(struct vty *vty, if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n", ospf->instance); + ospf_show_vrf_name(ospf, vty, NULL); + vty_out(vty, "\n OSPF Router with ID (%s)\n\n", inet_ntoa(ospf->router_id)); @@ -8368,6 +8396,8 @@ static int show_ip_ospf_border_routers_common(struct vty *vty, if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); + ospf_show_vrf_name(ospf, vty, NULL); + if (ospf->new_table == NULL) { vty_out(vty, "No OSPF routing information exist\n"); return CMD_SUCCESS; @@ -8460,6 +8490,8 @@ static int show_ip_ospf_route_common(struct vty *vty, struct ospf *ospf) if (ospf->instance) vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); + ospf_show_vrf_name(ospf, vty, NULL); + if (ospf->new_table == NULL) { vty_out(vty, "No OSPF routing information exist\n"); return CMD_SUCCESS; @@ -8633,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"); @@ -8729,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); @@ -9234,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; @@ -9328,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 @@ -9591,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 bd944ae748..7e6146e0d3 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, @@ -1134,12 +1133,16 @@ void ospf_distribute_list_update(struct ospf *ospf, int type, /* External info does not exist. */ ext = ospf_external_lookup(type, instance); - if (!ext || !(rt = EXTERNAL_INFO(ext))) + if (!ext || !(rt = EXTERNAL_INFO(ext))) { + XFREE(MTYPE_OSPF_DIST_ARGS, args); return; + } /* If exists previously invoked thread, then let it continue. */ - if (ospf->t_distribute_update) + if (ospf->t_distribute_update) { + XFREE(MTYPE_OSPF_DIST_ARGS, args); return; + } /* Set timer. */ ospf->t_distribute_update = NULL; diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 24d3abf2a7..9e1cf81160 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); @@ -634,6 +635,7 @@ static void ospf_finish_final(struct ospf *ospf) /* Reset interface. */ for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi)) ospf_if_free(oi); + list_delete_and_null(&ospf->oiflist); /* De-Register VRF */ ospf_zebra_vrf_deregister(ospf); @@ -736,7 +738,6 @@ static void ospf_finish_final(struct ospf *ospf) list_delete_and_null(&ospf->areas); list_delete_and_null(&ospf->oi_write_q); - list_delete_and_null(&ospf->oiflist); for (i = ZEBRA_ROUTE_SYSTEM; i <= ZEBRA_ROUTE_MAX; i++) { struct list *ext_list; @@ -828,6 +829,8 @@ static void ospf_area_free(struct ospf_area *area) struct route_node *rn; struct ospf_lsa *lsa; + ospf_opaque_type10_lsa_term(area); + /* Free LSDBs. */ LSDB_LOOP(ROUTER_LSDB(area), rn, lsa) ospf_discard_from_db(area->ospf, area->lsdb, lsa); @@ -1252,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 314162c78b..f8903d71e9 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 7ce345d8e3..a9239c2835 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) @@ -1063,58 +1054,48 @@ static void pim_show_interfaces_single(struct pim_instance *pim, // FHR for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up)) { - if (ifp == up->rpf.source_nexthop.interface) { - if (up->flags - & PIM_UPSTREAM_FLAG_MASK_FHR) { - if (!json_fhr_sources) { - json_fhr_sources = - json_object_new_object(); - } - - pim_inet4_dump("<src?>", - up->sg.src, - src_str, - sizeof(src_str)); - pim_inet4_dump("<grp?>", - up->sg.grp, - grp_str, - sizeof(grp_str)); - pim_time_uptime( - uptime, sizeof(uptime), - now - up->state_transition); - - /* Does this group live in - * json_fhr_sources? If not - * create it. */ - json_object_object_get_ex( - json_fhr_sources, - grp_str, &json_group); - - if (!json_group) { - json_group = - json_object_new_object(); - json_object_object_add( - json_fhr_sources, - grp_str, - json_group); - } - - json_group_source = - json_object_new_object(); - json_object_string_add( - json_group_source, - "source", src_str); - json_object_string_add( - json_group_source, - "group", grp_str); - json_object_string_add( - json_group_source, - "upTime", uptime); - json_object_object_add( - json_group, src_str, - json_group_source); - } + if (ifp != up->rpf.source_nexthop.interface) + continue; + + if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_FHR)) + continue; + + if (!json_fhr_sources) + json_fhr_sources = + json_object_new_object(); + + pim_inet4_dump("<src?>", up->sg.src, + src_str, sizeof(src_str)); + pim_inet4_dump("<grp?>", up->sg.grp, + grp_str, sizeof(grp_str)); + pim_time_uptime(uptime, sizeof(uptime), + now - up->state_transition); + + /* + * Does this group live in json_fhr_sources? + * If not create it. + */ + json_object_object_get_ex(json_fhr_sources, + grp_str, + &json_group); + + if (!json_group) { + json_group = json_object_new_object(); + json_object_object_add( + json_fhr_sources, + grp_str, + json_group); } + + json_group_source = json_object_new_object(); + json_object_string_add(json_group_source, + "source", src_str); + json_object_string_add(json_group_source, + "group", grp_str); + json_object_string_add(json_group_source, + "upTime", uptime); + json_object_object_add(json_group, src_str, + json_group_source); } if (json_fhr_sources) { @@ -1237,37 +1218,33 @@ static void pim_show_interfaces_single(struct pim_instance *pim, print_header = 1; for (ALL_LIST_ELEMENTS_RO(pim->upstream_list, upnode, up)) { - if (strcmp(ifp->name, up->rpf.source_nexthop - .interface->name) - == 0) { - if (up->flags - & PIM_UPSTREAM_FLAG_MASK_FHR) { - - if (print_header) { - vty_out(vty, - "FHR - First Hop Router\n"); - vty_out(vty, - "----------------------\n"); - print_header = 0; - } - - pim_inet4_dump("<src?>", - up->sg.src, - src_str, - sizeof(src_str)); - pim_inet4_dump("<grp?>", - up->sg.grp, - grp_str, - sizeof(grp_str)); - pim_time_uptime( - uptime, sizeof(uptime), - now - up->state_transition); - vty_out(vty, - "%s : %s is a source, uptime is %s\n", - grp_str, src_str, - uptime); - } + + if (strcmp(ifp->name, + up->rpf.source_nexthop. + interface->name) != 0) + continue; + + if (!(up->flags & PIM_UPSTREAM_FLAG_MASK_FHR)) + continue; + + if (print_header) { + vty_out(vty, + "FHR - First Hop Router\n"); + vty_out(vty, + "----------------------\n"); + print_header = 0; } + + pim_inet4_dump("<src?>", up->sg.src, + src_str, sizeof(src_str)); + pim_inet4_dump("<grp?>", up->sg.grp, + grp_str, sizeof(grp_str)); + pim_time_uptime(uptime, sizeof(uptime), + now - up->state_transition); + vty_out(vty, + "%s : %s is a source, uptime is %s\n", + grp_str, src_str, + uptime); } if (!print_header) { @@ -1338,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; @@ -1351,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) @@ -1433,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; @@ -1451,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) @@ -1514,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; @@ -1533,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; @@ -1678,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; @@ -1693,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; @@ -1713,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; @@ -1739,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) @@ -2125,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; @@ -2147,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) @@ -2208,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; @@ -2400,6 +2370,30 @@ static void pim_show_upstream(struct pim_instance *pim, struct vty *vty, json_object_string_add( json_row, "inboundInterface", up->rpf.source_nexthop.interface->name); + + /* + * The RPF address we use is slightly different + * based upon what we are looking up. + * If we have a S, list that unless + * we are the FHR, else we just put + * the RP as the rpfAddress + */ + if (up->flags & PIM_UPSTREAM_FLAG_MASK_FHR || + up->sg.src.s_addr == INADDR_ANY) { + char rpf[PREFIX_STRLEN]; + struct pim_rpf *rpg; + + rpg = RP(pim, up->sg.grp); + pim_inet4_dump("<rpf?>", + rpg->rpf_addr.u.prefix4, + rpf, sizeof(rpf)); + json_object_string_add(json_row, + "rpfAddress", rpf); + } else { + json_object_string_add(json_row, + "rpfAddress", src_str); + } + json_object_string_add(json_row, "source", src_str); json_object_string_add(json_row, "group", grp_str); json_object_string_add(json_row, "state", state_str); @@ -2507,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; @@ -2521,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; @@ -2802,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; @@ -2818,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; @@ -2924,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; @@ -2989,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; @@ -2999,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; @@ -3066,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; @@ -3125,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"); } @@ -3160,12 +3140,12 @@ static void clear_interfaces(struct pim_instance *pim) clear_pim_interfaces(pim); } -#define PIM_GET_PIM_INTERFACE(pim_ifp, ifp) \ - pim_ifp = ifp->info; \ - if (!pim_ifp) { \ - vty_out(vty, \ +#define PIM_GET_PIM_INTERFACE(pim_ifp, ifp) \ + pim_ifp = ifp->info; \ + if (!pim_ifp) { \ + vty_out(vty, \ "%% Enable PIM and/or IGMP on this interface first\n"); \ - return CMD_WARNING_CONFIG_FAILED; \ + return CMD_WARNING_CONFIG_FAILED; \ } DEFUN (clear_ip_interfaces, @@ -3301,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) @@ -4320,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"); @@ -4328,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; @@ -6512,7 +6488,7 @@ DEFUN(interface_no_ip_pim_boundary_oil, { VTY_DECLVAR_CONTEXT(interface, iif); struct pim_interface *pim_ifp; - int idx; + int idx = 0; argv_find(argv, argc, "WORD", &idx); diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 8787145027..5dc64a1b3f 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 6aa5105c5f..5f597b17b1 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 7de3e4ca6c..e87dfbca95 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 a1de4837db..8f9058d994 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 cb722c17b2..d961aa4c49 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 ed5d1ecaa2..fdd37f2b91 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 fc377b5a52..450faf75bb 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 df70e9dd5e..db11e5f171 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 1b2cbb61c3..9282896c28 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 bededba7fc..a4b56d9fbf 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 5c65f522ef..d450d5a7f9 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 0bee9a8bf4..df3af2a17f 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -842,6 +842,8 @@ static void ripng_route_process(struct rte *rte, struct sockaddr_in6 *from, unusable). */ if (rte->metric != RIPNG_METRIC_INFINITY) ripng_ecmp_add(&newinfo); + else + route_unlock_node(rp); } else { /* If there is an existing route, compare the next hop address to the address of the router from which the datagram came. @@ -1377,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; @@ -1389,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)) @@ -1445,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; @@ -1465,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)) @@ -2010,7 +2012,7 @@ DEFUN (show_ipv6_ripng, len = 28 - len; if (len > 0) - len = vty_out(vty, "%*s", len, " "); + vty_out(vty, "%*s", len, " "); /* from */ if ((rinfo->type == ZEBRA_ROUTE_RIPNG) @@ -2058,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) @@ -2091,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; @@ -2791,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); } @@ -2968,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/vtysh/vtysh_main.c b/vtysh/vtysh_main.c index 99c05ef79b..8509a8a05a 100644 --- a/vtysh/vtysh_main.c +++ b/vtysh/vtysh_main.c @@ -451,7 +451,7 @@ int main(int argc, char **argv, char **env) exit(ret); } - if (dryrun && cmd) { + if (dryrun && cmd && cmd->line) { vtysh_execute("enable"); while (cmd) { struct cmd_rec *cr; @@ -552,7 +552,7 @@ int main(int argc, char **argv, char **env) } /* If eval mode. */ - if (cmd) { + if (cmd && cmd->line) { /* Enter into enable node. */ vtysh_execute("enable"); diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index 6396911e1b..1d108886de 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 9ec575b5b0..94738664b3 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 5a42e0c8f1..a2235904c6 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 a65dd21f63..e912b2dcf8 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 bc85e983e7..5567d53c3f 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 9907ef5b79..89c933f90f 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/redistribute.c b/zebra/redistribute.c index 890ad887da..cc679142f7 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -519,32 +519,20 @@ int zebra_add_import_table_entry(struct route_node *rn, struct route_entry *re, if (same) zebra_del_import_table_entry(rn, same); - if (re->nexthop_num == 1) { - rib_add(afi, SAFI_UNICAST, re->vrf_id, - ZEBRA_ROUTE_TABLE, re->table, 0, &p, - NULL, re->nexthop, - zebrad.rtm_table_default, re->metric, - re->mtu, - zebra_import_table_distance[afi] - [re->table]); - } else if (re->nexthop_num > 1) { - newre = XCALLOC(MTYPE_RE, - sizeof(struct route_entry)); - newre->type = ZEBRA_ROUTE_TABLE; - newre->distance = - zebra_import_table_distance[afi][re->table]; - newre->flags = re->flags; - newre->metric = re->metric; - newre->mtu = re->mtu; - newre->table = zebrad.rtm_table_default; - newre->nexthop_num = 0; - newre->uptime = time(NULL); - newre->instance = re->table; - route_entry_copy_nexthops(newre, re->nexthop); - - rib_add_multipath(afi, SAFI_UNICAST, &p, - NULL, newre); - } + newre = XCALLOC(MTYPE_RE,sizeof(struct route_entry)); + newre->type = ZEBRA_ROUTE_TABLE; + newre->distance = zebra_import_table_distance[afi][re->table]; + newre->flags = re->flags; + newre->metric = re->metric; + newre->mtu = re->mtu; + newre->table = zebrad.rtm_table_default; + newre->nexthop_num = 0; + newre->uptime = time(NULL); + newre->instance = re->table; + route_entry_copy_nexthops(newre, re->nexthop); + + rib_add_multipath(afi, SAFI_UNICAST, &p, NULL, newre); + return 0; } @@ -557,7 +545,7 @@ int zebra_del_import_table_entry(struct route_node *rn, struct route_entry *re) prefix_copy(&p, &rn->p); rib_delete(afi, SAFI_UNICAST, re->vrf_id, ZEBRA_ROUTE_TABLE, - re->table, re->flags, &p, NULL, NULL, + re->table, re->flags, &p, NULL, re->nexthop, zebrad.rtm_table_default, re->metric, false); return 0; diff --git a/zebra/rib.h b/zebra/rib.h index e3ed6210ca..61beebb409 100644 --- a/zebra/rib.h +++ b/zebra/rib.h @@ -71,7 +71,7 @@ struct route_entry { u_int32_t nexthop_mtu; /* Distance. */ - u_char distance; + uint8_t distance; /* Flags of this route. * This flag's definition is in lib/zebra.h ZEBRA_FLAG_* and is exposed @@ -296,7 +296,7 @@ extern int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, int flags, struct prefix *p, struct prefix_ipv6 *src_p, const struct nexthop *nh, u_int32_t table_id, u_int32_t metric, u_int32_t mtu, - u_char distance); + uint8_t distance); extern int rib_add_multipath(afi_t afi, safi_t safi, struct prefix *, struct prefix_ipv6 *src_p, struct route_entry *); @@ -330,7 +330,7 @@ extern void rib_unlink(struct route_node *, struct route_entry *); extern int rib_gc_dest(struct route_node *rn); extern struct route_table *rib_tables_iter_next(rib_tables_iter_t *iter); -extern u_char route_distance(int type); +extern uint8_t route_distance(int type); /* * Inline functions. diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 573f60f4ca..0cc2e0217f 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -267,7 +267,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, struct rtattr *tb[RTA_MAX + 1]; u_char flags = 0; struct prefix p; - struct prefix_ipv6 src_p; + struct prefix_ipv6 src_p = {}; vrf_id_t vrf_id = VRF_DEFAULT; char anyaddr[16] = {0}; @@ -277,6 +277,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, int table; int metric = 0; u_int32_t mtu = 0; + uint8_t distance = 0; void *dest = NULL; void *gate = NULL; @@ -405,16 +406,38 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, return 0; } + /* + * For ZEBRA_ROUTE_KERNEL types: + * + * The metric/priority of the route received from the kernel + * is a 32 bit number. We are going to interpret the high + * order byte as the Admin Distance and the low order 3 bytes + * as the metric. + * + * This will allow us to do two things: + * 1) Allow the creation of kernel routes that can be + * overridden by zebra. + * 2) Allow the old behavior for 'most' kernel route types + * if a user enters 'ip route ...' v4 routes get a metric + * of 0 and v6 routes get a metric of 1024. Both of these + * values will end up with a admin distance of 0, which + * will cause them to win for the purposes of zebra. + */ + if (proto == ZEBRA_ROUTE_KERNEL) { + distance = (metric >> 24) & 0xFF; + metric = (metric & 0x00FFFFFF); + } + if (IS_ZEBRA_DEBUG_KERNEL) { char buf[PREFIX_STRLEN]; char buf2[PREFIX_STRLEN]; zlog_debug( - "%s %s%s%s vrf %u", nl_msg_type_to_str(h->nlmsg_type), + "%s %s%s%s vrf %u metric: %d Admin Distance: %d", nl_msg_type_to_str(h->nlmsg_type), prefix2str(&p, buf, sizeof(buf)), src_p.prefixlen ? " from " : "", src_p.prefixlen ? prefix2str(&src_p, buf2, sizeof(buf2)) : "", - vrf_id); + vrf_id, metric, distance); } afi_t afi = AFI_IP; @@ -454,7 +477,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, memcpy(&nh.gate, gate, sz); rib_add(afi, SAFI_UNICAST, vrf_id, proto, - 0, flags, &p, NULL, &nh, table, metric, mtu, 0); + 0, flags, &p, NULL, &nh, table, metric, mtu, distance); } else { /* This is a multipath route */ @@ -466,7 +489,7 @@ static int netlink_route_change_read_unicast(struct sockaddr_nl *snl, re = XCALLOC(MTYPE_RE, sizeof(struct route_entry)); re->type = proto; - re->distance = 0; + re->distance = distance; re->flags = flags; re->metric = metric; re->mtu = mtu; @@ -822,7 +845,7 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, { struct nexthop_label *nh_label; mpls_lse_t out_lse[MPLS_MAX_LABELS]; - char label_buf[100]; + char label_buf[256]; /* * label_buf is *only* currently used within debugging. @@ -853,12 +876,13 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, 0, 0, bos); if (IS_ZEBRA_DEBUG_KERNEL) { if (!num_labels) - sprintf(label_buf, "label %d", + sprintf(label_buf, "label %u", nh_label->label[i]); else { - sprintf(label_buf1, "/%d", + sprintf(label_buf1, "/%u", nh_label->label[i]); - strcat(label_buf, label_buf1); + strlcat(label_buf, label_buf1, + sizeof(label_buf)); } } num_labels++; @@ -1021,7 +1045,7 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen, { struct nexthop_label *nh_label; mpls_lse_t out_lse[MPLS_MAX_LABELS]; - char label_buf[100]; + char label_buf[256]; rtnh->rtnh_len = sizeof(*rtnh); rtnh->rtnh_flags = 0; @@ -1057,12 +1081,13 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen, 0, 0, bos); if (IS_ZEBRA_DEBUG_KERNEL) { if (!num_labels) - sprintf(label_buf, "label %d", + sprintf(label_buf, "label %u", nh_label->label[i]); else { - sprintf(label_buf1, "/%d", + sprintf(label_buf1, "/%u", nh_label->label[i]); - strcat(label_buf, label_buf1); + strlcat(label_buf, label_buf1, + sizeof(label_buf)); } } num_labels++; @@ -1716,7 +1741,6 @@ static int netlink_macfdb_change(struct sockaddr_nl *snl, struct nlmsghdr *h, struct ndmsg *ndm; struct interface *ifp; struct zebra_if *zif; - struct zebra_vrf *zvrf; struct rtattr *tb[NDA_MAX + 1]; struct interface *br_if; struct ethaddr mac; @@ -1730,20 +1754,14 @@ static int netlink_macfdb_change(struct sockaddr_nl *snl, struct nlmsghdr *h, ndm = NLMSG_DATA(h); + /* We only process macfdb notifications if EVPN is enabled */ + if (!is_evpn_enabled()) + return 0; + /* The interface should exist. */ ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT), ndm->ndm_ifindex); - if (!ifp) - return 0; - - /* Locate VRF corresponding to interface. We only process MAC - * notifications - * if EVPN is enabled on this VRF. - */ - zvrf = vrf_info_lookup(ifp->vrf_id); - if (!zvrf || !EVPN_ENABLED(zvrf)) - return 0; - if (!ifp->info) + if (!ifp || !ifp->info) return 0; /* The interface should be something we're interested in. */ @@ -2033,7 +2051,6 @@ static int netlink_ipneigh_change(struct sockaddr_nl *snl, struct nlmsghdr *h, struct ndmsg *ndm; struct interface *ifp; struct zebra_if *zif; - struct zebra_vrf *zvrf; struct rtattr *tb[NDA_MAX + 1]; struct interface *link_if; struct ethaddr mac; @@ -2045,20 +2062,14 @@ static int netlink_ipneigh_change(struct sockaddr_nl *snl, struct nlmsghdr *h, ndm = NLMSG_DATA(h); + /* We only process neigh notifications if EVPN is enabled */ + if (!is_evpn_enabled()) + return 0; + /* The interface should exist. */ ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT), ndm->ndm_ifindex); - if (!ifp) - return 0; - - /* Locate VRF corresponding to interface. We only process neigh - * notifications - * if EVPN is enabled on this VRF. - */ - zvrf = vrf_info_lookup(ifp->vrf_id); - if (!zvrf || !EVPN_ENABLED(zvrf)) - return 0; - if (!ifp->info) + if (!ifp || !ifp->info) return 0; /* Drop "permanent" entries. */ diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 633604120c..6a8e2ac594 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 345637c044..529fc48edf 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 a42e6680e8..93b0723d8b 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_rib.c b/zebra/zebra_rib.c index 5c3ec10a79..d46e0730ee 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -129,9 +129,9 @@ _rnode_zlog(const char *_func, vrf_id_t vrf_id, struct route_node *rn, #define rnode_info(node, ...) \ _rnode_zlog(__func__, vrf_id, node, LOG_INFO, __VA_ARGS__) -u_char route_distance(int type) +uint8_t route_distance(int type) { - u_char distance; + uint8_t distance; if ((unsigned)type >= array_size(route_info)) distance = 150; @@ -325,9 +325,11 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop, resolved_hop = nexthop_new(); SET_FLAG(resolved_hop->flags, NEXTHOP_FLAG_ACTIVE); - /* If the resolving route specifies a gateway, use it */ - if (newhop->type == NEXTHOP_TYPE_IPV4 - || newhop->type == NEXTHOP_TYPE_IPV4_IFINDEX) { + + switch (newhop->type) { + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + /* If the resolving route specifies a gateway, use it */ resolved_hop->type = newhop->type; resolved_hop->gate.ipv4 = newhop->gate.ipv4; @@ -337,9 +339,9 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop, if (newhop->flags & NEXTHOP_FLAG_ONLINK) resolved_hop->flags |= NEXTHOP_FLAG_ONLINK; } - } - if (newhop->type == NEXTHOP_TYPE_IPV6 - || newhop->type == NEXTHOP_TYPE_IPV6_IFINDEX) { + break; + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: resolved_hop->type = newhop->type; resolved_hop->gate.ipv6 = newhop->gate.ipv6; @@ -347,18 +349,17 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop, resolved_hop->type = NEXTHOP_TYPE_IPV6_IFINDEX; resolved_hop->ifindex = newhop->ifindex; } - } - - /* If the resolving route is an interface route, - * it means the gateway we are looking up is connected - * to that interface. (The actual network is _not_ onlink). - * Therefore, the resolved route should have the original - * gateway as nexthop as it is directly connected. - * - * On Linux, we have to set the onlink netlink flag because - * otherwise, the kernel won't accept the route. - */ - if (newhop->type == NEXTHOP_TYPE_IFINDEX) { + break; + case NEXTHOP_TYPE_IFINDEX: + /* If the resolving route is an interface route, + * it means the gateway we are looking up is connected + * to that interface. (The actual network is _not_ onlink). + * Therefore, the resolved route should have the original + * gateway as nexthop as it is directly connected. + * + * On Linux, we have to set the onlink netlink flag because + * otherwise, the kernel won't accept the route. + */ resolved_hop->flags |= NEXTHOP_FLAG_ONLINK; if (afi == AFI_IP) { resolved_hop->type = NEXTHOP_TYPE_IPV4_IFINDEX; @@ -368,12 +369,13 @@ static void nexthop_set_resolved(afi_t afi, struct nexthop *newhop, resolved_hop->gate.ipv6 = nexthop->gate.ipv6; } resolved_hop->ifindex = newhop->ifindex; - } - - if (newhop->type == NEXTHOP_TYPE_BLACKHOLE) { + break; + case NEXTHOP_TYPE_BLACKHOLE: resolved_hop->type = NEXTHOP_TYPE_BLACKHOLE; resolved_hop->bh_type = nexthop->bh_type; + break; } + resolved_hop->rparent = nexthop; nexthop_add(&nexthop->resolved, resolved_hop); } @@ -2463,7 +2465,7 @@ void rib_delete(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, int rib_add(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type, u_short instance, int flags, struct prefix *p, struct prefix_ipv6 *src_p, const struct nexthop *nh, u_int32_t table_id, u_int32_t metric, - u_int32_t mtu, u_char distance) + u_int32_t mtu, uint8_t distance) { struct route_entry *re; struct nexthop *nexthop; diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index bf8a17c3ef..0d0a8dd747 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_vrf.h b/zebra/zebra_vrf.h index 6e2dc613df..1dfc0b3eb8 100644 --- a/zebra/zebra_vrf.h +++ b/zebra/zebra_vrf.h @@ -102,13 +102,15 @@ struct zebra_vrf { * VNI hash table (for EVPN). Only in default instance. */ struct hash *vni_table; + /* - * Whether EVPN is enabled or not. + * Whether EVPN is enabled or not. Only in default instance. */ int advertise_all_vni; /* * Whether we are advertising g/w macip in EVPN or not. + * Only in default instance. */ int advertise_gw_macip; diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index b704b97c5e..c0b5f9d10f 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -67,7 +67,7 @@ static void zvni_print_mac_hash_all_vni(struct hash_backet *backet, void *ctxt); static void zvni_print(zebra_vni_t *zvni, void **ctxt); static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]); -static int zvni_macip_send_msg_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr, struct ipaddr *ip, u_char flags, u_int16_t cmd); @@ -80,20 +80,20 @@ static int zvni_neigh_del(zebra_vni_t *zvni, zebra_neigh_t *n); static int zvni_neigh_del_hash_entry(struct hash_backet *backet, void *arg); static void zvni_neigh_del_from_vtep(zebra_vni_t *zvni, int uninstall, struct in_addr *r_vtep_ip); -static void zvni_neigh_del_all(struct zebra_vrf *zvrf, zebra_vni_t *zvni, +static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, u_int32_t flags); static zebra_neigh_t *zvni_neigh_lookup(zebra_vni_t *zvni, struct ipaddr *ip); -static int zvni_neigh_send_add_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, u_char flags); -static int zvni_neigh_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, u_char flags); static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n); static int zvni_neigh_uninstall(zebra_vni_t *zvni, zebra_neigh_t *n); static zebra_vni_t *zvni_map_svi(struct interface *ifp, struct interface *br_if); -static struct interface *zvni_map_to_svi(struct zebra_vrf *zvrf, vlanid_t vid, +static struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if); static unsigned int mac_hash_keymake(void *p); @@ -104,12 +104,12 @@ static int zvni_mac_del(zebra_vni_t *zvni, zebra_mac_t *mac); static int zvni_mac_del_hash_entry(struct hash_backet *backet, void *arg); static void zvni_mac_del_from_vtep(zebra_vni_t *zvni, int uninstall, struct in_addr *r_vtep_ip); -static void zvni_mac_del_all(struct zebra_vrf *zvrf, zebra_vni_t *zvni, +static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, u_int32_t flags); static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *macaddr); -static int zvni_mac_send_add_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, u_char flags); -static int zvni_mac_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr, u_char flags); static zebra_vni_t *zvni_map_vlan(struct interface *ifp, struct interface *br_if, vlanid_t vid); @@ -120,12 +120,12 @@ static void zvni_install_mac_hash(struct hash_backet *backet, void *ctxt); static unsigned int vni_hash_keymake(void *p); static int vni_hash_cmp(const void *p1, const void *p2); static void *zvni_alloc(void *p); -static zebra_vni_t *zvni_lookup(struct zebra_vrf *zvrf, vni_t vni); -static zebra_vni_t *zvni_add(struct zebra_vrf *zvrf, vni_t vni); -static int zvni_del(struct zebra_vrf *zvrf, zebra_vni_t *zvni); -static int zvni_send_add_to_client(struct zebra_vrf *zvrf, zebra_vni_t *zvni); -static int zvni_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni); -static void zvni_build_hash_table(struct zebra_vrf *zvrf); +static zebra_vni_t *zvni_lookup(vni_t vni); +static zebra_vni_t *zvni_add(vni_t vni); +static int zvni_del(zebra_vni_t *zvni); +static int zvni_send_add_to_client(zebra_vni_t *zvni); +static int zvni_send_del_to_client(vni_t vni); +static void zvni_build_hash_table(); static int zvni_vtep_match(struct in_addr *vtep_ip, zebra_vtep_t *zvtep); static zebra_vtep_t *zvni_vtep_find(zebra_vni_t *zvni, struct in_addr *vtep_ip); static zebra_vtep_t *zvni_vtep_add(zebra_vni_t *zvni, struct in_addr *vtep_ip); @@ -140,15 +140,44 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni, static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni, struct ipaddr *ip); struct interface *zebra_get_vrr_intf_for_svi(struct interface *ifp); -static int advertise_gw_macip_enabled(struct zebra_vrf *zvrf, - zebra_vni_t *zvni); +static int advertise_gw_macip_enabled(zebra_vni_t *zvni); static void zvni_deref_ip2mac(zebra_vni_t *zvni, zebra_mac_t *mac, int uninstall); /* Private functions */ -static int advertise_gw_macip_enabled(struct zebra_vrf *zvrf, zebra_vni_t *zvni) +/* + * Return number of valid MACs in a VNI's MAC hash table - all + * remote MACs and non-internal (auto) local MACs count. + */ +static u_int32_t num_valid_macs(zebra_vni_t *zvni) { + unsigned int i; + u_int32_t num_macs = 0; + struct hash *hash; + struct hash_backet *hb; + zebra_mac_t *mac; + + hash = zvni->mac_table; + if (!hash) + return num_macs; + for (i = 0; i < hash->size; i++) { + for (hb = hash->index[i]; hb; hb = hb->next) { + mac = (zebra_mac_t *)hb->data; + if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) + || !CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) + num_macs++; + } + } + + return num_macs; +} + +static int advertise_gw_macip_enabled(zebra_vni_t *zvni) +{ + struct zebra_vrf *zvrf; + + zvrf = vrf_info_lookup(VRF_DEFAULT); if (zvrf && zvrf->advertise_gw_macip) return 1; @@ -541,7 +570,7 @@ static void zvni_print_mac_hash_all_vni(struct hash_backet *backet, void *ctxt) /*We are iterating over a new VNI, set the count to 0*/ wctx->count = 0; - num_macs = hashcount(zvni->mac_table); + num_macs = num_valid_macs(zvni); if (!num_macs) return; @@ -600,7 +629,7 @@ static void zvni_print(zebra_vni_t *zvni, void **ctxt) vty_out(vty, " VxLAN interface: unknown\n"); return; } - num_macs = hashcount(zvni->mac_table); + num_macs = num_valid_macs(zvni); num_neigh = hashcount(zvni->neigh_table); if (json == NULL) vty_out(vty, " VxLAN interface: %s ifIndex: %u VTEP IP: %s\n", @@ -682,7 +711,7 @@ static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]) zvtep = zvtep->next; } - num_macs = hashcount(zvni->mac_table); + num_macs = num_valid_macs(zvni); num_neigh = hashcount(zvni->neigh_table); if (json == NULL) vty_out(vty, "%-10u %-21s %-15s %-8u %-8u %-15u\n", zvni->vni, @@ -719,7 +748,7 @@ static void zvni_print_hash(struct hash_backet *backet, void *ctxt[]) /* * Inform BGP about local MACIP. */ -static int zvni_macip_send_msg_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_macip_send_msg_to_client(vni_t vni, struct ethaddr *macaddr, struct ipaddr *ip, u_char flags, u_int16_t cmd) @@ -738,7 +767,7 @@ static int zvni_macip_send_msg_to_client(struct zebra_vrf *zvrf, vni_t vni, s = client->obuf; stream_reset(s); - zserv_create_header(s, cmd, zvrf_id(zvrf)); + zserv_create_header(s, cmd, VRF_DEFAULT); stream_putl(s, vni); stream_put(s, macaddr->octet, ETH_ALEN); if (ip) { @@ -761,8 +790,8 @@ static int zvni_macip_send_msg_to_client(struct zebra_vrf *zvrf, vni_t vni, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Send MACIP %s flags 0x%x MAC %s IP %s VNI %u to %s", - zvrf_id(zvrf), (cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del", + "Send MACIP %s flags 0x%x MAC %s IP %s VNI %u to %s", + (cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del", flags, prefix_mac2str(macaddr, buf, sizeof(buf)), ipaddr2str(ip, buf2, sizeof(buf2)), vni, zebra_route_string(client->proto)); @@ -882,8 +911,7 @@ static int zvni_neigh_del_hash_entry(struct hash_backet *backet, void *arg) && (n->flags & ZEBRA_NEIGH_REMOTE) && IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))) { if (wctx->upd_client && (n->flags & ZEBRA_NEIGH_LOCAL)) - zvni_neigh_send_del_to_client(wctx->zvrf, - wctx->zvni->vni, &n->ip, + zvni_neigh_send_del_to_client(wctx->zvni->vni, &n->ip, &n->emac, 0); if (wctx->uninstall) @@ -921,7 +949,7 @@ static void zvni_neigh_del_from_vtep(zebra_vni_t *zvni, int uninstall, /* * Delete all neighbor entries for this VNI. */ -static void zvni_neigh_del_all(struct zebra_vrf *zvrf, zebra_vni_t *zvni, +static void zvni_neigh_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, u_int32_t flags) { struct neigh_walk_ctx wctx; @@ -931,7 +959,6 @@ static void zvni_neigh_del_all(struct zebra_vrf *zvrf, zebra_vni_t *zvni, memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); wctx.zvni = zvni; - wctx.zvrf = zvrf; wctx.uninstall = uninstall; wctx.upd_client = upd_client; wctx.flags = flags; @@ -958,8 +985,7 @@ static zebra_neigh_t *zvni_neigh_lookup(zebra_vni_t *zvni, struct ipaddr *ip) } /* Process all neigh associated to a mac upon local mac add event */ -static void zvni_process_neigh_on_local_mac_add(struct zebra_vrf *zvrf, - zebra_vni_t *zvni, +static void zvni_process_neigh_on_local_mac_add(zebra_vni_t *zvni, zebra_mac_t *zmac) { zebra_neigh_t *n = NULL; @@ -974,8 +1000,7 @@ static void zvni_process_neigh_on_local_mac_add(struct zebra_vrf *zvrf, if (IS_ZEBRA_NEIGH_INACTIVE(n)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u: neigh %s (MAC %s) on VNI %u is now ACTIVE", - zvrf_id(zvrf), + "neigh %s (MAC %s) on VNI %u is now ACTIVE", ipaddr2str(&n->ip, buf2, sizeof(buf2)), prefix_mac2str(&n->emac, buf, @@ -984,12 +1009,11 @@ static void zvni_process_neigh_on_local_mac_add(struct zebra_vrf *zvrf, ZEBRA_NEIGH_SET_ACTIVE(n); zvni_neigh_send_add_to_client( - zvrf, zvni->vni, &n->ip, &n->emac, 0); + zvni->vni, &n->ip, &n->emac, 0); } else { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u: neigh %s (MAC %s) on VNI %u should NOT be ACTIVE", - zvrf_id(zvrf), + "neigh %s (MAC %s) on VNI %u should NOT be ACTIVE", ipaddr2str(&n->ip, buf2, sizeof(buf2)), prefix_mac2str(&n->emac, buf, @@ -1003,8 +1027,7 @@ static void zvni_process_neigh_on_local_mac_add(struct zebra_vrf *zvrf, } /* Process all neigh associated to a mac upon local mac del event */ -static void zvni_process_neigh_on_local_mac_del(struct zebra_vrf *zvrf, - zebra_vni_t *zvni, +static void zvni_process_neigh_on_local_mac_del(zebra_vni_t *zvni, zebra_mac_t *zmac) { zebra_neigh_t *n = NULL; @@ -1017,8 +1040,7 @@ static void zvni_process_neigh_on_local_mac_del(struct zebra_vrf *zvrf, if (IS_ZEBRA_NEIGH_ACTIVE(n)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u: neigh %s (MAC %s) on VNI %u is now INACTIVE", - zvrf_id(zvrf), + "neigh %s (MAC %s) on VNI %u is now INACTIVE", ipaddr2str(&n->ip, buf2, sizeof(buf2)), prefix_mac2str(&n->emac, buf, @@ -1027,13 +1049,12 @@ static void zvni_process_neigh_on_local_mac_del(struct zebra_vrf *zvrf, ZEBRA_NEIGH_SET_INACTIVE(n); zvni_neigh_send_del_to_client( - zvrf, zvni->vni, &n->ip, &n->emac, 0); + zvni->vni, &n->ip, &n->emac, 0); } } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_err( - "%u: local MAC %s getting deleted on VNI %u has remote neigh %s", - zvrf_id(zvrf), + "local MAC %s getting deleted on VNI %u has remote neigh %s", prefix_mac2str(&n->emac, buf, sizeof(buf)), zvni->vni, @@ -1043,8 +1064,7 @@ static void zvni_process_neigh_on_local_mac_del(struct zebra_vrf *zvrf, } /* process all neigh associated to a mac entry upon remote mac add */ -static void zvni_process_neigh_on_remote_mac_add(struct zebra_vrf *zvrf, - zebra_vni_t *zvni, +static void zvni_process_neigh_on_remote_mac_add(zebra_vni_t *zvni, zebra_mac_t *zmac) { zebra_neigh_t *n = NULL; @@ -1057,8 +1077,7 @@ static void zvni_process_neigh_on_remote_mac_add(struct zebra_vrf *zvrf, if (IS_ZEBRA_NEIGH_ACTIVE(n)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u: neigh %s (MAC %s) on VNI %u INACTIVE", - zvrf_id(zvrf), + "neigh %s (MAC %s) on VNI %u INACTIVE", ipaddr2str(&n->ip, buf2, sizeof(buf2)), prefix_mac2str(&n->emac, buf, @@ -1067,15 +1086,14 @@ static void zvni_process_neigh_on_remote_mac_add(struct zebra_vrf *zvrf, ZEBRA_NEIGH_SET_INACTIVE(n); zvni_neigh_send_del_to_client( - zvrf, zvni->vni, &n->ip, &n->emac, 0); + zvni->vni, &n->ip, &n->emac, 0); } } } } /* process all neigh associated to mac entry upon remote mac del */ -static void zvni_process_neigh_on_remote_mac_del(struct zebra_vrf *zvrf, - zebra_vni_t *zvni, +static void zvni_process_neigh_on_remote_mac_del(zebra_vni_t *zvni, zebra_mac_t *zmac) { zebra_neigh_t *n = NULL; @@ -1087,8 +1105,7 @@ static void zvni_process_neigh_on_remote_mac_del(struct zebra_vrf *zvrf, if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_err( - "%u: remote MAC %s getting deleted on VNI %u has local neigh %s", - zvrf_id(zvrf), + "remote MAC %s getting deleted on VNI %u has local neigh %s", prefix_mac2str(&n->emac, buf, sizeof(buf)), zvni->vni, @@ -1100,22 +1117,22 @@ static void zvni_process_neigh_on_remote_mac_del(struct zebra_vrf *zvrf, /* * Inform BGP about local neighbor addition. */ -static int zvni_neigh_send_add_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, u_char flags) { - return zvni_macip_send_msg_to_client(zvrf, vni, macaddr, ip, flags, + return zvni_macip_send_msg_to_client(vni, macaddr, ip, flags, ZEBRA_MACIP_ADD); } /* * Inform BGP about local neighbor deletion. */ -static int zvni_neigh_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip, struct ethaddr *macaddr, u_char flags) { - return zvni_macip_send_msg_to_client(zvrf, vni, macaddr, ip, flags, + return zvni_macip_send_msg_to_client(vni, macaddr, ip, flags, ZEBRA_MACIP_DEL); } @@ -1124,7 +1141,6 @@ static int zvni_neigh_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni, */ static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n) { - struct zebra_vrf *zvrf; struct zebra_if *zif; struct zebra_l2info_vxlan *vxl; struct interface *vlan_if; @@ -1132,15 +1148,12 @@ static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n) if (!(n->flags & ZEBRA_NEIGH_REMOTE)) return 0; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - assert(zvrf); zif = zvni->vxlan_if->info; if (!zif) return -1; vxl = &zif->l2info.vxl; - vlan_if = zvni_map_to_svi(zvrf, vxl->access_vlan, - zif->brslave_info.br_if); + vlan_if = zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); if (!vlan_if) return -1; @@ -1152,7 +1165,6 @@ static int zvni_neigh_install(zebra_vni_t *zvni, zebra_neigh_t *n) */ static int zvni_neigh_uninstall(zebra_vni_t *zvni, zebra_neigh_t *n) { - struct zebra_vrf *zvrf; struct zebra_if *zif; struct zebra_l2info_vxlan *vxl; struct interface *vlan_if; @@ -1166,15 +1178,11 @@ static int zvni_neigh_uninstall(zebra_vni_t *zvni, zebra_neigh_t *n) return -1; } - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - assert(zvrf); - zif = zvni->vxlan_if->info; if (!zif) return -1; vxl = &zif->l2info.vxl; - vlan_if = zvni_map_to_svi(zvrf, vxl->access_vlan, - zif->brslave_info.br_if); + vlan_if = zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); if (!vlan_if) return -1; @@ -1203,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; @@ -1225,15 +1232,10 @@ struct interface *zebra_get_vrr_intf_for_svi(struct interface *ifp) static int zvni_del_macip_for_intf(struct interface *ifp, zebra_vni_t *zvni) { - struct zebra_vrf *zvrf = NULL; struct listnode *cnode = NULL, *cnnode = NULL; struct connected *c = NULL; struct ethaddr macaddr; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - if (!zvrf) - return -1; - memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { @@ -1263,15 +1265,10 @@ static int zvni_del_macip_for_intf(struct interface *ifp, zebra_vni_t *zvni) static int zvni_add_macip_for_intf(struct interface *ifp, zebra_vni_t *zvni) { - struct zebra_vrf *zvrf = NULL; struct listnode *cnode = NULL, *cnnode = NULL; struct connected *c = NULL; struct ethaddr macaddr; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - if (!zvrf) - return -1; - memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { @@ -1305,7 +1302,6 @@ static int zvni_add_macip_for_intf(struct interface *ifp, zebra_vni_t *zvni) static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni, struct ethaddr *macaddr, struct ipaddr *ip) { - struct zebra_vrf *zvrf = NULL; struct zebra_if *zif = NULL; struct zebra_l2info_vxlan *vxl = NULL; zebra_neigh_t *n = NULL; @@ -1313,10 +1309,6 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni, char buf[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - if (!zvrf) - return -1; - zif = zvni->vxlan_if->info; if (!zif) return -1; @@ -1327,8 +1319,7 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni, if (!mac) { mac = zvni_mac_add(zvni, macaddr); if (!mac) { - zlog_err("%u:Failed to add MAC %s intf %s(%u) VID %u", - ifp->vrf_id, + zlog_err("Failed to add MAC %s intf %s(%u) VID %u", prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, vxl->access_vlan); return -1; @@ -1347,8 +1338,8 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni, n = zvni_neigh_add(zvni, ip, macaddr); if (!n) { zlog_err( - "%u:Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u", - ifp->vrf_id, ipaddr2str(ip, buf2, sizeof(buf2)), + "Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u", + ipaddr2str(ip, buf2, sizeof(buf2)), prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, zvni->vni); return -1; @@ -1362,12 +1353,12 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s add to BGP", - ifp->vrf_id, ifp->name, ifp->ifindex, zvni->vni, + "SVI %s(%u) VNI %u, sending GW MAC %s IP %s add to BGP", + ifp->name, ifp->ifindex, zvni->vni, prefix_mac2str(macaddr, buf, sizeof(buf)), ipaddr2str(ip, buf2, sizeof(buf2))); - zvni_neigh_send_add_to_client(zvrf, zvni->vni, ip, macaddr, + zvni_neigh_send_add_to_client(zvni->vni, ip, macaddr, ZEBRA_MAC_TYPE_GW); return 0; @@ -1379,16 +1370,11 @@ static int zvni_gw_macip_add(struct interface *ifp, zebra_vni_t *zvni, static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni, struct ipaddr *ip) { - struct zebra_vrf *zvrf = NULL; zebra_neigh_t *n = NULL; zebra_mac_t *mac = NULL; char buf1[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - if (!zvrf) - return -1; - /* If the neigh entry is not present nothing to do*/ n = zvni_neigh_lookup(zvni, ip); if (!n) @@ -1397,8 +1383,7 @@ static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni, /* mac entry should be present */ mac = zvni_mac_lookup(zvni, &n->emac); if (!mac) { - zlog_err("%u: MAC %s doesnt exists for neigh %s on VNI %u", - ifp->vrf_id, + zlog_err("MAC %s doesnt exists for neigh %s on VNI %u", prefix_mac2str(&n->emac, buf1, sizeof(buf1)), ipaddr2str(ip, buf2, sizeof(buf2)), zvni->vni); return -1; @@ -1410,13 +1395,13 @@ static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP", - ifp->vrf_id, ifp->name, ifp->ifindex, zvni->vni, + "SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP", + ifp->name, ifp->ifindex, zvni->vni, prefix_mac2str(&(n->emac), buf1, sizeof(buf1)), ipaddr2str(ip, buf2, sizeof(buf2))); /* Remove neighbor from BGP. */ - zvni_neigh_send_del_to_client(zvrf, zvni->vni, &n->ip, &n->emac, + zvni_neigh_send_del_to_client(zvni->vni, &n->ip, &n->emac, ZEBRA_MAC_TYPE_GW); /* Delete this neighbor entry. */ @@ -1430,7 +1415,7 @@ static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni, } static void zvni_gw_macip_del_for_vni_hash(struct hash_backet *backet, - void *zvrf) + void *ctxt) { zebra_vni_t *zvni = NULL; struct zebra_if *zif = NULL; @@ -1455,8 +1440,7 @@ static void zvni_gw_macip_del_for_vni_hash(struct hash_backet *backet, zl2_info = zif->l2info.vxl; - vlan_if = zvni_map_to_svi(zvrf, zl2_info.access_vlan, - zif->brslave_info.br_if); + vlan_if = zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); if (!vlan_if) return; @@ -1472,7 +1456,7 @@ static void zvni_gw_macip_del_for_vni_hash(struct hash_backet *backet, } static void zvni_gw_macip_add_for_vni_hash(struct hash_backet *backet, - void *zvrf) + void *ctxt) { zebra_vni_t *zvni = NULL; struct zebra_if *zif = NULL; @@ -1485,7 +1469,7 @@ static void zvni_gw_macip_add_for_vni_hash(struct hash_backet *backet, if (!zvni) return; - if (!advertise_gw_macip_enabled(zvrf, zvni)) + if (!advertise_gw_macip_enabled(zvni)) return; ifp = zvni->vxlan_if; @@ -1498,14 +1482,11 @@ static void zvni_gw_macip_add_for_vni_hash(struct hash_backet *backet, return; zl2_info = zif->l2info.vxl; - vlan_if = zvni_map_to_svi(zvrf, zl2_info.access_vlan, + vlan_if = zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); if (!vlan_if) return; - if (!advertise_gw_macip_enabled(zvrf, zvni)) - return; - /* Add primary SVI MAC-IP */ zvni_add_macip_for_intf(vlan_if, zvni); @@ -1617,7 +1598,7 @@ static int zvni_mac_del_hash_entry(struct hash_backet *backet, void *arg) sticky = CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY) ? 1 : 0; zvni_mac_send_del_to_client( - wctx->zvrf, wctx->zvni->vni, &mac->macaddr, + wctx->zvni->vni, &mac->macaddr, (sticky ? ZEBRA_MAC_TYPE_STICKY : 0)); } @@ -1655,7 +1636,7 @@ static void zvni_mac_del_from_vtep(zebra_vni_t *zvni, int uninstall, /* * Delete all MAC entries for this VNI. */ -static void zvni_mac_del_all(struct zebra_vrf *zvrf, zebra_vni_t *zvni, +static void zvni_mac_del_all(zebra_vni_t *zvni, int uninstall, int upd_client, u_int32_t flags) { struct mac_walk_ctx wctx; @@ -1665,7 +1646,6 @@ static void zvni_mac_del_all(struct zebra_vrf *zvrf, zebra_vni_t *zvni, memset(&wctx, 0, sizeof(struct mac_walk_ctx)); wctx.zvni = zvni; - wctx.zvrf = zvrf; wctx.uninstall = uninstall; wctx.upd_client = upd_client; wctx.flags = flags; @@ -1693,43 +1673,39 @@ static zebra_mac_t *zvni_mac_lookup(zebra_vni_t *zvni, struct ethaddr *mac) /* * Inform BGP about local MAC addition. */ -static int zvni_mac_send_add_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, u_char flags) { - return zvni_macip_send_msg_to_client(zvrf, vni, macaddr, NULL, flags, + return zvni_macip_send_msg_to_client(vni, macaddr, NULL, flags, ZEBRA_MACIP_ADD); } /* * Inform BGP about local MAC deletion. */ -static int zvni_mac_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni, +static int zvni_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr, u_char flags) { - return zvni_macip_send_msg_to_client(zvrf, vni, macaddr, NULL, flags, + return zvni_macip_send_msg_to_client(vni, macaddr, NULL, flags, ZEBRA_MACIP_DEL); } /* * Map port or (port, VLAN) to a VNI. This is invoked upon getting MAC - * notifications, to see if there are of interest. - * TODO: Need to make this as a hash table. + * notifications, to see if they are of interest. */ static zebra_vni_t *zvni_map_vlan(struct interface *ifp, struct interface *br_if, vlanid_t vid) { - struct zebra_vrf *zvrf; - struct listnode *node; - struct interface *tmp_if; + struct zebra_ns *zns; + struct route_node *rn; + struct interface *tmp_if = NULL; struct zebra_if *zif; struct zebra_l2info_bridge *br; - struct zebra_l2info_vxlan *vxl; + struct zebra_l2info_vxlan *vxl = NULL; u_char bridge_vlan_aware; zebra_vni_t *zvni; - - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); + int found = 0; /* Determine if bridge is VLAN-aware or not */ zif = br_if->info; @@ -1739,7 +1715,11 @@ static zebra_vni_t *zvni_map_vlan(struct interface *ifp, /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */ /* TODO: Optimize with a hash. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(zvrf_id(zvrf)), node, tmp_if)) { + zns = zebra_ns_lookup(NS_DEFAULT); + for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { + tmp_if = (struct interface *)rn->info; + if (!tmp_if) + continue; zif = tmp_if->info; if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) continue; @@ -1750,36 +1730,35 @@ static zebra_vni_t *zvni_map_vlan(struct interface *ifp, if (zif->brslave_info.br_if != br_if) continue; - if (!bridge_vlan_aware) - break; - - if (vxl->access_vlan == vid) + if (!bridge_vlan_aware || vxl->access_vlan == vid) { + found = 1; break; + } } - if (!tmp_if) + if (!found) return NULL; - zvni = zvni_lookup(zvrf, vxl->vni); + zvni = zvni_lookup(vxl->vni); return zvni; } /* * Map SVI and associated bridge to a VNI. This is invoked upon getting * neighbor notifications, to see if they are of interest. - * TODO: Need to make this as a hash table. */ static zebra_vni_t *zvni_map_svi(struct interface *ifp, struct interface *br_if) { - struct zebra_vrf *zvrf; - struct listnode *node; - struct interface *tmp_if; + struct zebra_ns *zns; + struct route_node *rn; + struct interface *tmp_if = NULL; struct zebra_if *zif; struct zebra_l2info_bridge *br; - struct zebra_l2info_vxlan *vxl; + struct zebra_l2info_vxlan *vxl = NULL; u_char bridge_vlan_aware; vlanid_t vid = 0; zebra_vni_t *zvni; + int found = 0; if (!br_if) return NULL; @@ -1788,10 +1767,6 @@ static zebra_vni_t *zvni_map_svi(struct interface *ifp, struct interface *br_if) if (!IS_ZEBRA_IF_BRIDGE(br_if)) return NULL; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); - /* Determine if bridge is VLAN-aware or not */ zif = br_if->info; assert(zif); @@ -1811,7 +1786,11 @@ static zebra_vni_t *zvni_map_svi(struct interface *ifp, struct interface *br_if) /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */ /* TODO: Optimize with a hash. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(zvrf_id(zvrf)), node, tmp_if)) { + zns = zebra_ns_lookup(NS_DEFAULT); + for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { + tmp_if = (struct interface *)rn->info; + if (!tmp_if) + continue; zif = tmp_if->info; if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) continue; @@ -1822,17 +1801,16 @@ static zebra_vni_t *zvni_map_svi(struct interface *ifp, struct interface *br_if) if (zif->brslave_info.br_if != br_if) continue; - if (!bridge_vlan_aware) - break; - - if (vxl->access_vlan == vid) + if (!bridge_vlan_aware || vxl->access_vlan == vid) { + found = 1; break; + } } - if (!tmp_if) + if (!found) return NULL; - zvni = zvni_lookup(zvrf, vxl->vni); + zvni = zvni_lookup(vxl->vni); return zvni; } @@ -1843,15 +1821,16 @@ static zebra_vni_t *zvni_map_svi(struct interface *ifp, struct interface *br_if) * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge inteface * itself */ -static struct interface *zvni_map_to_svi(struct zebra_vrf *zvrf, vlanid_t vid, - struct interface *br_if) +static struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if) { - struct listnode *node; - struct interface *tmp_if; + struct zebra_ns *zns; + struct route_node *rn; + struct interface *tmp_if = NULL; struct zebra_if *zif; struct zebra_l2info_bridge *br; struct zebra_l2info_vlan *vl; u_char bridge_vlan_aware; + int found = 0; /* Defensive check, caller expected to invoke only with valid bridge. */ if (!br_if) @@ -1869,9 +1848,11 @@ static struct interface *zvni_map_to_svi(struct zebra_vrf *zvrf, vlanid_t vid, /* Identify corresponding VLAN interface. */ /* TODO: Optimize with a hash. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(zvrf_id(zvrf)), node, tmp_if)) { + zns = zebra_ns_lookup(NS_DEFAULT); + for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { + tmp_if = (struct interface *)rn->info; /* Check oper status of the SVI. */ - if (!if_is_operative(tmp_if)) + if (!tmp_if || !if_is_operative(tmp_if)) continue; zif = tmp_if->info; if (!zif || zif->zif_type != ZEBRA_IF_VLAN @@ -1879,11 +1860,13 @@ static struct interface *zvni_map_to_svi(struct zebra_vrf *zvrf, vlanid_t vid, continue; vl = (struct zebra_l2info_vlan *)&zif->l2info.vl; - if (vl->vid == vid) + if (vl->vid == vid) { + found = 1; break; + } } - return tmp_if; + return found ? tmp_if : NULL; } /* @@ -1986,9 +1969,10 @@ static void zvni_deref_ip2mac(zebra_vni_t *zvni, zebra_mac_t *mac, /* * Read and populate local MACs and neighbors corresponding to this VNI. */ -static void zvni_read_mac_neigh(struct zebra_vrf *zvrf, zebra_vni_t *zvni, +static void zvni_read_mac_neigh(zebra_vni_t *zvni, struct interface *ifp) { + struct zebra_ns *zns; struct zebra_if *zif; struct interface *vlan_if; struct zebra_l2info_vxlan *vxl; @@ -1996,19 +1980,19 @@ static void zvni_read_mac_neigh(struct zebra_vrf *zvrf, zebra_vni_t *zvni, zif = ifp->info; vxl = &zif->l2info.vxl; + zns = zebra_ns_lookup(NS_DEFAULT); if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u", - ifp->vrf_id, ifp->name, ifp->ifindex, zvni->vni, + "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u", + ifp->name, ifp->ifindex, zvni->vni, zif->brslave_info.bridge_ifindex); - macfdb_read_for_bridge(zvrf->zns, ifp, zif->brslave_info.br_if); - vlan_if = zvni_map_to_svi(zvrf, vxl->access_vlan, - zif->brslave_info.br_if); + macfdb_read_for_bridge(zns, ifp, zif->brslave_info.br_if); + vlan_if = zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); if (vlan_if) { - if (advertise_gw_macip_enabled(zvrf, zvni)) { + if (advertise_gw_macip_enabled(zvni)) { /* Add SVI MAC-IP */ zvni_add_macip_for_intf(vlan_if, zvni); @@ -2018,7 +2002,7 @@ static void zvni_read_mac_neigh(struct zebra_vrf *zvrf, zebra_vni_t *zvni, zvni_add_macip_for_intf(vrr_if, zvni); } - neigh_read_for_vlan(zvrf->zns, vlan_if); + neigh_read_for_vlan(zns, vlan_if); } } @@ -2059,11 +2043,14 @@ static void *zvni_alloc(void *p) /* * Look up VNI hash entry. */ -static zebra_vni_t *zvni_lookup(struct zebra_vrf *zvrf, vni_t vni) +static zebra_vni_t *zvni_lookup(vni_t vni) { + struct zebra_vrf *zvrf; zebra_vni_t tmp_vni; zebra_vni_t *zvni = NULL; + zvrf = vrf_info_lookup(VRF_DEFAULT); + assert(zvrf); memset(&tmp_vni, 0, sizeof(zebra_vni_t)); tmp_vni.vni = vni; zvni = hash_lookup(zvrf->vni_table, &tmp_vni); @@ -2074,11 +2061,14 @@ static zebra_vni_t *zvni_lookup(struct zebra_vrf *zvrf, vni_t vni) /* * Add VNI hash entry. */ -static zebra_vni_t *zvni_add(struct zebra_vrf *zvrf, vni_t vni) +static zebra_vni_t *zvni_add(vni_t vni) { + struct zebra_vrf *zvrf; zebra_vni_t tmp_zvni; zebra_vni_t *zvni = NULL; + zvrf = vrf_info_lookup(VRF_DEFAULT); + assert(zvrf); memset(&tmp_zvni, 0, sizeof(zebra_vni_t)); tmp_zvni.vni = vni; zvni = hash_get(zvrf->vni_table, &tmp_zvni, zvni_alloc); @@ -2098,10 +2088,14 @@ static zebra_vni_t *zvni_add(struct zebra_vrf *zvrf, vni_t vni) /* * Delete VNI hash entry. */ -static int zvni_del(struct zebra_vrf *zvrf, zebra_vni_t *zvni) +static int zvni_del(zebra_vni_t *zvni) { + struct zebra_vrf *zvrf; zebra_vni_t *tmp_zvni; + zvrf = vrf_info_lookup(VRF_DEFAULT); + assert(zvrf); + zvni->vxlan_if = NULL; /* Free the neighbor hash table. */ @@ -2123,7 +2117,7 @@ static int zvni_del(struct zebra_vrf *zvrf, zebra_vni_t *zvni) /* * Inform BGP about local VNI addition. */ -static int zvni_send_add_to_client(struct zebra_vrf *zvrf, zebra_vni_t *zvni) +static int zvni_send_add_to_client(zebra_vni_t *zvni) { struct zserv *client; struct stream *s; @@ -2136,7 +2130,7 @@ static int zvni_send_add_to_client(struct zebra_vrf *zvrf, zebra_vni_t *zvni) s = client->obuf; stream_reset(s); - zserv_create_header(s, ZEBRA_VNI_ADD, zvrf_id(zvrf)); + zserv_create_header(s, ZEBRA_VNI_ADD, VRF_DEFAULT); stream_putl(s, zvni->vni); stream_put_in_addr(s, &zvni->local_vtep_ip); @@ -2144,7 +2138,7 @@ static int zvni_send_add_to_client(struct zebra_vrf *zvrf, zebra_vni_t *zvni) stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Send VNI_ADD %u %s to %s", zvrf_id(zvrf), + zlog_debug("Send VNI_ADD %u %s to %s", zvni->vni, inet_ntoa(zvni->local_vtep_ip), zebra_route_string(client->proto)); @@ -2155,7 +2149,7 @@ static int zvni_send_add_to_client(struct zebra_vrf *zvrf, zebra_vni_t *zvni) /* * Inform BGP about local VNI deletion. */ -static int zvni_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni) +static int zvni_send_del_to_client(vni_t vni) { struct zserv *client; struct stream *s; @@ -2168,14 +2162,14 @@ static int zvni_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni) s = client->obuf; stream_reset(s); - zserv_create_header(s, ZEBRA_VNI_DEL, zvrf_id(zvrf)); + zserv_create_header(s, ZEBRA_VNI_DEL, VRF_DEFAULT); stream_putl(s, vni); /* Write packet size. */ stream_putw_at(s, 0, stream_get_endp(s)); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Send VNI_DEL %u to %s", zvrf_id(zvrf), vni, + zlog_debug("Send VNI_DEL %u to %s", vni, zebra_route_string(client->proto)); client->vnidel_cnt++; @@ -2186,18 +2180,23 @@ static int zvni_send_del_to_client(struct zebra_vrf *zvrf, vni_t vni) * Build the VNI hash table by going over the VxLAN interfaces. This * is called when EVPN (advertise-all-vni) is enabled. */ -static void zvni_build_hash_table(struct zebra_vrf *zvrf) +static void zvni_build_hash_table() { - struct listnode *node; + struct zebra_ns *zns; + struct route_node *rn; struct interface *ifp; /* Walk VxLAN interfaces and create VNI hash. */ - for (ALL_LIST_ELEMENTS_RO(vrf_iflist(zvrf_id(zvrf)), node, ifp)) { + zns = zebra_ns_lookup(NS_DEFAULT); + for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { struct zebra_if *zif; struct zebra_l2info_vxlan *vxl; zebra_vni_t *zvni; vni_t vni; + ifp = (struct interface *)rn->info; + if (!ifp) + continue; zif = ifp->info; if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) continue; @@ -2207,24 +2206,24 @@ static void zvni_build_hash_table(struct zebra_vrf *zvrf) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Create VNI hash for intf %s(%u) VNI %u local IP %s", - zvrf_id(zvrf), ifp->name, ifp->ifindex, vni, + "Create VNI hash for intf %s(%u) VNI %u local IP %s", + ifp->name, ifp->ifindex, vni, inet_ntoa(vxl->vtep_ip)); /* VNI hash entry is not expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (zvni) { zlog_err( - "VNI hash already present for VRF %d IF %s(%u) VNI %u", - zvrf_id(zvrf), ifp->name, ifp->ifindex, vni); + "VNI hash already present for IF %s(%u) VNI %u", + ifp->name, ifp->ifindex, vni); continue; } - zvni = zvni_add(zvrf, vni); + zvni = zvni_add(vni); if (!zvni) { zlog_err( - "Failed to add VNI hash, VRF %d IF %s(%u) VNI %u", - zvrf_id(zvrf), ifp->name, ifp->ifindex, vni); + "Failed to add VNI hash, IF %s(%u) VNI %u", + ifp->name, ifp->ifindex, vni); return; } @@ -2233,7 +2232,7 @@ static void zvni_build_hash_table(struct zebra_vrf *zvrf) /* Inform BGP if interface is up and mapped to bridge. */ if (if_is_operative(ifp) && zif->brslave_info.br_if) - zvni_send_add_to_client(zvrf, zvni); + zvni_send_add_to_client(zvni); } } @@ -2359,14 +2358,14 @@ static void zvni_cleanup_all(struct hash_backet *backet, void *zvrf) return; /* Free up all neighbors and MACs, if any. */ - zvni_neigh_del_all(zvrf, zvni, 1, 0, DEL_ALL_NEIGH); - zvni_mac_del_all(zvrf, zvni, 1, 0, DEL_ALL_MAC); + zvni_neigh_del_all(zvni, 1, 0, DEL_ALL_NEIGH); + zvni_mac_del_all(zvni, 1, 0, DEL_ALL_MAC); /* Free up all remote VTEPs, if any. */ zvni_vtep_del_all(zvni, 1); /* Delete the hash entry. */ - zvni_del(zvrf, zvni); + zvni_del(zvni); } @@ -2383,9 +2382,9 @@ void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf, struct neigh_walk_ctx wctx; json_object *json = NULL; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { if (use_json) vty_out(vty, "{}\n"); @@ -2437,7 +2436,7 @@ void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf, json_object *json = NULL; void *args[2]; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; if (use_json) @@ -2467,9 +2466,9 @@ void zebra_vxlan_print_specific_neigh_vni(struct vty *vty, zebra_neigh_t *n; json_object *json = NULL; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { if (use_json) vty_out(vty, "{}\n"); @@ -2510,9 +2509,9 @@ void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, struct neigh_walk_ctx wctx; json_object *json = NULL; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { if (use_json) vty_out(vty, "{}\n"); @@ -2551,9 +2550,9 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf, json_object *json = NULL; json_object *json_mac = NULL; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { if (use_json) vty_out(vty, "{}\n"); @@ -2561,7 +2560,7 @@ void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf, vty_out(vty, "%% VNI %u does not exist\n", vni); return; } - num_macs = hashcount(zvni->mac_table); + num_macs = num_valid_macs(zvni); if (!num_macs) return; @@ -2603,7 +2602,7 @@ void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf, struct mac_walk_ctx wctx; json_object *json = NULL; - if (!EVPN_ENABLED(zvrf)) { + if (!is_evpn_enabled()) { if (use_json) vty_out(vty, "{}\n"); return; @@ -2634,7 +2633,7 @@ void zebra_vxlan_print_macs_all_vni_vtep(struct vty *vty, struct mac_walk_ctx wctx; json_object *json = NULL; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; if (use_json) @@ -2663,9 +2662,9 @@ void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf, zebra_vni_t *zvni; zebra_mac_t *mac; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { vty_out(vty, "%% VNI %u does not exist\n", vni); return; @@ -2693,9 +2692,9 @@ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, json_object *json = NULL; json_object *json_mac = NULL; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { if (use_json) vty_out(vty, "{}\n"); @@ -2703,7 +2702,7 @@ void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, vty_out(vty, "%% VNI %u does not exist\n", vni); return; } - num_macs = hashcount(zvni->mac_table); + num_macs = num_valid_macs(zvni); if (!num_macs) return; @@ -2741,9 +2740,9 @@ void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, json_object *json = NULL; void *args[2]; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { if (use_json) vty_out(vty, "{}\n"); @@ -2773,7 +2772,7 @@ void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, json_object *json = NULL; void *args[2]; - if (!EVPN_ENABLED(zvrf)) + if (!is_evpn_enabled()) return; num_vnis = hashcount(zvrf->vni_table); if (!num_vnis) { @@ -2819,7 +2818,6 @@ int zebra_vxlan_local_neigh_del(struct interface *ifp, { zebra_vni_t *zvni; zebra_neigh_t *n; - struct zebra_vrf *zvrf; char buf[INET6_ADDRSTRLEN]; char buf2[ETHER_ADDR_STRLEN]; zebra_mac_t *zmac; @@ -2838,8 +2836,8 @@ int zebra_vxlan_local_neigh_del(struct interface *ifp, } if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Del neighbor %s intf %s(%u) -> VNI %u", - ifp->vrf_id, ipaddr2str(ip, buf, sizeof(buf)), + zlog_debug("Del neighbor %s intf %s(%u) -> VNI %u", + ipaddr2str(ip, buf, sizeof(buf)), ifp->name, ifp->ifindex, zvni->vni); /* If entry doesn't exist, nothing to do. */ @@ -2851,8 +2849,8 @@ int zebra_vxlan_local_neigh_del(struct interface *ifp, if (!zmac) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_err( - "%u: trying to del a neigh %s without a mac %s on VNI %u", - ifp->vrf_id, ipaddr2str(ip, buf, sizeof(buf)), + "Trying to del a neigh %s without a mac %s on VNI %u", + ipaddr2str(ip, buf, sizeof(buf)), prefix_mac2str(&n->emac, buf2, sizeof(buf2)), zvni->vni); @@ -2867,13 +2865,9 @@ int zebra_vxlan_local_neigh_del(struct interface *ifp, return 0; } - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - assert(zvrf); - /* Remove neighbor from BGP. */ if (IS_ZEBRA_NEIGH_ACTIVE(n)) - zvni_neigh_send_del_to_client(zvrf, zvni->vni, &n->ip, &n->emac, + zvni_neigh_send_del_to_client(zvni->vni, &n->ip, &n->emac, 0); /* Delete this neighbor entry. */ @@ -2899,7 +2893,6 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, { zebra_vni_t *zvni; zebra_neigh_t *n; - struct zebra_vrf *zvrf; zebra_mac_t *zmac, *old_zmac; char buf[ETHER_ADDR_STRLEN]; char buf2[INET6_ADDRSTRLEN]; @@ -2911,15 +2904,11 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, if (!zvni) return 0; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - assert(zvrf); - if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Add/Update neighbor %s MAC %s intf %s(%u) state 0x%x " + "Add/Update neighbor %s MAC %s intf %s(%u) state 0x%x " "%s-> VNI %u", - ifp->vrf_id, ipaddr2str(ip, buf2, sizeof(buf2)), + ipaddr2str(ip, buf2, sizeof(buf2)), prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, state, ext_learned ? "ext-learned " : "", zvni->vni); @@ -2929,15 +2918,13 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, if (!zmac) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u: AUTO MAC %s created for neigh %s on VNI %u", - ifp->vrf_id, + "AUTO MAC %s created for neigh %s on VNI %u", prefix_mac2str(macaddr, buf, sizeof(buf)), ipaddr2str(ip, buf2, sizeof(buf2)), zvni->vni); zmac = zvni_mac_add(zvni, macaddr); if (!zmac) { - zlog_warn("%u:Failed to add MAC %s VNI %u", - zvrf_id(zvrf), + zlog_warn("Failed to add MAC %s VNI %u", prefix_mac2str(macaddr, buf, sizeof(buf)), zvni->vni); return -1; @@ -2969,7 +2956,7 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, * as this means a different MACIP route. * Also, need to do some unlinking/relinking. */ - zvni_neigh_send_del_to_client(zvrf, zvni->vni, &n->ip, + zvni_neigh_send_del_to_client(zvni->vni, &n->ip, &n->emac, 0); old_zmac = zvni_mac_lookup(zvni, &n->emac); if (old_zmac) { @@ -3002,8 +2989,8 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, n = zvni_neigh_add(zvni, ip, macaddr); if (!n) { zlog_err( - "%u:Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u", - ifp->vrf_id, ipaddr2str(ip, buf2, sizeof(buf2)), + "Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u", + ipaddr2str(ip, buf2, sizeof(buf2)), prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, zvni->vni); return -1; @@ -3018,8 +3005,8 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, if (!CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL)) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u: Skipping neigh %s add to client as MAC %s is not local on VNI %u", - ifp->vrf_id, ipaddr2str(ip, buf2, sizeof(buf2)), + "Skipping neigh %s add to client as MAC %s is not local on VNI %u", + ipaddr2str(ip, buf2, sizeof(buf2)), prefix_mac2str(macaddr, buf, sizeof(buf)), zvni->vni); @@ -3028,13 +3015,13 @@ int zebra_vxlan_local_neigh_add_update(struct interface *ifp, /* Inform BGP. */ if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u: neigh %s (MAC %s) is now ACTIVE on VNI %u", - ifp->vrf_id, ipaddr2str(ip, buf2, sizeof(buf2)), + zlog_debug("neigh %s (MAC %s) is now ACTIVE on VNI %u", + ipaddr2str(ip, buf2, sizeof(buf2)), prefix_mac2str(macaddr, buf, sizeof(buf)), zvni->vni); ZEBRA_NEIGH_SET_ACTIVE(n); - return zvni_neigh_send_add_to_client(zvrf, zvni->vni, ip, macaddr, 0); + return zvni_neigh_send_add_to_client(zvni->vni, ip, macaddr, 0); } @@ -3082,21 +3069,20 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, int sock, u_short length, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Recv MACIP Del MAC %s IP %s VNI %u Remote VTEP %s from %s", - zvrf_id(zvrf), + "Recv MACIP Del MAC %s IP %s VNI %u Remote VTEP %s from %s", prefix_mac2str(&macaddr, buf, sizeof(buf)), ipaddr2str(&ip, buf1, sizeof(buf1)), vni, inet_ntoa(vtep_ip), zebra_route_string(client->proto)); /* Locate VNI hash entry - expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "Failed to locate VNI hash upon remote MACIP DEL, " - "VRF %d VNI %u", - zvrf_id(zvrf), vni); + "VNI %u", + vni); continue; } ifp = zvni->vxlan_if; @@ -3129,10 +3115,9 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, int sock, u_short length, if (n && !mac) { zlog_err( - "failed to locate MAC %s for neigh %s in VRF %u VNI %u", + "Failed to locate MAC %s for neigh %s VNI %u", prefix_mac2str(&macaddr, buf, sizeof(buf)), - ipaddr2str(&ip, buf1, sizeof(buf1)), - zvrf_id(zvrf), vni); + ipaddr2str(&ip, buf1, sizeof(buf1)), vni); continue; } @@ -3163,7 +3148,7 @@ int zebra_vxlan_remote_macip_del(struct zserv *client, int sock, u_short length, } } else { if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { - zvni_process_neigh_on_remote_mac_del(zvrf, zvni, + zvni_process_neigh_on_remote_mac_del(zvni, mac); if (list_isempty(mac->neigh_list)) { @@ -3234,19 +3219,19 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, int sock, u_short length, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Recv MACIP Add %sMAC %s IP %s VNI %u Remote VTEP %s from %s", - zvrf_id(zvrf), sticky ? "sticky " : "", + "Recv MACIP Add %sMAC %s IP %s VNI %u Remote VTEP %s from %s", + sticky ? "sticky " : "", prefix_mac2str(&macaddr, buf, sizeof(buf)), ipaddr2str(&ip, buf1, sizeof(buf1)), vni, inet_ntoa(vtep_ip), zebra_route_string(client->proto)); /* Locate VNI hash entry - expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { zlog_err( - "Failed to locate VNI hash upon remote MACIP ADD, VRF %d VNI %u", - zvrf_id(zvrf), vni); + "Failed to locate VNI hash upon remote MACIP ADD, VNI %u", + vni); continue; } ifp = zvni->vxlan_if; @@ -3272,8 +3257,8 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, int sock, u_short length, if (!zvtep) { if (zvni_vtep_add(zvni, &vtep_ip) == NULL) { zlog_err( - "Failed to add remote VTEP, VRF %d VNI %u zvni %p", - zvrf_id(zvrf), vni, zvni); + "Failed to add remote VTEP, VNI %u zvni %p", + vni, zvni); continue; } @@ -3298,8 +3283,7 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, int sock, u_short length, mac = zvni_mac_add(zvni, &macaddr); if (!mac) { zlog_warn( - "%u:Failed to add MAC %s VNI %u Remote VTEP %s", - zvrf_id(zvrf), + "Failed to add MAC %s VNI %u Remote VTEP %s", prefix_mac2str(&macaddr, buf, sizeof(buf)), vni, inet_ntoa(vtep_ip)); @@ -3322,7 +3306,7 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, int sock, u_short length, else UNSET_FLAG(mac->flags, ZEBRA_MAC_STICKY); - zvni_process_neigh_on_remote_mac_add(zvrf, zvni, mac); + zvni_process_neigh_on_remote_mac_add(zvni, mac); /* Install the entry. */ zvni_mac_install(zvni, mac); @@ -3350,8 +3334,7 @@ int zebra_vxlan_remote_macip_add(struct zserv *client, int sock, u_short length, n = zvni_neigh_add(zvni, &ip, &macaddr); if (!n) { zlog_warn( - "%u:Failed to add Neigh %s MAC %s VNI %u Remote VTEP %s", - zvrf_id(zvrf), + "Failed to add Neigh %s MAC %s VNI %u Remote VTEP %s", ipaddr2str(&ip, buf1, sizeof(buf1)), prefix_mac2str(&macaddr, buf, @@ -3397,7 +3380,6 @@ int zebra_vxlan_check_del_local_mac(struct interface *ifp, struct ethaddr *macaddr, vlanid_t vid) { struct zebra_if *zif; - struct zebra_vrf *zvrf; struct zebra_l2info_vxlan *vxl; vni_t vni; zebra_vni_t *zvni; @@ -3410,16 +3392,12 @@ int zebra_vxlan_check_del_local_mac(struct interface *ifp, vxl = &zif->l2info.vxl; vni = vxl->vni; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); - - /* If EVPN is not enabled, nothing to do. */ - if (!EVPN_ENABLED(zvrf)) + /* Check if EVPN is enabled. */ + if (!is_evpn_enabled()) return 0; /* Locate hash entry; it is expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) return 0; @@ -3434,13 +3412,13 @@ int zebra_vxlan_check_del_local_mac(struct interface *ifp, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Add/update remote MAC %s intf %s(%u) VNI %u - del local", - ifp->vrf_id, prefix_mac2str(macaddr, buf, sizeof(buf)), + "Add/update remote MAC %s intf %s(%u) VNI %u - del local", + prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, vni); /* Remove MAC from BGP. */ sticky = CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY) ? 1 : 0; - zvni_mac_send_del_to_client(zvrf, zvni->vni, macaddr, + zvni_mac_send_del_to_client(zvni->vni, macaddr, (sticky ? ZEBRA_MAC_TYPE_STICKY : 0)); /* @@ -3467,7 +3445,6 @@ int zebra_vxlan_check_readd_remote_mac(struct interface *ifp, struct ethaddr *macaddr, vlanid_t vid) { struct zebra_if *zif; - struct zebra_vrf *zvrf; struct zebra_l2info_vxlan *vxl; vni_t vni; zebra_vni_t *zvni; @@ -3479,16 +3456,12 @@ int zebra_vxlan_check_readd_remote_mac(struct interface *ifp, vxl = &zif->l2info.vxl; vni = vxl->vni; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); - - /* If EVPN is not enabled, nothing to do. */ - if (!EVPN_ENABLED(zvrf)) + /* Check if EVPN is enabled. */ + if (!is_evpn_enabled()) return 0; /* Locate hash entry; it is expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) return 0; @@ -3502,8 +3475,7 @@ int zebra_vxlan_check_readd_remote_mac(struct interface *ifp, return 0; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Del remote MAC %s intf %s(%u) VNI %u - readd", - ifp->vrf_id, + zlog_debug("Del remote MAC %s intf %s(%u) VNI %u - readd", prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, vni); @@ -3519,7 +3491,6 @@ int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if, { zebra_vni_t *zvni; zebra_mac_t *mac; - struct zebra_vrf *zvrf; char buf[ETHER_ADDR_STRLEN]; u_char sticky; @@ -3536,8 +3507,7 @@ int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if, } if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Del MAC %s intf %s(%u) VID %u -> VNI %u", - ifp->vrf_id, + zlog_debug("Del MAC %s intf %s(%u) VID %u -> VNI %u", prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, vid, zvni->vni); @@ -3550,17 +3520,13 @@ int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if, if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) return 0; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - assert(zvrf); - /* Remove MAC from BGP. */ sticky = CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY) ? 1 : 0; - zvni_mac_send_del_to_client(zvrf, zvni->vni, macaddr, + zvni_mac_send_del_to_client(zvni->vni, macaddr, (sticky ? ZEBRA_MAC_TYPE_STICKY : 0)); /* Update all the neigh entries associated with this mac */ - zvni_process_neigh_on_local_mac_del(zvrf, zvni, mac); + zvni_process_neigh_on_local_mac_del(zvni, mac); /* * If there are no neigh associated with the mac delete the mac @@ -3586,7 +3552,6 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, { zebra_vni_t *zvni; zebra_mac_t *mac; - struct zebra_vrf *zvrf; char buf[ETHER_ADDR_STRLEN]; int add = 1; u_char mac_sticky; @@ -3598,8 +3563,8 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, if (!zvni) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Add/Update %sMAC %s intf %s(%u) VID %u, could not find VNI", - ifp->vrf_id, sticky ? "sticky " : "", + "Add/Update %sMAC %s intf %s(%u) VID %u, could not find VNI", + sticky ? "sticky " : "", prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, vid); return 0; @@ -3613,8 +3578,8 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u", - ifp->vrf_id, sticky ? "sticky " : "", + "Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u", + sticky ? "sticky " : "", prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, vid, zvni->vni); @@ -3638,9 +3603,8 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, && mac->fwd_info.local.vid == vid) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u, " + "Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u, " "entry exists and has not changed ", - ifp->vrf_id, sticky ? "sticky " : "", prefix_mac2str(macaddr, buf, sizeof(buf)), @@ -3671,15 +3635,10 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, } } - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); - assert(zvrf); - if (!mac) { mac = zvni_mac_add(zvni, macaddr); if (!mac) { - zlog_err("%u:Failed to add MAC %s intf %s(%u) VID %u", - ifp->vrf_id, + zlog_err("Failed to add MAC %s intf %s(%u) VID %u", prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, ifp->ifindex, vid); return -1; @@ -3701,8 +3660,8 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, /* Inform BGP if required. */ if (add) { - zvni_process_neigh_on_local_mac_add(zvrf, zvni, mac); - return zvni_mac_send_add_to_client(zvrf, zvni->vni, macaddr, + zvni_process_neigh_on_local_mac_add(zvni, mac); + return zvni_mac_send_add_to_client(zvni->vni, macaddr, sticky); } @@ -3724,6 +3683,13 @@ int zebra_vxlan_remote_vtep_del(struct zserv *client, int sock, u_short length, struct interface *ifp; struct zebra_if *zif; + assert(is_evpn_enabled()); + if (zvrf_id(zvrf) != VRF_DEFAULT) { + zlog_err("Recv MACIP DEL for non-default VRF %u", + zvrf_id(zvrf)); + return -1; + } + s = client->ibuf; while (l < length) { @@ -3734,18 +3700,18 @@ int zebra_vxlan_remote_vtep_del(struct zserv *client, int sock, u_short length, l += IPV4_MAX_BYTELEN; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Recv VTEP_DEL %s VNI %u from %s", - zvrf_id(zvrf), inet_ntoa(vtep_ip), vni, + zlog_debug("Recv VTEP_DEL %s VNI %u from %s", + inet_ntoa(vtep_ip), vni, zebra_route_string(client->proto)); /* Locate VNI hash entry - expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "Failed to locate VNI hash upon remote VTEP DEL, " - "VRF %d VNI %u", - zvrf_id(zvrf), vni); + "VNI %u", + vni); continue; } @@ -3795,7 +3761,12 @@ int zebra_vxlan_remote_vtep_add(struct zserv *client, int sock, u_short length, struct interface *ifp; struct zebra_if *zif; - assert(EVPN_ENABLED(zvrf)); + assert(is_evpn_enabled()); + if (zvrf_id(zvrf) != VRF_DEFAULT) { + zlog_err("Recv MACIP ADD for non-default VRF %u", + zvrf_id(zvrf)); + return -1; + } s = client->ibuf; @@ -3807,16 +3778,16 @@ int zebra_vxlan_remote_vtep_add(struct zserv *client, int sock, u_short length, l += IPV4_MAX_BYTELEN; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Recv VTEP_ADD %s VNI %u from %s", - zvrf_id(zvrf), inet_ntoa(vtep_ip), vni, + zlog_debug("Recv VTEP_ADD %s VNI %u from %s", + inet_ntoa(vtep_ip), vni, zebra_route_string(client->proto)); /* Locate VNI hash entry - expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { zlog_err( - "Failed to locate VNI hash upon remote VTEP ADD, VRF %d VNI %u", - zvrf_id(zvrf), vni); + "Failed to locate VNI hash upon remote VTEP ADD, VNI %u", + vni); continue; } @@ -3841,8 +3812,8 @@ int zebra_vxlan_remote_vtep_add(struct zserv *client, int sock, u_short length, if (zvni_vtep_add(zvni, &vtep_ip) == NULL) { zlog_err( - "Failed to add remote VTEP, VRF %d VNI %u zvni %p", - zvrf_id(zvrf), vni, zvni); + "Failed to add remote VTEP, VNI %u zvni %p", + vni, zvni); continue; } @@ -3866,16 +3837,12 @@ int zebra_vxlan_add_del_gw_macip(struct interface *ifp, struct prefix *p, struct ipaddr ip; struct ethaddr macaddr; zebra_vni_t *zvni = NULL; - struct zebra_vrf *zvrf = NULL; memset(&ip, 0, sizeof(struct ipaddr)); memset(&macaddr, 0, sizeof(struct ethaddr)); - zvrf = vrf_info_lookup(ifp->vrf_id); - if (!zvrf) - return -1; - - if (!EVPN_ENABLED(zvrf)) + /* Check if EVPN is enabled. */ + if (!is_evpn_enabled()) return 0; if (IS_ZEBRA_IF_MACVLAN(ifp)) { @@ -3896,8 +3863,8 @@ int zebra_vxlan_add_del_gw_macip(struct interface *ifp, struct prefix *p, svi_if = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT), ifp_zif->link_ifindex); if (!svi_if) { - zlog_err("%u:MACVLAN %s(%u) without link information", - ifp->vrf_id, ifp->name, ifp->ifindex); + zlog_err("MACVLAN %s(%u) without link information", + ifp->name, ifp->ifindex); return -1; } @@ -3948,7 +3915,7 @@ int zebra_vxlan_add_del_gw_macip(struct interface *ifp, struct prefix *p, /* check if we are advertising gw macip routes */ - if (!advertise_gw_macip_enabled(zvrf, zvni)) + if (!advertise_gw_macip_enabled(zvni)) return 0; memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); @@ -4002,8 +3969,8 @@ int zebra_vxlan_svi_up(struct interface *ifp, struct interface *link_if) } if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:SVI %s(%u) VNI %u is UP, installing neighbors", - ifp->vrf_id, ifp->name, ifp->ifindex, zvni->vni); + zlog_debug("SVI %s(%u) VNI %u is UP, installing neighbors", + ifp->name, ifp->ifindex, zvni->vni); /* Install any remote neighbors for this VNI. */ memset(&n_wctx, 0, sizeof(struct neigh_walk_ctx)); @@ -4020,17 +3987,12 @@ int zebra_vxlan_svi_up(struct interface *ifp, struct interface *link_if) int zebra_vxlan_if_down(struct interface *ifp) { struct zebra_if *zif; - struct zebra_vrf *zvrf; zebra_vni_t *zvni; struct zebra_l2info_vxlan *vxl; vni_t vni; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); - - /* If EVPN is not enabled, nothing further to be done. */ - if (!EVPN_ENABLED(zvrf)) + /* Check if EVPN is enabled. */ + if (!is_evpn_enabled()) return 0; zif = ifp->info; @@ -4039,26 +4001,26 @@ int zebra_vxlan_if_down(struct interface *ifp) vni = vxl->vni; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Intf %s(%u) VNI %u is DOWN", ifp->vrf_id, + zlog_debug("Intf %s(%u) VNI %u is DOWN", ifp->name, ifp->ifindex, vni); /* Locate hash entry; it is expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { zlog_err( - "Failed to locate VNI hash at DOWN, VRF %d IF %s(%u) VNI %u", - ifp->vrf_id, ifp->name, ifp->ifindex, vni); + "Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u", + ifp->name, ifp->ifindex, vni); return -1; } assert(zvni->vxlan_if == ifp); /* Delete this VNI from BGP. */ - zvni_send_del_to_client(zvrf, zvni->vni); + zvni_send_del_to_client(zvni->vni); /* Free up all neighbors and MACs, if any. */ - zvni_neigh_del_all(zvrf, zvni, 1, 0, DEL_ALL_NEIGH); - zvni_mac_del_all(zvrf, zvni, 1, 0, DEL_ALL_MAC); + zvni_neigh_del_all(zvni, 1, 0, DEL_ALL_NEIGH); + zvni_mac_del_all(zvni, 1, 0, DEL_ALL_MAC); /* Free up all remote VTEPs, if any. */ zvni_vtep_del_all(zvni, 1); @@ -4072,17 +4034,12 @@ int zebra_vxlan_if_down(struct interface *ifp) int zebra_vxlan_if_up(struct interface *ifp) { struct zebra_if *zif; - struct zebra_vrf *zvrf; zebra_vni_t *zvni; struct zebra_l2info_vxlan *vxl; vni_t vni; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); - - /* If EVPN is not enabled, nothing further to be done. */ - if (!EVPN_ENABLED(zvrf)) + /* Check if EVPN is enabled. */ + if (!is_evpn_enabled()) return 0; zif = ifp->info; @@ -4091,15 +4048,15 @@ int zebra_vxlan_if_up(struct interface *ifp) vni = vxl->vni; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Intf %s(%u) VNI %u is UP", ifp->vrf_id, + zlog_debug("Intf %s(%u) VNI %u is UP", ifp->name, ifp->ifindex, vni); /* Locate hash entry; it is expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { zlog_err( - "Failed to locate VNI hash at UP, VRF %d IF %s(%u) VNI %u", - ifp->vrf_id, ifp->name, ifp->ifindex, vni); + "Failed to locate VNI hash at UP, IF %s(%u) VNI %u", + ifp->name, ifp->ifindex, vni); return -1; } @@ -4108,8 +4065,8 @@ int zebra_vxlan_if_up(struct interface *ifp) /* If part of a bridge, inform BGP about this VNI. */ /* Also, read and populate local MACs and neighbors. */ if (zif->brslave_info.br_if) { - zvni_send_add_to_client(zvrf, zvni); - zvni_read_mac_neigh(zvrf, zvni, ifp); + zvni_send_add_to_client(zvni); + zvni_read_mac_neigh(zvni, ifp); } return 0; @@ -4122,17 +4079,12 @@ int zebra_vxlan_if_up(struct interface *ifp) int zebra_vxlan_if_del(struct interface *ifp) { struct zebra_if *zif; - struct zebra_vrf *zvrf; zebra_vni_t *zvni; struct zebra_l2info_vxlan *vxl; vni_t vni; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); - - /* If EVPN is not enabled, nothing further to be done. */ - if (!EVPN_ENABLED(zvrf)) + /* Check if EVPN is enabled. */ + if (!is_evpn_enabled()) return 0; zif = ifp->info; @@ -4141,32 +4093,32 @@ int zebra_vxlan_if_del(struct interface *ifp) vni = vxl->vni; if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:Del VNI %u intf %s(%u)", ifp->vrf_id, vni, - ifp->name, ifp->ifindex); + zlog_debug("Del VNI %u intf %s(%u)", + vni, ifp->name, ifp->ifindex); /* Locate hash entry; it is expected to exist. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { zlog_err( - "Failed to locate VNI hash at del, VRF %d IF %s(%u) VNI %u", - ifp->vrf_id, ifp->name, ifp->ifindex, vni); + "Failed to locate VNI hash at del, IF %s(%u) VNI %u", + ifp->name, ifp->ifindex, vni); return 0; } /* Delete VNI from BGP. */ - zvni_send_del_to_client(zvrf, zvni->vni); + zvni_send_del_to_client(zvni->vni); /* Free up all neighbors and MAC, if any. */ - zvni_neigh_del_all(zvrf, zvni, 0, 0, DEL_ALL_NEIGH); - zvni_mac_del_all(zvrf, zvni, 0, 0, DEL_ALL_MAC); + zvni_neigh_del_all(zvni, 0, 0, DEL_ALL_NEIGH); + zvni_mac_del_all(zvni, 0, 0, DEL_ALL_MAC); /* Free up all remote VTEPs, if any. */ zvni_vtep_del_all(zvni, 0); /* Delete the hash entry. */ - if (zvni_del(zvrf, zvni)) { - zlog_err("Failed to del VNI hash %p, VRF %d IF %s(%u) VNI %u", - zvni, ifp->vrf_id, ifp->name, ifp->ifindex, zvni->vni); + if (zvni_del(zvni)) { + zlog_err("Failed to del VNI hash %p, IF %s(%u) VNI %u", + zvni, ifp->name, ifp->ifindex, zvni->vni); return -1; } @@ -4179,17 +4131,12 @@ int zebra_vxlan_if_del(struct interface *ifp) int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) { struct zebra_if *zif; - struct zebra_vrf *zvrf; zebra_vni_t *zvni; struct zebra_l2info_vxlan *vxl; vni_t vni; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); - - /* If EVPN is not enabled, nothing further to be done. */ - if (!EVPN_ENABLED(zvrf)) + /* Check if EVPN is enabled. */ + if (!is_evpn_enabled()) return 0; zif = ifp->info; @@ -4198,19 +4145,19 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) vni = vxl->vni; /* Update VNI hash. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { zlog_err( - "Failed to find VNI hash on update, VRF %d IF %s(%u) VNI %u", - ifp->vrf_id, ifp->name, ifp->ifindex, vni); + "Failed to find VNI hash on update, IF %s(%u) VNI %u", + ifp->name, ifp->ifindex, vni); return -1; } if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Update VNI %u intf %s(%u) VLAN %u local IP %s " + "Update VNI %u intf %s(%u) VLAN %u local IP %s " "master %u chg 0x%x", - ifp->vrf_id, vni, ifp->name, ifp->ifindex, + vni, ifp->name, ifp->ifindex, vxl->access_vlan, inet_ntoa(vxl->vtep_ip), zif->brslave_info.bridge_ifindex, chgflags); @@ -4219,9 +4166,9 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) && (zif->brslave_info.bridge_ifindex == IFINDEX_INTERNAL)) { /* Delete from client, remove all remote VTEPs */ /* Also, free up all MACs and neighbors. */ - zvni_send_del_to_client(zvrf, zvni->vni); - zvni_neigh_del_all(zvrf, zvni, 1, 0, DEL_ALL_NEIGH); - zvni_mac_del_all(zvrf, zvni, 1, 0, DEL_ALL_MAC); + zvni_send_del_to_client(zvni->vni); + zvni_neigh_del_all(zvni, 1, 0, DEL_ALL_NEIGH); + zvni_mac_del_all(zvni, 1, 0, DEL_ALL_MAC); zvni_vtep_del_all(zvni, 1); return 0; } @@ -4231,8 +4178,8 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) /* Remove all existing local neighbors and MACs for this VNI * (including from BGP) */ - zvni_neigh_del_all(zvrf, zvni, 0, 1, DEL_LOCAL_MAC); - zvni_mac_del_all(zvrf, zvni, 0, 1, DEL_LOCAL_MAC); + zvni_neigh_del_all(zvni, 0, 1, DEL_LOCAL_MAC); + zvni_mac_del_all(zvni, 0, 1, DEL_LOCAL_MAC); } zvni->local_vtep_ip = vxl->vtep_ip; @@ -4248,19 +4195,19 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) /* Inform BGP, if there is a change of interest. */ if (chgflags & (ZEBRA_VXLIF_MASTER_CHANGE | ZEBRA_VXLIF_LOCAL_IP_CHANGE)) - zvni_send_add_to_client(zvrf, zvni); + zvni_send_add_to_client(zvni); /* If there is a valid new master or a VLAN mapping change, read and * populate local MACs and neighbors. Also, reinstall any remote MACs * and neighbors for this VNI (based on new VLAN). */ if (chgflags & ZEBRA_VXLIF_MASTER_CHANGE) - zvni_read_mac_neigh(zvrf, zvni, ifp); + zvni_read_mac_neigh(zvni, ifp); else if (chgflags & ZEBRA_VXLIF_VLAN_CHANGE) { struct mac_walk_ctx m_wctx; struct neigh_walk_ctx n_wctx; - zvni_read_mac_neigh(zvrf, zvni, ifp); + zvni_read_mac_neigh(zvni, ifp); memset(&m_wctx, 0, sizeof(struct mac_walk_ctx)); m_wctx.zvni = zvni; @@ -4281,17 +4228,12 @@ int zebra_vxlan_if_update(struct interface *ifp, u_int16_t chgflags) int zebra_vxlan_if_add(struct interface *ifp) { struct zebra_if *zif; - struct zebra_vrf *zvrf; zebra_vni_t *zvni; struct zebra_l2info_vxlan *vxl; vni_t vni; - /* Locate VRF corresponding to interface. */ - zvrf = vrf_info_lookup(ifp->vrf_id); - assert(zvrf); - - /* If EVPN is not enabled, nothing further to be done. */ - if (!EVPN_ENABLED(zvrf)) + /* Check if EVPN is enabled. */ + if (!is_evpn_enabled()) return 0; zif = ifp->info; @@ -4301,19 +4243,19 @@ int zebra_vxlan_if_add(struct interface *ifp) if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:Add VNI %u intf %s(%u) VLAN %u local IP %s master %u", - ifp->vrf_id, vni, ifp->name, ifp->ifindex, + "Add VNI %u intf %s(%u) VLAN %u local IP %s master %u", + vni, ifp->name, ifp->ifindex, vxl->access_vlan, inet_ntoa(vxl->vtep_ip), zif->brslave_info.bridge_ifindex); /* Create or update VNI hash. */ - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) { - zvni = zvni_add(zvrf, vni); + zvni = zvni_add(vni); if (!zvni) { zlog_err( - "Failed to add VNI hash, VRF %d IF %s(%u) VNI %u", - ifp->vrf_id, ifp->name, ifp->ifindex, vni); + "Failed to add VNI hash, IF %s(%u) VNI %u", + ifp->name, ifp->ifindex, vni); return -1; } } @@ -4326,10 +4268,10 @@ int zebra_vxlan_if_add(struct interface *ifp) return 0; /* Inform BGP */ - zvni_send_add_to_client(zvrf, zvni); + zvni_send_add_to_client(zvni); /* Read and populate local MACs and neighbors */ - zvni_read_mac_neigh(zvrf, zvni, ifp); + zvni_read_mac_neigh(zvni, ifp); return 0; } @@ -4347,16 +4289,21 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, int sock, zebra_vni_t *zvni = NULL; struct interface *ifp = NULL; + if (zvrf_id(zvrf) != VRF_DEFAULT) { + zlog_err("EVPN GW-MACIP Adv for non-default VRF %u", + zvrf_id(zvrf)); + return -1; + } + s = client->ibuf; advertise = stream_getc(s); vni = stream_get3(s); if (!vni) { if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:EVPN gateway macip Adv %s, currently %s", - zvrf_id(zvrf), + zlog_debug("EVPN gateway macip Adv %s, currently %s", advertise ? "enabled" : "disabled", - advertise_gw_macip_enabled(zvrf, NULL) + advertise_gw_macip_enabled(NULL) ? "enabled" : "disabled"); @@ -4365,12 +4312,12 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, int sock, zvrf->advertise_gw_macip = advertise; - if (advertise_gw_macip_enabled(zvrf, zvni)) + if (advertise_gw_macip_enabled(zvni)) hash_iterate(zvrf->vni_table, - zvni_gw_macip_add_for_vni_hash, zvrf); + zvni_gw_macip_add_for_vni_hash, NULL); else hash_iterate(zvrf->vni_table, - zvni_gw_macip_del_for_vni_hash, zvrf); + zvni_gw_macip_del_for_vni_hash, NULL); } else { struct zebra_if *zif = NULL; @@ -4380,14 +4327,13 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, int sock, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( - "%u:EVPN gateway macip Adv %s on VNI %d , currently %s", - zvrf_id(zvrf), + "EVPN gateway macip Adv %s on VNI %d , currently %s", advertise ? "enabled" : "disabled", vni, - advertise_gw_macip_enabled(zvrf, zvni) + advertise_gw_macip_enabled(zvni) ? "enabled" : "disabled"); - zvni = zvni_lookup(zvrf, vni); + zvni = zvni_lookup(vni); if (!zvni) return 0; @@ -4408,12 +4354,12 @@ int zebra_vxlan_advertise_gw_macip(struct zserv *client, int sock, zl2_info = zif->l2info.vxl; - vlan_if = zvni_map_to_svi(zvrf, zl2_info.access_vlan, + vlan_if = zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); if (!vlan_if) return 0; - if (advertise_gw_macip_enabled(zvrf, zvni)) { + if (advertise_gw_macip_enabled(zvni)) { /* Add primary SVI MAC-IP */ zvni_add_macip_for_intf(vlan_if, zvni); @@ -4448,25 +4394,31 @@ int zebra_vxlan_advertise_all_vni(struct zserv *client, int sock, struct stream *s; int advertise; + if (zvrf_id(zvrf) != VRF_DEFAULT) { + zlog_err("EVPN VNI Adv for non-default VRF %u", + zvrf_id(zvrf)); + return -1; + } + s = client->ibuf; advertise = stream_getc(s); if (IS_ZEBRA_DEBUG_VXLAN) - zlog_debug("%u:EVPN VNI Adv %s, currently %s", zvrf_id(zvrf), + zlog_debug("EVPN VNI Adv %s, currently %s", advertise ? "enabled" : "disabled", - EVPN_ENABLED(zvrf) ? "enabled" : "disabled"); + is_evpn_enabled() ? "enabled" : "disabled"); if (zvrf->advertise_all_vni == advertise) return 0; zvrf->advertise_all_vni = advertise; - if (EVPN_ENABLED(zvrf)) { + if (is_evpn_enabled()) { /* Build VNI hash table and inform BGP. */ - zvni_build_hash_table(zvrf); + zvni_build_hash_table(); /* Add all SVI (L3 GW) MACs to BGP*/ hash_iterate(zvrf->vni_table, zvni_gw_macip_add_for_vni_hash, - zvrf); + NULL); /* Read the MAC FDB */ macfdb_read(zvrf->zns); @@ -4498,6 +4450,8 @@ void zebra_vxlan_init_tables(struct zebra_vrf *zvrf) /* Close all VNI handling */ void zebra_vxlan_close_tables(struct zebra_vrf *zvrf) { + if (!zvrf) + return; hash_iterate(zvrf->vni_table, zvni_cleanup_all, zvrf); hash_free(zvrf->vni_table); } diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h index f7c1afc959..8b43615bb3 100644 --- a/zebra/zebra_vxlan.h +++ b/zebra/zebra_vxlan.h @@ -35,6 +35,14 @@ /* Is EVPN enabled? */ #define EVPN_ENABLED(zvrf) (zvrf)->advertise_all_vni +static inline int +is_evpn_enabled() +{ + struct zebra_vrf *zvrf = NULL; + zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); + return zvrf ? zvrf->advertise_all_vni : 0; +} + /* VxLAN interface change flags of interest. */ #define ZEBRA_VXLIF_LOCAL_IP_CHANGE 0x1 diff --git a/zebra/zserv.c b/zebra/zserv.c index fd2c5dd97c..cbc9f2bed9 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -825,6 +825,7 @@ static int zserv_fec_register(struct zserv *client, int sock, u_short length) while (l < length) { flags = stream_getw(s); + memset(&p, 0, sizeof(p)); p.family = stream_getw(s); if (p.family != AF_INET && p.family != AF_INET6) { zlog_err( @@ -875,6 +876,7 @@ static int zserv_fec_unregister(struct zserv *client, int sock, u_short length) while (l < length) { // flags = stream_getw(s); (void)stream_getw(s); + memset(&p, 0, sizeof(p)); p.family = stream_getw(s); if (p.family != AF_INET && p.family != AF_INET6) { zlog_err( @@ -998,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; |
