diff --git a/internal/home/clients.go b/internal/home/clients.go index f1626eb6..27ad5481 100644 --- a/internal/home/clients.go +++ b/internal/home/clients.go @@ -56,8 +56,9 @@ type clientsContainer struct { // dhcp is the DHCP service implementation. dhcp DHCP - // dnsServer is used for checking clients IP status access list status - dnsServer BlockedClientChecker + // clientChecker checks if a client is blocked by the current access + // settings. + clientChecker BlockedClientChecker // etcHosts contains list of rewrite rules taken from the operating system's // hosts database. @@ -408,7 +409,7 @@ func (clients *clientsContainer) clientOrArtificial( id string, ) (c *querylog.Client, art bool) { defer func() { - c.Disallowed, c.DisallowedRule = clients.dnsServer.IsBlockedClient(ip, id) + c.Disallowed, c.DisallowedRule = clients.clientChecker.IsBlockedClient(ip, id) if c.WHOIS == nil { c.WHOIS = &whois.Info{} } @@ -543,12 +544,7 @@ func (clients *clientsContainer) findDHCP(ip netip.Addr) (c *client.Persistent, return nil, false } - c, found := clients.clientIndex.FindByMAC(foundMAC) - if found { - return c, true - } - - return nil, false + return clients.clientIndex.FindByMAC(foundMAC) } // runtimeClient returns a runtime client from internal index. Note that it diff --git a/internal/home/clientshttp.go b/internal/home/clientshttp.go index 0a744f79..40a91f86 100644 --- a/internal/home/clientshttp.go +++ b/internal/home/clientshttp.go @@ -451,7 +451,7 @@ func (clients *clientsContainer) handleFindClient(w http.ResponseWriter, r *http cj = clients.findRuntime(ip, idStr) } else { cj = clientToJSON(c) - disallowed, rule := clients.dnsServer.IsBlockedClient(ip, idStr) + disallowed, rule := clients.clientChecker.IsBlockedClient(ip, idStr) cj.Disallowed, cj.DisallowedRule = &disallowed, &rule } @@ -474,7 +474,7 @@ func (clients *clientsContainer) findRuntime(ip netip.Addr, idStr string) (cj *c // blocked IP list. // // See https://github.com/AdguardTeam/AdGuardHome/issues/2428. - disallowed, rule := clients.dnsServer.IsBlockedClient(ip, idStr) + disallowed, rule := clients.clientChecker.IsBlockedClient(ip, idStr) cj = &clientJSON{ IDs: []string{idStr}, Disallowed: &disallowed, @@ -492,7 +492,7 @@ func (clients *clientsContainer) findRuntime(ip netip.Addr, idStr string) (cj *c WHOIS: whoisOrEmpty(rc), } - disallowed, rule := clients.dnsServer.IsBlockedClient(ip, idStr) + disallowed, rule := clients.clientChecker.IsBlockedClient(ip, idStr) cj.Disallowed, cj.DisallowedRule = &disallowed, &rule return cj diff --git a/internal/home/clientshttp_internal_test.go b/internal/home/clientshttp_internal_test.go index c0dd2a7f..c5be1720 100644 --- a/internal/home/clientshttp_internal_test.go +++ b/internal/home/clientshttp_internal_test.go @@ -70,7 +70,7 @@ func newPersistentClientWithIDs(tb testing.TB, name string, ids []string) (c *cl func assertClients(tb testing.TB, want, got []*client.Persistent) { tb.Helper() - require.Len(tb, want, len(got)) + require.Len(tb, got, len(want)) sortFunc := func(a, b *client.Persistent) (n int) { return cmp.Compare(a.Name, b.Name) @@ -335,7 +335,7 @@ func TestClientsContainer_HandleUpdateClient(t *testing.T) { func TestClientsContainer_HandleFindClient(t *testing.T) { clients := newClientsContainer(t) - clients.dnsServer = &testBlockedClientChecker{ + clients.clientChecker = &testBlockedClientChecker{ onIsBlockedClient: func(ip netip.Addr, clientID string) (ok bool, rule string) { return false, "" }, diff --git a/internal/home/dns.go b/internal/home/dns.go index 0ca9717d..08e1bcd0 100644 --- a/internal/home/dns.go +++ b/internal/home/dns.go @@ -149,7 +149,7 @@ func initDNSServer( return fmt.Errorf("dnsforward.NewServer: %w", err) } - Context.clients.dnsServer = Context.dnsServer + Context.clients.clientChecker = Context.dnsServer dnsConf, err := newServerConfig(&config.DNS, config.Clients.Sources, tlsConf, httpReg) if err != nil {