From 3e3b27dd15c46ff664ee3ce5013a8f3cdb7d9519 Mon Sep 17 00:00:00 2001 From: Yeechan Lu Date: Mon, 17 Apr 2023 02:26:41 +0000 Subject: [PATCH] packet/bgp: Support EVPN ND Extended Community This patch supports EVPN ND Extended Community which described on "rfc9047 Propagation of ARP/ND Flags in an Ethernet Virtual Private Network (EVPN)". --- pkg/packet/bgp/bgp.go | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go index 90f51acf8..b389ea3e9 100644 --- a/pkg/packet/bgp/bgp.go +++ b/pkg/packet/bgp/bgp.go @@ -180,6 +180,7 @@ const ( EC_SUBTYPE_ESI_LABEL ExtendedCommunityAttrSubType = 0x01 // EC_TYPE: 0x06 EC_SUBTYPE_ES_IMPORT ExtendedCommunityAttrSubType = 0x02 // EC_TYPE: 0x06 EC_SUBTYPE_ROUTER_MAC ExtendedCommunityAttrSubType = 0x03 // EC_TYPE: 0x06 + EC_SUBTYPE_ND ExtendedCommunityAttrSubType = 0x08 // EC_TYPE: 0x06 EC_SUBTYPE_UUID_BASED_RT ExtendedCommunityAttrSubType = 0x11 ) @@ -12123,6 +12124,45 @@ func NewRoutersMacExtended(mac string) *RouterMacExtended { } } +type NdExtended struct { + Flag byte +} + +func (e *NdExtended) Serialize() ([]byte, error) { + buf := make([]byte, 8) + buf[0] = byte(EC_TYPE_EVPN) + buf[1] = byte(EC_SUBTYPE_ND) + buf[2] = e.Flag + return buf, nil +} + +func (e *NdExtended) String() string { + return "arp/nd flag: " + fmt.Sprintf("%d", e.Flag) +} + +func (e *NdExtended) MarshalJSON() ([]byte, error) { + t, s := e.GetTypes() + return json.Marshal(struct { + Type ExtendedCommunityAttrType `json:"type"` + Subtype ExtendedCommunityAttrSubType `json:"subtype"` + Flag byte `json:"flag"` + }{ + Type: t, + Subtype: s, + Flag: e.Flag, + }) +} + +func (e *NdExtended) GetTypes() (ExtendedCommunityAttrType, ExtendedCommunityAttrSubType) { + return EC_TYPE_EVPN, EC_SUBTYPE_ND +} + +func NewNdExtended(flag byte) *NdExtended { + return &NdExtended{ + Flag: flag, + } +} + func parseEvpnExtended(data []byte) (ExtendedCommunityInterface, error) { if ExtendedCommunityAttrType(data[0]) != EC_TYPE_EVPN { return nil, NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, fmt.Sprintf("ext comm type is not EC_TYPE_EVPN: %d", data[0])) @@ -12157,6 +12197,10 @@ func parseEvpnExtended(data []byte) (ExtendedCommunityInterface, error) { return &RouterMacExtended{ Mac: net.HardwareAddr(data[2:8]), }, nil + case EC_SUBTYPE_ND: + return &NdExtended{ + Flag: data[2], + }, nil } return nil, NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, fmt.Sprintf("unknown evpn subtype: %d", subType)) } @@ -14724,6 +14768,10 @@ func (e *RouterMacExtended) Flat() map[string]string { return map[string]string{} } +func (e *NdExtended) Flat() map[string]string { + return map[string]string{} +} + func (e *TrafficRateExtended) Flat() map[string]string { return map[string]string{} }