diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c index 54a966e191fa..de70adeefabb 100644 --- a/bgpd/bgp_labelpool.c +++ b/bgpd/bgp_labelpool.c @@ -1728,6 +1728,12 @@ bgp_label_per_nexthop_find(struct bgp_label_per_nexthop_cache_head *tree, void bgp_label_per_nexthop_free(struct bgp_label_per_nexthop_cache *blnc) { + if (blnc->allocation_in_progress) { + blnc->allocation_in_progress = false; + bgp_label_per_nexthop_cache_del(blnc->tree, blnc); + return; + } + if (blnc->label != MPLS_INVALID_LABEL) { bgp_zebra_send_nexthop_label(ZEBRA_MPLS_LABELS_DELETE, blnc->label, blnc->nh->ifindex, diff --git a/bgpd/bgp_labelpool.h b/bgpd/bgp_labelpool.h index a17482d112e8..2a2c8dc94f36 100644 --- a/bgpd/bgp_labelpool.h +++ b/bgpd/bgp_labelpool.h @@ -79,6 +79,8 @@ struct bgp_label_per_nexthop_cache { /* Back pointer to the cache tree this entry belongs to. */ struct bgp_label_per_nexthop_cache_head *tree; + + bool allocation_in_progress; }; DECLARE_RBTREE_UNIQ(bgp_label_per_nexthop_cache, diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 6a8df3b68e18..032923766cb5 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -1405,6 +1405,11 @@ static int bgp_mplsvpn_get_label_per_nexthop_cb(mpls_label_t label, */ blnc->label = MPLS_INVALID_LABEL; + if (!blnc->allocation_in_progress) { + bgp_label_per_nexthop_free(blnc); + return 0; + } + if (old_label == blnc->label) return 0; /* no change */ @@ -1478,6 +1483,7 @@ _vpn_leak_from_vrf_get_per_nexthop_label(struct bgp_path_info *pi, /* request a label to zebra for this nexthop * the response from zebra will trigger the callback */ + blnc->allocation_in_progress = true; bgp_lp_get(LP_TYPE_NEXTHOP, blnc, bgp_mplsvpn_get_label_per_nexthop_cb); }