diff options
| author | varuntumbe <varuntumbe1@gmail.com> | 2024-12-12 17:57:02 +0530 | 
|---|---|---|
| committer | varuntumbe <varuntumbe1@gmail.com> | 2024-12-16 21:27:46 +0530 | 
| commit | d5c2f2df199819bc7497db5a5d69a569eaccc1f9 (patch) | |
| tree | 9e63ced855fc163ab3d6ed19b63f737b9efbcbf7 /bgpd | |
| parent | c8e624bfd5bda89545fca853540d4f2fc7e25d83 (diff) | |
bgpd: Releasing the label in bgp_delete flow
Releasing the vpn label from label pool chunk using bgp_lp_release routine whenever vpn session is removed.
bgp_lp_release will clear corresponding bit in the allocated map of the label pool chunk and increases nfree by 1
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'bgpd')
| -rw-r--r-- | bgpd/bgp_mplsvpn.c | 29 | ||||
| -rw-r--r-- | bgpd/bgp_mplsvpn.h | 1 | ||||
| -rw-r--r-- | bgpd/bgp_vty.c | 21 | ||||
| -rw-r--r-- | bgpd/bgpd.c | 3 | 
4 files changed, 35 insertions, 19 deletions
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index ca7f73dde9..e18293c047 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 39fed66781..18639fc69b 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 6ff94129dc..296ebaf0ac 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 dccac3eceb..0791919287 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)  | 
