From f254f4b6bdfd84de5d92af0e8f3bd73bff743791 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 15 Feb 2023 14:37:45 +0100 Subject: [PATCH 1/2] bgpd: fix mpls label pointer comparison Comparing pointers is not the appropriate way to know if the label values are the same or not. Perform a memcmp call instead is better. Fixes: 8ba710505735 ("bgpd: fix valgrind flagged errors") Signed-off-by: Philippe Guibert Signed-off-by: Louis Scalbert --- bgpd/bgp_route.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index ae3a88ddcc2c..997d57117ca4 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -4710,7 +4710,9 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, /* Update MPLS label */ if (has_valid_label) { extra = bgp_path_info_extra_get(pi); - if (extra->label != label) { + if (!bgp_labels_same((const mpls_label_t *)extra->label, + extra->num_labels, label, + num_labels)) { memcpy(&extra->label, label, num_labels * sizeof(mpls_label_t)); extra->num_labels = num_labels; @@ -4909,7 +4911,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, /* Update MPLS label */ if (has_valid_label) { extra = bgp_path_info_extra_get(new); - if (extra->label != label) { + if (!bgp_labels_same((const mpls_label_t *)extra->label, + extra->num_labels, label, num_labels)) { memcpy(&extra->label, label, num_labels * sizeof(mpls_label_t)); extra->num_labels = num_labels; From db1bb52c4b618c68407cbde3e65386fa44824d6f Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Fri, 26 Jan 2024 12:05:21 +0100 Subject: [PATCH 2/2] bgpd: use bgp_labels_same in bgp_update() Use bgp_labels_same() for all label comparisons in bgpd. Signed-off-by: Louis Scalbert --- bgpd/bgp_route.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 997d57117ca4..8bcbd3dd8cea 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -4520,12 +4520,12 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, hook_call(bgp_process, bgp, afi, safi, dest, peer, true); /* Same attribute comes in. */ - if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) - && same_attr - && (!has_valid_label - || memcmp(&(bgp_path_info_extra_get(pi))->label, label, - num_labels * sizeof(mpls_label_t)) - == 0)) { + if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) && same_attr && + (!has_valid_label || + (bgp_path_info_extra_get(pi) && + bgp_labels_same((const mpls_label_t *)pi->extra->label, + pi->extra->num_labels, label, + num_labels)))) { if (CHECK_FLAG(bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING) && peer->sort == BGP_PEER_EBGP