Skip to content

Commit 265a7d7

Browse files
committed
Allow for zero-length ND_LLADDR
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]>
1 parent eac8438 commit 265a7d7

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

neigh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func (a *NeighAttributes) decode(ad *netlink.AttributeDecoder) error {
194194
// Allow IEEE 802 MAC-48, EUI-48, EUI-64, or 20-octet
195195
// IP over InfiniBand link-layer addresses
196196
l := len(ad.Bytes())
197-
if l != 6 && l != 8 && l != 20 {
197+
if l != 0 && l != 6 && l != 8 && l != 20 {
198198
return errInvalidNeighMessageAttr
199199
}
200200
a.LLAddress = ad.Bytes()

neigh_test.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package rtnetlink
33
import (
44
"bytes"
55
"net"
6-
"reflect"
76
"testing"
87

8+
"github.com/google/go-cmp/cmp"
99
"github.com/jsimonetti/rtnetlink/internal/unix"
1010
)
1111

@@ -167,6 +167,29 @@ func TestNeighMessageUnmarshalBinary(t *testing.T) {
167167
Type: unix.NTF_PROXY,
168168
},
169169
},
170+
{
171+
name: "zero-length attributes",
172+
m: &NeighMessage{
173+
Index: 2,
174+
State: 64,
175+
Type: unix.NTF_PROXY,
176+
Attributes: &NeighAttributes{
177+
Address: net.ParseIP("0.0.0.0"),
178+
LLAddress: []byte{},
179+
IfIndex: 0,
180+
},
181+
},
182+
b: []byte{
183+
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
184+
0x40, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00,
185+
0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x01, 0x00,
186+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187+
0x00, 0x00, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
188+
0x04, 0x00, 0x02, 0x00,
189+
0x00, 0x00, 0x08, 0x00, 0x08, 0x00,
190+
0x00, 0x00, 0x00, 0x00,
191+
},
192+
},
170193
}
171194

172195
for _, tt := range tests {
@@ -180,9 +203,8 @@ func TestNeighMessageUnmarshalBinary(t *testing.T) {
180203
if err != nil {
181204
return
182205
}
183-
184-
if want, got := tt.m, m; !reflect.DeepEqual(want, got) {
185-
t.Fatalf("unexpected Message:\n- want: %#v\n- got: %#v", want, got)
206+
if diff := cmp.Diff(tt.m, m); diff != "" {
207+
t.Fatalf("unexpected parsed messages (-want +got):\n%s", diff)
186208
}
187209
})
188210
}

0 commit comments

Comments
 (0)