]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: move label allocation code to a specific function
authorPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 25 May 2023 10:40:45 +0000 (12:40 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 16 Jun 2023 08:54:58 +0000 (10:54 +0200)
The label allocation mechanism is called implicitly for
labeled unicast paths. The check should be explicit, because
the current patch set will extend the mechanism for mpls vpn
paths, and the code should explicitly tell which safi calls
which code.

Fix this implicit call by checking the safi value. Move the
code to a specific function.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_route.c

index c4c08cf10c2b2376d8ad334dee0363d631c4f4e0..72db9975fdde9a86ddf59a3c585a3a26e5ecb52b 100644 (file)
@@ -3097,6 +3097,58 @@ need_null_label:
        return true;
 }
 
+/* Right now, since we only deal with per-prefix labels, it is not
+ * necessary to do this upon changes to best path. Exceptions:
+ * - label index has changed -> recalculate resulting label
+ * - path_info sub_type changed -> switch to/from null label value
+ * - no valid label (due to removed static label binding) -> get new one
+ */
+static void bgp_lu_handle_label_allocation(struct bgp *bgp,
+                                          struct bgp_dest *dest,
+                                          struct bgp_path_info *new_select,
+                                          struct bgp_path_info *old_select,
+                                          afi_t afi)
+{
+       mpls_label_t mpls_label_null;
+
+       if (bgp->allocate_mpls_labels[afi][SAFI_UNICAST]) {
+               if (new_select) {
+                       if (!old_select ||
+                           bgp_label_index_differs(new_select, old_select) ||
+                           new_select->sub_type != old_select->sub_type ||
+                           !bgp_is_valid_label(&dest->local_label)) {
+                               /* control label imposition for local
+                                * routes, aggregate and redistributed
+                                * routes
+                                */
+                               mpls_label_null = MPLS_LABEL_IMPLICIT_NULL;
+                               if (bgp_lu_need_null_label(bgp, new_select, afi,
+                                                          &mpls_label_null)) {
+                                       if (CHECK_FLAG(
+                                                   dest->flags,
+                                                   BGP_NODE_REGISTERED_FOR_LABEL) ||
+                                           CHECK_FLAG(
+                                                   dest->flags,
+                                                   BGP_NODE_LABEL_REQUESTED))
+                                               bgp_unregister_for_label(dest);
+                                       dest->local_label = mpls_lse_encode(
+                                               mpls_label_null, 0, 0, 1);
+                                       bgp_set_valid_label(&dest->local_label);
+                               } else
+                                       bgp_register_for_label(dest,
+                                                              new_select);
+                       }
+               } else if (CHECK_FLAG(dest->flags,
+                                     BGP_NODE_REGISTERED_FOR_LABEL) ||
+                          CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) {
+                       bgp_unregister_for_label(dest);
+               }
+       } else if (CHECK_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL) ||
+                  CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) {
+               bgp_unregister_for_label(dest);
+       }
+}
+
 /*
  * old_select = The old best path
  * new_select = the new best path
@@ -3123,7 +3175,6 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
        struct bgp_path_info *old_select;
        struct bgp_path_info_pair old_and_new;
        int debug = 0;
-       mpls_label_t mpls_label_null;
 
        if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) {
                if (dest)
@@ -3174,49 +3225,12 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
        old_select = old_and_new.old;
        new_select = old_and_new.new;
 
-       /* Do we need to allocate or free labels?
-        * Right now, since we only deal with per-prefix labels, it is not
-        * necessary to do this upon changes to best path. Exceptions:
-        * - label index has changed -> recalculate resulting label
-        * - path_info sub_type changed -> switch to/from null label value
-        * - no valid label (due to removed static label binding) -> get new one
-        */
-       if (bgp->allocate_mpls_labels[afi][safi]) {
-               if (new_select) {
-                       if (!old_select
-                           || bgp_label_index_differs(new_select, old_select)
-                           || new_select->sub_type != old_select->sub_type
-                           || !bgp_is_valid_label(&dest->local_label)) {
-                               /* control label imposition for local routes,
-                                * aggregate and redistributed routes
-                                */
-                               mpls_label_null = MPLS_LABEL_IMPLICIT_NULL;
-                               if (bgp_lu_need_null_label(bgp, new_select, afi,
-                                                          &mpls_label_null)) {
-                                       if (CHECK_FLAG(
-                                                   dest->flags,
-                                                   BGP_NODE_REGISTERED_FOR_LABEL)
-                                           || CHECK_FLAG(
-                                                   dest->flags,
-                                                   BGP_NODE_LABEL_REQUESTED))
-                                               bgp_unregister_for_label(dest);
-                                       dest->local_label = mpls_lse_encode(
-                                               mpls_label_null, 0, 0, 1);
-                                       bgp_set_valid_label(&dest->local_label);
-                               } else
-                                       bgp_register_for_label(dest,
-                                                              new_select);
-                       }
-               } else if (CHECK_FLAG(dest->flags,
-                                     BGP_NODE_REGISTERED_FOR_LABEL)
-                          || CHECK_FLAG(dest->flags,
-                                        BGP_NODE_LABEL_REQUESTED)) {
-                       bgp_unregister_for_label(dest);
-               }
-       } else if (CHECK_FLAG(dest->flags, BGP_NODE_REGISTERED_FOR_LABEL)
-                  || CHECK_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED)) {
-               bgp_unregister_for_label(dest);
-       }
+       if (safi == SAFI_UNICAST || safi == SAFI_LABELED_UNICAST)
+               /* label unicast path :
+                * Do we need to allocate or free labels?
+                */
+               bgp_lu_handle_label_allocation(bgp, dest, new_select,
+                                              old_select, afi);
 
        if (debug)
                zlog_debug(