Skip to content

Commit

Permalink
add upstream lookup for resolver
Browse files Browse the repository at this point in the history
  • Loading branch information
yabinma committed Sep 26, 2024
1 parent 3f24927 commit aeec67e
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion dns/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"sync"

"github.com/gravitl/netclient/config"
"github.com/miekg/dns"
"golang.org/x/exp/slog"
)
Expand Down Expand Up @@ -43,7 +44,24 @@ func handleDNSRequest(w dns.ResponseWriter, r *dns.Msg) {
if resp != nil {
reply.Answer = append(reply.Answer, resp)
} else {
reply.Rcode = dns.RcodeNameError
if config.Netclient().DNSManagerType != DNS_MANAGER_STUB {
client := &dns.Client{}
for _, v := range config.Netclient().NameServers {
resp, _, err := client.Exchange(r, v+":53")
if err != nil {
continue
}

if resp.Rcode != dns.RcodeSuccess {
continue
}

reply.Answer = append(reply.Answer, resp.Answer[0])
break
}
} else {
reply.Rcode = dns.RcodeNameError
}
}

err := w.WriteMsg(reply)
Expand Down

0 comments on commit aeec67e

Please sign in to comment.