This commit is contained in:
Yaman Qalieh 2024-05-03 06:23:04 +01:00 committed by GitHub
commit 6bfac2f6d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 15 deletions

View File

@ -50,18 +50,20 @@ func hwAddrToLinkLayerAddr(hwa net.HardwareAddr) (lla []byte, err error) {
return nil, err
}
if len(hwa) == 6 || len(hwa) == 8 {
lla = make([]byte, 8)
copy(lla, hwa)
switch len(hwa) {
// EUI-48 are 6 bytes, so 6 + 2 prefix bytes is divisible by 8
case 6:
lla = make([]byte, 6)
return lla, nil
// EUI-64 are 8 bytes, so pad to 14 so that with the prefix, it's divisible by 8
case 8:
lla = make([]byte, 14)
// The last validated type by netutil.ValidateMAC is 20 byte InfiniBand link-layer address
default:
lla = make([]byte, 22)
}
// Assume that netutil.ValidateMAC prevents lengths other than 20 by
// now.
lla = make([]byte, 24)
copy(lla, hwa)
return lla, nil
}
@ -93,7 +95,9 @@ func hwAddrToLinkLayerAddr(hwa net.HardwareAddr) (lla []byte, err error) {
// - Reserved[2]
// - MTU[4]
// - Option=Source link-layer address(1):
// - Link-Layer Address[8/24]
// - Type[1]
// - Length * 8bytes[1]
// - Link-Layer Address[6/14/22]
// - Option=Recursive DNS Server(25):
// - Type[1]
// - Length * 8bytes[1]
@ -176,7 +180,7 @@ func createICMPv6RAPacket(params icmpv6RA) (data []byte, err error) {
// Option=Source link-layer address:
data[i] = 1 // Type
data[i+1] = 1 // Length
data[i+1] = byte((len(lla) + 2) / 8) // Length of this entire option in bytes
i += 2
copy(data[i:], lla) // Link-Layer Address[8/24]

View File

@ -17,10 +17,9 @@ func TestCreateICMPv6RAPacket(t *testing.T) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x05, 0xdc,
0x01, 0x01, 0x0a, 0x00, 0x27, 0x00, 0x00, 0x00,
0x00, 0x00, 0x19, 0x03, 0x00, 0x00, 0x00, 0x00,
0x0e, 0x10, 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x08, 0x00, 0x27, 0xff, 0xfe, 0x00,
0x00, 0x00,
0x19, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x10,
0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x27, 0xff, 0xfe, 0x00, 0x00, 0x00,
}
gotData, err := createICMPv6RAPacket(icmpv6RA{