Fix tests

This commit is contained in:
Andrey Meshkov 2019-02-22 18:41:59 +03:00
parent ad4b58472f
commit 1da954fa97
1 changed files with 15 additions and 7 deletions

View File

@ -386,9 +386,9 @@ func (s *Server) genDNSFilterMessage(d *proxy.DNSContext, result *dnsfilter.Resu
switch result.Reason { switch result.Reason {
case dnsfilter.FilteredSafeBrowsing: case dnsfilter.FilteredSafeBrowsing:
return s.genBlockedHost(m, safeBrowsingBlockHost, d.Upstream) return s.genBlockedHost(m, safeBrowsingBlockHost, d)
case dnsfilter.FilteredParental: case dnsfilter.FilteredParental:
return s.genBlockedHost(m, parentalBlockHost, d.Upstream) return s.genBlockedHost(m, parentalBlockHost, d)
default: default:
if result.IP != nil { if result.IP != nil {
return s.genARecord(m, result.IP) return s.genARecord(m, result.IP)
@ -417,22 +417,30 @@ func (s *Server) genARecord(request *dns.Msg, ip net.IP) *dns.Msg {
return &resp return &resp
} }
func (s *Server) genBlockedHost(request *dns.Msg, newAddr string, upstream upstream.Upstream) *dns.Msg { func (s *Server) genBlockedHost(request *dns.Msg, newAddr string, d *proxy.DNSContext) *dns.Msg {
// look up the hostname, TODO: cache // look up the hostname, TODO: cache
replReq := dns.Msg{} replReq := dns.Msg{}
replReq.SetQuestion(dns.Fqdn(newAddr), request.Question[0].Qtype) replReq.SetQuestion(dns.Fqdn(newAddr), request.Question[0].Qtype)
replReq.RecursionDesired = true replReq.RecursionDesired = true
reply, err := upstream.Exchange(&replReq)
newContext := &proxy.DNSContext{
Proto: d.Proto,
Addr: d.Addr,
StartTime: time.Now(),
Req: &replReq,
}
err := s.dnsProxy.Resolve(newContext)
if err != nil { if err != nil {
log.Printf("Couldn't look up replacement host '%s' on upstream %s: %s", newAddr, upstream.Address(), err) log.Printf("Couldn't look up replacement host '%s': %s", newAddr, err)
return s.genServerFailure(request) return s.genServerFailure(request)
} }
resp := dns.Msg{} resp := dns.Msg{}
resp.SetReply(request) resp.SetReply(request)
resp.Authoritative, resp.RecursionAvailable = true, true resp.Authoritative, resp.RecursionAvailable = true, true
if reply != nil { if newContext.Res != nil {
for _, answer := range reply.Answer { for _, answer := range newContext.Res.Answer {
answer.Header().Name = request.Question[0].Name answer.Header().Name = request.Question[0].Name
resp.Answer = append(resp.Answer, answer) resp.Answer = append(resp.Answer, answer)
} }