Patterns are now fully supported in cloaking rules

Fixes #306
This commit is contained in:
Frank Denis 2018-04-09 13:16:30 +02:00
parent 7d10628a5f
commit 44880f9b2c
2 changed files with 8 additions and 8 deletions

View File

@ -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

View File

@ -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 {