From b1657c2b2a89e0b6c8d815f958f472ac5fae7451 Mon Sep 17 00:00:00 2001 From: Gunjan Gupta Date: Fri, 3 Jan 2025 20:52:31 +0530 Subject: [PATCH 1/6] dhcpd: Fix slaac configuration which was not working due to invalid icmp packet Signed-off-by: Gunjan Gupta --- internal/dhcpd/routeradv.go | 23 ++++++++++------------- internal/dhcpd/routeradv_test.go | 7 +++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/internal/dhcpd/routeradv.go b/internal/dhcpd/routeradv.go index 2b480b46..32b7e6dc 100644 --- a/internal/dhcpd/routeradv.go +++ b/internal/dhcpd/routeradv.go @@ -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: diff --git a/internal/dhcpd/routeradv_test.go b/internal/dhcpd/routeradv_test.go index 94f7afd3..e007d460 100644 --- a/internal/dhcpd/routeradv_test.go +++ b/internal/dhcpd/routeradv_test.go @@ -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{ From 0c72cde4c3f0f6ca076c96d5941b4971349642a1 Mon Sep 17 00:00:00 2001 From: Gunjan Gupta Date: Sat, 4 Jan 2025 00:21:49 +0530 Subject: [PATCH 2/6] Change comment message to match implementation Signed-off-by: Gunjan Gupta --- internal/dhcpd/routeradv.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/dhcpd/routeradv.go b/internal/dhcpd/routeradv.go index 32b7e6dc..b2376f70 100644 --- a/internal/dhcpd/routeradv.go +++ b/internal/dhcpd/routeradv.go @@ -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 From 74640fb06c466e4d0352fc1046b4e2e52ab4b845 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Thu, 6 Mar 2025 15:15:06 +0300 Subject: [PATCH 3/6] all: imp code & test, log changes --- CHANGELOG.md | 2 + internal/dhcpd/routeradv.go | 31 ++++++----- internal/dhcpd/routeradv_internal_test.go | 63 +++++++++++++++++++++++ internal/dhcpd/routeradv_test.go | 37 ------------- 4 files changed, 80 insertions(+), 53 deletions(-) create mode 100644 internal/dhcpd/routeradv_internal_test.go delete mode 100644 internal/dhcpd/routeradv_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index cf02db7b..3c5a8945 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,9 +28,11 @@ NOTE: Add new changes BELOW THIS COMMENT. ### Fixed +- Invalid ICMPv6 Router Advertisement messages ([#7547]). - The formatting of large numbers on the dashboard ([#7329]). [#7329]: https://github.com/AdguardTeam/AdGuardHome/issues/7329 +[#7547]: https://github.com/AdguardTeam/AdGuardHome/issues/7547