summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2018-08-08 00:58:17 +0000
committerMikael Magnusson <mikma@users.sourceforge.net>2021-10-19 01:26:17 +0200
commit51175d2cc2e4a8f7100c0e368ff5dfc64b2ac4a1 (patch)
treefd7ba8efab93acc4b2fdbe10e2d39003932476a5
parentc8e54e7f8a2a49c8c035d5becf33b21fc0babf25 (diff)
support Wireguard tunnel encapsulation
Signed-off-by: Mikael Magnusson <mikma@users.sourceforge.net>
-rw-r--r--api/attribute.proto4
-rw-r--r--internal/pkg/apiutil/attribute.go6
-rw-r--r--pkg/packet/bgp/bgp.go55
3 files changed, 64 insertions, 1 deletions
diff --git a/api/attribute.proto b/api/attribute.proto
index 619fc691..71968f98 100644
--- a/api/attribute.proto
+++ b/api/attribute.proto
@@ -497,6 +497,10 @@ message TunnelEncapSubTLVEncapsulation {
bytes cookie = 2;
}
+message TunnelEncapSubTLVWireguard {
+ bytes peer = 1;
+}
+
message TunnelEncapSubTLVProtocol { uint32 protocol = 1; }
message TunnelEncapSubTLVColor { uint32 color = 1; }
diff --git a/internal/pkg/apiutil/attribute.go b/internal/pkg/apiutil/attribute.go
index 19060932..0262c59d 100644
--- a/internal/pkg/apiutil/attribute.go
+++ b/internal/pkg/apiutil/attribute.go
@@ -1168,6 +1168,10 @@ func NewTunnelEncapAttributeFromNative(a *bgp.PathAttributeTunnelEncap) *api.Tun
Key: sv.Key,
Cookie: sv.Cookie,
}
+ case *bgp.TunnelEncapSubTLVWireguard:
+ subTlv = &api.TunnelEncapSubTLVWireguard{
+ Peer: sv.Peer,
+ }
case *bgp.TunnelEncapSubTLVProtocol:
subTlv = &api.TunnelEncapSubTLVProtocol{
Protocol: uint32(sv.Protocol),
@@ -1662,6 +1666,8 @@ func unmarshalAttribute(an *any.Any) (bgp.PathAttributeInterface, error) {
switch sv := subValue.Message.(type) {
case *api.TunnelEncapSubTLVEncapsulation:
subTlv = bgp.NewTunnelEncapSubTLVEncapsulation(sv.Key, sv.Cookie)
+ case *api.TunnelEncapSubTLVWireguard:
+ subTlv = bgp.NewTunnelEncapSubTLVWireguard(sv.Peer)
case *api.TunnelEncapSubTLVProtocol:
subTlv = bgp.NewTunnelEncapSubTLVProtocol(uint16(sv.Protocol))
case *api.TunnelEncapSubTLVColor:
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: