net/dns: add debugging traces to DNS manager selection on linux.

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/1710/head
David Anderson 4 years ago
parent 4b70c7b717
commit bb0710d51d

@ -47,7 +47,6 @@ func NewManager(logf logger.Logf, oscfg OSConfigurator, linkMon *monitor.Mon) *M
resolver: resolver.New(logf, linkMon), resolver: resolver.New(logf, linkMon),
os: oscfg, os: oscfg,
} }
m.logf("using %T", m.os) m.logf("using %T", m.os)
return m return m
} }

@ -18,9 +18,29 @@ import (
"tailscale.com/types/logger" "tailscale.com/types/logger"
) )
func NewOSConfigurator(logf logger.Logf, interfaceName string) (OSConfigurator, error) { type kv struct {
k, v string
}
func (kv kv) String() string {
return fmt.Sprintf("%s=%s", kv.k, kv.v)
}
func NewOSConfigurator(logf logger.Logf, interfaceName string) (ret OSConfigurator, err error) {
var debug []kv
dbg := func(k, v string) {
debug = append(debug, kv{k, v})
}
defer func() {
if ret != nil {
dbg("ret", fmt.Sprintf("%T", ret))
}
logf("dns: %v", debug)
}()
bs, err := ioutil.ReadFile("/etc/resolv.conf") bs, err := ioutil.ReadFile("/etc/resolv.conf")
if os.IsNotExist(err) { if os.IsNotExist(err) {
dbg("rc", "missing")
return newDirectManager() return newDirectManager()
} }
if err != nil { if err != nil {
@ -29,32 +49,49 @@ func NewOSConfigurator(logf logger.Logf, interfaceName string) (OSConfigurator,
switch resolvOwner(bs) { switch resolvOwner(bs) {
case "systemd-resolved": case "systemd-resolved":
dbg("rc", "resolved")
if err := dbusPing("org.freedesktop.resolve1", "/org/freedesktop/resolve1"); err != nil { if err := dbusPing("org.freedesktop.resolve1", "/org/freedesktop/resolve1"); err != nil {
dbg("resolved", "no")
return newDirectManager() return newDirectManager()
} }
if err := dbusPing("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/DnsManager"); err != nil { if err := dbusPing("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/DnsManager"); err != nil {
dbg("nm", "no")
return newResolvedManager(logf) return newResolvedManager(logf)
} }
dbg("nm", "yes")
if err := nmIsUsingResolved(); err != nil { if err := nmIsUsingResolved(); err != nil {
dbg("nm-resolved", "no")
return newResolvedManager(logf) return newResolvedManager(logf)
} }
dbg("nm-resolved", "yes")
return newNMManager(interfaceName) return newNMManager(interfaceName)
case "resolvconf": case "resolvconf":
dbg("rc", "resolvconf")
if err := resolvconfSourceIsNM(bs); err == nil { if err := resolvconfSourceIsNM(bs); err == nil {
dbg("src-is-nm", "yes")
if err := dbusPing("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/DnsManager"); err == nil { if err := dbusPing("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/DnsManager"); err == nil {
dbg("nm", "yes")
return newNMManager(interfaceName) return newNMManager(interfaceName)
} }
dbg("nm", "no")
} }
dbg("src-is-nm", "no")
if _, err := exec.LookPath("resolvconf"); err != nil { if _, err := exec.LookPath("resolvconf"); err != nil {
dbg("resolvconf", "no")
return newDirectManager() return newDirectManager()
} }
dbg("resolvconf", "yes")
return newResolvconfManager(logf) return newResolvconfManager(logf)
case "NetworkManager": case "NetworkManager":
dbg("rc", "nm")
if err := dbusPing("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/DnsManager"); err != nil { if err := dbusPing("org.freedesktop.NetworkManager", "/org/freedesktop/NetworkManager/DnsManager"); err != nil {
dbg("nm", "no")
return newDirectManager() return newDirectManager()
} }
dbg("nm", "yes")
return newNMManager(interfaceName) return newNMManager(interfaceName)
default: default:
dbg("rc", "unknown")
return newDirectManager() return newDirectManager()
} }
} }

Loading…
Cancel
Save