diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a276ffc090..74a25d2dfb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,8 @@ NOTE: Add new changes BELOW THIS COMMENT. ### Fixed +- Support for link-local subnets, i.e. `fe80::/16`, as client identifiers + ([#6312]). - Support for link-local subnets, i.e. `fe80::/16`, in the access settings ([#6192]). - The ability to apply an invalid configuration for private RDNS, which led to @@ -43,6 +45,7 @@ NOTE: Add new changes BELOW THIS COMMENT. [#5345]: https://github.com/AdguardTeam/AdGuardHome/issues/5345 [#5812]: https://github.com/AdguardTeam/AdGuardHome/issues/5812 [#6192]: https://github.com/AdguardTeam/AdGuardHome/issues/6192 +[#6312]: https://github.com/AdguardTeam/AdGuardHome/issues/6312 [#6854]: https://github.com/AdguardTeam/AdGuardHome/issues/6854 [#6875]: https://github.com/AdguardTeam/AdGuardHome/issues/6875 diff --git a/internal/client/index.go b/internal/client/index.go index a7f36c482c7..a3d19cb884f 100644 --- a/internal/client/index.go +++ b/internal/client/index.go @@ -192,15 +192,14 @@ func (ci *Index) Find(id string) (c *Persistent, ok bool) { // find finds persistent client by IP address. func (ci *Index) findByIP(ip netip.Addr) (c *Persistent, found bool) { - ip = ip.WithZone("") - uid, found := ci.ipToUID[ip] if found { return ci.uidToClient[uid], true } ci.subnetToUID.Range(func(pref netip.Prefix, id UID) (cont bool) { - if pref.Contains(ip) { + // Remove zone before checking because prefixes stip zones. + if pref.Contains(ip.WithZone("")) { uid, found = id, true return false diff --git a/internal/client/index_internal_test.go b/internal/client/index_internal_test.go index abf38710427..a03d9a221c1 100644 --- a/internal/client/index_internal_test.go +++ b/internal/client/index_internal_test.go @@ -35,27 +35,49 @@ func TestClientIndex(t *testing.T) { cliID = "client-id" cliMAC = "11:11:11:11:11:11" + + linkLocalIP = "fe80::abcd:abcd:abcd:ab%eth0" + linkLocalSubnet = "fe80::/16" ) - clients := []*Persistent{{ - Name: "client1", - IPs: []netip.Addr{ - netip.MustParseAddr(cliIP1), - netip.MustParseAddr(cliIPv6), - }, - }, { - Name: "client2", - IPs: []netip.Addr{netip.MustParseAddr(cliIP2)}, - Subnets: []netip.Prefix{netip.MustParsePrefix(cliSubnet)}, - }, { - Name: "client_with_mac", - MACs: []net.HardwareAddr{mustParseMAC(cliMAC)}, - }, { - Name: "client_with_id", - ClientIDs: []string{cliID}, - }} + var ( + ClientOne = &Persistent{ + Name: "client1", + IPs: []netip.Addr{ + netip.MustParseAddr(cliIP1), + netip.MustParseAddr(cliIPv6), + }, + } + + ClientTwo = &Persistent{ + Name: "client2", + IPs: []netip.Addr{netip.MustParseAddr(cliIP2)}, + Subnets: []netip.Prefix{netip.MustParsePrefix(cliSubnet)}, + } + + ClientWithMAC = &Persistent{ + Name: "client_with_mac", + MACs: []net.HardwareAddr{mustParseMAC(cliMAC)}, + } + + ClientWithID = &Persistent{ + Name: "client_with_id", + ClientIDs: []string{cliID}, + } + + ClientLinkLocal = &Persistent{ + Name: "client_link_local", + Subnets: []netip.Prefix{netip.MustParsePrefix(linkLocalSubnet)}, + } + ) - ci := newIDIndex(clients) + ci := newIDIndex([]*Persistent{ + ClientOne, + ClientTwo, + ClientWithMAC, + ClientWithID, + ClientLinkLocal, + }) testCases := []struct { want *Persistent @@ -64,19 +86,23 @@ func TestClientIndex(t *testing.T) { }{{ name: "ipv4_ipv6", ids: []string{cliIP1, cliIPv6}, - want: clients[0], + want: ClientOne, }, { name: "ipv4_subnet", ids: []string{cliIP2, cliSubnetIP}, - want: clients[1], + want: ClientTwo, }, { name: "mac", ids: []string{cliMAC}, - want: clients[2], + want: ClientWithMAC, }, { name: "client_id", ids: []string{cliID}, - want: clients[3], + want: ClientWithID, + }, { + name: "client_link_local_subnet", + ids: []string{linkLocalIP}, + want: ClientLinkLocal, }} for _, tc := range testCases { diff --git a/internal/client/persistent.go b/internal/client/persistent.go index 8345f41896a..06e346f4dfc 100644 --- a/internal/client/persistent.go +++ b/internal/client/persistent.go @@ -161,7 +161,7 @@ func (c *Persistent) setID(id string) (err error) { var ip netip.Addr if ip, err = netip.ParseAddr(id); err == nil { - c.IPs = append(c.IPs, ip.WithZone("")) + c.IPs = append(c.IPs, ip) return nil }