]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: add a function to compare two label lists
authorPhilippe Guibert <philippe.guibert@6wind.com>
Thu, 20 Apr 2023 11:10:15 +0000 (13:10 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 16 Jun 2023 08:54:58 +0000 (10:54 +0200)
Create a bgp_labels_same() function that does the
same operations as the static function labels_same from
bgp_mplsvpn.c.

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

index 0f3faeb29759f303bcc8a9943b07423ff35c5046..30090e0590b7a5512cb65ee7dccf44c2a1e1d7a1 100644 (file)
@@ -470,3 +470,20 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
 
        return BGP_NLRI_PARSE_OK;
 }
+
+bool bgp_labels_same(const mpls_label_t *tbl_a, const uint32_t num_labels_a,
+                    const mpls_label_t *tbl_b, const uint32_t num_labels_b)
+{
+       uint32_t i;
+
+       if (num_labels_a != num_labels_b)
+               return false;
+       if (num_labels_a == 0)
+               return true;
+
+       for (i = 0; i < num_labels_a; i++) {
+               if (tbl_a[i] != tbl_b[i])
+                       return false;
+       }
+       return true;
+}
index ac7fbb27fbe964ef3ea8f9f05a3dd1a18ce478fa..b54403ee89b0ca7830a0f0cd7ceaa713413b37bb 100644 (file)
@@ -26,6 +26,10 @@ extern mpls_label_t bgp_adv_label(struct bgp_dest *dest,
 
 extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
                                struct bgp_nlri *packet);
+extern bool bgp_labels_same(const mpls_label_t *tbl_a,
+                           const uint32_t num_labels_a,
+                           const mpls_label_t *tbl_b,
+                           const uint32_t num_labels_b);
 
 static inline int bgp_labeled_safi(safi_t safi)
 {
index dc9bd3cff525ad19a8857a131e3512216cd66673..931d776e28324d28fb8dcb60120633003e2062b4 100644 (file)
@@ -952,8 +952,6 @@ void transpose_sid(struct in6_addr *sid, uint32_t label, uint8_t offset,
 static bool labels_same(struct bgp_path_info *bpi, mpls_label_t *label,
                        uint32_t n)
 {
-       uint32_t i;
-
        if (!bpi->extra) {
                if (!n)
                        return true;
@@ -961,14 +959,9 @@ static bool labels_same(struct bgp_path_info *bpi, mpls_label_t *label,
                        return false;
        }
 
-       if (n != bpi->extra->num_labels)
-               return false;
-
-       for (i = 0; i < n; ++i) {
-               if (label[i] != bpi->extra->label[i])
-                       return false;
-       }
-       return true;
+       return bgp_labels_same((const mpls_label_t *)bpi->extra->label,
+                              bpi->extra->num_labels,
+                              (const mpls_label_t *)label, n);
 }
 
 /*