summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2023-04-20 13:10:15 +0200
committerPhilippe Guibert <philippe.guibert@6wind.com>2023-06-16 10:54:58 +0200
commit162c5d83adecac7de8f2923bb25b70fe11dc0783 (patch)
treec39d2bf7f3f76924c4ca1bb8da47c37eed5fe481
parent0fb16305200113a92e3862e05d6833217f935211 (diff)
bgpd: add a function to compare two label lists
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>
-rw-r--r--bgpd/bgp_label.c17
-rw-r--r--bgpd/bgp_label.h4
-rw-r--r--bgpd/bgp_mplsvpn.c13
3 files changed, 24 insertions, 10 deletions
diff --git a/bgpd/bgp_label.c b/bgpd/bgp_label.c
index 0f3faeb297..30090e0590 100644
--- a/bgpd/bgp_label.c
+++ b/bgpd/bgp_label.c
@@ -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;
+}
diff --git a/bgpd/bgp_label.h b/bgpd/bgp_label.h
index ac7fbb27fb..b54403ee89 100644
--- a/bgpd/bgp_label.h
+++ b/bgpd/bgp_label.h
@@ -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)
{
diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c
index dc9bd3cff5..931d776e28 100644
--- a/bgpd/bgp_mplsvpn.c
+++ b/bgpd/bgp_mplsvpn.c
@@ -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);
}
/*