From 081422e8e71085d3a3d4d2ff0bc1e1abaff0d52e Mon Sep 17 00:00:00 2001 From: Enke Chen Date: Mon, 14 Oct 2024 18:42:15 -0700 Subject: [PATCH] bgpd: fix route selection with AIGP The nexthop metric should be added to AIGP when calculating the bestpath in bgp_path_info_cmp(). Signed-off-by: Enke Chen --- bgpd/bgp_attr.c | 10 ---------- bgpd/bgp_attr.h | 10 ++++++++++ bgpd/bgp_route.c | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 7cdf98cba7..7aa9bbbb91 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -480,16 +480,6 @@ static bool bgp_attr_aigp_get_tlv_metric(uint8_t *pnt, int length, return false; } -static uint64_t bgp_aigp_metric_total(struct bgp_path_info *bpi) -{ - uint64_t aigp = bgp_attr_get_aigp_metric(bpi->attr); - - if (bpi->nexthop) - return aigp + bpi->nexthop->metric; - else - return aigp; -} - static void stream_put_bgp_aigp_tlv_metric(struct stream *s, struct bgp_path_info *bpi) { diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index a8ca8c1fa6..02ddf88b62 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -598,6 +598,16 @@ static inline void bgp_attr_set_aigp_metric(struct attr *attr, uint64_t aigp) SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)); } +static inline uint64_t bgp_aigp_metric_total(struct bgp_path_info *bpi) +{ + uint64_t aigp = bgp_attr_get_aigp_metric(bpi->attr); + + if (bpi->nexthop) + return aigp + bpi->nexthop->metric; + else + return aigp; +} + static inline struct cluster_list *bgp_attr_get_cluster(const struct attr *attr) { return attr->cluster1; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 9cefec0706..0f196157c8 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1068,8 +1068,8 @@ int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, if (CHECK_FLAG(newattr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)) && CHECK_FLAG(existattr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)) && CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP)) { - uint64_t new_aigp = bgp_attr_get_aigp_metric(newattr); - uint64_t exist_aigp = bgp_attr_get_aigp_metric(existattr); + uint64_t new_aigp = bgp_aigp_metric_total(new); + uint64_t exist_aigp = bgp_aigp_metric_total(exist); if (new_aigp < exist_aigp) { *reason = bgp_path_selection_aigp; -- 2.39.5