From 162c5d83adecac7de8f2923bb25b70fe11dc0783 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Thu, 20 Apr 2023 13:10:15 +0200 Subject: [PATCH] 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 --- bgpd/bgp_label.c | 17 +++++++++++++++++ bgpd/bgp_label.h | 4 ++++ bgpd/bgp_mplsvpn.c | 13 +++---------- 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); } /* -- 2.39.5