Skip to content

Commit

Permalink
Pull request: 3185 fix recursion vol.2
Browse files Browse the repository at this point in the history
Merge in DNS/adguard-home from fix-recursion to master

Closes AdguardTeam#3185.

Squashed commit of the following:

commit c78650b
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Mon May 31 13:12:46 2021 +0300

    all: fix changelog

commit e43017a
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Sun May 30 22:39:05 2021 +0300

    dnsforward: reduce recursion ttl

commit 79208a8
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Sun May 30 22:29:27 2021 +0300

    dnsforward: only check recursion for private rdns

commit 1b8075b
Author: Eugene Burkov <e.burkov@adguard.com>
Date:   Sun May 30 22:18:11 2021 +0300

    dnsforward: rm recursion detecting from upstream
  • Loading branch information
EugeneOne1 authored and heyxkhoa committed Mar 17, 2023
1 parent 7510ded commit dc2372c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion internal/dnsforward/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 11 additions & 9 deletions internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion internal/dnsforward/recursiondetector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc2372c

Please sign in to comment.