From 6feb8f4c51b5c763215d4d14cbaf53a4bbee0963 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Jan 2022 08:19:24 -0800 Subject: [PATCH] net/dns: log why resolved does not look like it's on use [Linux] Updates #3742 Updates #3531 Change-Id: I9fc7fa0f4bcab1cf8001ba92408c660a5b25f105 Signed-off-by: Brad Fitzpatrick --- net/dns/manager_linux.go | 4 +++- net/dns/manager_linux_test.go | 14 ++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/net/dns/manager_linux.go b/net/dns/manager_linux.go index f2f6a1a7b..337648298 100644 --- a/net/dns/manager_linux.go +++ b/net/dns/manager_linux.go @@ -95,6 +95,7 @@ func dnsMode(logf logger.Logf, env newOSConfigEnv) (ret string, err error) { // try to program resolved in that case. // https://github.com/tailscale/tailscale/issues/2136 if err := resolvedIsActuallyResolver(bs); err != nil { + logf("dns: resolvedIsActuallyResolver error: %v", err) dbg("resolved", "not-in-use") return "direct", nil } @@ -184,6 +185,7 @@ func dnsMode(logf logger.Logf, env newOSConfigEnv) (ret string, err error) { // Sometimes, NetworkManager owns the configuration but points // it at systemd-resolved. if err := resolvedIsActuallyResolver(bs); err != nil { + logf("dns: resolvedIsActuallyResolver error: %v", err) dbg("resolved", "not-in-use") // You'd think we would use newNMManager here. However, as // explained in @@ -300,7 +302,7 @@ func resolvedIsActuallyResolver(bs []byte) error { } for _, ns := range cfg.Nameservers { if ns != netaddr.IPv4(127, 0, 0, 53) { - return errors.New("resolv.conf doesn't point to systemd-resolved") + return fmt.Errorf("resolv.conf doesn't point to systemd-resolved; points to %v", cfg.Nameservers) } } return nil diff --git a/net/dns/manager_linux_test.go b/net/dns/manager_linux_test.go index 7000f2cec..1bbd97592 100644 --- a/net/dns/manager_linux_test.go +++ b/net/dns/manager_linux_test.go @@ -34,8 +34,9 @@ func TestLinuxDNSMode(t *testing.T) { resolvDotConf( "# Managed by NetworkManager", "nameserver 10.0.0.1")), - wantLog: "dns: [rc=nm resolved=not-in-use ret=direct]", - want: "direct", + wantLog: "dns: resolvedIsActuallyResolver error: resolv.conf doesn't point to systemd-resolved; points to [10.0.0.1]\n" + + "dns: [rc=nm resolved=not-in-use ret=direct]", + want: "direct", }, { name: "resolvconf_but_no_resolvconf_binary", @@ -123,10 +124,11 @@ func TestLinuxDNSMode(t *testing.T) { // alleged that it was managed by systemd-resolved, but it // was actually a completely static config file pointing // elsewhere. - name: "allegedly_resolved_but_not_in_resolv.conf", - env: env(resolvDotConf("# Managed by systemd-resolved", "nameserver 10.0.0.1")), - wantLog: "dns: [rc=resolved resolved=not-in-use ret=direct]", - want: "direct", + name: "allegedly_resolved_but_not_in_resolv.conf", + env: env(resolvDotConf("# Managed by systemd-resolved", "nameserver 10.0.0.1")), + wantLog: "dns: resolvedIsActuallyResolver error: resolv.conf doesn't point to systemd-resolved; points to [10.0.0.1]\n" + + "dns: [rc=resolved resolved=not-in-use ret=direct]", + want: "direct", }, { // We used to incorrectly decide that resolved wasn't in