Skip to content

Commit

Permalink
Add more LL address sizes (#183)
Browse files Browse the repository at this point in the history
Next to IEEE 802 MAC-48 and EUI-48, also
allow EUI-64, or 20-octet IP over InfiniBand
link-layer addresses

Signed-off-by: Jeroen Simonetti <[email protected]>
  • Loading branch information
jsimonetti authored Aug 17, 2023
1 parent d48f14c commit 691cffc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion neigh.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ func (a *NeighAttributes) decode(ad *netlink.AttributeDecoder) error {
}
a.Address = ad.Bytes()
case unix.NDA_LLADDR:
if len(ad.Bytes()) != 6 {
// 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 {
return errInvalidNeighMessageAttr
}
a.LLAddress = ad.Bytes()
Expand Down
39 changes: 39 additions & 0 deletions neigh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,45 @@ func TestNeighMessageMarshalBinary(t *testing.T) {
0x00, 0x00, 0x00, 0x00,
},
},
{
name: "infiniband LL address",
m: &NeighMessage{
Index: 2,
State: 64,
Type: unix.NTF_PROXY,
Attributes: &NeighAttributes{
LLAddress: []byte{0x0, 0x0, 0x0, 0x0, 0xfe, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x02, 0x0, 0x5e, 0x10, 0x0, 0x0, 0x0, 0x01},
},
},
b: []byte{
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00,
0x18, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x02, 0x00, 0x5e, 0x10, 0x00, 0x00, 0x00, 0x01,
0x08, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00,
},
},
{
name: "EUI-64 LL",
m: &NeighMessage{
Index: 2,
State: 64,
Type: unix.NTF_PROXY,
Attributes: &NeighAttributes{
LLAddress: []byte{0x0, 0x0, 0x0, 0x0, 0xfe, 0x80, 0x0, 0xd},
},
},
b: []byte{
0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x08, 0x06, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00,
0x0c, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0xfe, 0x80, 0x00, 0x0d, 0x08, 0x00, 0x08, 0x00,
0x00, 0x00, 0x00, 0x00,
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 691cffc

Please sign in to comment.