From 44880f9b2cfc057322a88c5e847be0aa07d0afd2 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Mon, 9 Apr 2018 13:16:30 +0200 Subject: [PATCH] Patterns are now fully supported in cloaking rules Fixes #306 --- dnscrypt-proxy/example-cloaking-rules.txt | 3 +-- dnscrypt-proxy/plugin_cloak.go | 13 +++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dnscrypt-proxy/example-cloaking-rules.txt b/dnscrypt-proxy/example-cloaking-rules.txt index 1e3e062a..ca51944c 100644 --- a/dnscrypt-proxy/example-cloaking-rules.txt +++ b/dnscrypt-proxy/example-cloaking-rules.txt @@ -9,8 +9,7 @@ # configuration file -www.google.com forcesafesearch.google.com -www.google.fr forcesafesearch.google.com +www.google.* forcesafesearch.google.com www.bing.com strict.bing.com diff --git a/dnscrypt-proxy/plugin_cloak.go b/dnscrypt-proxy/plugin_cloak.go index 708b33d5..885d8c9d 100644 --- a/dnscrypt-proxy/plugin_cloak.go +++ b/dnscrypt-proxy/plugin_cloak.go @@ -22,8 +22,8 @@ type CloakedName struct { type PluginCloak struct { sync.RWMutex - cloakedNames map[string]*CloakedName - ttl uint32 + patternMatcher *PatternMatcher + ttl uint32 } func (plugin *PluginCloak) Name() string { @@ -41,7 +41,7 @@ func (plugin *PluginCloak) Init(proxy *Proxy) error { return err } plugin.ttl = proxy.cacheMinTTL - plugin.cloakedNames = make(map[string]*CloakedName) + plugin.patternMatcher = NewPatternPatcher() for lineNo, line := range strings.Split(string(bin), "\n") { line = strings.TrimFunc(line, unicode.IsSpace) if len(line) == 0 || strings.HasPrefix(line, "#") { @@ -75,7 +75,7 @@ func (plugin *PluginCloak) Init(proxy *Proxy) error { } else { cloakedName.target = target } - plugin.cloakedNames[line] = &cloakedName + plugin.patternMatcher.Add(line, &cloakedName, lineNo+1) } return nil } @@ -103,11 +103,12 @@ func (plugin *PluginCloak) Eval(pluginsState *PluginsState, msg *dns.Msg) error } now := time.Now() plugin.RLock() - cloakedName := plugin.cloakedNames[qName] - if cloakedName == nil { + _, _, xcloakedName := plugin.patternMatcher.Eval(qName) + if xcloakedName == nil { plugin.RUnlock() return nil } + cloakedName := xcloakedName.(*CloakedName) ttl, expired := plugin.ttl, false if cloakedName.lastUpdate != nil { if elapsed := uint32(now.Sub(*cloakedName.lastUpdate).Seconds()); elapsed < ttl {