summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2021-01-20 18:48:17 +0000
committerMikael Magnusson <mikma@users.sourceforge.net>2021-10-19 01:26:17 +0200
commit9245bd2a488c1a89bfaa0d9c6ee0b46254b367ff (patch)
tree7933bd88cd6e1287af396447d965c4de2b2622f8
parent51175d2cc2e4a8f7100c0e368ff5dfc64b2ac4a1 (diff)
WIP tunnel encap attribute
-rw-r--r--cmd/gobgp/global.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/cmd/gobgp/global.go b/cmd/gobgp/global.go
index 6bc58d0c..bcd4acdd 100644
--- a/cmd/gobgp/global.go
+++ b/cmd/gobgp/global.go
@@ -16,6 +16,8 @@
package main
import (
+ "encoding/base64"
+ // "encoding/binary"
"encoding/json"
"fmt"
"net"
@@ -1103,6 +1105,92 @@ func extractPmsiTunnel(args []string) ([]string, bgp.PathAttributeInterface, err
return args, nil, nil
}
+func extractTunnelEncap(args []string) ([]string, bgp.PathAttributeInterface, error) {
+ for idx, arg := range args {
+ if arg == "tunnel-encap" {
+ var subencap bgp.TunnelEncapSubTLVInterface
+ var egress bgp.TunnelEncapSubTLVInterface
+ var udp_port bgp.TunnelEncapSubTLVInterface
+ var color bgp.TunnelEncapSubTLVInterface
+ subTlvsLen := 1
+ subidx := idx + 1
+ for subidx < len(args) {
+ arg = args[subidx]
+ if arg == "wireguard" {
+ if len(args) < (subidx + 1) {
+ return nil, nil, fmt.Errorf("invalid wireguard format")
+ }
+ peer, err := base64.StdEncoding.DecodeString(args[subidx+1])
+ if err != nil {
+ return nil, nil, err
+ }
+ subencap = bgp.NewTunnelEncapSubTLVWireguard(peer)
+ subTlvsLen++
+ subidx += 2
+ } else if arg == "egress" {
+ if len(args) < (subidx + 2) {
+ return nil, nil, fmt.Errorf("invalid egress endpoint format")
+ }
+ egress = bgp.NewTunnelEncapSubTLVEgressEndpoint(args[subidx+1])
+ subTlvsLen++
+ subidx += 2
+ } else if arg == "udp" {
+ if len(args) < (subidx + 2) {
+ return nil, nil, fmt.Errorf("invalid udp format")
+ }
+ port, err := strconv.ParseUint(args[subidx+1], 10, 16)
+ if err != nil {
+ return nil, nil, fmt.Errorf("invalid udp format")
+ }
+ udp_port = bgp.NewTunnelEncapSubTLVUDPDestPort(uint16(port))
+ subTlvsLen++
+ subidx += 2
+ } else if arg == "color" {
+ if len(args) < (subidx + 2) {
+ return nil, nil, fmt.Errorf("invalid color extended community format")
+ }
+ value, err := strconv.ParseUint(args[subidx+1], 10, 32)
+ if err != nil {
+ return nil, nil, fmt.Errorf("invalid color extended community format")
+ }
+ color = bgp.NewTunnelEncapSubTLVColor(uint32(value))
+ subTlvsLen++
+ subidx += 2
+ } else {
+ print("FOO:" + args[subidx+1])
+ break
+ }
+ }
+
+ tlvsLen := 1
+ tlvs := make([]*bgp.TunnelEncapTLV, 0, tlvsLen)
+ subTlvs := make([]bgp.TunnelEncapSubTLVInterface, 0, subTlvsLen)
+
+ if subencap != nil {
+ subTlvs = append(subTlvs, subencap)
+ }
+ if egress != nil {
+ subTlvs = append(subTlvs, egress)
+ }
+ if udp_port != nil {
+ subTlvs = append(subTlvs, udp_port)
+ }
+ if color != nil {
+ subTlvs = append(subTlvs, color)
+ }
+
+ tlvType := bgp.TUNNEL_TYPE_WIREGUARD // Experimental Wireguard
+ tlvs = append(tlvs, bgp.NewTunnelEncapTLV(bgp.TunnelType(tlvType), subTlvs))
+
+ //subTlv = bgp.NewTunnelEncapSubTLVProtocol(uint16())
+ encap := bgp.NewPathAttributeTunnelEncap(tlvs)
+
+ return append(args[:idx], args[subidx:]...), encap, nil
+ }
+ }
+ return args, nil, nil
+}
+
func extractAigp(args []string) ([]string, bgp.PathAttributeInterface, error) {
for idx, arg := range args {
if arg == "aigp" {
@@ -1161,6 +1249,7 @@ func parsePath(rf bgp.RouteFamily, args []string) (*api.Path, error) {
extractAggregator, // 7 AGGREGATOR
extractCommunity, // 8 COMMUNITY
extractPmsiTunnel, // 22 PMSI_TUNNEL
+ extractTunnelEncap, // 23 Tunnel Encapsulation Attribute
extractAigp, // 26 AIGP
extractLargeCommunity, // 32 LARGE_COMMUNITY
}