From 4d2fb62c2a88963e64f58c7554ab540564ab81c5 Mon Sep 17 00:00:00 2001 From: "G. Paul Ziemba" Date: Fri, 16 Feb 2018 11:13:32 -0800 Subject: [PATCH] bgpd: vpn-vrf leaking code review fixes Signed-off-by: G. Paul Ziemba --- bgpd/bgp_mplsvpn.c | 23 +++++++++++++++++----- bgpd/bgp_route.c | 48 ++++++++++++++++++++++++++++++++++++++++++++-- bgpd/bgp_vty.c | 11 ++++++----- 3 files changed, 70 insertions(+), 12 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 26cdc0f165f9..e30448a28835 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -267,6 +267,14 @@ static void leak_update(struct bgp *bgp, /* destination bgp instance */ struct prefix *p = &bn->p; struct bgp_info *bi; struct bgp_info *new; + char buf_prefix[PREFIX_STRLEN]; + const char *pDestInstanceName = "default"; + + if (debug) { + prefix2str(&bn->p, buf_prefix, sizeof(buf_prefix)); + if (bgp->name) + pDestInstanceName = bgp->name; + } /* * match peer, parent @@ -285,8 +293,10 @@ static void leak_update(struct bgp *bgp, /* destination bgp instance */ bgp_attr_unintern(&new_attr); if (debug) - zlog_debug("%s: Found route, no change", - __func__); + zlog_debug( + "%s: ->%s: %s: Found route, no change", + __func__, pDestInstanceName, + buf_prefix); return; } @@ -308,7 +318,8 @@ static void leak_update(struct bgp *bgp, /* destination bgp instance */ bgp_unlock_node(bn); if (debug) - zlog_debug("%s: Found route, changed attr", __func__); + zlog_debug("%s: ->%s: %s Found route, changed attr", + __func__, pDestInstanceName, buf_prefix); return; } @@ -327,7 +338,8 @@ static void leak_update(struct bgp *bgp, /* destination bgp instance */ bgp_process(bgp, bn, afi, safi); if (debug) - zlog_debug("%s: Added new route", __func__); + zlog_debug("%s: ->%s: %s: Added new route", + __func__, pDestInstanceName, buf_prefix); } /* cf vnc_import_bgp_add_route_mode_nvegroup() and add_vnc_route() */ @@ -883,7 +895,8 @@ void vpn_leak_to_vrf_update_all(struct bgp *bgp_vrf, /* to */ for (bi = bn->info; bi; bi = bi->next) { - if (bi->type == ZEBRA_ROUTE_BGP_VPN) + if ((bi->type == ZEBRA_ROUTE_BGP_VPN) && + (bi->extra->parent == bgp_vrf)) continue; vpn_leak_to_vrf_update_onevrf(bgp_vrf, bgp_vpn, diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index f243c0ccc3f1..225c2229eb81 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -3126,6 +3126,11 @@ int bgp_update(struct peer *peer, struct prefix *p, u_int32_t addpath_id, vpn_leak_from_vrf_update(bgp_get_default(), bgp, ri); } + if ((SAFI_MPLS_VPN == safi) + && (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + + vpn_leak_to_vrf_update(bgp, ri); + } #if ENABLE_BGP_VNC if (SAFI_MPLS_VPN == safi) { @@ -3248,6 +3253,11 @@ int bgp_update(struct peer *peer, struct prefix *p, u_int32_t addpath_id, || bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { vpn_leak_from_vrf_update(bgp_get_default(), bgp, new); } + if ((SAFI_MPLS_VPN == safi) + && (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + + vpn_leak_to_vrf_update(bgp, new); + } #if ENABLE_BGP_VNC if (SAFI_MPLS_VPN == safi) { mpls_label_t label_decoded = decode_label(label); @@ -3287,9 +3297,16 @@ int bgp_update(struct peer *peer, struct prefix *p, u_int32_t addpath_id, bgp_evpn_unimport_route(bgp, afi, safi, p, ri); if (SAFI_UNICAST == safi - && bgp->inst_type == BGP_INSTANCE_TYPE_VRF) { + && (bgp->inst_type == BGP_INSTANCE_TYPE_VRF + || bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, ri); } + if ((SAFI_MPLS_VPN == safi) + && (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + + vpn_leak_to_vrf_withdraw(bgp, ri); + } bgp_rib_remove(rn, ri, peer, afi, safi); } @@ -3384,6 +3401,11 @@ int bgp_withdraw(struct peer *peer, struct prefix *p, u_int32_t addpath_id, || bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, ri); } + if ((SAFI_MPLS_VPN == safi) + && (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + + vpn_leak_to_vrf_withdraw(bgp, ri); + } } else if (bgp_debug_update(peer, p, NULL, 1)) { bgp_debug_rdpfxpath2str(afi, safi, prd, p, label, num_labels, addpath_id ? 1 : 0, addpath_id, pfx_buf, @@ -4524,7 +4546,7 @@ static void bgp_static_update_safi(struct bgp *bgp, struct prefix *p, bgp_aggregate_increment(bgp, p, ri, afi, safi); bgp_process(bgp, rn, afi, safi); - if (SAFI_UNICAST == safi + if (SAFI_MPLS_VPN == safi && bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT) { vpn_leak_to_vrf_update(bgp, ri); } @@ -6032,6 +6054,12 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, bgp_process(bgp, bn, afi, SAFI_UNICAST); bgp_unlock_node(bn); aspath_unintern(&attr.aspath); + + if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF) + || (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + + vpn_leak_from_vrf_update(bgp_get_default(), bgp, bi); + } return; } } @@ -6044,6 +6072,12 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, bgp_info_add(bn, new); bgp_unlock_node(bn); bgp_process(bgp, bn, afi, SAFI_UNICAST); + + if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF) + || (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + + vpn_leak_from_vrf_update(bgp_get_default(), bgp, new); + } } /* Unintern original. */ @@ -6070,6 +6104,11 @@ void bgp_redistribute_delete(struct bgp *bgp, struct prefix *p, u_char type, break; if (ri) { + if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF) + || (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + + vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, ri); + } bgp_aggregate_decrement(bgp, p, ri, afi, SAFI_UNICAST); bgp_info_delete(rn, ri); bgp_process(bgp, rn, afi, SAFI_UNICAST); @@ -6095,6 +6134,11 @@ void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type, break; if (ri) { + if ((bgp->inst_type == BGP_INSTANCE_TYPE_VRF) + || (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) { + + vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, ri); + } bgp_aggregate_decrement(bgp, &rn->p, ri, afi, SAFI_UNICAST); bgp_info_delete(rn, ri); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index cb80eb610377..7118f3ebfa75 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -6337,7 +6337,8 @@ DEFUN (vpn_policy_nexthop, if (!doafi[afi]) continue; - /* pre-change: un-export vpn routes (vpn->vrf routes unaffected) + /* + * pre-change: un-export vpn routes (vpn->vrf routes unaffected) */ vpn_leak_prechange(BGP_VPN_POLICY_DIR_TOVPN, afi, bgp_get_default(), bgp); @@ -6345,11 +6346,11 @@ DEFUN (vpn_policy_nexthop, if (nhself) { UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_NEXTHOP_SET); - continue; + } else { + bgp->vpn_policy[afi].tovpn_nexthop = p; + SET_FLAG(bgp->vpn_policy[afi].flags, + BGP_VPN_POLICY_TOVPN_NEXTHOP_SET); } - bgp->vpn_policy[afi].tovpn_nexthop = p; - SET_FLAG(bgp->vpn_policy[afi].flags, - BGP_VPN_POLICY_TOVPN_NEXTHOP_SET); /* post-change: re-export vpn routes */ vpn_leak_postchange(BGP_VPN_POLICY_DIR_TOVPN, afi,