Commit fa7d395ef4 for frr

commit fa7d395ef44630910a0040a3d287b277b5a7ff5b
Author: Philippe Guibert <philippe.guibert@6wind.com>
Date:   Mon Oct 12 17:45:16 2026 +0200

    bgpd: cap the aigp metric when it is increased

    A route received with an AIGP metric close to 0xffffffffffffffff, for
    instance 0xfffffffffffffff0, and advertised with the local address as
    nexthop is advertised with a small AIGP metric when the IGP metric to
    the nexthop is above 0xf. The route becomes the most preferred one in
    the next AS, instead of the least preferred one.

    RFC 7311 section 3.4.3 requires the AIGP metric to be capped at
    0xffffffffffffffff when it is increased, and forbids a wrap around.
    bgp_aigp_metric_total() adds the IGP metric to the AIGP metric without
    any check.

    Fix this by capping the addition at UINT64_MAX.

    Fixes: 97a52c82a569 ("bgpd: Implement Accumulated IGP Metric Attribute for BGP")
    Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>

diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 30093c59bf..756655539d 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -752,6 +752,11 @@ static inline uint64_t bgp_attr_get_aigp_metric(const struct attr *attr)
 extern void bgp_attr_set_aigp_metric(struct attr *attr, uint64_t aigp);
 extern void bgp_attr_unset_aigp_metric(struct attr *attr);

+static inline uint64_t bgp_aigp_metric_add(uint64_t aigp, uint64_t value)
+{
+	return aigp > UINT64_MAX - value ? UINT64_MAX : aigp + value;
+}
+
 static inline uint64_t bgp_aigp_metric_total(struct bgp_path_info *bpi, const struct attr *attr)
 {
 	uint64_t aigp = bgp_attr_get_aigp_metric(attr);
@@ -760,7 +765,7 @@ static inline uint64_t bgp_aigp_metric_total(struct bgp_path_info *bpi, const st
 	if (bpi->peer == bpi->peer->bgp->peer_self)
 		return aigp;

-	return bpi->extra ? (aigp + bpi->extra->igpmetric) : aigp;
+	return bpi->extra ? bgp_aigp_metric_add(aigp, bpi->extra->igpmetric) : aigp;
 }

 static inline void bgp_attr_set_med(struct attr *attr, uint32_t med)