* dnsforward: parental control server can be an IP address, not just host name

This commit is contained in:
Simon Zolin 2019-07-22 12:33:45 +03:00
parent 4134a8c30e
commit 4a05ab0057
1 changed files with 20 additions and 0 deletions

View File

@ -601,7 +601,27 @@ func (s *Server) genAAAAAnswer(req *dns.Msg, ip net.IP) *dns.AAAA {
return answer return answer
} }
// generate DNS response message with an IP address
func (s *Server) genResponseWithIP(req *dns.Msg, ip net.IP) *dns.Msg {
if req.Question[0].Qtype == dns.TypeA && ip.To4() != nil {
return s.genARecord(req, ip.To4())
} else if req.Question[0].Qtype == dns.TypeAAAA && ip.To4() == nil {
return s.genAAAARecord(req, ip)
}
// empty response
resp := dns.Msg{}
resp.SetReply(req)
return &resp
}
func (s *Server) genBlockedHost(request *dns.Msg, newAddr string, d *proxy.DNSContext) *dns.Msg { func (s *Server) genBlockedHost(request *dns.Msg, newAddr string, d *proxy.DNSContext) *dns.Msg {
ip := net.ParseIP(newAddr)
if ip != nil {
return s.genResponseWithIP(request, ip)
}
// 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)