Check if protection is enabled before running the host through dnsfilter.

Closes #476.
This commit is contained in:
Eugene Bujak 2018-12-11 14:20:14 +03:00
parent 69a387547d
commit 5c4ec62d96
1 changed files with 12 additions and 8 deletions

View File

@ -426,9 +426,12 @@ func (s *Server) handlePacketInternal(msg *dns.Msg, addr net.Addr, conn *net.UDP
return s.genNotImpl(msg), nil, nil, nil return s.genNotImpl(msg), nil, nil, nil
} }
// use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise
host := strings.TrimSuffix(msg.Question[0].Name, ".") host := strings.TrimSuffix(msg.Question[0].Name, ".")
res, err := s.dnsFilter.CheckHost(host) // use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise
var res dnsfilter.Result
var err error
if s.ProtectionEnabled {
res, err = s.dnsFilter.CheckHost(host)
if err != nil { if err != nil {
log.Printf("dnsfilter failed to check host '%s': %s", host, err) log.Printf("dnsfilter failed to check host '%s': %s", host, err)
return s.genServerFailure(msg), &res, nil, err return s.genServerFailure(msg), &res, nil, err
@ -436,6 +439,7 @@ func (s *Server) handlePacketInternal(msg *dns.Msg, addr net.Addr, conn *net.UDP
log.Printf("Host %s is filtered, reason - '%s', matched rule: '%s'", host, res.Reason, res.Rule) log.Printf("Host %s is filtered, reason - '%s', matched rule: '%s'", host, res.Reason, res.Rule)
return s.genNXDomain(msg), &res, nil, nil return s.genNXDomain(msg), &res, nil, nil
} }
}
{ {
val, ok := s.cache.Get(msg) val, ok := s.cache.Get(msg)