Commit 52465dbc58 for frr
commit 52465dbc583e13c58900b4b5f0bade100606ddf6
Author: Donald Sharp <sharpd@nvidia.com>
Date: Thu Nov 12 10:52:56 2026 -0500
bgpd: add accessors for the EVPN ESI
Add bgp_attr_get_esi() and bgp_attr_set_esi() and use them for every
read and write of the Ethernet Segment Identifier 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 6cf0529096..7cb20afcd2 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -1459,7 +1459,7 @@ bool attrhash_cmp(const void *p1, const void *p2)
IPV4_ADDR_SAME(&attr1->mp_nexthop_global_in, &attr2->mp_nexthop_global_in) &&
IPV4_ADDR_SAME(&attr1->originator_id, &attr2->originator_id) &&
overlay_index_same(attr1, attr2) &&
- !memcmp(&attr1->esi, &attr2->esi, sizeof(esi_t)) &&
+ !memcmp(bgp_attr_get_esi(attr1), bgp_attr_get_esi(attr2), sizeof(esi_t)) &&
bgp_attr_get_es_flags(attr1) == bgp_attr_get_es_flags(attr2) &&
bgp_attr_get_mm_seqnum(attr1) == bgp_attr_get_mm_seqnum(attr2) &&
bgp_attr_get_mm_sync_seqnum(attr1) == bgp_attr_get_mm_sync_seqnum(attr2) &&
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 399b416c41..9084c72af7 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -905,6 +905,16 @@ static inline void bgp_attr_set_rmac(struct attr *attr, const struct ethaddr *rm
attr->rmac = *rmac;
}
+static inline const esi_t *bgp_attr_get_esi(const struct attr *attr)
+{
+ return &attr->esi;
+}
+
+static inline void bgp_attr_set_esi(struct attr *attr, const esi_t *esi)
+{
+ attr->esi = *esi;
+}
+
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 9e6a371395..1bb79e49e5 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -1203,10 +1203,10 @@ struct bgp_dest *bgp_evpn_vni_node_lookup(const struct bgpevpn *vpn,
/*
* Add (update) or delete MACIP from zebra.
*/
-static enum zclient_send_status bgp_zebra_send_remote_macip(
- struct bgp *bgp, struct bgpevpn *vpn, const struct prefix_evpn *p,
- const struct ethaddr *mac, struct ipaddr *remote_vtep_ip, int add,
- uint8_t flags, uint32_t seq, esi_t *esi)
+static enum zclient_send_status
+bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, const struct prefix_evpn *p,
+ const struct ethaddr *mac, struct ipaddr *remote_vtep_ip, int add,
+ uint8_t flags, uint32_t seq, const esi_t *esi)
{
struct stream *s;
uint16_t ipa_len;
@@ -1713,10 +1713,9 @@ static void evpn_delete_old_local_route(struct bgp *bgp, struct bgpevpn *vpn,
(struct prefix_evpn *)bgp_dest_get_prefix(dest);
zlog_debug("local path deleted %pFX es %s; new-path-es %s", evp,
- esi_to_str(&old_local->attr->esi, esi_buf,
- sizeof(esi_buf)),
- new_select ? esi_to_str(&new_select->attr->esi,
- esi_buf2, sizeof(esi_buf2))
+ esi_to_str(bgp_attr_get_esi(old_local->attr), esi_buf, sizeof(esi_buf)),
+ new_select ? esi_to_str(bgp_attr_get_esi(new_select->attr), esi_buf2,
+ sizeof(esi_buf2))
: "");
}
@@ -2145,16 +2144,15 @@ static int update_evpn_type5_route(struct bgp *bgp_vrf, struct bgp_path_info *or
return 0;
}
-static void bgp_evpn_get_sync_info(struct bgp *bgp, esi_t *esi,
- struct bgp_dest *dest, uint32_t loc_seq,
- uint32_t *max_sync_seq, bool *active_on_peer,
+static void bgp_evpn_get_sync_info(struct bgp *bgp, const esi_t *esi, struct bgp_dest *dest,
+ uint32_t loc_seq, uint32_t *max_sync_seq, bool *active_on_peer,
bool *peer_router, bool *proxy_from_peer,
const struct ethaddr *mac)
{
struct bgp_path_info *tmp_pi;
struct bgp_path_info *second_best_path = NULL;
uint32_t tmp_mm_seq = 0;
- esi_t *tmp_esi;
+ const esi_t *tmp_esi;
int paths_eq;
struct ethaddr *tmp_mac;
bool mac_cmp = false;
@@ -2227,7 +2225,7 @@ static void update_evpn_route_entry_sync_info(struct bgp *bgp,
uint32_t loc_seq, bool setup_sync,
const struct ethaddr *mac)
{
- esi_t *esi;
+ const esi_t *esi;
uint8_t es_flags;
struct prefix_evpn *evp =
(struct prefix_evpn *)bgp_dest_get_prefix(dest);
@@ -2310,7 +2308,7 @@ static inline bool bgp_evpn_is_macip_with_l3vni(struct bgpevpn *vpn, const struc
* as well along with checking for mac-ip with l3vni.
*/
static inline bool bgp_evpn_route_add_l3_attrs_ok(struct bgpevpn *vpn, const struct prefix_evpn *p,
- esi_t *esi)
+ const esi_t *esi)
{
return bgp_evpn_is_macip_with_l3vni(vpn, p) && bgp_evpn_es_add_l3_attrs_ok(esi);
}
@@ -2589,7 +2587,7 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
SET_FLAG(es_flags, ATTR_ES_PROXY_ADVERT);
if (esi && bgp_evpn_is_esi_valid(esi)) {
- memcpy(&attr.esi, esi, sizeof(esi_t));
+ bgp_attr_set_esi(&attr, esi);
/* ES should not be marked local if ESI is in bypass */
if (bgp_evpn_is_esi_local_and_non_bypass(esi))
SET_FLAG(es_flags, ATTR_ES_IS_LOCAL);
@@ -2639,7 +2637,7 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
add_l3_attrs = bgp_evpn_route_add_l3_attrs_ok(vpn, p,
CHECK_FLAG(bgp_attr_get_es_flags(&attr),
ATTR_ES_IS_LOCAL)
- ? &attr.esi
+ ? bgp_attr_get_esi(&attr)
: NULL);
if (bgp->evpn_info)
@@ -2926,12 +2924,12 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
SET_FLAG(evpn_flags, ATTR_EVPN_FLAG_ROUTER);
}
bgp_attr_set_evpn_flags(&attr, evpn_flags);
- memcpy(&attr.esi, &local_pi->attr->esi, sizeof(esi_t));
+ bgp_attr_set_esi(&attr, bgp_attr_get_esi(local_pi->attr));
/*
* We are evaluating a change in local/non-local status.
* The es_flags need to align with the local ES status
*/
- if (bgp_evpn_is_esi_local_and_non_bypass(&attr.esi))
+ if (bgp_evpn_is_esi_local_and_non_bypass(bgp_attr_get_esi(&attr)))
SET_FLAG(es_flags, ATTR_ES_IS_LOCAL);
else
UNSET_FLAG(es_flags, ATTR_ES_IS_LOCAL);
@@ -2945,7 +2943,7 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
add_l3_attrs = bgp_evpn_route_add_l3_attrs_ok(vpn, &evp,
CHECK_FLAG(bgp_attr_get_es_flags(&attr),
ATTR_ES_IS_LOCAL)
- ? &attr.esi
+ ? bgp_attr_get_esi(&attr)
: NULL);
if (bgp->evpn_info)
@@ -2961,8 +2959,8 @@ 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, 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);
+ esi_to_str(bgp_attr_get_esi(&attr), buf3, sizeof(buf3)),
+ bgp_attr_get_es_flags(&attr), caller);
}
/* Update the route entry. */
@@ -3569,7 +3567,7 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf,
es_flags = bgp_attr_get_es_flags(&attr);
- bgp_evpn_es_vrf_use_nhg(bgp_vrf, &parent_pi->attr->esi, &use_l3nhg,
+ bgp_evpn_es_vrf_use_nhg(bgp_vrf, bgp_attr_get_esi(parent_pi->attr), &use_l3nhg,
&is_l3nhg_active, NULL);
if (use_l3nhg)
SET_FLAG(es_flags, ATTR_ES_L3_NHG_USE);
@@ -3767,10 +3765,8 @@ static int install_evpn_route_entry_in_vni_common(
/* If ESI is different or if its type has changed we
* need to reinstall the path in zebra
*/
- if ((old_local_es != new_local_es)
- || memcmp(&pi->attr->esi, &attr_new->esi,
- sizeof(attr_new->esi))) {
-
+ if ((old_local_es != new_local_es) ||
+ memcmp(bgp_attr_get_esi(pi->attr), bgp_attr_get_esi(attr_new), sizeof(esi_t))) {
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
zlog_debug("VNI %d path %pFX chg to %s es",
vpn->vni, &pi->net->rn->p,
@@ -4343,7 +4339,7 @@ static int bgp_evpn_route_rmac_self_check(struct bgp *bgp_vrf,
bool bgp_evpn_skip_vrf_import_of_local_es(struct bgp *bgp_vrf, const struct prefix_evpn *evp,
struct bgp_path_info *pi, int install)
{
- esi_t *esi;
+ const esi_t *esi;
if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE) {
esi = bgp_evpn_attr_get_esi(pi->attr);
@@ -5452,6 +5448,7 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi,
uint8_t num_labels = 0;
uint32_t eth_tag;
int ret = 0;
+ esi_t esi;
uint8_t es_flags;
/* Type-2 route should be either 33, 37 or 49 bytes or an
@@ -5484,10 +5481,11 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi,
/* Copy Ethernet Seg Identifier */
if (attr) {
- STREAM_GET(&attr->esi, pkt, sizeof(esi_t));
+ STREAM_GET(&esi, pkt, sizeof(esi_t));
+ bgp_attr_set_esi(attr, &esi);
es_flags = bgp_attr_get_es_flags(attr);
- if (bgp_evpn_is_esi_local_and_non_bypass(&attr->esi))
+ if (bgp_evpn_is_esi_local_and_non_bypass(bgp_attr_get_esi(attr)))
SET_FLAG(es_flags, ATTR_ES_IS_LOCAL);
else
UNSET_FLAG(es_flags, ATTR_ES_IS_LOCAL);
@@ -5847,7 +5845,7 @@ static void evpn_mpattr_encode_type5(struct stream *s, const struct prefix *p,
stream_putc(s, 8 + 10 + 4 + 1 + len + 3);
stream_put(s, prd->val, 8);
if (attr && bre && bre->type == OVERLAY_INDEX_ESI)
- stream_put(s, &attr->esi, sizeof(esi_t));
+ stream_put(s, bgp_attr_get_esi(attr), sizeof(esi_t));
else
stream_put(s, 0, sizeof(esi_t));
stream_putl(s, p_evpn_p->prefix_addr.eth_tag);
@@ -7275,7 +7273,7 @@ void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
stream_putc(s, len);
stream_put(s, prd->val, 8); /* RD */
if (attr)
- stream_put(s, &attr->esi, ESI_BYTES);
+ stream_put(s, bgp_attr_get_esi(attr), ESI_BYTES);
else
stream_put(s, 0, 10);
stream_putl(s, evp->prefix.macip_addr.eth_tag); /* Ethernet Tag ID */
diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c
index 420d81f223..fdb9ce91a0 100644
--- a/bgpd/bgp_evpn_mh.c
+++ b/bgpd/bgp_evpn_mh.c
@@ -1744,7 +1744,7 @@ static void bgp_evpn_path_es_unlink(struct bgp_path_es_info *es_info)
*/
}
-void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni, esi_t *esi)
+void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni, const esi_t *esi)
{
struct bgp_path_es_info *es_info;
struct bgp_evpn_es *es;
@@ -2200,7 +2200,7 @@ static void bgp_evpn_es_remote_info_re_eval(struct bgp_evpn_es *es)
/* If ES is present and local it needs to be active/oper-up for
* including L3 EC
*/
-bool bgp_evpn_es_add_l3_attrs_ok(esi_t *esi)
+bool bgp_evpn_es_add_l3_attrs_ok(const esi_t *esi)
{
struct bgp_evpn_es *es;
@@ -2485,7 +2485,7 @@ static void bgp_evpn_local_es_do_del(struct bgp *bgp, struct bgp_evpn_es *es)
bgp_evpn_es_local_info_clear(es, false);
}
-bool bgp_evpn_is_esi_local_and_non_bypass(esi_t *esi)
+bool bgp_evpn_is_esi_local_and_non_bypass(const esi_t *esi)
{
struct bgp_evpn_es *es = NULL;
@@ -3349,9 +3349,8 @@ void bgp_evpn_es_evi_vrf_ref(struct bgpevpn *vpn)
* in zebra.
* - if L3NHG has been activated install the route via that L3NHG
*/
-void bgp_evpn_es_vrf_use_nhg(struct bgp *bgp_vrf, esi_t *esi, bool *use_l3nhg,
- bool *is_l3nhg_active,
- struct bgp_evpn_es_vrf **es_vrf_p)
+void bgp_evpn_es_vrf_use_nhg(struct bgp *bgp_vrf, const esi_t *esi, bool *use_l3nhg,
+ bool *is_l3nhg_active, struct bgp_evpn_es_vrf **es_vrf_p)
{
struct bgp_evpn_es *es;
struct bgp_evpn_es_vrf *es_vrf;
@@ -3378,7 +3377,7 @@ void bgp_evpn_es_vrf_use_nhg(struct bgp *bgp_vrf, esi_t *esi, bool *use_l3nhg,
bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf, struct bgp_path_info *pi,
uint32_t *nhg_p)
{
- esi_t *esi;
+ const esi_t *esi;
struct bgp_evpn_es_vrf *es_vrf = NULL;
struct bgp_path_info *parent_pi;
struct bgp_dest *bd;
diff --git a/bgpd/bgp_evpn_mh.h b/bgpd/bgp_evpn_mh.h
index 0cef7650a3..8cdf72a2f5 100644
--- a/bgpd/bgp_evpn_mh.h
+++ b/bgpd/bgp_evpn_mh.h
@@ -348,14 +348,14 @@ static inline int bgp_evpn_is_es_local(struct bgp_evpn_es *es)
}
extern esi_t *zero_esi;
-static inline bool bgp_evpn_is_esi_valid(esi_t *esi)
+static inline bool bgp_evpn_is_esi_valid(const esi_t *esi)
{
return !!memcmp(esi, zero_esi, sizeof(esi_t));
}
-static inline esi_t *bgp_evpn_attr_get_esi(struct attr *attr)
+static inline const esi_t *bgp_evpn_attr_get_esi(const struct attr *attr)
{
- return attr ? &attr->esi : zero_esi;
+ return attr ? bgp_attr_get_esi(attr) : zero_esi;
}
static inline bool bgp_evpn_attr_is_sync(struct attr *attr)
@@ -439,23 +439,21 @@ void bgp_evpn_es_evi_show_vni(struct vty *vty, vni_t vni,
void bgp_evpn_es_evi_show(struct vty *vty, bool uj, bool detail);
struct bgp_evpn_es *bgp_evpn_es_find(const esi_t *esi);
extern void bgp_evpn_vrf_es_init(struct bgp *bgp_vrf);
-extern bool bgp_evpn_is_esi_local_and_non_bypass(esi_t *esi);
+extern bool bgp_evpn_is_esi_local_and_non_bypass(const esi_t *esi);
extern void bgp_evpn_es_vrf_deref(struct bgp_evpn_es_evi *es_evi);
extern void bgp_evpn_es_vrf_ref(struct bgp_evpn_es_evi *es_evi,
struct bgp *bgp_vrf);
extern void bgp_evpn_path_mh_info_free(struct bgp_path_mh_info *mh_info);
-extern void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni,
- esi_t *esi);
+extern void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni, const esi_t *esi);
extern bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf,
struct bgp_path_info *pi, uint32_t *nhg_p);
extern void bgp_evpn_es_vrf_show(struct vty *vty, bool uj,
struct bgp_evpn_es *es);
extern void bgp_evpn_es_vrf_show_esi(struct vty *vty, esi_t *esi, bool uj);
extern void bgp_evpn_switch_ead_evi_rx(void);
-extern bool bgp_evpn_es_add_l3_attrs_ok(esi_t *esi);
-extern void bgp_evpn_es_vrf_use_nhg(struct bgp *bgp_vrf, esi_t *esi,
- bool *use_l3nhg, bool *is_l3nhg_active,
- struct bgp_evpn_es_vrf **es_vrf_p);
+extern bool bgp_evpn_es_add_l3_attrs_ok(const esi_t *esi);
+extern void bgp_evpn_es_vrf_use_nhg(struct bgp *bgp_vrf, const esi_t *esi, bool *use_l3nhg,
+ bool *is_l3nhg_active, struct bgp_evpn_es_vrf **es_vrf_p);
extern void bgp_evpn_nh_init(struct bgp *bgp_vrf);
extern void bgp_evpn_nh_finish(struct bgp *bgp_vrf);
extern void bgp_evpn_nh_show(struct vty *vty, bool uj);
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 9e2934caf9..cc67d8fa99 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -1017,8 +1017,8 @@ int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
uint32_t new_mm_seq;
uint32_t exist_mm_seq;
int nh_cmp;
- esi_t *exist_esi;
- esi_t *new_esi;
+ const esi_t *exist_esi;
+ const esi_t *new_esi;
bool same_esi;
bool old_proxy;
bool new_proxy;
@@ -9104,7 +9104,8 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
ipaddr_set_v6(&bre->gw_ip, &bgp_static->gatewayIp.u.prefix6);
bgp_attr_set_evpn_overlay(&attr, bre);
}
- memcpy(&attr.esi, bgp_static->eth_s_id, sizeof(esi_t));
+ if (bgp_static->eth_s_id)
+ bgp_attr_set_esi(&attr, bgp_static->eth_s_id);
if (bgp_static->encap_tunneltype == BGP_ENCAP_TYPE_VXLAN) {
struct bgp_encap_type_vxlan bet;
memset(&bet, 0, sizeof(bet));
@@ -13083,10 +13084,10 @@ void route_vty_out(struct vty *vty, const struct prefix *p, struct bgp_path_info
vty_out(vty, "%s", bgp_origin_str[attr->origin]);
if (json_paths) {
- if (bgp_evpn_is_esi_valid(&attr->esi)) {
+ if (bgp_evpn_is_esi_valid(bgp_attr_get_esi(attr))) {
json_object_string_add(json_path, "esi",
- esi_to_str(&attr->esi,
- esi_buf, sizeof(esi_buf)));
+ esi_to_str(bgp_attr_get_esi(attr), esi_buf,
+ sizeof(esi_buf)));
}
if ((safi == SAFI_EVPN || safi == SAFI_UNREACH) &&
bgp_attr_exists(attr, BGP_ATTR_EXT_COMMUNITIES)) {
@@ -13141,11 +13142,11 @@ void route_vty_out(struct vty *vty, const struct prefix *p, struct bgp_path_info
vty_out(vty, "\n");
if (safi == SAFI_EVPN) {
- if (bgp_evpn_is_esi_valid(&attr->esi)) {
+ if (bgp_evpn_is_esi_valid(bgp_attr_get_esi(attr))) {
/* XXX - add these params to the json out */
vty_out(vty, "%*s", 20, " ");
vty_out(vty, "ESI:%s",
- esi_to_str(&attr->esi, esi_buf,
+ esi_to_str(bgp_attr_get_esi(attr), esi_buf,
sizeof(esi_buf)));
vty_out(vty, "\n");
@@ -13741,7 +13742,7 @@ static void route_vty_out_detail_es_info(struct vty *vty,
bool peer_active = !!CHECK_FLAG(bgp_attr_get_es_flags(attr), ATTR_ES_PEER_ACTIVE);
bool peer_proxy = !!CHECK_FLAG(bgp_attr_get_es_flags(attr), ATTR_ES_PEER_PROXY);
- esi_to_str(&attr->esi, esi_buf, sizeof(esi_buf));
+ esi_to_str(bgp_attr_get_esi(attr), esi_buf, sizeof(esi_buf));
if (json_path) {
json_object *json_es_info = NULL;
@@ -14450,10 +14451,8 @@ skip_nexthop:
"used");
}
- if (safi == SAFI_EVPN &&
- bgp_evpn_is_esi_valid(&attr->esi)) {
+ if (safi == SAFI_EVPN && bgp_evpn_is_esi_valid(bgp_attr_get_esi(attr)))
route_vty_out_detail_es_info(vty, path, attr, json_path);
- }
/* Line 3 display Origin, Med, Locpref, Weight, Tag, valid,
* Int/Ext/Local, Atomic, best */