This commit is contained in:
Ghvst Code 2024-04-25 20:33:35 +05:30 committed by GitHub
commit b0fd36effa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 39 additions and 0 deletions

View File

@ -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

View File

@ -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
}

View File

@ -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 ""
}