Skip to content

Commit

Permalink
bgpd: Releasing the label in bgp_delete flow
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
varuntumbe committed Dec 16, 2024
1 parent c8e624b commit d5c2f2d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
29 changes: 29 additions & 0 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 1 addition & 0 deletions bgpd/bgp_mplsvpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 2 additions & 19 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions bgpd/bgpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d5c2f2d

Please sign in to comment.