Skip to content

Commit

Permalink
Allow for zero-length ND_LLADDR
Browse files Browse the repository at this point in the history
Fixes #199
This change allows for neighbor entries with a
zero-length LLADDR attribute.
This has the side-effect that consumers of this
module might have to filter this entry, depending
on their usage.

Signed-off-by: Jeroen Simonetti <[email protected]>
  • Loading branch information
jsimonetti committed Nov 27, 2023
1 parent eac8438 commit 98743e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion neigh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
30 changes: 27 additions & 3 deletions neigh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package rtnetlink
import (
"bytes"
"net"
"reflect"
"testing"

"github.com/google/go-cmp/cmp"
"github.com/jsimonetti/rtnetlink/internal/unix"
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
})
}
Expand Down

0 comments on commit 98743e7

Please sign in to comment.