diff options
Diffstat (limited to 'pkg/packet')
-rw-r--r-- | pkg/packet/bgp/bgp.go | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go index c46bc878..6a13896f 100644 --- a/pkg/packet/bgp/bgp.go +++ b/pkg/packet/bgp/bgp.go @@ -17,6 +17,7 @@ package bgp import ( "bytes" + "encoding/base64" "encoding/binary" "encoding/json" "errors" @@ -188,6 +189,7 @@ const ( TUNNEL_TYPE_MPLS_IN_UDP TunnelType = 13 TUNNEL_TYPE_SR_POLICY TunnelType = 15 TUNNEL_TYPE_GENEVE TunnelType = 19 + TUNNEL_TYPE_WIREGUARD TunnelType = 51820 ) func (p TunnelType) String() string { @@ -214,6 +216,8 @@ func (p TunnelType) String() string { return "sr-policy" case TUNNEL_TYPE_GENEVE: return "geneve" + case TUNNEL_TYPE_WIREGUARD: + return "wireguard" default: return fmt.Sprintf("TunnelType(%d)", uint8(p)) } @@ -11691,6 +11695,50 @@ func NewTunnelEncapSubTLVEncapsulation(key uint32, cookie []byte) *TunnelEncapSu } } +type TunnelEncapSubTLVWireguard struct { + TunnelEncapSubTLV + Peer []byte +} + +func (t *TunnelEncapSubTLVWireguard) DecodeFromBytes(data []byte) error { + value, err := t.TunnelEncapSubTLV.DecodeFromBytes(data) + if err != nil { + return err + } + if t.Length < 32 { // FIXME + return NewMessageError(BGP_ERROR_UPDATE_MESSAGE_ERROR, BGP_ERROR_SUB_MALFORMED_ATTRIBUTE_LIST, nil, "Not all TunnelEncapSubTLVWireguard bytes available") + } + t.Peer = value + return nil +} + +func (t *TunnelEncapSubTLVWireguard) Serialize() ([]byte, error) { + return t.TunnelEncapSubTLV.Serialize(t.Peer) +} + +func (t *TunnelEncapSubTLVWireguard) String() string { + return fmt.Sprintf("{Peer: %s}", base64.StdEncoding.EncodeToString(t.Peer)) +} + +func (t *TunnelEncapSubTLVWireguard) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Type EncapSubTLVType `json:"type"` + Peer []byte `json:"peer"` + }{ + Type: t.Type, + Peer: t.Peer, + }) +} + +func NewTunnelEncapSubTLVWireguard(peer []byte) *TunnelEncapSubTLVWireguard { + return &TunnelEncapSubTLVWireguard{ + TunnelEncapSubTLV: TunnelEncapSubTLV{ + Type: ENCAP_SUBTLV_TYPE_ENCAPSULATION, + }, + Peer: peer, + } +} + type TunnelEncapSubTLVProtocol struct { TunnelEncapSubTLV Protocol uint16 @@ -11962,7 +12010,12 @@ func (t *TunnelEncapTLV) DecodeFromBytes(data []byte) error { var subTlv TunnelEncapSubTLVInterface switch subType { case ENCAP_SUBTLV_TYPE_ENCAPSULATION: - subTlv = &TunnelEncapSubTLVEncapsulation{} + switch t.Type { + case TUNNEL_TYPE_WIREGUARD: + subTlv = &TunnelEncapSubTLVWireguard{} + default: + subTlv = &TunnelEncapSubTLVEncapsulation{} + } case ENCAP_SUBTLV_TYPE_PROTOCOL: subTlv = &TunnelEncapSubTLVProtocol{} case ENCAP_SUBTLV_TYPE_COLOR: |