diff options
-rw-r--r-- | config/bgp_configs.go | 33 | ||||
-rw-r--r-- | gobgp/cmd/common.go | 6 | ||||
-rw-r--r-- | packet/bgp/bgp.go | 51 | ||||
-rw-r--r-- | packet/bgp/bgp_test.go | 12 | ||||
-rw-r--r-- | tools/pyang_plugins/gobgp.yang | 9 |
5 files changed, 70 insertions, 41 deletions
diff --git a/config/bgp_configs.go b/config/bgp_configs.go index 63389547..47d070b4 100644 --- a/config/bgp_configs.go +++ b/config/bgp_configs.go @@ -229,7 +229,8 @@ const ( AFI_SAFI_TYPE_IPV4_MULTICAST AfiSafiType = "ipv4-multicast" AFI_SAFI_TYPE_IPV6_MULTICAST AfiSafiType = "ipv6-multicast" AFI_SAFI_TYPE_RTC AfiSafiType = "rtc" - AFI_SAFI_TYPE_ENCAP AfiSafiType = "encap" + AFI_SAFI_TYPE_IPV4_ENCAP AfiSafiType = "ipv4-encap" + AFI_SAFI_TYPE_IPV6_ENCAP AfiSafiType = "ipv6-encap" AFI_SAFI_TYPE_IPV4_FLOWSPEC AfiSafiType = "ipv4-flowspec" AFI_SAFI_TYPE_L3VPN_IPV4_FLOWSPEC AfiSafiType = "l3vpn-ipv4-flowspec" AFI_SAFI_TYPE_IPV6_FLOWSPEC AfiSafiType = "ipv6-flowspec" @@ -252,13 +253,14 @@ var AfiSafiTypeToIntMap = map[AfiSafiType]int{ AFI_SAFI_TYPE_IPV4_MULTICAST: 10, AFI_SAFI_TYPE_IPV6_MULTICAST: 11, AFI_SAFI_TYPE_RTC: 12, - AFI_SAFI_TYPE_ENCAP: 13, - AFI_SAFI_TYPE_IPV4_FLOWSPEC: 14, - AFI_SAFI_TYPE_L3VPN_IPV4_FLOWSPEC: 15, - AFI_SAFI_TYPE_IPV6_FLOWSPEC: 16, - AFI_SAFI_TYPE_L3VPN_IPV6_FLOWSPEC: 17, - AFI_SAFI_TYPE_L2VPN_FLOWSPEC: 18, - AFI_SAFI_TYPE_OPAQUE: 19, + AFI_SAFI_TYPE_IPV4_ENCAP: 13, + AFI_SAFI_TYPE_IPV6_ENCAP: 14, + AFI_SAFI_TYPE_IPV4_FLOWSPEC: 15, + AFI_SAFI_TYPE_L3VPN_IPV4_FLOWSPEC: 16, + AFI_SAFI_TYPE_IPV6_FLOWSPEC: 17, + AFI_SAFI_TYPE_L3VPN_IPV6_FLOWSPEC: 18, + AFI_SAFI_TYPE_L2VPN_FLOWSPEC: 19, + AFI_SAFI_TYPE_OPAQUE: 20, } func (v AfiSafiType) ToInt() int { @@ -283,13 +285,14 @@ var IntToAfiSafiTypeMap = map[int]AfiSafiType{ 10: AFI_SAFI_TYPE_IPV4_MULTICAST, 11: AFI_SAFI_TYPE_IPV6_MULTICAST, 12: AFI_SAFI_TYPE_RTC, - 13: AFI_SAFI_TYPE_ENCAP, - 14: AFI_SAFI_TYPE_IPV4_FLOWSPEC, - 15: AFI_SAFI_TYPE_L3VPN_IPV4_FLOWSPEC, - 16: AFI_SAFI_TYPE_IPV6_FLOWSPEC, - 17: AFI_SAFI_TYPE_L3VPN_IPV6_FLOWSPEC, - 18: AFI_SAFI_TYPE_L2VPN_FLOWSPEC, - 19: AFI_SAFI_TYPE_OPAQUE, + 13: AFI_SAFI_TYPE_IPV4_ENCAP, + 14: AFI_SAFI_TYPE_IPV6_ENCAP, + 15: AFI_SAFI_TYPE_IPV4_FLOWSPEC, + 16: AFI_SAFI_TYPE_L3VPN_IPV4_FLOWSPEC, + 17: AFI_SAFI_TYPE_IPV6_FLOWSPEC, + 18: AFI_SAFI_TYPE_L3VPN_IPV6_FLOWSPEC, + 19: AFI_SAFI_TYPE_L2VPN_FLOWSPEC, + 20: AFI_SAFI_TYPE_OPAQUE, } func (v AfiSafiType) Validate() error { diff --git a/gobgp/cmd/common.go b/gobgp/cmd/common.go index c436c23a..1a04a3aa 100644 --- a/gobgp/cmd/common.go +++ b/gobgp/cmd/common.go @@ -450,8 +450,10 @@ func checkAddressFamily(def bgp.RouteFamily) (bgp.RouteFamily, error) { rf = bgp.RF_IPv6_MPLS case "evpn": rf = bgp.RF_EVPN - case "encap": - rf = bgp.RF_ENCAP + case "encap", "ipv4-encap": + rf = bgp.RF_IPv4_ENCAP + case "ipv6-encap": + rf = bgp.RF_IPv6_ENCAP case "rtc": rf = bgp.RF_RTC_UC case "ipv4-flowspec", "ipv4-flow", "flow4": diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go index 9680c08d..9ea753c4 100644 --- a/packet/bgp/bgp.go +++ b/packet/bgp/bgp.go @@ -2007,6 +2007,7 @@ func NewEVPNNLRI(routetype uint8, length uint8, routetypedata EVPNRouteTypeInter type EncapNLRI struct { IPAddrPrefixDefault + addrlen uint8 } func (n *EncapNLRI) DecodeFromBytes(data []byte) error { @@ -2016,17 +2017,15 @@ func (n *EncapNLRI) DecodeFromBytes(data []byte) error { return NewMessageError(eCode, eSubCode, nil, "prefix misses length field") } n.Length = data[0] - return n.decodePrefix(data[1:], n.Length, n.Length/8) + if n.addrlen == 0 { + n.addrlen = 4 + } + return n.decodePrefix(data[1:], n.Length, n.addrlen) } func (n *EncapNLRI) Serialize() ([]byte, error) { buf := make([]byte, 1) - buf[0] = net.IPv6len * 8 - if n.Prefix.To4() != nil { - buf[0] = net.IPv4len * 8 - n.Prefix = n.Prefix.To4() - } - n.Length = buf[0] + buf[0] = n.Length pbuf, err := n.serializePrefix(n.Length) if err != nil { return nil, err @@ -2039,10 +2038,7 @@ func (n *EncapNLRI) String() string { } func (n *EncapNLRI) AFI() uint16 { - if n.Prefix.To4() != nil { - return AFI_IP - } - return AFI_IP6 + return AFI_IP } func (n *EncapNLRI) SAFI() uint8 { @@ -2051,7 +2047,25 @@ func (n *EncapNLRI) SAFI() uint8 { func NewEncapNLRI(endpoint string) *EncapNLRI { return &EncapNLRI{ - IPAddrPrefixDefault{0, net.ParseIP(endpoint)}, + IPAddrPrefixDefault{32, net.ParseIP(endpoint).To4()}, + 4, + } +} + +type Encapv6NLRI struct { + EncapNLRI +} + +func (n *Encapv6NLRI) AFI() uint16 { + return AFI_IP6 +} + +func NewEncapv6NLRI(endpoint string) *Encapv6NLRI { + return &Encapv6NLRI{ + EncapNLRI{ + IPAddrPrefixDefault{128, net.ParseIP(endpoint)}, + 16, + }, } } @@ -3269,7 +3283,8 @@ const ( RF_VPLS RouteFamily = AFI_L2VPN<<16 | SAFI_VPLS RF_EVPN RouteFamily = AFI_L2VPN<<16 | SAFI_EVPN RF_RTC_UC RouteFamily = AFI_IP<<16 | SAFI_ROUTE_TARGET_CONSTRTAINS - RF_ENCAP RouteFamily = AFI_IP<<16 | SAFI_ENCAPSULATION + RF_IPv4_ENCAP RouteFamily = AFI_IP<<16 | SAFI_ENCAPSULATION + RF_IPv6_ENCAP RouteFamily = AFI_IP6<<16 | SAFI_ENCAPSULATION RF_FS_IPv4_UC RouteFamily = AFI_IP<<16 | SAFI_FLOW_SPEC_UNICAST RF_FS_IPv4_VPN RouteFamily = AFI_IP<<16 | SAFI_FLOW_SPEC_VPN RF_FS_IPv6_UC RouteFamily = AFI_IP6<<16 | SAFI_FLOW_SPEC_UNICAST @@ -3292,7 +3307,8 @@ var AddressFamilyNameMap = map[RouteFamily]string{ RF_VPLS: "l2vpn-vpls", RF_EVPN: "l2vpn-evpn", RF_RTC_UC: "rtc", - RF_ENCAP: "encap", + RF_IPv4_ENCAP: "ipv4-encap", + RF_IPv6_ENCAP: "ipv6-encap", RF_FS_IPv4_UC: "ipv4-flowspec", RF_FS_IPv4_VPN: "l3vpn-ipv4-flowspec", RF_FS_IPv6_UC: "ipv6-flowspec", @@ -3315,7 +3331,8 @@ var AddressFamilyValueMap = map[string]RouteFamily{ AddressFamilyNameMap[RF_VPLS]: RF_VPLS, AddressFamilyNameMap[RF_EVPN]: RF_EVPN, AddressFamilyNameMap[RF_RTC_UC]: RF_RTC_UC, - AddressFamilyNameMap[RF_ENCAP]: RF_ENCAP, + AddressFamilyNameMap[RF_IPv4_ENCAP]: RF_IPv4_ENCAP, + AddressFamilyNameMap[RF_IPv6_ENCAP]: RF_IPv6_ENCAP, AddressFamilyNameMap[RF_FS_IPv4_UC]: RF_FS_IPv4_UC, AddressFamilyNameMap[RF_FS_IPv4_VPN]: RF_FS_IPv4_VPN, AddressFamilyNameMap[RF_FS_IPv6_UC]: RF_FS_IPv6_UC, @@ -3349,8 +3366,10 @@ func NewPrefixFromRouteFamily(afi uint16, safi uint8) (prefix AddrPrefixInterfac prefix = NewEVPNNLRI(0, 0, nil) case RF_RTC_UC: prefix = &RouteTargetMembershipNLRI{} - case RF_ENCAP: + case RF_IPv4_ENCAP: prefix = NewEncapNLRI("") + case RF_IPv6_ENCAP: + prefix = NewEncapv6NLRI("") case RF_FS_IPv4_UC: prefix = &FlowSpecIPv4Unicast{} case RF_FS_IPv4_VPN: diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go index 612e8c7b..af4e2938 100644 --- a/packet/bgp/bgp_test.go +++ b/packet/bgp/bgp_test.go @@ -18,7 +18,6 @@ package bgp import ( "bytes" "encoding/binary" - "fmt" "github.com/stretchr/testify/assert" "net" "reflect" @@ -213,14 +212,14 @@ func Test_RFC5512(t *testing.T) { assert.Equal(nil, err) assert.Equal("10.0.0.1", n2.String()) - n1 = NewEncapNLRI("2001::1") - buf1, err = n1.Serialize() + n3 := NewEncapv6NLRI("2001::1") + buf1, err = n3.Serialize() assert.Equal(nil, err) - n2 = NewEncapNLRI("") - err = n2.DecodeFromBytes(buf1) + n4 := NewEncapv6NLRI("") + err = n4.DecodeFromBytes(buf1) assert.Equal(nil, err) - assert.Equal("2001::1", n2.String()) + assert.Equal("2001::1", n4.String()) } func Test_ASLen(t *testing.T) { @@ -446,5 +445,4 @@ func Test_FlowSpecNlriL2(t *testing.T) { t.Error(len(buf2), n2, buf2) t.Log(bytes.Equal(buf1, buf2)) } - fmt.Println(n1, n2) } diff --git a/tools/pyang_plugins/gobgp.yang b/tools/pyang_plugins/gobgp.yang index c8f6029c..911de3bc 100644 --- a/tools/pyang_plugins/gobgp.yang +++ b/tools/pyang_plugins/gobgp.yang @@ -84,13 +84,20 @@ module gobgp { reference "RFC4684"; } - identity ENCAP { + identity IPV4-ENCAP { base bgp-types:afi-safi-type; description "Encapsulation (AFI,SAFI = 1,7)"; reference "RFC5512"; } + identity IPV6-ENCAP { + base bgp-types:afi-safi-type; + description + "Encapsulation (AFI,SAFI = 2,7)"; + reference "RFC5512"; + } + identity IPV4-FLOWSPEC { base bgp-types:afi-safi-type; description |