net/dns: make debian_resolvconf correctly clear DNS configs.

More of #1720.

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/1749/head
David Anderson 4 years ago
parent 3b1ab78954
commit 53213114ec

@ -89,6 +89,15 @@ func newDebianResolvconfManager(logf logger.Logf) (*resolvconfManager, error) {
return ret, nil
}
func (m *resolvconfManager) deleteTailscaleConfig() error {
cmd := exec.Command("resolvconf", "-d", resolvconfConfigName)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("running %s: %s", cmd, out)
}
return nil
}
func (m *resolvconfManager) SetDNS(config OSConfig) error {
if !m.scriptInstalled {
m.logf("injecting resolvconf workaround script")
@ -101,19 +110,25 @@ func (m *resolvconfManager) SetDNS(config OSConfig) error {
m.scriptInstalled = true
}
if config.IsZero() {
if err := m.deleteTailscaleConfig(); err != nil {
return err
}
} else {
stdin := new(bytes.Buffer)
writeResolvConf(stdin, config.Nameservers, config.SearchDomains) // dns_direct.go
// This resolvconf implementation doesn't support exclusive mode
// or interface priorities, so it will end up blending our
// configuration with other sources. However, this will get fixed
// up by the script we injected above.
// This resolvconf implementation doesn't support exclusive
// mode or interface priorities, so it will end up blending
// our configuration with other sources. However, this will
// get fixed up by the script we injected above.
cmd := exec.Command("resolvconf", "-a", resolvconfConfigName)
cmd.Stdin = stdin
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("running %s: %s", cmd, out)
}
}
return nil
}
@ -156,10 +171,8 @@ func (m *resolvconfManager) GetBaseConfig() (OSConfig, error) {
}
func (m *resolvconfManager) Close() error {
cmd := exec.Command("resolvconf", "-d", resolvconfConfigName)
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("running %s: %s", cmd, out)
if err := m.deleteTailscaleConfig(); err != nil {
return err
}
if m.scriptInstalled {

@ -234,7 +234,7 @@ func (m directManager) restoreBackup() error {
}
func (m directManager) SetDNS(config OSConfig) error {
if config.Equal(OSConfig{}) {
if config.IsZero() {
if err := m.restoreBackup(); err != nil {
return err
}

@ -52,6 +52,10 @@ type OSConfig struct {
MatchDomains []dnsname.FQDN
}
func (o OSConfig) IsZero() bool {
return len(o.Nameservers) == 0 && len(o.SearchDomains) == 0 && len(o.MatchDomains) == 0
}
func (a OSConfig) Equal(b OSConfig) bool {
if len(a.Nameservers) != len(b.Nameservers) {
return false

Loading…
Cancel
Save