dnsforward -- use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise

This commit is contained in:
Eugene Bujak 2018-11-30 14:04:17 +03:00
parent 0a4627f4f0
commit be4b65fdca
1 changed files with 17 additions and 17 deletions

View File

@ -393,21 +393,7 @@ func (s *Server) handlePacket(p []byte, addr net.Addr, conn *net.UDPConn) {
} }
} }
{ // use dnsfilter before cache -- changed settings or filters would require cache invalidation otherwise
val, ok := s.cache.Get(&msg)
if ok && val != nil {
err = s.respond(val, addr, conn)
if err != nil {
if isConnClosed(err) {
// ignore this error, the connection was closed and that's ok
return
}
log.Printf("Couldn't respond to UDP packet: %s", err)
return
}
return
}
}
host := strings.TrimSuffix(msg.Question[0].Name, ".") host := strings.TrimSuffix(msg.Question[0].Name, ".")
res, err := s.dnsFilter.CheckHost(host) res, err := s.dnsFilter.CheckHost(host)
if err != nil { if err != nil {
@ -426,9 +412,23 @@ func (s *Server) handlePacket(p []byte, addr net.Addr, conn *net.UDPConn) {
} }
} }
{
val, ok := s.cache.Get(&msg)
if ok && val != nil {
err = s.respond(val, addr, conn)
if err != nil {
if isConnClosed(err) {
// ignore this error, the connection was closed and that's ok
return
}
log.Printf("Couldn't respond to UDP packet: %s", err)
return
}
return
}
}
// TODO: replace with single-socket implementation // TODO: replace with single-socket implementation
// TODO: replace 8.8.8.8:53 with configurable upstreams
// TODO: support DoH, DoT and TCP
upstream := s.chooseUpstream() upstream := s.chooseUpstream()
reply, err := upstream.Exchange(&msg) reply, err := upstream.Exchange(&msg)
if err != nil { if err != nil {