bgpd: Use BGP instance to derive the VRF for route uninstall

When uninstalling routes from zebra, ensure that the BGP instance for
which processing is being done is used to derive the VRF. It is incorrect
to derive the VRF from the peer when dealing with scenarios like VRF route
leaking, EVPN symmetric/external routing etc., where the peer which sourced
the route could belong to a different VRF.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by:   Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by:   Mitesh Kanjariya <mitesh@cumulusnetworks.com>

Ticket: CM-18413
Reviewed By: CCR-6778
Testing Done: Manual testing of BGP route withdraw/delete, bgp-min
This commit is contained in:
vivek 2017-11-01 13:36:46 -07:00 committed by Donald Sharp
parent 3103e8d22f
commit 568e10ca58
3 changed files with 19 additions and 13 deletions

View File

@ -2313,7 +2313,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn,
|| old_select->sub_type == BGP_ROUTE_AGGREGATE
|| old_select->sub_type == BGP_ROUTE_IMPORTED))
bgp_zebra_withdraw(p, old_select, safi);
bgp_zebra_withdraw(p, old_select, bgp, safi);
}
}
@ -3984,7 +3984,8 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi)
}
}
static void bgp_cleanup_table(struct bgp_table *table, safi_t safi)
static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table,
safi_t safi)
{
struct bgp_node *rn;
struct bgp_info *ri;
@ -4000,7 +4001,8 @@ static void bgp_cleanup_table(struct bgp_table *table, safi_t safi)
|| ri->sub_type == BGP_ROUTE_IMPORTED)) {
if (bgp_fibupd_safi(safi))
bgp_zebra_withdraw(&rn->p, ri, safi);
bgp_zebra_withdraw(&rn->p, ri,
bgp, safi);
bgp_info_reap(rn, ri);
}
}
@ -4015,7 +4017,8 @@ void bgp_cleanup_routes(struct bgp *bgp)
for (afi = AFI_IP; afi < AFI_MAX; ++afi) {
if (afi == AFI_L2VPN)
continue;
bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
bgp_cleanup_table(bgp, bgp->rib[afi][SAFI_UNICAST],
SAFI_UNICAST);
/*
* VPN and ENCAP and EVPN tables are two-level (RD is top level)
*/
@ -4025,7 +4028,7 @@ void bgp_cleanup_routes(struct bgp *bgp)
for (rn = bgp_table_top(bgp->rib[afi][safi]); rn;
rn = bgp_route_next(rn)) {
if (rn->info) {
bgp_cleanup_table(
bgp_cleanup_table(bgp,
(struct bgp_table *)(rn->info),
safi);
bgp_table_finish((struct bgp_table **)&(
@ -4038,7 +4041,7 @@ void bgp_cleanup_routes(struct bgp *bgp)
for (rn = bgp_table_top(bgp->rib[afi][safi]); rn;
rn = bgp_route_next(rn)) {
if (rn->info) {
bgp_cleanup_table(
bgp_cleanup_table(bgp,
(struct bgp_table *)(rn->info),
safi);
bgp_table_finish((struct bgp_table **)&(
@ -4052,7 +4055,8 @@ void bgp_cleanup_routes(struct bgp *bgp)
for (rn = bgp_table_top(bgp->rib[AFI_L2VPN][SAFI_EVPN]); rn;
rn = bgp_route_next(rn)) {
if (rn->info) {
bgp_cleanup_table((struct bgp_table *)(rn->info),
bgp_cleanup_table(bgp,
(struct bgp_table *)(rn->info),
SAFI_EVPN);
bgp_table_finish((struct bgp_table **)&(rn->info));
rn->info = NULL;

View File

@ -1303,7 +1303,8 @@ void bgp_zebra_announce_table(struct bgp *bgp, afi_t afi, safi_t safi)
safi);
}
void bgp_zebra_withdraw(struct prefix *p, struct bgp_info *info, safi_t safi)
void bgp_zebra_withdraw(struct prefix *p, struct bgp_info *info,
struct bgp *bgp, safi_t safi)
{
struct zapi_route api;
struct peer *peer;
@ -1329,12 +1330,12 @@ void bgp_zebra_withdraw(struct prefix *p, struct bgp_info *info, safi_t safi)
/* Don't try to install if we're not connected to Zebra or Zebra doesn't
* know of this instance.
*/
if (!bgp_install_info_to_zebra(peer->bgp))
if (!bgp_install_info_to_zebra(bgp))
return;
memset(&api, 0, sizeof(api));
memcpy(&api.rmac, &(info->attr->rmac), sizeof(struct ethaddr));
api.vrf_id = peer->bgp->vrf_id;
api.vrf_id = bgp->vrf_id;
api.type = ZEBRA_ROUTE_BGP;
api.safi = safi;
api.prefix = *p;
@ -1353,14 +1354,14 @@ void bgp_zebra_withdraw(struct prefix *p, struct bgp_info *info, safi_t safi)
if ((peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
|| CHECK_FLAG(peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)
|| bgp_flag_check(peer->bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
|| bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK))
SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION);
if (bgp_debug_zebra(p)) {
char buf[PREFIX_STRLEN];
prefix2str(&api.prefix, buf, sizeof(buf));
zlog_debug("Tx route delete VRF %u %s", peer->bgp->vrf_id, buf);
zlog_debug("Tx route delete VRF %u %s", bgp->vrf_id, buf);
}
zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api);

View File

@ -33,7 +33,8 @@ extern void bgp_config_write_redistribute(struct vty *, struct bgp *, afi_t,
extern void bgp_zebra_announce(struct bgp_node *, struct prefix *,
struct bgp_info *, struct bgp *, afi_t, safi_t);
extern void bgp_zebra_announce_table(struct bgp *, afi_t, safi_t);
extern void bgp_zebra_withdraw(struct prefix *, struct bgp_info *, safi_t);
extern void bgp_zebra_withdraw(struct prefix *, struct bgp_info *,
struct bgp *, safi_t);
extern void bgp_zebra_initiate_radv(struct bgp *bgp, struct peer *peer);
extern void bgp_zebra_terminate_radv(struct bgp *bgp, struct peer *peer);