From 411c6c316cf617046b4002a69dd404f4938d061d Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Fri, 14 Jan 2022 16:30:20 -0700 Subject: [PATCH] net/dns/resolvd: store nameservers Currently only search domains are stored. This was an oversight (under?) on my part. As things are now, when MagicDNS is on and "Override local DNS" is off, the dns forwarder has to timeout before names resolve. This introduces a pretty annoying lang that makes everything feel extremely slow. You will also see an error: "upstream nameservers not set". I tested with "Override local DNS" on and off. In both situations things seem to function as expected (and quickly). Signed-off-by: Aaron Bieber --- net/dns/resolvd.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/net/dns/resolvd.go b/net/dns/resolvd.go index 42b09ee5a..5ccde75ec 100644 --- a/net/dns/resolvd.go +++ b/net/dns/resolvd.go @@ -16,6 +16,7 @@ "regexp" "strings" + "inet.af/netaddr" "tailscale.com/types/logger" "tailscale.com/util/dnsname" ) @@ -130,6 +131,25 @@ func (m resolvdManager) readResolvConf() (config OSConfig, err error) { config.SearchDomains = append(config.SearchDomains, fqdn) continue } + + if strings.HasPrefix(line, "nameserver") { + s := strings.TrimPrefix(line, "nameserver") + parts := strings.Split(s, " # ") + if len(parts) == 0 { + return OSConfig{}, err + } + nameserver := strings.TrimSpace(parts[0]) + ip, err := netaddr.ParseIP(nameserver) + if err != nil { + return OSConfig{}, err + } + config.Nameservers = append(config.Nameservers, ip) + continue + } + } + + if err = scanner.Err(); err != nil { + return OSConfig{}, err } return config, nil