Skip to content

Commit

Permalink
packet/bgp: Support EVPN ND Extended Community
Browse files Browse the repository at this point in the history
This patch supports EVPN ND Extended Community which described on
"rfc9047 Propagation of ARP/ND Flags in an Ethernet Virtual Private
Network (EVPN)".
  • Loading branch information
orzFly committed Apr 17, 2023
1 parent bab5b30 commit 3e3b27d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkg/packet/bgp/bgp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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]))
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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{}
}
Expand Down

0 comments on commit 3e3b27d

Please sign in to comment.