From d1f11f17731ce5158c1e2ce1f61d22fe8b2f5842 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 1 Jul 2018 18:44:11 -0400 Subject: [PATCH] Support DNS over HTTP servers --- resolver.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/resolver.go b/resolver.go index 6aa7627..a83df5f 100644 --- a/resolver.go +++ b/resolver.go @@ -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 }