Commit 6907699826 for frr

commit 6907699826e8425cdaf7caca350d1dcaf0901a8c
Author: Donald Sharp <sharpd@nvidia.com>
Date:   Thu Nov 12 14:08:45 2026 -0500

    bgpd: Move evpn attr values into attr_extra

    Make the move ofthe evpn attr values into the attr_extra
    so that struct attr does not pay the prices of not using
    evpn.

    Signed-off-by: Donald Sharp <sharpd@nvidia.com>

diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 9084c72af7..a7157d5347 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -144,6 +144,67 @@ struct attr_extra {
 	/* EVPN overlay index */
 	struct bgp_route_evpn *evpn_overlay;

+	/* ES info */
+	uint8_t es_flags;
+	/* Path is not "locally-active" on the advertising VTEP. This is
+	 * translated into an ARP-ND ECOM.
+	 */
+#define ATTR_ES_PROXY_ADVERT (1 << 0)
+	/* Destination ES is present locally. This flag is set on local
+	 * paths and sync paths
+	 */
+#define ATTR_ES_IS_LOCAL (1 << 1)
+	/* There are one or more non-best paths from ES peers. Note that
+	 * this flag is only set on the local MAC-IP paths in the VNI
+	 * route table (not set in the global routing table). And only
+	 * non-proxy advertisements from an ES peer can result in this
+	 * flag being set.
+	 */
+#define ATTR_ES_PEER_ACTIVE (1 << 2)
+	/* There are one or more non-best proxy paths from ES peers */
+#define ATTR_ES_PEER_PROXY (1 << 3)
+	/* An ES peer has router bit set - only applicable if
+	 * ATTR_ES_PEER_ACTIVE is set
+	 */
+#define ATTR_ES_PEER_ROUTER (1 << 4)
+
+	/* These two flags are only set on L3 routes installed in a
+	 * VRF as a result of EVPN MAC-IP route
+	 * XXX - while splitting up per-family attrs these need to be
+	 * classified as non-EVPN
+	 */
+#define ATTR_ES_L3_NHG_USE    (1 << 5)
+#define ATTR_ES_L3_NHG_ACTIVE (1 << 6)
+#define ATTR_ES_L3_NHG	      (ATTR_ES_L3_NHG_USE | ATTR_ES_L3_NHG_ACTIVE)
+
+	uint8_t df_alg;
+
+	/* EVPN flags */
+	uint8_t evpn_flags;
+#define ATTR_EVPN_FLAG_STICKY	  (1 << 0)
+#define ATTR_EVPN_FLAG_DEFAULT_GW (1 << 1)
+/* NA router flag (R-bit) support in EVPN */
+#define ATTR_EVPN_FLAG_ROUTER (1 << 2)
+
+	/* EVPN DF preference for DF election on local ESs */
+	uint16_t df_pref;
+
+	/* EVPN MAC Mobility sequence number, if any. */
+	uint32_t mm_seqnum;
+	/* highest MM sequence number rxed in a MAC-IP route from an
+	 * ES peer (this includes both proxy and non-proxy MAC-IP
+	 * advertisements from ES peers).
+	 * This is only applicable to local paths in the VNI routing
+	 * table and derived from other imported/non-best paths.
+	 */
+	uint32_t mm_sync_seqnum;
+
+	/* EVPN local router-mac */
+	struct ethaddr rmac;
+
+	/* EVPN ES */
+	esi_t esi;
+
 	/* AIGP TLVs */
 	struct bgp_aigp_tlvs *aigp_tlvs;

@@ -209,51 +270,9 @@ struct attr {
 	/* Path origin attribute */
 	uint8_t origin;

-	/* ES info */
-	uint8_t es_flags;
-	/* Path is not "locally-active" on the advertising VTEP. This is
-	 * translated into an ARP-ND ECOM.
-	 */
-#define ATTR_ES_PROXY_ADVERT (1 << 0)
-	/* Destination ES is present locally. This flag is set on local
-	 * paths and sync paths
-	 */
-#define ATTR_ES_IS_LOCAL (1 << 1)
-	/* There are one or more non-best paths from ES peers. Note that
-	 * this flag is only set on the local MAC-IP paths in the VNI
-	 * route table (not set in the global routing table). And only
-	 * non-proxy advertisements from an ES peer can result in this
-	 * flag being set.
-	 */
-#define ATTR_ES_PEER_ACTIVE (1 << 2)
-	/* There are one or more non-best proxy paths from ES peers */
-#define ATTR_ES_PEER_PROXY (1 << 3)
-	/* An ES peer has router bit set - only applicable if
-	 * ATTR_ES_PEER_ACTIVE is set
-	 */
-#define ATTR_ES_PEER_ROUTER (1 << 4)
-
-	/* These two flags are only set on L3 routes installed in a
-	 * VRF as a result of EVPN MAC-IP route
-	 * XXX - while splitting up per-family attrs these need to be
-	 * classified as non-EVPN
-	 */
-#define ATTR_ES_L3_NHG_USE    (1 << 5)
-#define ATTR_ES_L3_NHG_ACTIVE (1 << 6)
-#define ATTR_ES_L3_NHG	      (ATTR_ES_L3_NHG_USE | ATTR_ES_L3_NHG_ACTIVE)
-
 	/* Distance as applied by Route map */
 	uint8_t distance;

-	uint8_t df_alg;
-
-	/* EVPN flags */
-	uint8_t evpn_flags;
-#define ATTR_EVPN_FLAG_STICKY	  (1 << 0)
-#define ATTR_EVPN_FLAG_DEFAULT_GW (1 << 1)
-/* NA router flag (R-bit) support in EVPN */
-#define ATTR_EVPN_FLAG_ROUTER (1 << 2)
-
 	/* has the route-map changed any attribute?
 	   Used on the peer outbound side. */
 	uint16_t rmap_change_flags;
@@ -269,9 +288,6 @@ struct attr {
 		struct attr *parsed_attr;
 	} attr_intern_reuse;

-	/* EVPN DF preference for DF election on local ESs */
-	uint16_t df_pref;
-
 	/* MP Nexthop length */
 	uint8_t mp_nexthop_len;

@@ -327,21 +343,6 @@ struct attr {
 #ifdef ENABLE_BGP_VNC
 	struct bgp_attr_encap_subtlv *vnc_subtlvs; /* VNC-specific */
 #endif
-	/* EVPN MAC Mobility sequence number, if any. */
-	uint32_t mm_seqnum;
-	/* highest MM sequence number rxed in a MAC-IP route from an
-	 * ES peer (this includes both proxy and non-proxy MAC-IP
-	 * advertisements from ES peers).
-	 * This is only applicable to local paths in the VNI routing
-	 * table and derived from other imported/non-best paths.
-	 */
-	uint32_t mm_sync_seqnum;
-
-	/* EVPN local router-mac */
-	struct ethaddr rmac;
-
-	/* EVPN ES */
-	esi_t esi;

 	/* Nexthop type */
 	enum nexthop_types_t nh_type;
@@ -837,82 +838,161 @@ static inline void bgp_attr_set_originator_id(struct attr *attr, struct in_addr

 static inline uint8_t bgp_attr_get_es_flags(const struct attr *attr)
 {
-	return attr->es_flags;
+	return attr->extra ? attr->extra->es_flags : 0;
 }

 static inline void bgp_attr_set_es_flags(struct attr *attr, uint8_t es_flags)
 {
-	attr->es_flags = es_flags;
+	uint8_t old = bgp_attr_get_es_flags(attr);
+
+	if (es_flags && !old)
+		bgp_attr_extra_get(attr)->es_flags = es_flags;
+	else if (es_flags && old)
+		attr->extra->es_flags = es_flags; /* replace; refcnt unchanged */
+	else if (!es_flags && old) {
+		attr->extra->es_flags = 0;
+		bgp_attr_extra_put(attr);
+	}
 }

 static inline uint8_t bgp_attr_get_df_alg(const struct attr *attr)
 {
-	return attr->df_alg;
+	return attr->extra ? attr->extra->df_alg : 0;
 }

 static inline void bgp_attr_set_df_alg(struct attr *attr, uint8_t df_alg)
 {
-	attr->df_alg = df_alg;
+	uint8_t old = bgp_attr_get_df_alg(attr);
+
+	if (df_alg && !old)
+		bgp_attr_extra_get(attr)->df_alg = df_alg;
+	else if (df_alg && old)
+		attr->extra->df_alg = df_alg; /* replace; refcnt unchanged */
+	else if (!df_alg && old) {
+		attr->extra->df_alg = 0;
+		bgp_attr_extra_put(attr);
+	}
 }

 static inline uint8_t bgp_attr_get_evpn_flags(const struct attr *attr)
 {
-	return attr->evpn_flags;
+	return attr->extra ? attr->extra->evpn_flags : 0;
 }

 static inline void bgp_attr_set_evpn_flags(struct attr *attr, uint8_t evpn_flags)
 {
-	attr->evpn_flags = evpn_flags;
+	uint8_t old = bgp_attr_get_evpn_flags(attr);
+
+	if (evpn_flags && !old)
+		bgp_attr_extra_get(attr)->evpn_flags = evpn_flags;
+	else if (evpn_flags && old)
+		attr->extra->evpn_flags = evpn_flags; /* replace; refcnt unchanged */
+	else if (!evpn_flags && old) {
+		attr->extra->evpn_flags = 0;
+		bgp_attr_extra_put(attr);
+	}
 }

 static inline uint16_t bgp_attr_get_df_pref(const struct attr *attr)
 {
-	return attr->df_pref;
+	return attr->extra ? attr->extra->df_pref : 0;
 }

 static inline void bgp_attr_set_df_pref(struct attr *attr, uint16_t df_pref)
 {
-	attr->df_pref = df_pref;
+	uint16_t old = bgp_attr_get_df_pref(attr);
+
+	if (df_pref && !old)
+		bgp_attr_extra_get(attr)->df_pref = df_pref;
+	else if (df_pref && old)
+		attr->extra->df_pref = df_pref; /* replace; refcnt unchanged */
+	else if (!df_pref && old) {
+		attr->extra->df_pref = 0;
+		bgp_attr_extra_put(attr);
+	}
 }

 static inline uint32_t bgp_attr_get_mm_seqnum(const struct attr *attr)
 {
-	return attr->mm_seqnum;
+	return attr->extra ? attr->extra->mm_seqnum : 0;
 }

 static inline void bgp_attr_set_mm_seqnum(struct attr *attr, uint32_t mm_seqnum)
 {
-	attr->mm_seqnum = mm_seqnum;
+	uint32_t old = bgp_attr_get_mm_seqnum(attr);
+
+	if (mm_seqnum && !old)
+		bgp_attr_extra_get(attr)->mm_seqnum = mm_seqnum;
+	else if (mm_seqnum && old)
+		attr->extra->mm_seqnum = mm_seqnum; /* replace; refcnt unchanged */
+	else if (!mm_seqnum && old) {
+		attr->extra->mm_seqnum = 0;
+		bgp_attr_extra_put(attr);
+	}
 }

 static inline uint32_t bgp_attr_get_mm_sync_seqnum(const struct attr *attr)
 {
-	return attr->mm_sync_seqnum;
+	return attr->extra ? attr->extra->mm_sync_seqnum : 0;
 }

 static inline void bgp_attr_set_mm_sync_seqnum(struct attr *attr, uint32_t mm_sync_seqnum)
 {
-	attr->mm_sync_seqnum = mm_sync_seqnum;
+	uint32_t old = bgp_attr_get_mm_sync_seqnum(attr);
+
+	if (mm_sync_seqnum && !old)
+		bgp_attr_extra_get(attr)->mm_sync_seqnum = mm_sync_seqnum;
+	else if (mm_sync_seqnum && old)
+		attr->extra->mm_sync_seqnum = mm_sync_seqnum; /* replace; refcnt unchanged */
+	else if (!mm_sync_seqnum && old) {
+		attr->extra->mm_sync_seqnum = 0;
+		bgp_attr_extra_put(attr);
+	}
 }

 static inline const struct ethaddr *bgp_attr_get_rmac(const struct attr *attr)
 {
-	return &attr->rmac;
+	static const struct ethaddr zero_rmac;
+
+	return attr->extra ? &attr->extra->rmac : &zero_rmac;
 }

 static inline void bgp_attr_set_rmac(struct attr *attr, const struct ethaddr *rmac)
 {
-	attr->rmac = *rmac;
+	bool new_set = rmac && !is_zero_mac(rmac);
+	bool old_set = !is_zero_mac(bgp_attr_get_rmac(attr));
+
+	if (new_set && !old_set)
+		bgp_attr_extra_get(attr)->rmac = *rmac;
+	else if (new_set && old_set)
+		attr->extra->rmac = *rmac; /* replace; refcnt unchanged */
+	else if (!new_set && old_set) {
+		attr->extra->rmac = (struct ethaddr){};
+		bgp_attr_extra_put(attr);
+	}
 }

 static inline const esi_t *bgp_attr_get_esi(const struct attr *attr)
 {
-	return &attr->esi;
+	static const esi_t zero_esi;
+
+	return attr->extra ? &attr->extra->esi : &zero_esi;
 }

 static inline void bgp_attr_set_esi(struct attr *attr, const esi_t *esi)
 {
-	attr->esi = *esi;
+	static const esi_t zero_esi;
+	bool new_set = esi && memcmp(esi, &zero_esi, sizeof(zero_esi));
+	bool old_set = memcmp(bgp_attr_get_esi(attr), &zero_esi, sizeof(zero_esi));
+
+	if (new_set && !old_set)
+		bgp_attr_extra_get(attr)->esi = *esi;
+	else if (new_set && old_set)
+		attr->extra->esi = *esi; /* replace; refcnt unchanged */
+	else if (!new_set && old_set) {
+		attr->extra->esi = (esi_t){};
+		bgp_attr_extra_put(attr);
+	}
 }

 static inline struct bgp_route_evpn *
diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c
index 1bb79e49e5..b1fa9140c5 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -2138,8 +2138,7 @@ static int update_evpn_type5_route(struct bgp *bgp_vrf, struct bgp_path_info *or
 	/* uninten temporary */
 	if (!src_attr)
 		aspath_unintern(&attr.aspath);
-	else
-		bgp_attr_extra_discard(&attr);
+	bgp_attr_extra_discard(&attr);

 	return 0;
 }
@@ -3035,6 +3034,7 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn,

 	/* Unintern temporary. */
 	aspath_unintern(&attr.aspath);
+	bgp_attr_extra_discard(&attr);
 }

 static void update_type2_route(struct bgp *bgp, struct bgpevpn *vpn,