mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2025-02-20 11:44:09 +08:00
Merge 0c72cde4c3f0f6ca076c96d5941b4971349642a1 into 1e0873aa71849de9ffc6814b620dbbf920ffa9f8
This commit is contained in:
commit
e38ecff3d6
@ -15,8 +15,8 @@ import (
|
||||
)
|
||||
|
||||
type raCtx struct {
|
||||
raAllowSLAAC bool // send RA packets without MO flags
|
||||
raSLAACOnly bool // send RA packets with MO flags
|
||||
raAllowSLAAC bool // send RA packets with MO flags
|
||||
raSLAACOnly bool // send RA packets without MO flags
|
||||
ipAddr net.IP // source IP address (link-local-unicast)
|
||||
dnsIPAddr net.IP // IP address for DNS Server option
|
||||
prefixIPAddr net.IP // IP address for Prefix option
|
||||
@ -50,16 +50,7 @@ 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)
|
||||
|
||||
return lla, nil
|
||||
}
|
||||
|
||||
// Assume that netutil.ValidateMAC prevents lengths other than 20 by
|
||||
// now.
|
||||
lla = make([]byte, 24)
|
||||
lla = make([]byte, len(hwa))
|
||||
copy(lla, hwa)
|
||||
|
||||
return lla, nil
|
||||
@ -109,9 +100,15 @@ func createICMPv6RAPacket(params icmpv6RA) (data []byte, err error) {
|
||||
return nil, fmt.Errorf("converting source link layer address: %w", err)
|
||||
}
|
||||
|
||||
// Calculate length of source link layer address section
|
||||
// This is based on calculation from radvd's add_ra_option_sllao function
|
||||
sllao_bytes := len(lla) + 2
|
||||
sllao_len := (sllao_bytes + 7) / 8
|
||||
sllao_pad_bytes := sllao_len * 8 - sllao_bytes
|
||||
|
||||
// TODO(a.garipov): Don't use a magic constant here. Refactor the code
|
||||
// and make all constants named instead of all those comments..
|
||||
data = make([]byte, 82+len(lla))
|
||||
data = make([]byte, 80+sllao_bytes+sllao_pad_bytes)
|
||||
i := 0
|
||||
|
||||
// ICMPv6:
|
||||
@ -176,11 +173,11 @@ 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(sllao_len) // Length
|
||||
i += 2
|
||||
|
||||
copy(data[i:], lla) // Link-Layer Address[8/24]
|
||||
i += len(lla)
|
||||
i += len(lla) + sllao_pad_bytes
|
||||
|
||||
// Option=Recursive DNS Server:
|
||||
|
||||
|
@ -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{
|
||||
|
Loading…
x
Reference in New Issue
Block a user