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 <bradfitz@tailscale.com>
pull/3801/head
Brad Fitzpatrick 3 years ago committed by Brad Fitzpatrick
parent ff3442d92d
commit 6feb8f4c51

@ -95,6 +95,7 @@ func dnsMode(logf logger.Logf, env newOSConfigEnv) (ret string, err error) {
// try to program resolved in that case. // try to program resolved in that case.
// https://github.com/tailscale/tailscale/issues/2136 // https://github.com/tailscale/tailscale/issues/2136
if err := resolvedIsActuallyResolver(bs); err != nil { if err := resolvedIsActuallyResolver(bs); err != nil {
logf("dns: resolvedIsActuallyResolver error: %v", err)
dbg("resolved", "not-in-use") dbg("resolved", "not-in-use")
return "direct", nil 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 // Sometimes, NetworkManager owns the configuration but points
// it at systemd-resolved. // it at systemd-resolved.
if err := resolvedIsActuallyResolver(bs); err != nil { if err := resolvedIsActuallyResolver(bs); err != nil {
logf("dns: resolvedIsActuallyResolver error: %v", err)
dbg("resolved", "not-in-use") dbg("resolved", "not-in-use")
// You'd think we would use newNMManager here. However, as // You'd think we would use newNMManager here. However, as
// explained in // explained in
@ -300,7 +302,7 @@ func resolvedIsActuallyResolver(bs []byte) error {
} }
for _, ns := range cfg.Nameservers { for _, ns := range cfg.Nameservers {
if ns != netaddr.IPv4(127, 0, 0, 53) { 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 return nil

@ -34,8 +34,9 @@ func TestLinuxDNSMode(t *testing.T) {
resolvDotConf( resolvDotConf(
"# Managed by NetworkManager", "# Managed by NetworkManager",
"nameserver 10.0.0.1")), "nameserver 10.0.0.1")),
wantLog: "dns: [rc=nm resolved=not-in-use ret=direct]", wantLog: "dns: resolvedIsActuallyResolver error: resolv.conf doesn't point to systemd-resolved; points to [10.0.0.1]\n" +
want: "direct", "dns: [rc=nm resolved=not-in-use ret=direct]",
want: "direct",
}, },
{ {
name: "resolvconf_but_no_resolvconf_binary", 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 // alleged that it was managed by systemd-resolved, but it
// was actually a completely static config file pointing // was actually a completely static config file pointing
// elsewhere. // elsewhere.
name: "allegedly_resolved_but_not_in_resolv.conf", name: "allegedly_resolved_but_not_in_resolv.conf",
env: env(resolvDotConf("# Managed by systemd-resolved", "nameserver 10.0.0.1")), env: env(resolvDotConf("# Managed by systemd-resolved", "nameserver 10.0.0.1")),
wantLog: "dns: [rc=resolved resolved=not-in-use ret=direct]", wantLog: "dns: resolvedIsActuallyResolver error: resolv.conf doesn't point to systemd-resolved; points to [10.0.0.1]\n" +
want: "direct", "dns: [rc=resolved resolved=not-in-use ret=direct]",
want: "direct",
}, },
{ {
// We used to incorrectly decide that resolved wasn't in // We used to incorrectly decide that resolved wasn't in

Loading…
Cancel
Save