From: Mitesh Kanjariya Date: Tue, 20 Feb 2018 08:23:06 +0000 (-0800) Subject: bgpd: allow advertise-subnet cmd without enabling advertise ipv4 unicast X-Git-Tag: frr-5.0-dev~171^2~8 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=fdf19f06f2fd96513d5da7b835155bd607cf999a;p=mirror%2Ffrr.git bgpd: allow advertise-subnet cmd without enabling advertise ipv4 unicast Type-5 routes can be useful in multiple scenarios such as advertise-subnet, default-originate etc. Currently, the code has a restriction that to allow advertising type-5 routes, user has to first enable advertise ipvX command. This restriction is not necessary and should be removed. Signed-off-by: Mitesh Kanjariya --- diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index ec8e2907a6..6a3496a4d0 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -2553,10 +2553,12 @@ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi, static void delete_withdraw_vrf_routes(struct bgp *bgp_vrf) { /* delete all ipv4 routes and withdraw from peers */ - bgp_evpn_withdraw_type5_routes(bgp_vrf, AFI_IP, SAFI_UNICAST); + if (advertise_type5_routes(bgp_vrf, AFI_IP)) + bgp_evpn_withdraw_type5_routes(bgp_vrf, AFI_IP, SAFI_UNICAST); /* delete all ipv6 routes and withdraw from peers */ - bgp_evpn_withdraw_type5_routes(bgp_vrf, AFI_IP6, SAFI_UNICAST); + if (advertise_type5_routes(bgp_vrf, AFI_IP6)) + bgp_evpn_withdraw_type5_routes(bgp_vrf, AFI_IP6, SAFI_UNICAST); } /* update and advertise all ipv4 and ipv6 routes in thr vrf table as type-5 @@ -2564,10 +2566,12 @@ static void delete_withdraw_vrf_routes(struct bgp *bgp_vrf) static void update_advertise_vrf_routes(struct bgp *bgp_vrf) { /* update all ipv4 routes */ - bgp_evpn_advertise_type5_routes(bgp_vrf, AFI_IP, SAFI_UNICAST); + if (advertise_type5_routes(bgp_vrf, AFI_IP)) + bgp_evpn_advertise_type5_routes(bgp_vrf, AFI_IP, SAFI_UNICAST); /* update all ipv6 routes */ - bgp_evpn_advertise_type5_routes(bgp_vrf, AFI_IP6, SAFI_UNICAST); + if (advertise_type5_routes(bgp_vrf, AFI_IP6)) + bgp_evpn_advertise_type5_routes(bgp_vrf, AFI_IP6, SAFI_UNICAST); } /* @@ -3189,10 +3193,6 @@ void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, struct prefix *p, struct prefix_evpn evp; char buf[PREFIX_STRLEN]; - /* NOTE: Check needed as this is called per-route also. */ - if (!advertise_type5_routes(bgp_vrf, afi)) - return; - build_type5_prefix_from_ip_prefix(&evp, p); ret = delete_evpn_type5_route(bgp_vrf, &evp); if (ret) { @@ -3211,10 +3211,6 @@ void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, struct bgp_table *table = NULL; struct bgp_node *rn = NULL; - /* Bail out early if we don't have to advertise type-5 routes. */ - if (!advertise_type5_routes(bgp_vrf, afi)) - return; - table = bgp_vrf->rib[afi][safi]; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) bgp_evpn_withdraw_type5_route(bgp_vrf, &rn->p, afi, safi); @@ -3235,10 +3231,6 @@ void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, struct prefix *p, struct prefix_evpn evp; char buf[PREFIX_STRLEN]; - /* NOTE: Check needed as this is called per-route also. */ - if (!advertise_type5_routes(bgp_vrf, afi)) - return; - /* only advertise subnet routes as type-5 */ if (is_host_route(p)) return; @@ -3263,10 +3255,6 @@ void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, struct bgp_node *rn = NULL; struct bgp_info *ri; - /* Bail out early if we don't have to advertise type-5 routes. */ - if (!advertise_type5_routes(bgp_vrf, afi)) - return; - table = bgp_vrf->rib[afi][safi]; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { /* Need to identify the "selected" route entry to use its diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h index a8dcbc112b..cd3b7e3af2 100644 --- a/bgpd/bgp_evpn.h +++ b/bgpd/bgp_evpn.h @@ -55,6 +55,23 @@ static inline vni_t label2vni(mpls_label_t *label) return vni; } +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 bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, struct prefix *p, struct attr *src_attr, diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h index cc0ec82344..5ff16c39e9 100644 --- a/bgpd/bgp_evpn_private.h +++ b/bgpd/bgp_evpn_private.h @@ -349,23 +349,6 @@ 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 *bgp_vrf, struct ecommunity *ecomadd); diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 1373afec4e..c3cab18d2e 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -2690,14 +2690,6 @@ DEFUN (bgp_evpn_advertise_vni_subnet, if (!bgp_vrf) return CMD_WARNING; - if (!(advertise_type5_routes(bgp_vrf, AFI_IP) || - advertise_type5_routes(bgp_vrf, AFI_IP6))) { - vty_out(vty, - "%%Please enable ip prefix advertisement under l2vpn evpn in %s", - vrf_id_to_name(bgp_vrf->vrf_id)); - return CMD_WARNING; - } - evpn_set_advertise_subnet(bgp, vpn); return CMD_SUCCESS; } @@ -2841,7 +2833,7 @@ DEFUN (no_bgp_evpn_advertise_type5, if (afi == AFI_IP) { - /* if we are already advertising ipv4 prefix as type-5 + /* if we are not advertising ipv4 prefix as type-5 * nothing to do */ if (CHECK_FLAG(bgp_vrf->vrf_flags, @@ -2852,7 +2844,7 @@ DEFUN (no_bgp_evpn_advertise_type5, } } else { - /* if we are already advertising ipv6 prefix as type-5 + /* if we are not advertising ipv6 prefix as type-5 * nothing to do */ if (CHECK_FLAG(bgp_vrf->vrf_flags, diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 20bf9635a3..0d226f9e72 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2228,10 +2228,10 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn, /* advertise/withdraw type-5 routes */ if ((afi == AFI_IP || afi == AFI_IP6) && (safi == SAFI_UNICAST)) { - if (new_select) + if (advertise_type5_routes(bgp, afi) && new_select) bgp_evpn_advertise_type5_route( bgp, &rn->p, new_select->attr, afi, safi); - else if (old_select) + else if (advertise_type5_routes(bgp, afi) && old_select) bgp_evpn_withdraw_type5_route(bgp, &rn->p, afi, safi); }