summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJeff Bean <bean@uber.com>2018-06-22 19:41:59 -0700
committerJeff Bean <bean@uber.com>2018-06-22 19:41:59 -0700
commitfb034c3aba46e318fcbd748cef02796a05305aa2 (patch)
tree5fb3b56a723dac39a28589d941caad123a1f4f7e
parent154650594c5b40b2905eb73b90f52de72f6ced16 (diff)
fixing some typos and found one conversion bug
-rw-r--r--config/default_linux.go17
-rw-r--r--packet/bgp/bgp.go8
-rw-r--r--packet/bgp/bgp_test.go9
-rw-r--r--packet/bgp/validate_test.go6
4 files changed, 31 insertions, 9 deletions
diff --git a/config/default_linux.go b/config/default_linux.go
index f83b76fe..8cfcc501 100644
--- a/config/default_linux.go
+++ b/config/default_linux.go
@@ -53,3 +53,20 @@ func GetIPv6LinkLocalNeighborAddress(ifname string) (string, error) {
return fmt.Sprintf("%s%%%s", addr, ifname), nil
}
+
+func isLocalLinkLocalAddress(ifindex int, addr net.IP) (bool, error) {
+ ifi, err := net.InterfaceByIndex(ifindex)
+ if err != nil {
+ return false, err
+ }
+ addrs, err := ifi.Addrs()
+ if err != nil {
+ return false, err
+ }
+ for _, a := range addrs {
+ if ip, _, _ := net.ParseCIDR(a.String()); addr.Equal(ip) {
+ return true, nil
+ }
+ }
+ return false, nil
+}
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index b882f9a6..145f7d99 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -1573,7 +1573,7 @@ func (l *MPLSLabelStack) DecodeFromBytes(data []byte) error {
}
}
- if foundBottom {
+ if !foundBottom {
l.Labels = []uint32{}
return nil
}
@@ -1850,13 +1850,13 @@ func (l *LabeledIPAddrPrefix) DecodeFromBytes(data []byte, options ...*Marshalli
l.Length = uint8(data[0])
data = data[1:]
l.Labels.DecodeFromBytes(data)
+
if int(l.Length)-8*(l.Labels.Len()) < 0 {
l.Labels.Labels = []uint32{}
}
restbits := int(l.Length) - 8*(l.Labels.Len())
data = data[l.Labels.Len():]
- l.decodePrefix(data, uint8(restbits), l.addrlen)
- return nil
+ return l.decodePrefix(data, uint8(restbits), l.addrlen)
}
func (l *LabeledIPAddrPrefix) Serialize(options ...*MarshallingOption) ([]byte, error) {
@@ -9258,10 +9258,12 @@ func (msg *BGPHeader) DecodeFromBytes(data []byte, options ...*MarshallingOption
if uint16(len(data)) < BGP_HEADER_LENGTH {
return NewMessageError(BGP_ERROR_MESSAGE_HEADER_ERROR, BGP_ERROR_SUB_BAD_MESSAGE_LENGTH, nil, "not all BGP message header")
}
+
msg.Len = binary.BigEndian.Uint16(data[16:18])
if int(msg.Len) < BGP_HEADER_LENGTH {
return NewMessageError(BGP_ERROR_MESSAGE_HEADER_ERROR, BGP_ERROR_SUB_BAD_MESSAGE_LENGTH, nil, "unknown message type")
}
+
msg.Type = data[18]
return nil
}
diff --git a/packet/bgp/bgp_test.go b/packet/bgp/bgp_test.go
index 555369db..a4801f27 100644
--- a/packet/bgp/bgp_test.go
+++ b/packet/bgp/bgp_test.go
@@ -19,6 +19,7 @@ import (
"bytes"
"encoding/binary"
"net"
+ "reflect"
"strconv"
"testing"
@@ -53,15 +54,17 @@ func Test_Message(t *testing.T) {
for _, m1 := range l {
buf1, err := m1.Serialize()
- require.NoError(t, err)
+ assert.NoError(t, err)
t.Log("LEN =", len(buf1))
m2, err := ParseBGPMessage(buf1)
- require.NoError(t, err)
+ assert.NoError(t, err)
// FIXME: shouldn't but workaround for some structs.
+ _, err = m2.Serialize()
+ assert.NoError(t, err)
- assert.Equal(t, m1, m2)
+ assert.True(t, reflect.DeepEqual(m1, m2))
}
}
diff --git a/packet/bgp/validate_test.go b/packet/bgp/validate_test.go
index f780b5cc..8bdec550 100644
--- a/packet/bgp/validate_test.go
+++ b/packet/bgp/validate_test.go
@@ -56,12 +56,12 @@ func Test_Validate_CapV6(t *testing.T) {
assert := assert.New(t)
message := bgpupdateV6().Body.(*BGPUpdate)
res, err := ValidateUpdateMsg(message, map[RouteFamily]BGPAddPathMode{RF_IPv6_UC: BGP_ADD_PATH_BOTH}, false, false)
- assert.Equal(true, res)
assert.NoError(err)
+ assert.True(res)
res, err = ValidateUpdateMsg(message, map[RouteFamily]BGPAddPathMode{RF_IPv4_UC: BGP_ADD_PATH_BOTH}, false, false)
- require.NoError(t, err)
- assert.Equal(false, res)
+ assert.Error(err)
+ assert.False(res)
}
func Test_Validate_OK(t *testing.T) {