Pull request 1952: 5948-fix-dns-filter

Updates #5948.

Squashed commit of the following:

commit 9dbc197f004a19211e5fedeb9bdd7075e2915fce
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Mon Aug 7 15:06:38 2023 +0300

    all: imp chlog

commit fbcccc2ff3663fc8ae0cd75ef6ac4cdcc0fa7d36
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Thu Aug 3 16:58:35 2023 +0300

    all: upd chlog

commit 4f9e8fcbfb4d43fd98a99529f20e9d40946ee5c1
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date:   Wed Aug 2 19:24:42 2023 +0300

    dnsforward: fix dns filter
This commit is contained in:
Stanislav Chzhen 2023-08-07 16:07:21 +03:00
parent 5eb3cd0f92
commit 93a0601f41
7 changed files with 13 additions and 14 deletions

View File

@ -53,6 +53,13 @@ In this release, the schema version has changed from 24 to 25.
remove the new object `pprof`, set back `debug_pprof`, and change the remove the new object `pprof`, set back `debug_pprof`, and change the
`schema_version` back to `24`. `schema_version` back to `24`.
### Fixed
- Panic on shutting down while DNS requests are in process of filtering
([#5948]).
[#5948]: https://github.com/AdguardTeam/AdGuardHome/issues/5948
<!-- <!--
NOTE: Add new changes ABOVE THIS COMMENT. NOTE: Add new changes ABOVE THIS COMMENT.
--> -->

View File

@ -244,7 +244,7 @@ func (s *Server) Close() {
s.serverLock.Lock() s.serverLock.Lock()
defer s.serverLock.Unlock() defer s.serverLock.Unlock()
s.dnsFilter = nil // TODO(s.chzhen): Remove it.
s.stats = nil s.stats = nil
s.queryLog = nil s.queryLog = nil
s.dnsProxy = nil s.dnsProxy = nil

View File

@ -335,7 +335,7 @@ func TestServer_timeout(t *testing.T) {
}, },
} }
s, err := NewServer(DNSCreateParams{}) s, err := NewServer(DNSCreateParams{DNSFilter: &filtering.DNSFilter{}})
require.NoError(t, err) require.NoError(t, err)
err = s.Prepare(srvConf) err = s.Prepare(srvConf)
@ -345,7 +345,7 @@ func TestServer_timeout(t *testing.T) {
}) })
t.Run("default", func(t *testing.T) { t.Run("default", func(t *testing.T) {
s, err := NewServer(DNSCreateParams{}) s, err := NewServer(DNSCreateParams{DNSFilter: &filtering.DNSFilter{}})
require.NoError(t, err) require.NoError(t, err)
s.conf.FilteringConfig.BlockingMode = BlockingModeDefault s.conf.FilteringConfig.BlockingMode = BlockingModeDefault

View File

@ -145,10 +145,6 @@ func (s *Server) checkHostRules(host string, rrtype uint16, setts *filtering.Set
s.serverLock.RLock() s.serverLock.RLock()
defer s.serverLock.RUnlock() defer s.serverLock.RUnlock()
if s.dnsFilter == nil {
return nil, nil
}
var res filtering.Result var res filtering.Result
res, err = s.dnsFilter.CheckHostRules(host, rrtype, setts) res, err = s.dnsFilter.CheckHostRules(host, rrtype, setts)
if err != nil { if err != nil {

View File

@ -667,7 +667,7 @@ func (s *Server) parseUpstreamLine(
PreferIPv6: opts.PreferIPv6, PreferIPv6: opts.PreferIPv6,
} }
if s.dnsFilter != nil && s.dnsFilter.EtcHosts != nil { if s.dnsFilter.EtcHosts != nil {
resolved := s.resolveUpstreamHost(extractUpstreamHost(upstreamAddr)) resolved := s.resolveUpstreamHost(extractUpstreamHost(upstreamAddr))
sortNetIPAddrs(resolved, opts.PreferIPv6) sortNetIPAddrs(resolved, opts.PreferIPv6)
opts.ServerIPAddrs = resolved opts.ServerIPAddrs = resolved

View File

@ -762,10 +762,6 @@ func (s *Server) processFilteringBeforeRequest(ctx *dnsContext) (rc resultCode)
s.serverLock.RLock() s.serverLock.RLock()
defer s.serverLock.RUnlock() defer s.serverLock.RUnlock()
if s.dnsFilter == nil {
return resultCodeSuccess
}
var err error var err error
if ctx.result, err = s.filterDNSRequest(ctx); err != nil { if ctx.result, err = s.filterDNSRequest(ctx); err != nil {
ctx.err = err ctx.err = err
@ -972,7 +968,7 @@ func (s *Server) filterAfterResponse(dctx *dnsContext, pctx *proxy.DNSContext) (
// Check the response only if it's from an upstream. Don't check the // Check the response only if it's from an upstream. Don't check the
// response if the protection is disabled since dnsrewrite rules aren't // response if the protection is disabled since dnsrewrite rules aren't
// applied to it anyway. // applied to it anyway.
if !dctx.protectionEnabled || !dctx.responseFromUpstream || s.dnsFilter == nil { if !dctx.protectionEnabled || !dctx.responseFromUpstream {
return resultCodeSuccess return resultCodeSuccess
} }

View File

@ -94,7 +94,7 @@ func (s *Server) prepareUpstreamConfig(
uc.Upstreams = defaultUpstreamConfig.Upstreams uc.Upstreams = defaultUpstreamConfig.Upstreams
} }
if s.dnsFilter != nil && s.dnsFilter.EtcHosts != nil { if s.dnsFilter.EtcHosts != nil {
err = s.replaceUpstreamsWithHosts(uc, opts) err = s.replaceUpstreamsWithHosts(uc, opts)
if err != nil { if err != nil {
return nil, fmt.Errorf("resolving upstreams with hosts: %w", err) return nil, fmt.Errorf("resolving upstreams with hosts: %w", err)