From c95acf73abec683acf46788bd32e775b68d75225 Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Mon, 31 May 2021 15:24:21 +0300 Subject: [PATCH] Pull request: dnsforward: preserve domain name case Updates #3194. Squashed commit of the following: commit 42a363c56b9b7441f9dc4bfc9d881b1b1e8f6b57 Author: Ainar Garipov Date: Mon May 31 15:15:59 2021 +0300 dnsforward: preserve domain name case --- CHANGELOG.md | 2 ++ internal/dnsforward/access.go | 8 +++++--- internal/dnsforward/filter.go | 9 +++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b23ee286..d4153a51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ released by then. ### Fixed +- Domain name case in responses ([#3194]). - Custom upstreams selection for clients with client IDs in DNS-over-TLS and DNS-over-HTTP ([#3186]). - Incorrect client-based filtering applying logic ([#2875]). @@ -48,6 +49,7 @@ released by then. [#3184]: https://github.com/AdguardTeam/AdGuardHome/issues/3184 [#3185]: https://github.com/AdguardTeam/AdGuardHome/issues/3185 [#3186]: https://github.com/AdguardTeam/AdGuardHome/issues/3186 +[#3194]: https://github.com/AdguardTeam/AdGuardHome/issues/3194 [#3198]: https://github.com/AdguardTeam/AdGuardHome/issues/3198 diff --git a/internal/dnsforward/access.go b/internal/dnsforward/access.go index 62c1e35b..73b40bd7 100644 --- a/internal/dnsforward/access.go +++ b/internal/dnsforward/access.go @@ -129,10 +129,12 @@ func (a *accessCtx) IsBlockedIP(ip net.IP) (bool, string) { } // IsBlockedDomain - return TRUE if this domain should be blocked -func (a *accessCtx) IsBlockedDomain(host string) bool { +func (a *accessCtx) IsBlockedDomain(host string) (ok bool) { a.lock.Lock() - _, ok := a.blockedHostsEngine.Match(host) - a.lock.Unlock() + defer a.lock.Unlock() + + _, ok = a.blockedHostsEngine.Match(strings.ToLower(host)) + return ok } diff --git a/internal/dnsforward/filter.go b/internal/dnsforward/filter.go index 69ffa9a6..baabded2 100644 --- a/internal/dnsforward/filter.go +++ b/internal/dnsforward/filter.go @@ -20,13 +20,10 @@ func (s *Server) beforeRequestHandler(_ *proxy.Proxy, d *proxy.DNSContext) (bool } if len(d.Req.Question) == 1 { - // It's lowercased here since this handler is called before any - // other one. - name := strings.ToLower(d.Req.Question[0].Name) - d.Req.Question[0].Name = name - host := strings.TrimSuffix(name, ".") + host := strings.TrimSuffix(d.Req.Question[0].Name, ".") if s.access.IsBlockedDomain(host) { - log.Tracef("Domain %s is blocked by settings", host) + log.Tracef("domain %s is blocked by access settings", host) + return false, nil } }