summaryrefslogtreecommitdiffhomepage
path: root/pkg/packet/bgp/bgp.go
diff options
context:
space:
mode:
authorKonrad Zemek <konrad.zemek@gmail.com>2021-08-12 16:21:13 +0000
committerKonrad Zemek <konrad.zemek@gmail.com>2021-08-12 16:21:13 +0000
commit696ff4de8ec2906d00de2a21df40e261af59803a (patch)
tree2b11bc4d207d2258de13f235c6dd58fce8ca4443 /pkg/packet/bgp/bgp.go
parent8fbb5abc7ccef36ebeba6d3ae4f5b03fed19878f (diff)
Fix extended-nexthop & add-path capability parsing.
The capabilities' DecodeFromBytes() was eating as much data as given, while these functions would normally be called with all the data remaining to parse - e.g. including following capabilities. Fixes osrg/gobgp#2399
Diffstat (limited to 'pkg/packet/bgp/bgp.go')
-rw-r--r--pkg/packet/bgp/bgp.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/pkg/packet/bgp/bgp.go b/pkg/packet/bgp/bgp.go
index 418e8e63..ac7b77d2 100644
--- a/pkg/packet/bgp/bgp.go
+++ b/pkg/packet/bgp/bgp.go
@@ -507,11 +507,13 @@ type CapExtendedNexthop struct {
func (c *CapExtendedNexthop) DecodeFromBytes(data []byte) error {
c.DefaultParameterCapability.DecodeFromBytes(data)
data = data[2:]
- if len(data) < 6 {
+ capLen := int(c.CapLen)
+ if capLen%6 != 0 || capLen < 6 || len(data) < capLen {
return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilityExtendedNexthop bytes available")
}
+
c.Tuples = []*CapExtendedNexthopTuple{}
- for len(data) >= 6 {
+ for capLen >= 6 {
t := &CapExtendedNexthopTuple{
binary.BigEndian.Uint16(data[0:2]),
binary.BigEndian.Uint16(data[2:4]),
@@ -519,6 +521,7 @@ func (c *CapExtendedNexthop) DecodeFromBytes(data []byte) error {
}
c.Tuples = append(c.Tuples, t)
data = data[6:]
+ capLen -= 6
}
return nil
}
@@ -756,17 +759,20 @@ type CapAddPath struct {
func (c *CapAddPath) DecodeFromBytes(data []byte) error {
c.DefaultParameterCapability.DecodeFromBytes(data)
data = data[2:]
- if len(data) < 4 {
+ capLen := int(c.CapLen)
+ if capLen%4 != 0 || capLen < 4 || len(data) < capLen {
return NewMessageError(BGP_ERROR_OPEN_MESSAGE_ERROR, BGP_ERROR_SUB_UNSUPPORTED_CAPABILITY, nil, "Not all CapabilityAddPath bytes available")
}
+
c.Tuples = []*CapAddPathTuple{}
- for len(data) >= 4 {
+ for capLen >= 4 {
t := &CapAddPathTuple{
RouteFamily: AfiSafiToRouteFamily(binary.BigEndian.Uint16(data[:2]), data[2]),
Mode: BGPAddPathMode(data[3]),
}
c.Tuples = append(c.Tuples, t)
data = data[4:]
+ capLen -= 4
}
return nil
}