* format accepted: AA:BB:CC:DD:EE:FF:GG:HH:II:JJ
* if id is null, check only is done
*/
-bool str2esi(const char *str, struct eth_segment_id *id)
+bool str2esi(const char *str, esi_t *id)
{
- unsigned int a[ESI_LEN];
+ unsigned int a[ESI_BYTES];
int i;
if (!str)
return false;
if (sscanf(str, "%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x", a + 0, a + 1,
a + 2, a + 3, a + 4, a + 5, a + 6, a + 7, a + 8, a + 9)
- != ESI_LEN) {
+ != ESI_BYTES) {
/* error in incoming str length */
return false;
}
/* valid mac address */
if (!id)
return true;
- for (i = 0; i < ESI_LEN; ++i)
+ for (i = 0; i < ESI_BYTES; ++i)
id->val[i] = a[i] & 0xff;
return true;
}
-char *esi2str(struct eth_segment_id *id)
-{
- char *ptr;
- uint8_t *val;
-
- if (!id)
- return NULL;
-
- val = id->val;
- ptr = XMALLOC(MTYPE_TMP,
- (ESI_LEN * 2 + ESI_LEN - 1 + 1) * sizeof(char));
-
- snprintf(ptr, (ESI_LEN * 2 + ESI_LEN - 1 + 1),
- "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", val[0],
- val[1], val[2], val[3], val[4], val[5], val[6], val[7], val[8],
- val[9]);
-
- return ptr;
-}
-
char *ecom_mac2str(char *ecom_mac)
{
char *en;
return false;
}
-
-extern bool is_zero_esi(const struct eth_segment_id *esi)
-{
- int i;
-
- for (i = 0; i < ESI_LEN; i++)
- if (esi->val[i])
- return false;
-
- return true;
-}
#ifndef _QUAGGA_BGP_ATTR_EVPN_H
#define _QUAGGA_BGP_ATTR_EVPN_H
-/* value of first byte of ESI */
-#define ESI_TYPE_ARBITRARY 0 /* */
-#define ESI_TYPE_LACP 1 /* <> */
-#define ESI_TYPE_BRIDGE 2 /* <Root bridge Mac-6B>:<Root Br Priority-2B>:00 */
-#define ESI_TYPE_MAC 3 /* <Syst Mac Add-6B>:<Local Discriminator Value-3B> */
-#define ESI_TYPE_ROUTER 4 /* <RouterId-4B>:<Local Discriminator Value-4B> */
-#define ESI_TYPE_AS 5 /* <AS-4B>:<Local Discriminator Value-4B> */
-
-#define MAX_ESI {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}
-#define ESI_LEN 10
-
#define MAX_ET 0xffffffff
struct attr;
-/* EVPN ESI */
-struct eth_segment_id {
- uint8_t val[ESI_LEN];
-};
-
union gw_addr {
struct in_addr ipv4;
struct in6_addr ipv6;
};
struct bgp_route_evpn {
- struct eth_segment_id eth_s_id;
union gw_addr gw_ip;
};
-extern bool str2esi(const char *str, struct eth_segment_id *id);
-extern char *esi2str(struct eth_segment_id *id);
+extern bool str2esi(const char *str, esi_t *id);
extern char *ecom_mac2str(char *ecom_mac);
extern void bgp_add_routermac_ecom(struct attr *attr,
extern bool is_zero_gw_ip(const union gw_addr *gw_ip, afi_t afi);
-extern bool is_zero_esi(const struct eth_segment_id *esi);
#endif /* _QUAGGA_BGP_ATTR_EVPN_H */
#include "bgpd/bgp_encap_types.h"
#include "bgpd/bgp_encap_tlv.h"
#include "bgpd/bgp_evpn.h"
+#include "bgpd/bgp_evpn_mh.h"
#include "bgpd/bgp_evpn_vty.h"
#include "bgpd/bgp_flowspec.h"
#include "bgpd/bgp_flowspec_util.h"
}
static void overlay_index_update(struct attr *attr,
- struct eth_segment_id *eth_s_id,
union gw_addr *gw_ip)
{
if (!attr)
return;
-
- if (eth_s_id == NULL) {
- memset(&(attr->evpn_overlay.eth_s_id), 0,
- sizeof(struct eth_segment_id));
- } else {
- memcpy(&(attr->evpn_overlay.eth_s_id), eth_s_id,
- sizeof(struct eth_segment_id));
- }
if (gw_ip == NULL) {
memset(&(attr->evpn_overlay.gw_ip), 0, sizeof(union gw_addr));
} else {
}
static bool overlay_index_equal(afi_t afi, struct bgp_path_info *path,
- struct eth_segment_id *eth_s_id,
union gw_addr *gw_ip)
{
- struct eth_segment_id *path_eth_s_id, *path_eth_s_id_remote;
union gw_addr *path_gw_ip, *path_gw_ip_remote;
union {
- struct eth_segment_id esi;
+ esi_t esi;
union gw_addr ip;
} temp;
if (afi != AFI_L2VPN)
return true;
- path_eth_s_id = &(path->attr->evpn_overlay.eth_s_id);
path_gw_ip = &(path->attr->evpn_overlay.gw_ip);
if (gw_ip == NULL) {
} else
path_gw_ip_remote = gw_ip;
- if (eth_s_id == NULL) {
- memset(&temp, 0, sizeof(temp));
- path_eth_s_id_remote = &temp.esi;
- } else
- path_eth_s_id_remote = eth_s_id;
-
- if (!memcmp(path_gw_ip, path_gw_ip_remote, sizeof(union gw_addr)))
- return false;
-
- return !memcmp(path_eth_s_id, path_eth_s_id_remote,
- sizeof(struct eth_segment_id));
+ return !!memcmp(path_gw_ip, path_gw_ip_remote, sizeof(union gw_addr));
}
/* Check if received nexthop is valid or not. */
num_labels * sizeof(mpls_label_t))
== 0)
&& (overlay_index_equal(
- afi, pi, evpn == NULL ? NULL : &evpn->eth_s_id,
+ afi, pi,
evpn == NULL ? NULL : &evpn->gw_ip))) {
if (CHECK_FLAG(bgp->af_flags[afi][safi],
BGP_CONFIG_DAMPENING)
/* Update Overlay Index */
if (afi == AFI_L2VPN) {
overlay_index_update(
- pi->attr, evpn == NULL ? NULL : &evpn->eth_s_id,
+ pi->attr,
evpn == NULL ? NULL : &evpn->gw_ip);
}
/* Update Overlay Index */
if (afi == AFI_L2VPN) {
overlay_index_update(new->attr,
- evpn == NULL ? NULL : &evpn->eth_s_id,
evpn == NULL ? NULL : &evpn->gw_ip);
}
/* Nexthop reachability check. */
else if (bgp_static->gatewayIp.family == AF_INET6)
memcpy(&(add.ipv6), &(bgp_static->gatewayIp.u.prefix6),
sizeof(struct in6_addr));
- overlay_index_update(&attr, bgp_static->eth_s_id, &add);
+ memcpy(&attr.esi, bgp_static->eth_s_id, sizeof(esi_t));
if (bgp_static->encap_tunneltype == BGP_ENCAP_TYPE_VXLAN) {
struct bgp_encap_type_vxlan bet;
memset(&bet, 0, sizeof(struct bgp_encap_type_vxlan));
if (pi) {
memset(&add, 0, sizeof(union gw_addr));
if (attrhash_cmp(pi->attr, attr_new)
- && overlay_index_equal(afi, pi, bgp_static->eth_s_id, &add)
+ && overlay_index_equal(afi, pi, &add)
&& !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
bgp_dest_unlock_node(dest);
bgp_attr_unintern(&attr_new);
if (esi) {
bgp_static->eth_s_id =
XCALLOC(MTYPE_ATTR,
- sizeof(struct eth_segment_id));
+ sizeof(esi_t));
str2esi(esi, bgp_static->eth_s_id);
}
if (routermac) {
}
}
- char *str = esi2str(&(attr->evpn_overlay.eth_s_id));
-
- if (!json_path)
- vty_out(vty, "%s", str);
- else
- json_object_string_add(json_overlay, "esi", str);
-
- XFREE(MTYPE_TMP, str);
-
if (is_evpn_prefix_ipaddr_v4((struct prefix_evpn *)p)) {
inet_ntop(AF_INET, &(attr->evpn_overlay.gw_ip.ipv4), buf,
BUFSIZ);
char buf[PREFIX_STRLEN * 2];
char buf2[SU_ADDRSTRLEN];
char rdbuf[RD_ADDRSTRLEN];
+ char esi_buf[ESI_BYTES];
/* Network configuration. */
for (pdest = bgp_table_top(bgp->route[afi][safi]); pdest;
continue;
char *macrouter = NULL;
- char *esi = NULL;
if (bgp_static->router_mac)
macrouter = prefix_mac2str(
bgp_static->router_mac, NULL, 0);
if (bgp_static->eth_s_id)
- esi = esi2str(bgp_static->eth_s_id);
+ esi_to_str(bgp_static->eth_s_id,
+ esi_buf, sizeof(esi_buf));
p = bgp_dest_get_prefix(dest);
prd = (struct prefix_rd *)bgp_dest_get_prefix(pdest);
" network %s rd %s ethtag %u label %u esi %s gwip %s routermac %s\n",
buf, rdbuf,
p->u.prefix_evpn.prefix_addr.eth_tag,
- decode_label(&bgp_static->label), esi, buf2,
+ decode_label(&bgp_static->label), esi_buf, buf2,
macrouter);
XFREE(MTYPE_TMP, macrouter);
- XFREE(MTYPE_TMP, esi);
}
}
}