diff --git a/cmd/tailscale/cli/netcheck.go b/cmd/tailscale/cli/netcheck.go index a33ee067f..98345b8e0 100644 --- a/cmd/tailscale/cli/netcheck.go +++ b/cmd/tailscale/cli/netcheck.go @@ -11,6 +11,7 @@ import ( "io" "log" "net/http" + "runtime" "sort" "strings" "time" @@ -18,6 +19,7 @@ import ( "github.com/peterbourgon/ff/v3/ffcli" "tailscale.com/envknob" "tailscale.com/ipn" + "tailscale.com/net/dns" "tailscale.com/net/netcheck" "tailscale.com/net/netmon" "tailscale.com/net/portmapper" @@ -147,6 +149,13 @@ func printReport(dm *tailcfg.DERPMap, report *netcheck.Report) error { printf("\t* CaptivePortal: %v\n", report.CaptivePortal) } + if runtime.GOOS == "linux" { + mode := dns.GetGlobalDnsMode() + if mode != "" { + printf("\t* Current DNS Mode: %v\n", mode) + } + } + // When DERP latency checking failed, // magicsock will try to pick the DERP server that // most of your other nodes are also using diff --git a/net/dns/manager_linux.go b/net/dns/manager_linux.go index e2a7224bc..a3536d127 100644 --- a/net/dns/manager_linux.go +++ b/net/dns/manager_linux.go @@ -31,6 +31,11 @@ func (kv kv) String() string { var publishOnce sync.Once +var ( + globalDnsMode string + dnsModeMutex sync.RWMutex +) + func NewOSConfigurator(logf logger.Logf, interfaceName string) (ret OSConfigurator, err error) { env := newOSConfigEnv{ fs: directFS{}, @@ -44,6 +49,8 @@ func NewOSConfigurator(logf logger.Logf, interfaceName string) (ret OSConfigurat if err != nil { return nil, err } + + setGlobalDnsMode(mode) publishOnce.Do(func() { sanitizedMode := strings.ReplaceAll(mode, "-", "_") m := clientmetric.NewGauge(fmt.Sprintf("dns_manager_linux_mode_%s", sanitizedMode)) @@ -425,3 +432,17 @@ func dbusReadString(name, objectPath, iface, member string) (string, error) { } return result.String(), nil } + +// setGlobalDnsMode safely sets the global DNS mode variable +func setGlobalDnsMode(mode string) { + dnsModeMutex.Lock() + defer dnsModeMutex.Unlock() + globalDnsMode = mode +} + +// GetGlobalDnsMode safely returns the global DNS mode variable +func GetGlobalDnsMode() string { + dnsModeMutex.RLock() + defer dnsModeMutex.RUnlock() + return globalDnsMode +} diff --git a/net/dns/manager_notlinux.go b/net/dns/manager_notlinux.go new file mode 100644 index 000000000..0f9a926f3 --- /dev/null +++ b/net/dns/manager_notlinux.go @@ -0,0 +1,9 @@ +//go:build !linux + +package dns + +// GetGlobalDnsMode exists to make the build happy on non-linux platforms. +// The actual implementation is in manager_linux.go & in there it safely returns the current resolv.conf mode +func GetGlobalDnsMode() string { + return "" +}