From b42063ee86379193fe4225dbbb4a41dee1b1c588 Mon Sep 17 00:00:00 2001
From: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed, 27 Dec 2023 19:47:38 +0300
Subject: [PATCH] Pull request 2121: 6584-stats-non-anonymized-ips

Squashed commit of the following:

commit 4767b7bf61a277f20d8326783cc44de1b736de3d
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Wed Dec 27 14:30:10 2023 +0300

    all: fix non-anonymized ips in stats
---
 CHANGELOG.md                 | 2 ++
 internal/dnsforward/stats.go | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 96b3fdec..ba073606 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,6 +58,7 @@ NOTE: Add new changes BELOW THIS COMMENT.
 
 ### Fixed
 
+- Non-anonymized IP addresses on the dashboard ([#6584]).
 - Maximum cache TTL requirement when editing minimum cache TTL in the Web UI
   ([#6409]).
 - Load balancing algorithm stuck on a single server ([#6480]).
@@ -74,6 +75,7 @@ NOTE: Add new changes BELOW THIS COMMENT.
 [#6534]: https://github.com/AdguardTeam/AdGuardHome/issues/6534
 [#6541]: https://github.com/AdguardTeam/AdGuardHome/issues/6541
 [#6545]: https://github.com/AdguardTeam/AdGuardHome/issues/6545
+[#6584]: https://github.com/AdguardTeam/AdGuardHome/issues/6584
 
 <!--
 NOTE: Add new changes ABOVE THIS COMMENT.
diff --git a/internal/dnsforward/stats.go b/internal/dnsforward/stats.go
index f67e5ad8..6a6b9853 100644
--- a/internal/dnsforward/stats.go
+++ b/internal/dnsforward/stats.go
@@ -25,10 +25,10 @@ func (s *Server) processQueryLogsAndStats(dctx *dnsContext) (rc resultCode) {
 
 	ip := pctx.Addr.Addr().AsSlice()
 	s.anonymizer.Load()(ip)
+	ipStr := net.IP(ip).String()
 
-	log.Debug("dnsforward: client ip for stats and querylog: %s", ip)
+	log.Debug("dnsforward: client ip for stats and querylog: %s", ipStr)
 
-	ipStr := pctx.Addr.Addr().String()
 	ids := []string{ipStr, dctx.clientID}
 	qt, cl := q.Qtype, q.Qclass