Commit 0dc3062a8c for frr

commit 0dc3062a8ccf038eaffa7ec1e1b9bf6da7e4b452
Author: Donald Sharp <sharpd@nvidia.com>
Date:   Thu Nov 12 10:48:59 2026 -0500

    bgpd: add accessors for the EVPN router MAC

    Add bgp_attr_get_rmac() and bgp_attr_set_rmac() and use them for
    every read and write of the router MAC stored on a route attribute.

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

diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index c04ccd2e26..6cf0529096 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -1415,7 +1415,7 @@ unsigned int attrhash_key_make(const void *p)
 	MIX(bgp_attr_get_pmsi_tnl_type(attr));
 	if (bgp_attr_get_pmsi_tnl_type(attr) == PMSI_TNLTYPE_INGR_REPL)
 		key = jhash(bgp_attr_get_tunn_id(attr)->s6_addr, IPV6_MAX_BYTELEN, key);
-	key = jhash(&attr->rmac, sizeof(attr->rmac), key);
+	key = jhash(bgp_attr_get_rmac(attr), sizeof(struct ethaddr), key);
 	if (bgp_attr_get_nhc(attr))
 		MIX(bgp_nhc_hash_key_make(bgp_attr_get_nhc(attr)));
 	if (bgp_attr_get_ls_attr(attr))
@@ -1476,7 +1476,8 @@ bool attrhash_cmp(const void *p1, const void *p2)
 		    attr1->nh_type == attr2->nh_type && attr1->bh_type == attr2->bh_type &&
 		    bgp_attr_get_otc(attr1) == bgp_attr_get_otc(attr2) &&
 		    bgp_attr_get_partial_attrs(attr1) == bgp_attr_get_partial_attrs(attr2) &&
-		    !memcmp(&attr1->rmac, &attr2->rmac, sizeof(struct ethaddr)) &&
+		    !memcmp(bgp_attr_get_rmac(attr1), bgp_attr_get_rmac(attr2),
+			    sizeof(struct ethaddr)) &&
 		    bgp_nhc_same(bgp_attr_get_nhc(attr1), bgp_attr_get_nhc(attr2)) &&
 		    bgp_ls_attr_same(bgp_attr_get_ls_attr(attr1), bgp_attr_get_ls_attr(attr2)) &&
 		    (bgp_attr_get_pmsi_tnl_type(attr1) == bgp_attr_get_pmsi_tnl_type(attr2)) &&
@@ -3504,6 +3505,7 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
 	bgp_encap_types tun_type = BGP_ENCAP_TYPE_VXLAN;/*Default tunnel type*/
 	uint8_t df_alg;
 	uint8_t evpn_flags;
