diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index ca7f73dde993..e18293c0470c 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -4074,6 +4074,35 @@ void bgp_vpn_leak_export(struct bgp *from_bgp) } } +/* It releases the label from labelpool which + * was previously assigned and unsets the flag based on reset arg + * This also used in vty to release the label and to change the allocation mode as well + */ +void bgp_vpn_release_label(struct bgp *bgp, afi_t afi, bool reset) +{ + if (!CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) + return; + /* + * label has previously been automatically + * assigned by labelpool: release it + * + * NB if tovpn_label == MPLS_LABEL_NONE it + * means the automatic assignment is in flight + * and therefore the labelpool callback must + * detect that the auto label is not needed. + */ + if (bgp->vpn_policy[afi].tovpn_label == MPLS_LABEL_NONE) + return; + if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_PER_NEXTHOP)) + return; + + bgp_lp_release(LP_TYPE_VRF, &bgp->vpn_policy[afi], bgp->vpn_policy[afi].tovpn_label); + bgp->vpn_policy[afi].tovpn_label = MPLS_LABEL_NONE; + + if (reset) + UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_AUTO); +} + /* The nexthops values are compared to * find in the tree the appropriate cache entry */ diff --git a/bgpd/bgp_mplsvpn.h b/bgpd/bgp_mplsvpn.h index 39fed667818a..18639fc69b23 100644 --- a/bgpd/bgp_mplsvpn.h +++ b/bgpd/bgp_mplsvpn.h @@ -352,6 +352,7 @@ extern void vpn_handle_router_id_update(struct bgp *bgp, bool withdraw, bool is_config); extern void bgp_vpn_leak_unimport(struct bgp *from_bgp); extern void bgp_vpn_leak_export(struct bgp *from_bgp); +extern void bgp_vpn_release_label(struct bgp *bgp, afi_t afi, bool reset); extern bool bgp_mplsvpn_path_uses_valid_mpls_label(struct bgp_path_info *pi); extern int diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 6ff94129dcf5..296ebaf0ac72 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -9941,26 +9941,9 @@ DEFPY (af_label_vpn_export, UNSET_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_MANUAL_REG); - } else if (CHECK_FLAG(bgp->vpn_policy[afi].flags, - BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) { + } else if (CHECK_FLAG(bgp->vpn_policy[afi].flags, BGP_VPN_POLICY_TOVPN_LABEL_AUTO)) /* release any previous auto label */ - if (bgp->vpn_policy[afi].tovpn_label != MPLS_LABEL_NONE) { - - /* - * label has previously been automatically - * assigned by labelpool: release it - * - * NB if tovpn_label == MPLS_LABEL_NONE it - * means the automatic assignment is in flight - * and therefore the labelpool callback must - * detect that the auto label is not needed. - */ - - bgp_lp_release(LP_TYPE_VRF, - &bgp->vpn_policy[afi], - bgp->vpn_policy[afi].tovpn_label); - } - } + bgp_vpn_release_label(bgp, afi, false); if (yes) { if (label_auto) { diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index dccac3eceb19..0791919287b1 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4006,6 +4006,9 @@ int bgp_delete(struct bgp *bgp) bgp_vpn_leak_unimport(bgp); + bgp_vpn_release_label(bgp, AFI_IP, true); + bgp_vpn_release_label(bgp, AFI_IP6, true); + hook_call(bgp_inst_delete, bgp); FOREACH_AFI_SAFI (afi, safi)