diff --git a/neigh.go b/neigh.go index cf5e60c..93f0674 100644 --- a/neigh.go +++ b/neigh.go @@ -194,7 +194,7 @@ func (a *NeighAttributes) decode(ad *netlink.AttributeDecoder) error { // Allow IEEE 802 MAC-48, EUI-48, EUI-64, or 20-octet // IP over InfiniBand link-layer addresses l := len(ad.Bytes()) - if l != 6 && l != 8 && l != 20 { + if l != 0 && l != 6 && l != 8 && l != 20 { return errInvalidNeighMessageAttr } a.LLAddress = ad.Bytes() diff --git a/neigh_test.go b/neigh_test.go index 5bc9f8a..3025979 100644 --- a/neigh_test.go +++ b/neigh_test.go @@ -3,9 +3,9 @@ package rtnetlink import ( "bytes" "net" - "reflect" "testing" + "github.com/google/go-cmp/cmp" "github.com/jsimonetti/rtnetlink/internal/unix" ) @@ -167,6 +167,29 @@ func TestNeighMessageUnmarshalBinary(t *testing.T) { Type: unix.NTF_PROXY, }, }, + { + name: "zero-length attributes", + m: &NeighMessage{ + Index: 2, + State: 64, + Type: unix.NTF_PROXY, + Attributes: &NeighAttributes{ + Address: net.ParseIP("0.0.0.0"), + LLAddress: []byte{}, + IfIndex: 0, + }, + }, + b: []byte{ + 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x00, 0x02, 0x00, + 0x00, 0x00, 0x08, 0x00, 0x08, 0x00, + 0x00, 0x00, 0x00, 0x00, + }, + }, } for _, tt := range tests { @@ -180,9 +203,10 @@ func TestNeighMessageUnmarshalBinary(t *testing.T) { if err != nil { return } + want, got := tt.m, m - if want, got := tt.m, m; !reflect.DeepEqual(want, got) { - t.Fatalf("unexpected Message:\n- want: %#v\n- got: %#v", want, got) + if diff := cmp.Diff(want, got); diff != "" { + t.Fatalf("unexpected parsed messages (-want +got):\n%s", diff) } }) }