From 3d0b43d7c5cfb4377d7d51966d50616ec37629ab Mon Sep 17 00:00:00 2001 From: vivek Date: Sun, 18 Aug 2019 23:07:59 -0700 Subject: [PATCH] bgpd: Ensure correct checks for EVPN route import In a situation where a VRF has configured route targets for importing EVPN routes, this configuration may exist prior to the VRF being ready to have EVPN routes installed into it - e.g., still missing the L3VNI configuration or associated interface information. Ensure that this is taken into account during EVPN route import and unimport. Without this fix, EVPN routes would end up being prematurely imported into the VRF routing table and consequently installed as inactive (because the nexthop information would be incorrect when BGP informs zebra). Signed-off-by: Vivek Venkatraman --- bgpd/bgp_evpn.c | 26 ++++++++++++++------------ bgpd/bgp_evpn_private.h | 5 +++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 3bc3d74de6..4d02e39ae2 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -4459,7 +4459,8 @@ void bgp_evpn_configure_import_rt_for_vrf(struct bgp *bgp_vrf, struct ecommunity *ecomadd) { /* uninstall routes from vrf */ - uninstall_routes_for_vrf(bgp_vrf); + if (is_l3vni_live(bgp_vrf)) + uninstall_routes_for_vrf(bgp_vrf); /* Cleanup the RT to VRF mapping */ bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf); @@ -4471,11 +4472,11 @@ void bgp_evpn_configure_import_rt_for_vrf(struct bgp *bgp_vrf, listnode_add_sort(bgp_vrf->vrf_import_rtl, ecomadd); SET_FLAG(bgp_vrf->vrf_flags, BGP_VRF_IMPORT_RT_CFGD); - /* map VRF to its RTs */ - bgp_evpn_map_vrf_to_its_rts(bgp_vrf); - - /* install routes matching the new VRF */ - install_routes_for_vrf(bgp_vrf); + /* map VRF to its RTs and install routes matching the new RTs */ + if (is_l3vni_live(bgp_vrf)) { + bgp_evpn_map_vrf_to_its_rts(bgp_vrf); + install_routes_for_vrf(bgp_vrf); + } } void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp *bgp_vrf, @@ -4485,7 +4486,8 @@ void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp *bgp_vrf, struct ecommunity *ecom = NULL; /* uninstall routes from vrf */ - uninstall_routes_for_vrf(bgp_vrf); + if (is_l3vni_live(bgp_vrf)) + uninstall_routes_for_vrf(bgp_vrf); /* Cleanup the RT to VRF mapping */ bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf); @@ -4509,11 +4511,11 @@ void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp *bgp_vrf, evpn_auto_rt_import_add_for_vrf(bgp_vrf); } - /* map VRFs to its RTs */ - bgp_evpn_map_vrf_to_its_rts(bgp_vrf); - - /* install routes matching this new RT */ - install_routes_for_vrf(bgp_vrf); + /* map VRFs to its RTs and install routes matching this new RT */ + if (is_l3vni_live(bgp_vrf)) { + bgp_evpn_map_vrf_to_its_rts(bgp_vrf); + install_routes_for_vrf(bgp_vrf); + } } void bgp_evpn_configure_export_rt_for_vrf(struct bgp *bgp_vrf, diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h index a5a091242f..f6bde2e9fa 100644 --- a/bgpd/bgp_evpn_private.h +++ b/bgpd/bgp_evpn_private.h @@ -275,6 +275,11 @@ static inline int is_vni_live(struct bgpevpn *vpn) return (CHECK_FLAG(vpn->flags, VNI_FLAG_LIVE)); } +static inline int is_l3vni_live(struct bgp *bgp_vrf) +{ + return (bgp_vrf->l3vni && bgp_vrf->l3vni_svi_ifindex); +} + static inline int is_rd_configured(struct bgpevpn *vpn) { return (CHECK_FLAG(vpn->flags, VNI_FLAG_RD_CFGD)); -- 2.39.5