diff --git a/CHANGELOG.md b/CHANGELOG.md index 17e31a65..b23ee286 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,8 @@ and this project adheres to ### Added -- Detection and handling of recurrent requests ([#3185]). +- Detection and handling of recurrent PTR requests for locally-served addresses + ([#3185]). - The ability to completely disable reverse DNS resolving of IPs from locally-served networks ([#3184]). - New flag `--local-frontend` to serve dinamically changeable frontend files diff --git a/internal/dnsforward/dns.go b/internal/dnsforward/dns.go index 76196da2..5d6fdf49 100644 --- a/internal/dnsforward/dns.go +++ b/internal/dnsforward/dns.go @@ -532,7 +532,6 @@ func (s *Server) processUpstream(ctx *dnsContext) (rc resultCode) { } // request was not filtered so let it be processed further - s.recDetector.add(*req) if ctx.err = s.dnsProxy.Resolve(d); ctx.err != nil { return resultCodeError } diff --git a/internal/dnsforward/dnsforward.go b/internal/dnsforward/dnsforward.go index e0c938e0..35069656 100644 --- a/internal/dnsforward/dnsforward.go +++ b/internal/dnsforward/dnsforward.go @@ -124,7 +124,7 @@ func domainNameToSuffix(tld string) (suffix string) { const ( // recursionTTL is the time recursive request is cached for. - recursionTTL = 5 * time.Second + recursionTTL = 1 * time.Second // cachedRecurrentReqNum is the maximum number of cached recurrent // requests. cachedRecurrentReqNum = 1000 @@ -265,13 +265,6 @@ func (s *Server) Exchange(ip net.IP) (host string, err error) { return "", nil } - var resolver *proxy.Proxy = s.localResolvers - if !s.subnetDetector.IsLocallyServedNetwork(ip) { - resolver = s.internalProxy - } else if !s.conf.UsePrivateRDNS { - return "", nil - } - arpa := dns.Fqdn(aghnet.ReverseAddr(ip)) req := &dns.Msg{ MsgHdr: dns.MsgHdr{ @@ -291,7 +284,16 @@ func (s *Server) Exchange(ip net.IP) (host string, err error) { StartTime: time.Now(), } - s.recDetector.add(*req) + var resolver *proxy.Proxy = s.internalProxy + if s.subnetDetector.IsLocallyServedNetwork(ip) { + if !s.conf.UsePrivateRDNS { + return "", nil + } + + resolver = s.localResolvers + s.recDetector.add(*req) + } + if err = resolver.Resolve(ctx); err != nil { return "", err } diff --git a/internal/dnsforward/recursiondetector.go b/internal/dnsforward/recursiondetector.go index 5203f518..e0e1537b 100644 --- a/internal/dnsforward/recursiondetector.go +++ b/internal/dnsforward/recursiondetector.go @@ -26,7 +26,7 @@ type recursionDetector struct { ttl time.Duration } -// check checks if the passed req was already sent by s. +// check checks if the passed req was already sent by the server. func (rd *recursionDetector) check(msg dns.Msg) (ok bool) { if len(msg.Question) == 0 { return false