Skip to content

Commit

Permalink
bgpd: vpn-vrf leaking code review fixes
Browse files Browse the repository at this point in the history
Signed-off-by: G. Paul Ziemba <paulz@labn.net>
  • Loading branch information
paulzlabn committed Feb 16, 2018
1 parent 3cf2192 commit 4d2fb62
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 12 deletions.
23 changes: 18 additions & 5 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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() */
Expand Down Expand Up @@ -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,
Expand Down
48 changes: 46 additions & 2 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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. */
Expand All @@ -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);
Expand All @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -6337,19 +6337,20 @@ 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);

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,
Expand Down

0 comments on commit 4d2fb62

Please sign in to comment.