+	struct ethaddr rmac;

 	if (length == 0) {
 		bgp_attr_set_ecommunity(attr, NULL);
@@ -3551,13 +3553,13 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
 		bgp_attr_set_es_flags(attr, bgp_attr_get_es_flags(attr) | ATTR_ES_PROXY_ADVERT);

 	/* Extract the Rmac, if any */
-	if (bgp_attr_rmac(attr, &attr->rmac)) {
-		if (bgp_debug_update(peer, NULL, NULL, 1)
-		    && bgp_mac_exist(&attr->rmac))
+	if (bgp_attr_rmac(attr, &rmac)) {
+		bgp_attr_set_rmac(attr, &rmac);
+		if (bgp_debug_update(peer, NULL, NULL, 1) && bgp_mac_exist(bgp_attr_get_rmac(attr)))
 			zlog_debug("%s: router mac %pEA is self mac", __func__,
-				   &attr->rmac);
+				   bgp_attr_get_rmac(attr));

-		frrtrace(1, frr_bgp, upd_rmac_is_self_mac, &attr->rmac);
+		frrtrace(1, frr_bgp, upd_rmac_is_self_mac, bgp_attr_get_rmac(attr));
 	}

 	/* Get the tunnel type from encap extended community */
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index c3c492a77d..399b416c41 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -895,6 +895,16 @@ static inline void bgp_attr_set_mm_sync_seqnum(struct attr *attr, uint32_t mm_sy
 	attr->mm_sync_seqnum = mm_sync_seqnum;
 }

+static inline const struct ethaddr *bgp_attr_get_rmac(const struct attr *attr)
+{
+	return &attr->rmac;
+}
+
+static inline void bgp_attr_set_rmac(struct attr *attr, const struct ethaddr *rmac)
+{
+	attr->rmac = *rmac;
+}
+
 static inline struct bgp_route_evpn *
 bgp_attr_get_evpn_overlay(const struct attr *attr)
 {
diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c
index 39ea0a0ffe..9e6a371395 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -942,7 +942,7 @@ static void bgp_evpn_get_rmac_nexthop(struct bgpevpn *vpn,
 {
 	struct bgp *bgp_vrf = vpn->bgp_vrf;

-	memset(&attr->rmac, 0, sizeof(struct ethaddr));
+	bgp_attr_set_rmac(attr, &(struct ethaddr){ 0 });
 	if (!bgp_vrf)
 		return;

@@ -960,11 +960,10 @@ static void bgp_evpn_get_rmac_nexthop(struct bgpevpn *vpn,
 	    bgp_vrf->evpn_info->is_anycast_mac &&
 	    bgp_evpn_pip_ip_usable(bgp_vrf, &vpn->originator_ip)) {
 		/* copy sys rmac and the system IP of the VTEP-IP family */
-		memcpy(&attr->rmac, &bgp_vrf->evpn_info->pip_rmac,
-		       ETH_ALEN);
+		bgp_attr_set_rmac(attr, &bgp_vrf->evpn_info->pip_rmac);
 		bgp_evpn_vtep_ip_to_attr_nh(&bgp_vrf->evpn_info->pip_ip, attr);
 	} else
-		memcpy(&attr->rmac, &bgp_vrf->rmac, ETH_ALEN);
+		bgp_attr_set_rmac(attr, &bgp_vrf->rmac);
 }

 /*
@@ -1382,8 +1381,8 @@ static void build_evpn_type5_route_extcomm(struct bgp *bgp_vrf, struct attr *att
 		ecommunity_append_val_unchecked(ecom, &fq_rt->ecom_val);

 	/* add the router mac extended community */
-	if (!is_zero_mac(&attr->rmac)) {
-		encode_rmac_extcomm(&eval_tmp, &attr->rmac);
+	if (!is_zero_mac(bgp_attr_get_rmac(attr))) {
+		encode_rmac_extcomm(&eval_tmp, bgp_attr_get_rmac(attr));
 		ecommunity_add_val(ecom, &eval_tmp, true, true);
 	}

@@ -1449,7 +1448,7 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr, int

 	/* Add RMAC, if told to. */
 	if (add_l3_ecomm) {
-		encode_rmac_extcomm(&eval_tmp, &attr->rmac);
+		encode_rmac_extcomm(&eval_tmp, bgp_attr_get_rmac(attr));
 		ecommunity_add_val(ecom, &eval_tmp, true, true);
 	}

@@ -2078,10 +2077,11 @@ static int update_evpn_type5_route(struct bgp *bgp_vrf, struct bgp_path_info *or

 	if (bgp_debug_zebra(NULL))
 		zlog_debug("VRF %s type-5 route evp %pFX RMAC %pEA nexthop %pI4 mp_nexthop %pI6 orig vtep %pIA",
-			   vrf_id_to_name(bgp_vrf->vrf_id), evp, &attr.rmac, &attr.nexthop,
-			   &attr.mp_nexthop_global, &bgp_vrf->originator_ip);
+			   vrf_id_to_name(bgp_vrf->vrf_id), evp, bgp_attr_get_rmac(&attr),
+			   &attr.nexthop, &attr.mp_nexthop_global, &bgp_vrf->originator_ip);

-	frrtrace(4, frr_bgp, evpn_advertise_type5, bgp_vrf->vrf_id, evp, &attr.rmac, &vtep_ip);
+	frrtrace(4, frr_bgp, evpn_advertise_type5, bgp_vrf->vrf_id, evp, bgp_attr_get_rmac(&attr),
+		 &vtep_ip);

 	if (src_safi == SAFI_MPLS_VPN) {
 		/* Set tnl_type to BGP_ENCAP_TYPE_RESERVED for VPN routes so
@@ -2624,13 +2624,10 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
 	if (bgp_debug_zebra(NULL)) {
 		char buf3[ESI_STR_LEN];

-		zlog_debug(
-			"VRF %s vni %u type-%u route evp %pFX RMAC %pEA nexthop %pIA esi %s",
-			vpn->bgp_vrf ? vrf_id_to_name(vpn->bgp_vrf->vrf_id)
-				     : "None",
-			vpn->vni, p->prefix.route_type, p, &attr.rmac,
-			&vpn->originator_ip,
-			esi_to_str(esi, buf3, sizeof(buf3)));
+		zlog_debug("VRF %s vni %u type-%u route evp %pFX RMAC %pEA nexthop %pIA esi %s",
+			   vpn->bgp_vrf ? vrf_id_to_name(vpn->bgp_vrf->vrf_id) : "None", vpn->vni,
+			   p->prefix.route_type, p, bgp_attr_get_rmac(&attr), &vpn->originator_ip,
+			   esi_to_str(esi, buf3, sizeof(buf3)));
 	}

 	vni2label(vpn->vni, &(attr.label));
@@ -2963,7 +2960,7 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn,

 		zlog_debug("VRF %s vni %u evp %pFX RMAC %pEA nexthop %pI4 esi %s esf 0x%x from %s",
 			   vpn->bgp_vrf ? vrf_id_to_name(vpn->bgp_vrf->vrf_id) : " ", vpn->vni,
-			   &evp, &attr.rmac, &attr.mp_nexthop_global_in,
+			   &evp, bgp_attr_get_rmac(&attr), &attr.mp_nexthop_global_in,
 			   esi_to_str(&attr.esi, buf3, sizeof(buf3)), bgp_attr_get_es_flags(&attr),
 			   caller);
 	}
@@ -4314,7 +4311,7 @@ static int bgp_evpn_route_rmac_self_check(struct bgp *bgp_vrf,
 	 * SVI comes up with MAC and stored in hash, triggers
 	 * bgp_mac_rescan_all_evpn_tables.
 	 */
-	if (memcmp(&bgp_vrf->rmac, &pi->attr->rmac, ETH_ALEN) == 0) {
+	if (memcmp(&bgp_vrf->rmac, bgp_attr_get_rmac(pi->attr), ETH_ALEN) == 0) {
 		/* Only do expensive string formatting if debug or trace is enabled. */
 		if (bgp_debug_update(pi->peer, NULL, NULL, 1) ||
 		    frrtrace_enabled(frr_bgp, upd_prefix_denied_due_to_self_mac)) {
@@ -4870,7 +4867,7 @@ static int install_uninstall_type5_route_in_vpn_rib(struct bgp *bgp, struct pref
 				 NULL);
 	bgp_attr_set_ecommunity(&attr, ecom);
 	attr.encap_tunneltype = BGP_ENCAP_TYPE_RESERVED;
-	memset(&attr.rmac, 0, sizeof(attr.rmac));
+	bgp_attr_set_rmac(&attr, &(struct ethaddr){ 0 });

 	if (!vpn_pi) {
 		attr_new = bgp_attr_intern(&attr);
@@ -5785,16 +5782,16 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,
 	else if (!ipaddr_is_zero(&evpn->gw_ip))
 		evpn->type = OVERLAY_INDEX_GATEWAY_IP;
 	if (attr) {
-		if (is_zero_mac(&attr->rmac) &&
-		    !bgp_evpn_is_esi_valid(&evpn->eth_s_id) &&
-		    ipaddr_is_zero(&evpn->gw_ip) && label == 0) {
+		if (is_zero_mac(bgp_attr_get_rmac(attr)) &&
+		    !bgp_evpn_is_esi_valid(&evpn->eth_s_id) && ipaddr_is_zero(&evpn->gw_ip) &&
+		    label == 0) {
 			flog_err(EC_BGP_EVPN_ROUTE_INVALID,
 				 "%s - Rx EVPN Type-5 ESI, gateway-IP, RMAC and label all zero",
 				 peer->host);
 			is_valid_update = false;
 		}

-		if (is_mcast_mac(&attr->rmac) || is_bcast_mac(&attr->rmac))
+		if (is_mcast_mac(bgp_attr_get_rmac(attr)) || is_bcast_mac(bgp_attr_get_rmac(attr)))
 			is_valid_update = false;
 	}

@@ -9800,7 +9797,7 @@ void bgp_evpn_fill_rmac_nh_to_attr(struct bgp *bgp_vrf, struct attr *attr, struc
 	 * use anycast-IP as nexthop and anycast RMAC.
 	 */
 	if (!use_pip) {
-		memcpy(&attr->rmac, &bgp_vrf->rmac, ETH_ALEN);
+		bgp_attr_set_rmac(attr, &bgp_vrf->rmac);
 		if (IS_IPADDR_V4(&bgp_vrf->originator_ip)) {
 			attr->nexthop = bgp_vrf->originator_ip.ipaddr_v4;
 			attr->mp_nexthop_global_in = bgp_vrf->originator_ip.ipaddr_v4;
@@ -9814,7 +9811,7 @@ void bgp_evpn_fill_rmac_nh_to_attr(struct bgp *bgp_vrf, struct attr *attr, struc
 			*vtep_ip = bgp_vrf->originator_ip;
 	} else {
 		/* copy sys rmac and the system IP of the VTEP-IP family */
-		memcpy(&attr->rmac, &bgp_vrf->evpn_info->pip_rmac, ETH_ALEN);
+		bgp_attr_set_rmac(attr, &bgp_vrf->evpn_info->pip_rmac);
 		bgp_evpn_vtep_ip_to_attr_nh(&bgp_vrf->evpn_info->pip_ip, attr);
 		if (vtep_ip)
 			*vtep_ip = bgp_vrf->evpn_info->pip_ip;
diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c
index 3ae1ea0104..420d81f223 100644
--- a/bgpd/bgp_evpn_mh.c
+++ b/bgpd/bgp_evpn_mh.c
@@ -4791,7 +4791,7 @@ static struct bgp_evpn_nh *bgp_evpn_nh_add(struct bgp *bgp_vrf,
 	/* Setup ref_pi when the nh is created */
 	if (CHECK_FLAG(pi->flags, BGP_PATH_VALID) && pi->attr) {
 		n->ref_pi = pi;
-		memcpy(&n->rmac, &pi->attr->rmac, ETH_ALEN);
+		memcpy(&n->rmac, bgp_attr_get_rmac(pi->attr), ETH_ALEN);
 	}

 	if (BGP_DEBUG(evpn_mh, EVPN_MH_ES))
@@ -4914,8 +4914,8 @@ static void bgp_evpn_nh_update_ref_pi(struct bgp_evpn_nh *nh)
 		/* If we have a new pi copy rmac from it and update
 		 * zebra if the new rmac is different
 		 */
-		if (memcmp(&nh->rmac, &nh->ref_pi->attr->rmac, ETH_ALEN)) {
-			memcpy(&nh->rmac, &nh->ref_pi->attr->rmac, ETH_ALEN);
+		if (memcmp(&nh->rmac, bgp_attr_get_rmac(nh->ref_pi->attr), ETH_ALEN)) {
+			memcpy(&nh->rmac, bgp_attr_get_rmac(nh->ref_pi->attr), ETH_ALEN);
 			bgp_evpn_nh_zebra_update(nh, true);
 		}
 		break;
diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h
index 85167f89cd..d681cefa79 100644
--- a/bgpd/bgp_evpn_private.h
+++ b/bgpd/bgp_evpn_private.h
@@ -632,8 +632,7 @@ static inline void encode_esi_label_extcomm(struct ecommunity_val *eval,
 		eval->val[2] |= (1 << 0);
 }

-static inline void encode_rmac_extcomm(struct ecommunity_val *eval,
-				       struct ethaddr *rmac)
+static inline void encode_rmac_extcomm(struct ecommunity_val *eval, const struct ethaddr *rmac)
 {
 	memset(eval, 0, sizeof(*eval));
 	eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
diff --git a/bgpd/bgp_mac.c b/bgpd/bgp_mac.c
index 1d942da948..e06c54d3b5 100644
--- a/bgpd/bgp_mac.c
+++ b/bgpd/bgp_mac.c
@@ -166,8 +166,8 @@ static void bgp_process_mac_rescan_table(struct bgp *bgp, struct peer *peer,
 			 * If the mac address is not the same then
 			 * we don't care and since we are looking
 			 */
-			if ((memcmp(&pi->attr->rmac, macaddr, ETH_ALEN) != 0)
-			    && !dest_affected)
+			if ((memcmp(bgp_attr_get_rmac(pi->attr), macaddr, ETH_ALEN) != 0) &&
+			    !dest_affected)
 				continue;

 			num_labels = BGP_PATH_INFO_NUM_LABELS(pi);
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 96584d5687..9e2934caf9 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -6556,7 +6556,8 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
 		goto filtered;
 	}

-	if (safi == SAFI_EVPN && (bgp_mac_entry_exists(p) || bgp_mac_exist(&attr->rmac))) {
+	if (safi == SAFI_EVPN &&
+	    (bgp_mac_entry_exists(p) || bgp_mac_exist(bgp_attr_get_rmac(attr)))) {
 		peer->stat_pfx_nh_invalid++;
 		reason = "self mac;";
 		bgp_attr_flush(&new_attr);
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 6a3381873a..b20043d3a5 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -1515,7 +1515,7 @@ route_set_evpn_router_mac(void *rule, const struct prefix *prefix, void *object)
 	}

 	bgp_attr_set_ecommunity(path->attr, new_ecom);
-	memcpy(&path->attr->rmac, rmac, ETH_ALEN);
+	bgp_attr_set_rmac(path->attr, rmac);

 	return RMAP_OKAY;
 }
diff --git a/bgpd/bgp_trace.h b/bgpd/bgp_trace.h
index 67b149b599..1a9b9c1e40 100644
--- a/bgpd/bgp_trace.h
+++ b/bgpd/bgp_trace.h
@@ -577,7 +577,7 @@ TRACEPOINT_EVENT(
 	frr_bgp,
 	evpn_advertise_type5,
 	TP_ARGS(vrf_id_t, vrf, const struct prefix_evpn *, pfx,
-		struct ethaddr *, rmac, struct ipaddr *, vtep),
+		const struct ethaddr *, rmac, struct ipaddr *, vtep),
 	TP_FIELDS(
 		ctf_integer(int, vrf_id, vrf)
 		ctf_array(unsigned char, ip, &pfx->prefix.prefix_addr.ip,
@@ -1202,7 +1202,7 @@ TRACEPOINT_LOGLEVEL(frr_bgp, upd_ignoring_non_ll_nexthop, TRACE_INFO)
 TRACEPOINT_EVENT(
 	frr_bgp,
 	upd_rmac_is_self_mac,
-	TP_ARGS(struct ethaddr *, rmac),
+	TP_ARGS(const struct ethaddr *, rmac),
 	TP_FIELDS(
 		ctf_array(unsigned char, rmac, rmac, sizeof(struct ethaddr))
 	)
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 3dfd508a62..325665c13b 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -1482,7 +1482,7 @@ static void bgp_zebra_announce_parse_nexthop(struct bgp_path_info *info, const s
 		}

 		if (is_evpn && !(bre && bre->type == OVERLAY_INDEX_GATEWAY_IP))
-			memcpy(&api_nh->rmac, &(mpinfo->attr->rmac),
+			memcpy(&api_nh->rmac, bgp_attr_get_rmac(mpinfo->attr),
 			       sizeof(struct ethaddr));

 		api_nh->weight = nh_weight;