]> git.proxmox.com Git - mirror_frr.git/blobdiff - zebra/label_manager.c
Merge pull request #12798 from donaldsharp/rib_match_multicast
[mirror_frr.git] / zebra / label_manager.c
index feec49ecc25a8531406e398e85496e5095565323..c77470a70109271812e9b9ea131f1ead7a37e842 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Label Manager for FRR
  *
@@ -5,20 +6,6 @@
  *                       Volta Networks Inc.
  *
  * This file is part of FRRouting (FRR)
- *
- * FRR is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * FRR is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; see the file COPYING; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -91,11 +78,8 @@ static int label_manager_get_chunk(struct label_manager_chunk **lmc,
                                   vrf_id_t vrf_id);
 static int label_manager_release_label_chunk(struct zserv *client,
                                             uint32_t start, uint32_t end);
-static int release_label_chunk(uint8_t proto, unsigned short instance,
-                              uint32_t session_id, uint32_t start,
-                              uint32_t end);
 
-static void delete_label_chunk(void *val)
+void delete_label_chunk(void *val)
 {
        XFREE(MTYPE_LM_CHUNK, val);
 }
@@ -178,11 +162,9 @@ void label_manager_init(void)
 }
 
 /* alloc and fill a label chunk */
-static struct label_manager_chunk *create_label_chunk(uint8_t proto,
-                                                     unsigned short instance,
-                                                     uint32_t session_id,
-                                                     uint8_t keep, uint32_t start,
-                                                     uint32_t end)
+struct label_manager_chunk *
+create_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
+                  uint8_t keep, uint32_t start, uint32_t end)
 {
        /* alloc chunk, fill it and return it */
        struct label_manager_chunk *lmc =
@@ -305,15 +287,13 @@ assign_specific_label_chunk(uint8_t proto, unsigned short instance,
  * @param base Desired starting label of the chunk; if MPLS_LABEL_BASE_ANY it does not apply
  * @return Pointer to the assigned label chunk, or NULL if the request could not be satisfied
  */
-static struct label_manager_chunk *assign_label_chunk(uint8_t proto,
-                                                     unsigned short instance,
-                                                     uint32_t session_id,
-                                                     uint8_t keep, uint32_t size,
-                                                     uint32_t base)
+struct label_manager_chunk *
+assign_label_chunk(uint8_t proto, unsigned short instance, uint32_t session_id,
+                  uint8_t keep, uint32_t size, uint32_t base)
 {
        struct label_manager_chunk *lmc;
        struct listnode *node;
-       uint32_t prev_end = 0;
+       uint32_t prev_end = MPLS_LABEL_UNRESERVED_MIN;
 
        /* handle chunks request with a specific base label */
        if (base != MPLS_LABEL_BASE_ANY)
@@ -335,8 +315,7 @@ static struct label_manager_chunk *assign_label_chunk(uint8_t proto,
                }
                /* check if we hadve a "hole" behind us that we can squeeze into
                 */
-               if ((lmc->start > prev_end)
-                   && (lmc->start - prev_end >= size)) {
+               if ((lmc->start > prev_end) && (lmc->start - prev_end > size)) {
                        lmc = create_label_chunk(proto, instance, session_id,
                                                 keep, prev_end + 1,
                                                 prev_end + size);
@@ -398,7 +377,7 @@ static int label_manager_release_label_chunk(struct zserv *client,
  * @param end Last label of the chunk
  * @return 0 on success, -1 otherwise
  */
-static int release_label_chunk(uint8_t proto, unsigned short instance,
+int release_label_chunk(uint8_t proto, unsigned short instance,
                        uint32_t session_id, uint32_t start, uint32_t end)
 {
        struct listnode *node;