Support DNS over HTTP servers
This commit is contained in:
parent
adf6a32039
commit
d1f11f1773
20
resolver.go
20
resolver.go
|
@ -86,14 +86,13 @@ func (r *Resolver) parseServerListFile(buf *os.File) {
|
||||||
continue
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
line = strings.TrimSpace(line[idx:])
|
|
||||||
|
|
||||||
tokens := strings.Split(line, "/")
|
tokens := strings.Split(line, "/")
|
||||||
switch len(tokens) {
|
switch len(tokens) {
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -162,6 +161,12 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error
|
||||||
WriteTimeout: r.Timeout(),
|
WriteTimeout: r.Timeout(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tlsClient := &dns.Client{
|
||||||
|
Net: "tcp-tls",
|
||||||
|
ReadTimeout: r.Timeout(),
|
||||||
|
WriteTimeout: r.Timeout(),
|
||||||
|
}
|
||||||
|
|
||||||
if net == "udp" && settings.ResolvConfig.SetEDNS0 {
|
if net == "udp" && settings.ResolvConfig.SetEDNS0 {
|
||||||
req = req.SetEdns0(65535, true)
|
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") {
|
if strings.HasPrefix(nameserver, "https") {
|
||||||
r, rtt, err = httpC.Exchange(req, nameserver)
|
r, rtt, err = httpC.Exchange(req, nameserver)
|
||||||
|
} else if strings.HasPrefix(nameserver, ":853") {
|
||||||
|
r, rtt, err = tlsClient.Exchange(req, nameserver)
|
||||||
} else {
|
} else {
|
||||||
r, rtt, err = c.Exchange(req, nameserver)
|
r, rtt, err = c.Exchange(req, nameserver)
|
||||||
}
|
}
|
||||||
|
@ -242,9 +249,8 @@ func (r *Resolver) Nameservers(qname string) []string {
|
||||||
ns := []string{}
|
ns := []string{}
|
||||||
if v, found := r.domain_server.search(queryKeys); found {
|
if v, found := r.domain_server.search(queryKeys); found {
|
||||||
logger.Debug("%s be found in domain server list, upstream: %v", qname, v)
|
logger.Debug("%s be found in domain server list, upstream: %v", qname, v)
|
||||||
server := v
|
|
||||||
nameserver := net.JoinHostPort(server, "53")
|
ns = append(ns, net.JoinHostPort(v, "53"))
|
||||||
ns = append(ns, nameserver)
|
|
||||||
//Ensure query the specific upstream nameserver in async Lookup() function.
|
//Ensure query the specific upstream nameserver in async Lookup() function.
|
||||||
return ns
|
return ns
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue