Skip to content

Commit 162c5d8

Browse files
committed
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 <[email protected]>
1 parent 0fb1630 commit 162c5d8

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

bgpd/bgp_label.c

+17
Original file line numberDiff line numberDiff line change
@@ -470,3 +470,20 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
470470

471471
return BGP_NLRI_PARSE_OK;
472472
}
473+
474+
bool bgp_labels_same(const mpls_label_t *tbl_a, const uint32_t num_labels_a,
475+
const mpls_label_t *tbl_b, const uint32_t num_labels_b)
476+
{
477+
uint32_t i;
478+
479+
if (num_labels_a != num_labels_b)
480+
return false;
481+
if (num_labels_a == 0)
482+
return true;
483+
484+
for (i = 0; i < num_labels_a; i++) {
485+
if (tbl_a[i] != tbl_b[i])
486+
return false;
487+
}
488+
return true;
489+
}

bgpd/bgp_label.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ extern mpls_label_t bgp_adv_label(struct bgp_dest *dest,
2626

2727
extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
2828
struct bgp_nlri *packet);
29+
extern bool bgp_labels_same(const mpls_label_t *tbl_a,
30+
const uint32_t num_labels_a,
31+
const mpls_label_t *tbl_b,
32+
const uint32_t num_labels_b);
2933

3034
static inline int bgp_labeled_safi(safi_t safi)
3135
{

bgpd/bgp_mplsvpn.c

+3-10
Original file line numberDiff line numberDiff line change
@@ -952,23 +952,16 @@ void transpose_sid(struct in6_addr *sid, uint32_t label, uint8_t offset,
952952
static bool labels_same(struct bgp_path_info *bpi, mpls_label_t *label,
953953
uint32_t n)
954954
{
955-
uint32_t i;
956-
957955
if (!bpi->extra) {
958956
if (!n)
959957
return true;
960958
else
961959
return false;
962960
}
963961

964-
if (n != bpi->extra->num_labels)
965-
return false;
966-
967-
for (i = 0; i < n; ++i) {
968-
if (label[i] != bpi->extra->label[i])
969-
return false;
970-
}
971-
return true;
962+
return bgp_labels_same((const mpls_label_t *)bpi->extra->label,
963+
bpi->extra->num_labels,
964+
(const mpls_label_t *)label, n);
972965
}
973966

974967
/*

0 commit comments

Comments
 (0)