bgpd: rename "struct bgp" variables in mplsvpn

The "struct bgp" variable names in the mplsvpn bgp code do not
explicitly say whether they refer to a source or destination BGP
instance. Some variable declarations are commented out with "from" and
"to" but this does not avoid confusion within the functions. The names
of "struct bgp" variables are reused in different functions but their
names sometimes refer to a source instance and sometimes to a
destination instance.

Rename the "struct bgp" variable names to from_bgp and to_bgp.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
This commit is contained in:
Louis Scalbert 2022-07-08 12:37:57 +02:00
parent 88ef29918c
commit 02212dee26
2 changed files with 128 additions and 132 deletions

View File

@ -767,7 +767,7 @@ static void unsetsids(struct bgp_path_info *bpi)
memset(extra->sid, 0, sizeof(extra->sid)); memset(extra->sid, 0, sizeof(extra->sid));
} }
static bool leak_update_nexthop_valid(struct bgp *bgp, struct bgp_dest *bn, static bool leak_update_nexthop_valid(struct bgp *to_bgp, struct bgp_dest *bn,
struct attr *new_attr, afi_t afi, struct attr *new_attr, afi_t afi,
safi_t safi, safi_t safi,
struct bgp_path_info *source_bpi, struct bgp_path_info *source_bpi,
@ -775,7 +775,7 @@ static bool leak_update_nexthop_valid(struct bgp *bgp, struct bgp_dest *bn,
const struct prefix *p, int debug) const struct prefix *p, int debug)
{ {
struct bgp_path_info *bpi_ultimate; struct bgp_path_info *bpi_ultimate;
struct bgp *bgp_nexthop = bgp; struct bgp *bgp_nexthop = to_bgp;
bool nh_valid; bool nh_valid;
bpi_ultimate = bgp_get_imported_bpi_ultimate(source_bpi); bpi_ultimate = bgp_get_imported_bpi_ultimate(source_bpi);
@ -795,15 +795,15 @@ static bool leak_update_nexthop_valid(struct bgp *bgp, struct bgp_dest *bn,
* TBD do we need to do anything about the * TBD do we need to do anything about the
* 'connected' parameter? * 'connected' parameter?
*/ */
nh_valid = bgp_find_or_add_nexthop(bgp, bgp_nexthop, afi, safi, nh_valid = bgp_find_or_add_nexthop(to_bgp, bgp_nexthop, afi,
bpi, NULL, 0, p); safi, bpi, NULL, 0, p);
/* /*
* If you are using SRv6 VPN instead of MPLS, it need to check * If you are using SRv6 VPN instead of MPLS, it need to check
* the SID allocation. If the sid is not allocated, the rib * the SID allocation. If the sid is not allocated, the rib
* will be invalid. * will be invalid.
*/ */
if (bgp->srv6_enabled && if (to_bgp->srv6_enabled &&
(!new_attr->srv6_l3vpn && !new_attr->srv6_vpn)) { (!new_attr->srv6_l3vpn && !new_attr->srv6_vpn)) {
nh_valid = false; nh_valid = false;
} }
@ -820,8 +820,8 @@ static bool leak_update_nexthop_valid(struct bgp *bgp, struct bgp_dest *bn,
* returns pointer to new bgp_path_info upon success * returns pointer to new bgp_path_info upon success
*/ */
static struct bgp_path_info * static struct bgp_path_info *
leak_update(struct bgp *bgp, /* destination bgp instance */ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
struct bgp_dest *bn, struct attr *new_attr, /* already interned */ struct attr *new_attr, /* already interned */
afi_t afi, safi_t safi, struct bgp_path_info *source_bpi, afi_t afi, safi_t safi, struct bgp_path_info *source_bpi,
mpls_label_t *label, uint32_t num_labels, struct bgp *bgp_orig, mpls_label_t *label, uint32_t num_labels, struct bgp *bgp_orig,
struct prefix *nexthop_orig, int nexthop_self_flag, int debug) struct prefix *nexthop_orig, int nexthop_self_flag, int debug)
@ -839,7 +839,7 @@ leak_update(struct bgp *bgp, /* destination bgp instance */
if (debug) if (debug)
zlog_debug( zlog_debug(
"%s: entry: leak-to=%s, p=%pBD, type=%d, sub_type=%d", "%s: entry: leak-to=%s, p=%pBD, type=%d, sub_type=%d",
__func__, bgp->name_pretty, bn, source_bpi->type, __func__, to_bgp->name_pretty, bn, source_bpi->type,
source_bpi->sub_type); source_bpi->sub_type);
/* /*
@ -874,7 +874,7 @@ leak_update(struct bgp *bgp, /* destination bgp instance */
if (debug) { if (debug) {
zlog_debug( zlog_debug(
"%s: ->%s(s_flags: 0x%x b_flags: 0x%x): %pFX: Found route, being removed, not leaking", "%s: ->%s(s_flags: 0x%x b_flags: 0x%x): %pFX: Found route, being removed, not leaking",
__func__, bgp->name_pretty, __func__, to_bgp->name_pretty,
source_bpi->flags, bpi->flags, p); source_bpi->flags, bpi->flags, p);
} }
return NULL; return NULL;
@ -887,7 +887,7 @@ leak_update(struct bgp *bgp, /* destination bgp instance */
if (debug) if (debug)
zlog_debug( zlog_debug(
"%s: ->%s: %pBD: Found route, no change", "%s: ->%s: %pBD: Found route, no change",
__func__, bgp->name_pretty, bn); __func__, to_bgp->name_pretty, bn);
return NULL; return NULL;
} }
@ -905,8 +905,9 @@ leak_update(struct bgp *bgp, /* destination bgp instance */
if (!ecommunity_cmp( if (!ecommunity_cmp(
bgp_attr_get_ecommunity(bpi->attr), bgp_attr_get_ecommunity(bpi->attr),
bgp_attr_get_ecommunity(new_attr))) { bgp_attr_get_ecommunity(new_attr))) {
vpn_leak_to_vrf_withdraw(bgp, bpi); vpn_leak_to_vrf_withdraw(to_bgp, bpi);
bgp_aggregate_decrement(bgp, p, bpi, afi, safi); bgp_aggregate_decrement(to_bgp, p, bpi, afi,
safi);
bgp_path_info_delete(bn, bpi); bgp_path_info_delete(bn, bpi);
} }
} }
@ -918,7 +919,7 @@ leak_update(struct bgp *bgp, /* destination bgp instance */
if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED))
bgp_path_info_restore(bn, bpi); bgp_path_info_restore(bn, bpi);
else else
bgp_aggregate_decrement(bgp, p, bpi, afi, safi); bgp_aggregate_decrement(to_bgp, p, bpi, afi, safi);
bgp_attr_unintern(&bpi->attr); bgp_attr_unintern(&bpi->attr);
bpi->attr = new_attr; bpi->attr = new_attr;
bpi->uptime = bgp_clock(); bpi->uptime = bgp_clock();
@ -961,20 +962,20 @@ leak_update(struct bgp *bgp, /* destination bgp instance */
if (nexthop_self_flag) if (nexthop_self_flag)
bgp_path_info_set_flag(bn, bpi, BGP_PATH_ANNC_NH_SELF); bgp_path_info_set_flag(bn, bpi, BGP_PATH_ANNC_NH_SELF);
if (leak_update_nexthop_valid(bgp, bn, new_attr, afi, safi, if (leak_update_nexthop_valid(to_bgp, bn, new_attr, afi, safi,
source_bpi, bpi, p, debug)) source_bpi, bpi, p, debug))
bgp_path_info_set_flag(bn, bpi, BGP_PATH_VALID); bgp_path_info_set_flag(bn, bpi, BGP_PATH_VALID);
else else
bgp_path_info_unset_flag(bn, bpi, BGP_PATH_VALID); bgp_path_info_unset_flag(bn, bpi, BGP_PATH_VALID);
/* Process change. */ /* Process change. */
bgp_aggregate_increment(bgp, p, bpi, afi, safi); bgp_aggregate_increment(to_bgp, p, bpi, afi, safi);
bgp_process(bgp, bn, afi, safi); bgp_process(to_bgp, bn, afi, safi);
bgp_dest_unlock_node(bn); bgp_dest_unlock_node(bn);
if (debug) if (debug)
zlog_debug("%s: ->%s: %pBD Found route, changed attr", zlog_debug("%s: ->%s: %pBD Found route, changed attr",
__func__, bgp->name_pretty, bn); __func__, to_bgp->name_pretty, bn);
return bpi; return bpi;
} }
@ -983,14 +984,14 @@ leak_update(struct bgp *bgp, /* destination bgp instance */
if (debug) { if (debug) {
zlog_debug( zlog_debug(
"%s: ->%s(s_flags: 0x%x): %pFX: New route, being removed, not leaking", "%s: ->%s(s_flags: 0x%x): %pFX: New route, being removed, not leaking",
__func__, bgp->name_pretty, __func__, to_bgp->name_pretty,
source_bpi->flags, p); source_bpi->flags, p);
} }
return NULL; return NULL;
} }
new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_IMPORTED, 0, new = info_make(ZEBRA_ROUTE_BGP, BGP_ROUTE_IMPORTED, 0,
bgp->peer_self, new_attr, bn); to_bgp->peer_self, new_attr, bn);
if (nexthop_self_flag) if (nexthop_self_flag)
bgp_path_info_set_flag(bn, new, BGP_PATH_ANNC_NH_SELF); bgp_path_info_set_flag(bn, new, BGP_PATH_ANNC_NH_SELF);
@ -1032,28 +1033,28 @@ leak_update(struct bgp *bgp, /* destination bgp instance */
if (nexthop_orig) if (nexthop_orig)
new->extra->nexthop_orig = *nexthop_orig; new->extra->nexthop_orig = *nexthop_orig;
if (leak_update_nexthop_valid(bgp, bn, new_attr, afi, safi, source_bpi, if (leak_update_nexthop_valid(to_bgp, bn, new_attr, afi, safi,
new, p, debug)) source_bpi, new, p, debug))
bgp_path_info_set_flag(bn, new, BGP_PATH_VALID); bgp_path_info_set_flag(bn, new, BGP_PATH_VALID);
else else
bgp_path_info_unset_flag(bn, new, BGP_PATH_VALID); bgp_path_info_unset_flag(bn, new, BGP_PATH_VALID);
bgp_aggregate_increment(bgp, p, new, afi, safi); bgp_aggregate_increment(to_bgp, p, new, afi, safi);
bgp_path_info_add(bn, new); bgp_path_info_add(bn, new);
bgp_dest_unlock_node(bn); bgp_dest_unlock_node(bn);
bgp_process(bgp, bn, afi, safi); bgp_process(to_bgp, bn, afi, safi);
if (debug) if (debug)
zlog_debug("%s: ->%s: %pBD: Added new route", __func__, zlog_debug("%s: ->%s: %pBD: Added new route", __func__,
bgp->name_pretty, bn); to_bgp->name_pretty, bn);
return new; return new;
} }
/* cf vnc_import_bgp_add_route_mode_nvegroup() and add_vnc_route() */ /* cf vnc_import_bgp_add_route_mode_nvegroup() and add_vnc_route() */
void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ void vpn_leak_from_vrf_update(struct bgp *to_bgp, /* to */
struct bgp *bgp_vrf, /* from */ struct bgp *from_bgp, /* from */
struct bgp_path_info *path_vrf) /* route */ struct bgp_path_info *path_vrf) /* route */
{ {
int debug = BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF); int debug = BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF);
@ -1069,7 +1070,7 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
int nexthop_self_flag = 0; int nexthop_self_flag = 0;
if (debug) if (debug)
zlog_debug("%s: from vrf %s", __func__, bgp_vrf->name_pretty); zlog_debug("%s: from vrf %s", __func__, from_bgp->name_pretty);
if (debug && bgp_attr_get_ecommunity(path_vrf->attr)) { if (debug && bgp_attr_get_ecommunity(path_vrf->attr)) {
char *s = ecommunity_ecom2str( char *s = ecommunity_ecom2str(
@ -1077,11 +1078,11 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
ECOMMUNITY_FORMAT_ROUTE_MAP, 0); ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
zlog_debug("%s: %s path_vrf->type=%d, EC{%s}", __func__, zlog_debug("%s: %s path_vrf->type=%d, EC{%s}", __func__,
bgp_vrf->name, path_vrf->type, s); from_bgp->name, path_vrf->type, s);
XFREE(MTYPE_ECOMMUNITY_STR, s); XFREE(MTYPE_ECOMMUNITY_STR, s);
} }
if (!bgp_vpn) if (!to_bgp)
return; return;
if (!afi) { if (!afi) {
@ -1094,10 +1095,10 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
if (!is_route_injectable_into_vpn(path_vrf)) if (!is_route_injectable_into_vpn(path_vrf))
return; return;
if (!vpn_leak_to_vpn_active(bgp_vrf, afi, &debugmsg)) { if (!vpn_leak_to_vpn_active(from_bgp, afi, &debugmsg)) {
if (debug) if (debug)
zlog_debug("%s: %s skipping: %s", __func__, zlog_debug("%s: %s skipping: %s", __func__,
bgp_vrf->name, debugmsg); from_bgp->name, debugmsg);
return; return;
} }
@ -1107,23 +1108,23 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
/* /*
* route map handling * route map handling
*/ */
if (bgp_vrf->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN]) { if (from_bgp->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN]) {
struct bgp_path_info info; struct bgp_path_info info;
route_map_result_t ret; route_map_result_t ret;
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.peer = bgp_vpn->peer_self; info.peer = to_bgp->peer_self;
info.attr = &static_attr; info.attr = &static_attr;
ret = route_map_apply( ret = route_map_apply(from_bgp->vpn_policy[afi]
bgp_vrf->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_TOVPN], .rmap[BGP_VPN_POLICY_DIR_TOVPN],
p, &info); p, &info);
if (RMAP_DENYMATCH == ret) { if (RMAP_DENYMATCH == ret) {
bgp_attr_flush(&static_attr); /* free any added parts */ bgp_attr_flush(&static_attr); /* free any added parts */
if (debug) if (debug)
zlog_debug( zlog_debug(
"%s: vrf %s route map \"%s\" says DENY, returning", "%s: vrf %s route map \"%s\" says DENY, returning",
__func__, bgp_vrf->name_pretty, __func__, from_bgp->name_pretty,
bgp_vrf->vpn_policy[afi] from_bgp->vpn_policy[afi]
.rmap[BGP_VPN_POLICY_DIR_TOVPN] .rmap[BGP_VPN_POLICY_DIR_TOVPN]
->name); ->name);
return; return;
@ -1151,17 +1152,17 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
old_ecom = bgp_attr_get_ecommunity(&static_attr); old_ecom = bgp_attr_get_ecommunity(&static_attr);
if (old_ecom) { if (old_ecom) {
new_ecom = ecommunity_dup(old_ecom); new_ecom = ecommunity_dup(old_ecom);
if (CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST], if (CHECK_FLAG(from_bgp->af_flags[afi][SAFI_UNICAST],
BGP_CONFIG_VRF_TO_VRF_EXPORT)) BGP_CONFIG_VRF_TO_VRF_EXPORT))
ecommunity_strip_rts(new_ecom); ecommunity_strip_rts(new_ecom);
new_ecom = ecommunity_merge(new_ecom, new_ecom = ecommunity_merge(
bgp_vrf->vpn_policy[afi] new_ecom, from_bgp->vpn_policy[afi]
.rtlist[BGP_VPN_POLICY_DIR_TOVPN]); .rtlist[BGP_VPN_POLICY_DIR_TOVPN]);
if (!old_ecom->refcnt) if (!old_ecom->refcnt)
ecommunity_free(&old_ecom); ecommunity_free(&old_ecom);
} else { } else {
new_ecom = ecommunity_dup( new_ecom = ecommunity_dup(
bgp_vrf->vpn_policy[afi] from_bgp->vpn_policy[afi]
.rtlist[BGP_VPN_POLICY_DIR_TOVPN]); .rtlist[BGP_VPN_POLICY_DIR_TOVPN]);
} }
bgp_attr_set_ecommunity(&static_attr, new_ecom); bgp_attr_set_ecommunity(&static_attr, new_ecom);
@ -1178,10 +1179,10 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
/* Nexthop */ /* Nexthop */
/* if policy nexthop not set, use 0 */ /* if policy nexthop not set, use 0 */
if (CHECK_FLAG(bgp_vrf->vpn_policy[afi].flags, if (CHECK_FLAG(from_bgp->vpn_policy[afi].flags,
BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) { BGP_VPN_POLICY_TOVPN_NEXTHOP_SET)) {
struct prefix *nexthop = struct prefix *nexthop =
&bgp_vrf->vpn_policy[afi].tovpn_nexthop; &from_bgp->vpn_policy[afi].tovpn_nexthop;
switch (nexthop->family) { switch (nexthop->family) {
case AF_INET: case AF_INET:
@ -1202,7 +1203,7 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
assert(0); assert(0);
} }
} else { } else {
if (!CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST], if (!CHECK_FLAG(from_bgp->af_flags[afi][SAFI_UNICAST],
BGP_CONFIG_VRF_TO_VRF_EXPORT)) { BGP_CONFIG_VRF_TO_VRF_EXPORT)) {
if (afi == AFI_IP) { if (afi == AFI_IP) {
/* /*
@ -1240,7 +1241,7 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
nexthop_self_flag = 1; nexthop_self_flag = 1;
} }
label_val = bgp_vrf->vpn_policy[afi].tovpn_label; label_val = from_bgp->vpn_policy[afi].tovpn_label;
if (label_val == MPLS_LABEL_NONE) { if (label_val == MPLS_LABEL_NONE) {
encode_label(MPLS_LABEL_IMPLICIT_NULL, &label); encode_label(MPLS_LABEL_IMPLICIT_NULL, &label);
} else { } else {
@ -1249,11 +1250,12 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
/* Set originator ID to "me" */ /* Set originator ID to "me" */
SET_FLAG(static_attr.flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)); SET_FLAG(static_attr.flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID));
static_attr.originator_id = bgp_vpn->router_id; static_attr.originator_id = to_bgp->router_id;
/* Set SID for SRv6 VPN */ /* Set SID for SRv6 VPN */
if (bgp_vrf->vpn_policy[afi].tovpn_sid_locator) { if (from_bgp->vpn_policy[afi].tovpn_sid_locator) {
encode_label(bgp_vrf->vpn_policy[afi].tovpn_sid_transpose_label, encode_label(
from_bgp->vpn_policy[afi].tovpn_sid_transpose_label,
&label); &label);
static_attr.srv6_l3vpn = XCALLOC(MTYPE_BGP_SRV6_L3VPN, static_attr.srv6_l3vpn = XCALLOC(MTYPE_BGP_SRV6_L3VPN,
sizeof(struct bgp_attr_srv6_l3vpn)); sizeof(struct bgp_attr_srv6_l3vpn));
@ -1272,7 +1274,7 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
static_attr.srv6_l3vpn->transposition_offset = static_attr.srv6_l3vpn->transposition_offset =
BGP_PREFIX_SID_SRV6_TRANSPOSITION_OFFSET; BGP_PREFIX_SID_SRV6_TRANSPOSITION_OFFSET;
memcpy(&static_attr.srv6_l3vpn->sid, memcpy(&static_attr.srv6_l3vpn->sid,
bgp_vrf->vpn_policy[afi].tovpn_sid_locator, from_bgp->vpn_policy[afi].tovpn_sid_locator,
sizeof(struct in6_addr)); sizeof(struct in6_addr));
} }
@ -1291,14 +1293,14 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
/* Now new_attr is an allocated interned attr */ /* Now new_attr is an allocated interned attr */
bn = bgp_afi_node_get(bgp_vpn->rib[afi][safi], afi, safi, p, bn = bgp_afi_node_get(to_bgp->rib[afi][safi], afi, safi, p,
&(bgp_vrf->vpn_policy[afi].tovpn_rd)); &(from_bgp->vpn_policy[afi].tovpn_rd));
struct bgp_path_info *new_info; struct bgp_path_info *new_info;
new_info = new_info =
leak_update(bgp_vpn, bn, new_attr, afi, safi, path_vrf, &label, leak_update(to_bgp, bn, new_attr, afi, safi, path_vrf, &label,
1, bgp_vrf, NULL, nexthop_self_flag, debug); 1, from_bgp, NULL, nexthop_self_flag, debug);
/* /*
* Routes actually installed in the vpn RIB must also be * Routes actually installed in the vpn RIB must also be
@ -1310,11 +1312,11 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
* because of loop checking. * because of loop checking.
*/ */
if (new_info) if (new_info)
vpn_leak_to_vrf_update(bgp_vrf, new_info); vpn_leak_to_vrf_update(from_bgp, new_info);
} }
void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, /* to */ void vpn_leak_from_vrf_withdraw(struct bgp *to_bgp, /* to */
struct bgp *bgp_vrf, /* from */ struct bgp *from_bgp, /* from */
struct bgp_path_info *path_vrf) /* route */ struct bgp_path_info *path_vrf) /* route */
{ {
int debug = BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF); int debug = BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF);
@ -1328,11 +1330,11 @@ void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, /* to */
if (debug) { if (debug) {
zlog_debug( zlog_debug(
"%s: entry: leak-from=%s, p=%pBD, type=%d, sub_type=%d", "%s: entry: leak-from=%s, p=%pBD, type=%d, sub_type=%d",
__func__, bgp_vrf->name_pretty, path_vrf->net, __func__, from_bgp->name_pretty, path_vrf->net,
path_vrf->type, path_vrf->sub_type); path_vrf->type, path_vrf->sub_type);
} }
if (!bgp_vpn) if (!to_bgp)
return; return;
if (!afi) { if (!afi) {
@ -1345,7 +1347,7 @@ void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, /* to */
if (!is_route_injectable_into_vpn(path_vrf)) if (!is_route_injectable_into_vpn(path_vrf))
return; return;
if (!vpn_leak_to_vpn_active(bgp_vrf, afi, &debugmsg)) { if (!vpn_leak_to_vpn_active(from_bgp, afi, &debugmsg)) {
if (debug) if (debug)
zlog_debug("%s: skipping: %s", __func__, debugmsg); zlog_debug("%s: skipping: %s", __func__, debugmsg);
return; return;
@ -1354,8 +1356,8 @@ void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, /* to */
if (debug) if (debug)
zlog_debug("%s: withdrawing (path_vrf=%p)", __func__, path_vrf); zlog_debug("%s: withdrawing (path_vrf=%p)", __func__, path_vrf);
bn = bgp_afi_node_get(bgp_vpn->rib[afi][safi], afi, safi, p, bn = bgp_afi_node_get(to_bgp->rib[afi][safi], afi, safi, p,
&(bgp_vrf->vpn_policy[afi].tovpn_rd)); &(from_bgp->vpn_policy[afi].tovpn_rd));
if (!bn) if (!bn)
return; return;
@ -1371,17 +1373,16 @@ void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, /* to */
if (bpi) { if (bpi) {
/* withdraw from looped vrfs as well */ /* withdraw from looped vrfs as well */
vpn_leak_to_vrf_withdraw(bgp_vpn, bpi); vpn_leak_to_vrf_withdraw(to_bgp, bpi);
bgp_aggregate_decrement(bgp_vpn, p, bpi, afi, safi); bgp_aggregate_decrement(to_bgp, p, bpi, afi, safi);
bgp_path_info_delete(bn, bpi); bgp_path_info_delete(bn, bpi);
bgp_process(bgp_vpn, bn, afi, safi); bgp_process(to_bgp, bn, afi, safi);
} }
bgp_dest_unlock_node(bn); bgp_dest_unlock_node(bn);
} }
void vpn_leak_from_vrf_withdraw_all(struct bgp *bgp_vpn, /* to */ void vpn_leak_from_vrf_withdraw_all(struct bgp *to_bgp, struct bgp *from_bgp,
struct bgp *bgp_vrf, /* from */
afi_t afi) afi_t afi)
{ {
int debug = BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF); int debug = BGP_DEBUG(vpn, VPN_LEAK_FROM_VRF);
@ -1389,9 +1390,9 @@ void vpn_leak_from_vrf_withdraw_all(struct bgp *bgp_vpn, /* to */
safi_t safi = SAFI_MPLS_VPN; safi_t safi = SAFI_MPLS_VPN;
/* /*
* Walk vpn table, delete bpi with bgp_orig == bgp_vrf * Walk vpn table, delete bpi with bgp_orig == from_bgp
*/ */
for (pdest = bgp_table_top(bgp_vpn->rib[afi][safi]); pdest; for (pdest = bgp_table_top(to_bgp->rib[afi][safi]); pdest;
pdest = bgp_route_next(pdest)) { pdest = bgp_route_next(pdest)) {
struct bgp_table *table; struct bgp_table *table;
@ -1420,28 +1421,26 @@ void vpn_leak_from_vrf_withdraw_all(struct bgp *bgp_vpn, /* to */
continue; continue;
if (!bpi->extra) if (!bpi->extra)
continue; continue;
if ((struct bgp *)bpi->extra->bgp_orig if ((struct bgp *)bpi->extra->bgp_orig ==
== bgp_vrf) { from_bgp) {
/* delete route */ /* delete route */
if (debug) if (debug)
zlog_debug("%s: deleting it", zlog_debug("%s: deleting it",
__func__); __func__);
/* withdraw from leak-to vrfs as well */ /* withdraw from leak-to vrfs as well */
vpn_leak_to_vrf_withdraw(bgp_vpn, bpi); vpn_leak_to_vrf_withdraw(to_bgp, bpi);
bgp_aggregate_decrement( bgp_aggregate_decrement(
bgp_vpn, to_bgp, bgp_dest_get_prefix(bn),
bgp_dest_get_prefix(bn), bpi, bpi, afi, safi);
afi, safi);
bgp_path_info_delete(bn, bpi); bgp_path_info_delete(bn, bpi);
bgp_process(bgp_vpn, bn, afi, safi); bgp_process(to_bgp, bn, afi, safi);
} }
} }
} }
} }
} }
void vpn_leak_from_vrf_update_all(struct bgp *bgp_vpn, /* to */ void vpn_leak_from_vrf_update_all(struct bgp *to_bgp, struct bgp *from_bgp,
struct bgp *bgp_vrf, /* from */
afi_t afi) afi_t afi)
{ {
struct bgp_dest *bn; struct bgp_dest *bn;
@ -1450,9 +1449,9 @@ void vpn_leak_from_vrf_update_all(struct bgp *bgp_vpn, /* to */
if (debug) if (debug)
zlog_debug("%s: entry, afi=%d, vrf=%s", __func__, afi, zlog_debug("%s: entry, afi=%d, vrf=%s", __func__, afi,
bgp_vrf->name_pretty); from_bgp->name_pretty);
for (bn = bgp_table_top(bgp_vrf->rib[afi][SAFI_UNICAST]); bn; for (bn = bgp_table_top(from_bgp->rib[afi][SAFI_UNICAST]); bn;
bn = bgp_route_next(bn)) { bn = bgp_route_next(bn)) {
if (debug) if (debug)
@ -1464,14 +1463,14 @@ void vpn_leak_from_vrf_update_all(struct bgp *bgp_vpn, /* to */
zlog_debug( zlog_debug(
"%s: calling vpn_leak_from_vrf_update", "%s: calling vpn_leak_from_vrf_update",
__func__); __func__);
vpn_leak_from_vrf_update(bgp_vpn, bgp_vrf, bpi); vpn_leak_from_vrf_update(to_bgp, from_bgp, bpi);
} }
} }
} }
static void static void
vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */
struct bgp *bgp_vpn, /* from */ struct bgp *from_bgp, /* from */
struct bgp_path_info *path_vpn) /* route */ struct bgp_path_info *path_vpn) /* route */
{ {
const struct prefix *p = bgp_dest_get_prefix(path_vpn->net); const struct prefix *p = bgp_dest_get_prefix(path_vpn->net);
@ -1492,7 +1491,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
int debug = BGP_DEBUG(vpn, VPN_LEAK_TO_VRF); int debug = BGP_DEBUG(vpn, VPN_LEAK_TO_VRF);
if (!vpn_leak_from_vpn_active(bgp_vrf, afi, &debugmsg)) { if (!vpn_leak_from_vpn_active(to_bgp, afi, &debugmsg)) {
if (debug) if (debug)
zlog_debug("%s: skipping: %s", __func__, debugmsg); zlog_debug("%s: skipping: %s", __func__, debugmsg);
return; return;
@ -1500,18 +1499,18 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
/* Check for intersection of route targets */ /* Check for intersection of route targets */
if (!ecom_intersect( if (!ecom_intersect(
bgp_vrf->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN], to_bgp->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
bgp_attr_get_ecommunity(path_vpn->attr))) { bgp_attr_get_ecommunity(path_vpn->attr))) {
if (debug) if (debug)
zlog_debug( zlog_debug(
"from vpn (%s) to vrf (%s), skipping after no intersection of route targets", "from vpn (%s) to vrf (%s), skipping after no intersection of route targets",
bgp_vpn->name_pretty, bgp_vrf->name_pretty); from_bgp->name_pretty, to_bgp->name_pretty);
return; return;
} }
if (debug) if (debug)
zlog_debug("%s: updating %pFX to vrf %s", __func__, p, zlog_debug("%s: updating %pFX to vrf %s", __func__, p,
bgp_vrf->name_pretty); to_bgp->name_pretty);
/* shallow copy */ /* shallow copy */
static_attr = *path_vpn->attr; static_attr = *path_vpn->attr;
@ -1521,7 +1520,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
/* If doing VRF-to-VRF leaking, strip RTs. */ /* If doing VRF-to-VRF leaking, strip RTs. */
old_ecom = bgp_attr_get_ecommunity(&static_attr); old_ecom = bgp_attr_get_ecommunity(&static_attr);
if (old_ecom && CHECK_FLAG(bgp_vrf->af_flags[afi][safi], if (old_ecom && CHECK_FLAG(to_bgp->af_flags[afi][safi],
BGP_CONFIG_VRF_TO_VRF_IMPORT)) { BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
new_ecom = ecommunity_dup(old_ecom); new_ecom = ecommunity_dup(old_ecom);
ecommunity_strip_rts(new_ecom); ecommunity_strip_rts(new_ecom);
@ -1554,7 +1553,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
nexthop_orig.u.prefix4 = path_vpn->attr->mp_nexthop_global_in; nexthop_orig.u.prefix4 = path_vpn->attr->mp_nexthop_global_in;
nexthop_orig.prefixlen = IPV4_MAX_BITLEN; nexthop_orig.prefixlen = IPV4_MAX_BITLEN;
if (CHECK_FLAG(bgp_vrf->af_flags[afi][safi], if (CHECK_FLAG(to_bgp->af_flags[afi][safi],
BGP_CONFIG_VRF_TO_VRF_IMPORT)) { BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
static_attr.nexthop.s_addr = static_attr.nexthop.s_addr =
nexthop_orig.u.prefix4.s_addr; nexthop_orig.u.prefix4.s_addr;
@ -1571,7 +1570,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
nexthop_orig.u.prefix6 = path_vpn->attr->mp_nexthop_global; nexthop_orig.u.prefix6 = path_vpn->attr->mp_nexthop_global;
nexthop_orig.prefixlen = IPV6_MAX_BITLEN; nexthop_orig.prefixlen = IPV6_MAX_BITLEN;
if (CHECK_FLAG(bgp_vrf->af_flags[afi][safi], if (CHECK_FLAG(to_bgp->af_flags[afi][safi],
BGP_CONFIG_VRF_TO_VRF_IMPORT)) { BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
static_attr.mp_nexthop_global = nexthop_orig.u.prefix6; static_attr.mp_nexthop_global = nexthop_orig.u.prefix6;
} }
@ -1581,15 +1580,15 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
/* /*
* route map handling * route map handling
*/ */
if (bgp_vrf->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_FROMVPN]) { if (to_bgp->vpn_policy[afi].rmap[BGP_VPN_POLICY_DIR_FROMVPN]) {
struct bgp_path_info info; struct bgp_path_info info;
route_map_result_t ret; route_map_result_t ret;
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
info.peer = bgp_vrf->peer_self; info.peer = to_bgp->peer_self;
info.attr = &static_attr; info.attr = &static_attr;
info.extra = path_vpn->extra; /* Used for source-vrf filter */ info.extra = path_vpn->extra; /* Used for source-vrf filter */
ret = route_map_apply(bgp_vrf->vpn_policy[afi] ret = route_map_apply(to_bgp->vpn_policy[afi]
.rmap[BGP_VPN_POLICY_DIR_FROMVPN], .rmap[BGP_VPN_POLICY_DIR_FROMVPN],
p, &info); p, &info);
if (RMAP_DENYMATCH == ret) { if (RMAP_DENYMATCH == ret) {
@ -1597,8 +1596,8 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
if (debug) if (debug)
zlog_debug( zlog_debug(
"%s: vrf %s vpn-policy route map \"%s\" says DENY, returning", "%s: vrf %s vpn-policy route map \"%s\" says DENY, returning",
__func__, bgp_vrf->name_pretty, __func__, to_bgp->name_pretty,
bgp_vrf->vpn_policy[afi] to_bgp->vpn_policy[afi]
.rmap[BGP_VPN_POLICY_DIR_FROMVPN] .rmap[BGP_VPN_POLICY_DIR_FROMVPN]
->name); ->name);
return; return;
@ -1614,7 +1613,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
new_attr = bgp_attr_intern(&static_attr); new_attr = bgp_attr_intern(&static_attr);
bgp_attr_flush(&static_attr); bgp_attr_flush(&static_attr);
bn = bgp_afi_node_get(bgp_vrf->rib[afi][safi], afi, safi, p, NULL); bn = bgp_afi_node_get(to_bgp->rib[afi][safi], afi, safi, p, NULL);
/* /*
* ensure labels are copied * ensure labels are copied
@ -1628,7 +1627,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
* labels for these routes enables the non-labeled nexthops * labels for these routes enables the non-labeled nexthops
* from the originating VRF to be considered valid for this route. * from the originating VRF to be considered valid for this route.
*/ */
if (!CHECK_FLAG(bgp_vrf->af_flags[afi][safi], if (!CHECK_FLAG(to_bgp->af_flags[afi][safi],
BGP_CONFIG_VRF_TO_VRF_IMPORT)) { BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
/* work back to original route */ /* work back to original route */
bpi_ultimate = bgp_get_imported_bpi_ultimate(path_vpn); bpi_ultimate = bgp_get_imported_bpi_ultimate(path_vpn);
@ -1666,14 +1665,14 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
if (path_vpn->extra && path_vpn->extra->bgp_orig) if (path_vpn->extra && path_vpn->extra->bgp_orig)
src_vrf = path_vpn->extra->bgp_orig; src_vrf = path_vpn->extra->bgp_orig;
else else
src_vrf = bgp_vpn; src_vrf = from_bgp;
leak_update(bgp_vrf, bn, new_attr, afi, safi, path_vpn, pLabels, leak_update(to_bgp, bn, new_attr, afi, safi, path_vpn, pLabels,
num_labels, src_vrf, &nexthop_orig, nexthop_self_flag, num_labels, src_vrf, &nexthop_orig, nexthop_self_flag,
debug); debug);
} }
void vpn_leak_to_vrf_update(struct bgp *bgp_vpn, /* from */ void vpn_leak_to_vrf_update(struct bgp *from_bgp, /* from */
struct bgp_path_info *path_vpn) /* route */ struct bgp_path_info *path_vpn) /* route */
{ {
struct listnode *mnode, *mnnode; struct listnode *mnode, *mnnode;
@ -1689,12 +1688,12 @@ void vpn_leak_to_vrf_update(struct bgp *bgp_vpn, /* from */
if (!path_vpn->extra if (!path_vpn->extra
|| path_vpn->extra->bgp_orig != bgp) { /* no loop */ || path_vpn->extra->bgp_orig != bgp) { /* no loop */
vpn_leak_to_vrf_update_onevrf(bgp, bgp_vpn, path_vpn); vpn_leak_to_vrf_update_onevrf(bgp, from_bgp, path_vpn);
} }
} }
} }
void vpn_leak_to_vrf_withdraw(struct bgp *bgp_vpn, /* from */ void vpn_leak_to_vrf_withdraw(struct bgp *from_bgp, /* from */
struct bgp_path_info *path_vpn) /* route */ struct bgp_path_info *path_vpn) /* route */
{ {
const struct prefix *p; const struct prefix *p;
@ -1778,8 +1777,7 @@ void vpn_leak_to_vrf_withdraw(struct bgp *bgp_vpn, /* from */
} }
} }
void vpn_leak_to_vrf_withdraw_all(struct bgp *bgp_vrf, /* to */ void vpn_leak_to_vrf_withdraw_all(struct bgp *to_bgp, afi_t afi)
afi_t afi)
{ {
struct bgp_dest *bn; struct bgp_dest *bn;
struct bgp_path_info *bpi; struct bgp_path_info *bpi;
@ -1791,40 +1789,38 @@ void vpn_leak_to_vrf_withdraw_all(struct bgp *bgp_vrf, /* to */
/* /*
* Walk vrf table, delete bpi with bgp_orig in a different vrf * Walk vrf table, delete bpi with bgp_orig in a different vrf
*/ */
for (bn = bgp_table_top(bgp_vrf->rib[afi][safi]); bn; for (bn = bgp_table_top(to_bgp->rib[afi][safi]); bn;
bn = bgp_route_next(bn)) { bn = bgp_route_next(bn)) {
for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; for (bpi = bgp_dest_get_bgp_path_info(bn); bpi;
bpi = bpi->next) { bpi = bpi->next) {
if (bpi->extra if (bpi->extra && bpi->extra->bgp_orig != to_bgp &&
&& bpi->extra->bgp_orig != bgp_vrf bpi->extra->parent &&
&& bpi->extra->parent is_pi_family_vpn(bpi->extra->parent)) {
&& is_pi_family_vpn(bpi->extra->parent)) {
/* delete route */ /* delete route */
bgp_aggregate_decrement(bgp_vrf, bgp_aggregate_decrement(to_bgp,
bgp_dest_get_prefix(bn), bgp_dest_get_prefix(bn),
bpi, afi, safi); bpi, afi, safi);
bgp_path_info_delete(bn, bpi); bgp_path_info_delete(bn, bpi);
bgp_process(bgp_vrf, bn, afi, safi); bgp_process(to_bgp, bn, afi, safi);
} }
} }
} }
} }
void vpn_leak_to_vrf_update_all(struct bgp *bgp_vrf, /* to */ void vpn_leak_to_vrf_update_all(struct bgp *to_bgp, struct bgp *vpn_from,
struct bgp *bgp_vpn, /* from */
afi_t afi) afi_t afi)
{ {
struct bgp_dest *pdest; struct bgp_dest *pdest;
safi_t safi = SAFI_MPLS_VPN; safi_t safi = SAFI_MPLS_VPN;
assert(bgp_vpn); assert(vpn_from);
/* /*
* Walk vpn table * Walk vpn table
*/ */
for (pdest = bgp_table_top(bgp_vpn->rib[afi][safi]); pdest; for (pdest = bgp_table_top(vpn_from->rib[afi][safi]); pdest;
pdest = bgp_route_next(pdest)) { pdest = bgp_route_next(pdest)) {
struct bgp_table *table; struct bgp_table *table;
struct bgp_dest *bn; struct bgp_dest *bn;
@ -1841,11 +1837,11 @@ void vpn_leak_to_vrf_update_all(struct bgp *bgp_vrf, /* to */
for (bpi = bgp_dest_get_bgp_path_info(bn); bpi; for (bpi = bgp_dest_get_bgp_path_info(bn); bpi;
bpi = bpi->next) { bpi = bpi->next) {
if (bpi->extra if (bpi->extra &&
&& bpi->extra->bgp_orig == bgp_vrf) bpi->extra->bgp_orig == to_bgp)
continue; continue;
vpn_leak_to_vrf_update_onevrf(bgp_vrf, bgp_vpn, vpn_leak_to_vrf_update_onevrf(to_bgp, vpn_from,
bpi); bpi);
} }
} }

View File

@ -53,27 +53,27 @@ extern int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd,
enum bgp_show_type type, void *output_arg, enum bgp_show_type type, void *output_arg,
int tags, bool use_json); int tags, bool use_json);
extern void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, struct bgp *bgp_vrf, extern void vpn_leak_from_vrf_update(struct bgp *to_bgp, struct bgp *from_bgp,
struct bgp_path_info *path_vrf); struct bgp_path_info *path_vrf);
extern void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, struct bgp *bgp_vrf, extern void vpn_leak_from_vrf_withdraw(struct bgp *to_bgp, struct bgp *from_bgp,
struct bgp_path_info *path_vrf); struct bgp_path_info *path_vrf);
extern void vpn_leak_from_vrf_withdraw_all(struct bgp *bgp_vpn, extern void vpn_leak_from_vrf_withdraw_all(struct bgp *to_bgp,
struct bgp *bgp_vrf, afi_t afi); struct bgp *from_bgp, afi_t afi);
extern void vpn_leak_from_vrf_update_all(struct bgp *bgp_vpn, extern void vpn_leak_from_vrf_update_all(struct bgp *to_bgp,
struct bgp *bgp_vrf, afi_t afi); struct bgp *from_bgp, afi_t afi);
extern void vpn_leak_to_vrf_withdraw_all(struct bgp *bgp_vrf, afi_t afi); extern void vpn_leak_to_vrf_withdraw_all(struct bgp *to_bgp, afi_t afi);
extern void vpn_leak_to_vrf_update_all(struct bgp *bgp_vrf, struct bgp *bgp_vpn, extern void vpn_leak_to_vrf_update_all(struct bgp *to_bgp, struct bgp *from_bgp,
afi_t afi); afi_t afi);
extern void vpn_leak_to_vrf_update(struct bgp *bgp_vpn, extern void vpn_leak_to_vrf_update(struct bgp *from_bgp,
struct bgp_path_info *path_vpn); struct bgp_path_info *path_vpn);
extern void vpn_leak_to_vrf_withdraw(struct bgp *bgp_vpn, extern void vpn_leak_to_vrf_withdraw(struct bgp *from_bgp,
struct bgp_path_info *path_vpn); struct bgp_path_info *path_vpn);
extern void vpn_leak_zebra_vrf_label_update(struct bgp *bgp, afi_t afi); extern void vpn_leak_zebra_vrf_label_update(struct bgp *bgp, afi_t afi);