From 29d847c3668275c0e74a4d5368d6d8f770500eb9 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Wed, 12 May 2021 20:04:50 +0300 Subject: [PATCH] Pull request: 2875 client settings Merge in DNS/adguard-home from 2875-client-settings to master Updates #2875. Squashed commit of the following: commit 43e5af66acb8ace71a329fe2effae6a78492d73f Author: Eugene Burkov Date: Wed May 12 18:12:03 2021 +0300 all: fix client settings applying --- CHANGELOG.md | 3 ++ internal/dnsforward/dnsforward.go | 4 +-- internal/dnsforward/filter.go | 2 -- internal/home/filter.go | 60 +++++++++++-------------------- 4 files changed, 25 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 42aef610..b1754378 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,11 @@ and this project adheres to ### Fixed +- Ignoring client-specific filtering settings when filtering is disabled in + general settings ([#2875]). - Disallowed domains are now case-insensitive ([#3115]). +[#2875]: https://github.com/AdguardTeam/AdGuardHome/issues/2875 [#3115]: https://github.com/AdguardTeam/AdGuardHome/issues/3115 diff --git a/internal/dnsforward/dnsforward.go b/internal/dnsforward/dnsforward.go index 6d8f8a27..71817c58 100644 --- a/internal/dnsforward/dnsforward.go +++ b/internal/dnsforward/dnsforward.go @@ -370,9 +370,7 @@ func (s *Server) setupResolvers(localAddrs []string) (err error) { // really applicable here since in case of listening on all network // interfaces we should check the whole interface's network to cut off // all the loopback addresses as well. - localAddrs = aghstrings.FilterOut(localAddrs, func(s string) (ok bool) { - return ourAddrsSet.Has(s) - }) + localAddrs = aghstrings.FilterOut(localAddrs, ourAddrsSet.Has) var upsConfig proxy.UpstreamConfig upsConfig, err = proxy.ParseUpstreamsConfig(localAddrs, upstream.Options{ diff --git a/internal/dnsforward/filter.go b/internal/dnsforward/filter.go index 93a72a86..331bbdc1 100644 --- a/internal/dnsforward/filter.go +++ b/internal/dnsforward/filter.go @@ -50,8 +50,6 @@ func (s *Server) getClientRequestFilteringSettings(ctx *dnsContext) *dnsfilter.F // filtered. func (s *Server) filterDNSRequest(ctx *dnsContext) (*dnsfilter.Result, error) { d := ctx.proxyCtx - // TODO(e.burkov): Consistently use req instead of d.Req since it is - // declared. req := d.Req host := strings.TrimSuffix(req.Question[0].Name, ".") res, err := s.dnsFilter.CheckHost(host, req.Question[0].Qtype, ctx.setts) diff --git a/internal/home/filter.go b/internal/home/filter.go index 639bec45..ccad20cb 100644 --- a/internal/home/filter.go +++ b/internal/home/filter.go @@ -76,16 +76,6 @@ type filter struct { dnsfilter.Filter `yaml:",inline"` } -// Creates a helper object for working with the user rules -func userFilter() filter { - f := filter{ - // User filter always has constant ID=0 - Enabled: true, - } - f.Filter.Data = []byte(strings.Join(config.UserRules, "\n")) - return f -} - const ( statusFound = 1 statusEnabledChanged = 2 @@ -689,41 +679,33 @@ func (filter *filter) LastTimeUpdated() time.Time { } func enableFilters(async bool) { - var filters []dnsfilter.Filter var whiteFilters []dnsfilter.Filter - if config.DNS.FilteringEnabled { - // convert array of filters + filters := []dnsfilter.Filter{{ + Data: []byte(strings.Join(config.UserRules, "\n")), + }} - userFilter := userFilter() - f := dnsfilter.Filter{ - ID: userFilter.ID, - Data: userFilter.Data, + for _, filter := range config.Filters { + if !filter.Enabled { + continue } - filters = append(filters, f) - for _, filter := range config.Filters { - if !filter.Enabled { - continue - } - - f = dnsfilter.Filter{ - ID: filter.ID, - FilePath: filter.Path(), - } - filters = append(filters, f) + filters = append(filters, dnsfilter.Filter{ + ID: filter.ID, + FilePath: filter.Path(), + }) + } + for _, filter := range config.WhitelistFilters { + if !filter.Enabled { + continue } - for _, filter := range config.WhitelistFilters { - if !filter.Enabled { - continue - } - f = dnsfilter.Filter{ - ID: filter.ID, - FilePath: filter.Path(), - } - whiteFilters = append(whiteFilters, f) - } + whiteFilters = append(whiteFilters, dnsfilter.Filter{ + ID: filter.ID, + FilePath: filter.Path(), + }) } - _ = Context.dnsFilter.SetFilters(filters, whiteFilters, async) + if err := Context.dnsFilter.SetFilters(filters, whiteFilters, async); err != nil { + log.Debug("enabling filters: %s", err) + } }