]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Releasing the label in bgp_delete flow 17580/head
authorvaruntumbe <varuntumbe1@gmail.com>
Thu, 12 Dec 2024 12:27:02 +0000 (17:57 +0530)
committervaruntumbe <varuntumbe1@gmail.com>
Mon, 16 Dec 2024 15:57:46 +0000 (21:27 +0530)
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>
bgpd/bgp_mplsvpn.c
bgpd/bgp_mplsvpn.h
bgpd/bgp_vty.c
bgpd/bgpd.c

index ca7f73dde993121421add72ac38cc3e4c633d33f..e18293c0470c82c0b7602d8b675799111f9cd1bd 100644 (file)
@@ -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
  */
index 39fed667818aa98b96e47d658b38618633edb9a5..18639fc69b23df0b0a841289372a294177b6f1d4 100644 (file)
@@ -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
index 6ff94129dcf587c28cede7fa3c74e5f786ccaa95..296ebaf0ac72fbcc9816b4458f632aaefbf1583a 100644 (file)
@@ -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) {
index dccac3eceb19be44790c6f7c10c1c964e998b395..0791919287b1eb0a00926bfddc417e023d436dd5 100644 (file)
@@ -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)