Support DNS over HTTP servers

This commit is contained in:
Tyler 2018-07-01 18:44:11 -04:00
parent adf6a32039
commit d1f11f1773
1 changed files with 13 additions and 7 deletions

View File

@ -86,14 +86,13 @@ func (r *Resolver) parseServerListFile(buf *os.File) {
continue
}
sli := strings.Split(line, "=")
line = strings.TrimSpace(line[idx:])
if len(sli) != 2 {
if strings.HasPrefix(line, "https://") {
r.servers = append(r.servers, line)
continue
}
line = strings.TrimSpace(line[idx:])
tokens := strings.Split(line, "/")
switch len(tokens) {
case 3:
@ -162,6 +161,12 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error
WriteTimeout: r.Timeout(),
}
tlsClient := &dns.Client{
Net: "tcp-tls",
ReadTimeout: r.Timeout(),
WriteTimeout: r.Timeout(),
}
if net == "udp" && settings.ResolvConfig.SetEDNS0 {
req = req.SetEdns0(65535, true)
}
@ -179,6 +184,8 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error
if strings.HasPrefix(nameserver, "https") {
r, rtt, err = httpC.Exchange(req, nameserver)
} else if strings.HasPrefix(nameserver, ":853") {
r, rtt, err = tlsClient.Exchange(req, nameserver)
} else {
r, rtt, err = c.Exchange(req, nameserver)
}
@ -242,9 +249,8 @@ func (r *Resolver) Nameservers(qname string) []string {
ns := []string{}
if v, found := r.domain_server.search(queryKeys); found {
logger.Debug("%s be found in domain server list, upstream: %v", qname, v)
server := v
nameserver := net.JoinHostPort(server, "53")
ns = append(ns, nameserver)
ns = append(ns, net.JoinHostPort(v, "53"))
//Ensure query the specific upstream nameserver in async Lookup() function.
return ns
}