From 06d2e8f3baf1ee648fec53116e405334ae25a117 Mon Sep 17 00:00:00 2001 From: Mitesh Kanjariya Date: Fri, 3 Nov 2017 14:54:20 -0700 Subject: [PATCH] bgpd: update/withdraw type-5 routes upon l3-vni add/del Signed-off-by: Mitesh Kanjariya --- bgpd/bgp_evpn.c | 12 ++++++++++++ bgpd/bgp_evpn_private.h | 29 +++++++++++++++++------------ bgpd/bgp_evpn_vty.c | 13 ++++--------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index ec3327265e..535cd00efa 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -3050,6 +3050,9 @@ void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, struct bgp_table *table = NULL; struct bgp_node *rn = NULL; + if (!advertise_type5_routes(bgp_vrf, afi)) + return; + table = bgp_vrf->rib[afi][SAFI_UNICAST]; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { @@ -3076,6 +3079,9 @@ void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, struct bgp_table *table = NULL; struct bgp_node *rn = NULL; + if (!advertise_type5_routes(bgp_vrf, afi)) + return; + table = bgp_vrf->rib[afi][SAFI_UNICAST]; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { @@ -4076,6 +4082,9 @@ int bgp_evpn_local_l3vni_add(vni_t l3vni, for (ALL_LIST_ELEMENTS_RO(bgp_vrf->l2vnis, node, vpn)) update_routes_for_vni(bgp_def, vpn); + /* advertise type-5 routes if needed */ + update_advertise_vrf_routes(bgp_vrf); + /* install all remote routes belonging to this l3vni into correspondng * vrf */ install_routes_for_vrf(bgp_vrf); @@ -4110,6 +4119,9 @@ int bgp_evpn_local_l3vni_del(vni_t l3vni, if (!CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_AUTO)) uninstall_routes_for_vrf(bgp_vrf); + /* delete/withdraw all type-5 routes */ + delete_withdraw_vrf_routes(bgp_vrf); + /* remove the l3vni from vrf instance */ bgp_vrf->l3vni = 0; diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h index 1cf3f2215f..89078124f0 100644 --- a/bgpd/bgp_evpn_private.h +++ b/bgpd/bgp_evpn_private.h @@ -127,18 +127,6 @@ static inline int bgp_evpn_vrf_rd_matches_existing(struct bgp *bgp_vrf, return (memcmp(&bgp_vrf->vrf_prd.val, prd->val, ECOMMUNITY_SIZE) == 0); } -static inline int is_evpn_prefix_routes_adv_enabled(struct bgp *bgp_vrf) -{ - if (!bgp_vrf->l3vni) - return 0; - - if (CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_ADVERTISE_IPV4_IN_EVPN) || - CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_ADVERTISE_IPV6_IN_EVPN)) - return 1; - - return 0; -} - static inline vni_t bgpevpn_get_l3vni(struct bgpevpn *vpn) { struct bgp *bgp_vrf = NULL; @@ -352,6 +340,23 @@ static inline void build_evpn_type3_prefix(struct prefix_evpn *p, p->prefix.ip.ipaddr_v4 = originator_ip; } +static inline int advertise_type5_routes(struct bgp *bgp_vrf, + afi_t afi) +{ + if (!bgp_vrf->l3vni) + return 0; + + if (afi == AFI_IP && + CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_ADVERTISE_IPV4_IN_EVPN)) + return 1; + + if (afi == AFI_IP6 && + CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_ADVERTISE_IPV6_IN_EVPN)) + return 1; + + return 0; +} + extern void evpn_rt_delete_auto(struct bgp*, vni_t, struct list*); extern void bgp_evpn_configure_export_rt_for_vrf(struct bgp*, struct ecommunity*); diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 849432fcad..1cff40f703 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -1497,8 +1497,7 @@ static void evpn_configure_vrf_rd(struct bgp *bgp_vrf, { /* If we have already advertise type-5 routes with a diffrent RD, we * have to delete and withdraw them first*/ - if (is_evpn_prefix_routes_adv_enabled(bgp_vrf)) - bgp_evpn_handle_vrf_rd_change(bgp_vrf, 1); + bgp_evpn_handle_vrf_rd_change(bgp_vrf, 1); /* update RD */ memcpy(&bgp_vrf->vrf_prd, rd, sizeof(struct prefix_rd)); @@ -1506,9 +1505,7 @@ static void evpn_configure_vrf_rd(struct bgp *bgp_vrf, /* We have a new RD for VRF. * Advertise all type-5 routes again with the new RD */ - if (is_evpn_prefix_routes_adv_enabled(bgp_vrf)) - bgp_evpn_handle_vrf_rd_change(bgp_vrf, 0); - + bgp_evpn_handle_vrf_rd_change(bgp_vrf, 0); } /* @@ -1518,16 +1515,14 @@ static void evpn_unconfigure_vrf_rd(struct bgp *bgp_vrf) { /* If we have already advertise type-5 routes with a diffrent RD, we * have to delete and withdraw them first*/ - if (is_evpn_prefix_routes_adv_enabled(bgp_vrf)) - bgp_evpn_handle_vrf_rd_change(bgp_vrf, 1); + bgp_evpn_handle_vrf_rd_change(bgp_vrf, 1); /* fall back to default RD */ bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf); /* We have a new RD for VRF. * Advertise all type-5 routes again with the new RD */ - if (is_evpn_prefix_routes_adv_enabled(bgp_vrf)) - bgp_evpn_handle_vrf_rd_change(bgp_vrf, 0); + bgp_evpn_handle_vrf_rd_change(bgp_vrf, 0); } /* -- 2.39.5