From af8e7922052d9d579496b5bbc9bb52850ae2094e Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 3 Feb 2025 16:08:45 +0100 Subject: [PATCH] bgpd: add L2 attr community support as per RFC8214 The L2 attribute extended community can not be decoded when using L2VPN EVPN as a route reflector. Decode the extended community and dump the detailed information about flags and MTU information. > rt4# show bgp l2vpn evpn > BGP table version is 1, local router ID is 4.4.4.4 > Status codes: s suppressed, d damped, h history, * valid, > best, i - internal > Origin codes: i - IGP, e - EGP, ? - incomplete > EVPN type-1 prefix: [1]:[EthTag]:[ESI]:[IPlen]:[VTEP-IP]:[Frag-id] > EVPN type-2 prefix: [2]:[EthTag]:[MAClen]:[MAC]:[IPlen]:[IP] > EVPN type-3 prefix: [3]:[EthTag]:[IPlen]:[OrigIP] > EVPN type-4 prefix: [4]:[ESI]:[IPlen]:[OrigIP] > EVPN type-5 prefix: [5]:[EthTag]:[IPlen]:[IP] > > Network Next Hop Metric LocPrf Weight Path > Route Distinguisher: 1.1.1.1:100 > *>i[1]:[12]:[00:00:00:00:00:00:00:00:00:00]:[32]:[0.0.0.0]:[0] > 1.1.1.1 100 0 i > RT:65500:100 L2: P flag:N, B Flag N, C word N, MTU 0 > Route Distinguisher: 5.5.5.5:100 > *>i[1]:[10]:[00:00:00:00:00:00:00:00:00:00]:[32]:[0.0.0.0]:[0] > 5.5.5.5 100 0 i > RT:65500:100 L2: P flag:N, B Flag N, C word N, MTU 0 > Signed-off-by: Philippe Guibert --- bgpd/bgp_ecommunity.c | 25 +++++++++++++++++++++++++ bgpd/bgp_ecommunity.h | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index e794ccb308..2c6ae65f85 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -1337,6 +1337,31 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) snprintf(encbuf, sizeof(encbuf), "DF: (alg: %u, pref: %u)", alg, pref); + } else if (*pnt == ECOMMUNITY_EVPN_SUBTYPE_LAYER2_ATTR) { + uint16_t flags, l2mtu; + + ++pnt; + memcpy(&flags, pnt, 2); + ++pnt; + ++pnt; + + memcpy(&l2mtu, pnt, 2); + + snprintf(encbuf, sizeof(encbuf), + "L2: P flag:%c, B Flag %c, C word %c, MTU %d", + CHECK_FLAG(flags, + ECOMMUNITY_EVPN_SUBTYPE_LAYER2_ATTR_PRIMARY_PE_FLAG) + ? 'Y' + : 'N', + CHECK_FLAG(flags, + ECOMMUNITY_EVPN_SUBTYPE_LAYER2_ATTR_BACKUP_PE_FLAG) + ? 'Y' + : 'N', + CHECK_FLAG(flags, + ECOMMUNITY_EVPN_SUBTYPE_LAYER2_ATTR_CONTROL_WORD_FLAG) + ? 'Y' + : 'N', + l2mtu); } else unk_ecom = true; } else if (type == ECOMMUNITY_ENCODE_REDIRECT_IP_NH) { diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h index af9d481c19..0e68b15807 100644 --- a/bgpd/bgp_ecommunity.h +++ b/bgpd/bgp_ecommunity.h @@ -68,12 +68,18 @@ #define ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL 0x01 #define ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT 0x02 #define ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC 0x03 +#define ECOMMUNITY_EVPN_SUBTYPE_LAYER2_ATTR 0x04 #define ECOMMUNITY_EVPN_SUBTYPE_DF_ELECTION 0x06 #define ECOMMUNITY_EVPN_SUBTYPE_DEF_GW 0x0d #define ECOMMUNITY_EVPN_SUBTYPE_ND 0x08 #define ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY 0x01 +/* Layer2 Attributes: RFC8214 */ +#define ECOMMUNITY_EVPN_SUBTYPE_LAYER2_ATTR_PRIMARY_PE_FLAG 0x01 +#define ECOMMUNITY_EVPN_SUBTYPE_LAYER2_ATTR_BACKUP_PE_FLAG 0x02 +#define ECOMMUNITY_EVPN_SUBTYPE_LAYER2_ATTR_CONTROL_WORD_FLAG 0x04 + /* DF alg bits - only lower 5 bits are applicable */ #define ECOMMUNITY_EVPN_SUBTYPE_DF_ALG_BITS 0x1f -- 2.39.5