From: vivek Date: Mon, 18 Sep 2017 21:45:34 +0000 (-0700) Subject: zebra: Handle L3 multi-tenancy correctly for EVPN X-Git-Tag: frr-4.0-dev~226^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=2853fed67a4891e9f9061f56799f79ec329d7df5;p=matthieu%2Ffrr.git zebra: Handle L3 multi-tenancy correctly for EVPN Fix following flaws that resulted in EVPN with L3 multi-tenancy (i.e., EVPN dealing with VxLAN routing in the presence of tenant VRFs) not working properly: 1. EVPN enable ("advertise-all-vni") is a global command, ensure it is accordingly processed. The config is maintained against the default VRF. 2. There was an incorrect attempt to derive the L3 VRF for L2 interfaces - the VRF only applies for L3 interfaces, though the code may initialize to the default value in other cases. 3. Functions to map (port, VLAN) to SVI or vice versa were incorrect - particularly, zvni_map_svi() since it was looking in the L3 VRF for "matching" L2 interface which it would never find. Fix. In addition, since the 'zebra_vrf *' parameter is not relevant in most places, it has been removed. Signed-off-by: Vivek Venkatraman Reviewed-by: Mitesh Kanjariya Reviewed-by: Donald Sharp Ticket: CM-17840 Reviewed By: CCR-6685 Testing Done: evpn-smoke, various manual tests --- diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 573f60f4ca..2d79e8341c 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1716,7 +1716,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 +1729,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 +2026,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 +2037,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/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..428d064535 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,17 @@ 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) +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; @@ -719,7 +721,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 +740,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 +763,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 +884,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 +922,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 +932,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 +958,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 +973,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 +982,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 +1000,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 +1013,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 +1022,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 +1037,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 +1050,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 +1059,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 +1078,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 +1090,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 +1114,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 +1121,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 +1138,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 +1151,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; @@ -1225,15 +1206,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 +1239,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 +1276,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 +1283,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 +1293,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 +1312,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 +1327,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 +1344,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 +1357,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 +1369,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 +1389,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 +1414,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 +1430,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 +1443,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 +1456,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 +1572,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 +1610,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 +1620,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 +1647,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 +1689,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 +1704,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 +1741,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 +1760,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 +1775,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 +1795,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 +1822,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 +1834,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 +1943,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 +1954,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 +1976,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 +2017,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 +2035,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 +2062,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 +2091,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 +2104,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 +2112,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 +2123,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 +2136,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 +2154,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 +2180,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 +2206,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 +2332,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 +2356,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 +2410,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 +2440,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 +2483,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 +2524,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"); @@ -2603,7 +2576,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 +2607,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 +2636,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 +2666,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"); @@ -2741,9 +2714,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 +2746,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 +2792,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 +2810,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 +2823,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 +2839,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 +2867,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 +2878,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 +2892,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 +2930,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 +2963,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 +2979,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 +2989,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 +3043,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 +3089,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 +3122,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 +3193,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 +3231,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 +3257,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 +3280,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 +3308,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 +3354,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 +3366,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 +3386,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 +3419,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 +3430,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 +3449,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 +3465,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 +3481,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 +3494,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 +3526,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 +3537,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 +3552,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 +3577,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 +3609,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 +3634,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 +3657,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 +3674,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 +3735,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 +3752,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 +3786,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 +3811,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 +3837,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 +3889,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 +3943,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 +3961,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 +3975,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 +4008,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 +4022,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 +4039,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 +4053,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 +4067,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 +4105,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 +4119,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 +4140,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 +4152,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 +4169,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 +4202,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 +4217,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 +4242,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 +4263,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 +4286,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 +4301,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 +4328,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 +4368,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 +4424,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