Skip to content

Commit

Permalink
all: upd chlog; imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
schzhn committed Apr 16, 2024
1 parent 7a4426c commit 155b2fe
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 26 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
5 changes: 2 additions & 3 deletions internal/client/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 48 additions & 22 deletions internal/client/index_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion internal/client/persistent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 155b2fe

Please sign in to comment.