From 21d88ef7611a0c5a26bde88aab2d3bb2d03989e5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 30 May 2018 18:17:17 -0400 Subject: [PATCH] bgpd: Lock originating bgp pointer for vrf route leaking There exists cases where we will attempt to hard delete the bgp instance( say a `no router bgp` is issued ) when we have vrf route leaking. If we do have this lock the bgp instance of the originator and do not let it be deleted out from under us until we are finished processing. Signed-off-by: Donald Sharp --- bgpd/bgp_mplsvpn.c | 2 +- bgpd/bgp_route.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index b58e9da6f4..eef711aa59 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -573,7 +573,7 @@ leak_update( new->extra->parent = bgp_info_lock(parent); bgp_lock_node((struct bgp_node *)((struct bgp_info *)parent)->net); if (bgp_orig) - new->extra->bgp_orig = bgp_orig; + new->extra->bgp_orig = bgp_lock(bgp_orig); if (nexthop_orig) new->extra->nexthop_orig = *nexthop_orig; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index a6322b1e06..1bf9db99fd 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -206,11 +206,19 @@ struct bgp_info *bgp_info_new(void) static void bgp_info_free(struct bgp_info *binfo) { /* unlink reference to parent, if any. */ - if (binfo->extra && binfo->extra->parent) { - bgp_unlock_node((struct bgp_node *)((struct bgp_info *)binfo - ->extra->parent)->net); - bgp_info_unlock((struct bgp_info *)binfo->extra->parent); - binfo->extra->parent = NULL; + if (binfo->extra) { + if (binfo->extra->parent) { + bgp_unlock_node( + (struct bgp_node *)((struct bgp_info *)binfo + ->extra->parent) + ->net); + bgp_info_unlock( + (struct bgp_info *)binfo->extra->parent); + binfo->extra->parent = NULL; + } + + if (binfo->extra->bgp_orig) + bgp_unlock(binfo->extra->bgp_orig); } if (binfo->attr) -- 2.39.5