fixing some typos and found one conversion bug

This commit is contained in:
Jeff Bean
2018-06-22 19:41:59 -07:00
parent 154650594c
commit fb034c3aba
4 changed files with 31 additions and 9 deletions
+17
View File
@@ -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
}
+5 -3
View File
@@ -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
}
+6 -3
View File
@@ -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))
}
}
+3 -3
View File
@@ -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) {