net/dns: add GetBaseConfig to OSConfigurator interface.

Part of #953, required to make split DNS work on more basic
platforms.

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/1677/head
David Anderson 4 years ago committed by Dave Anderson
parent fe9cd61d71
commit 68f76e9aa1

@ -163,6 +163,11 @@ func (m directManager) SupportsSplitDNS() bool {
return false
}
func (m directManager) GetBaseConfig() (OSConfig, error) {
// TODO
return OSConfig{}, nil
}
func (m directManager) Close() error {
if _, err := os.Stat(backupConf); err != nil {
// If the backup file does not exist, then Up never ran successfully.

@ -36,6 +36,11 @@ func (c *fakeOSConfigurator) SupportsSplitDNS() bool {
return c.SplitDNS
}
func (c *fakeOSConfigurator) GetBaseConfig() (OSConfig, error) {
// TODO
return OSConfig{}, nil
}
func (c *fakeOSConfigurator) Close() error { return nil }
func TestManager(t *testing.T) {

@ -300,6 +300,23 @@ func (m windowsManager) Close() error {
return m.SetDNS(OSConfig{})
}
func (m windowsManager) GetBaseConfig() (OSConfig, error) {
if m.nrptWorks {
return OSConfig{}, errors.New("GetBaseConfig not supported")
}
resolvers, err := m.getBasePrimaryResolver()
if err != nil {
return OSConfig{}, err
}
return OSConfig{
Nameservers: resolvers,
// Don't return any search domains here, because even Windows
// 7 correctly handles blending search domains from multiple
// sources, and any search domains we add here will get tacked
// onto the Tailscale config unnecessarily.
}, nil
}
// getBasePrimaryResolver returns a guess of the non-Tailscale primary
// resolver on the system.
// It's used on Windows 7 to emulate split DNS by trying to figure out

@ -202,6 +202,11 @@ func (m nmManager) SetDNS(config OSConfig) error {
func (m nmManager) SupportsSplitDNS() bool { return false }
func (m nmManager) GetBaseConfig() (OSConfig, error) {
// TODO
return OSConfig{}, nil
}
func (m nmManager) Close() error {
return m.SetDNS(OSConfig{})
}

@ -6,9 +6,10 @@ package dns
type noopManager struct{}
func (m noopManager) SetDNS(OSConfig) error { return nil }
func (m noopManager) SupportsSplitDNS() bool { return false }
func (m noopManager) Close() error { return nil }
func (m noopManager) SetDNS(OSConfig) error { return nil }
func (m noopManager) SupportsSplitDNS() bool { return false }
func (m noopManager) Close() error { return nil }
func (m noopManager) GetBaseConfig() (OSConfig, error) { return OSConfig{}, nil }
func NewNoopManager() noopManager {
return noopManager{}

@ -17,6 +17,13 @@ type OSConfigurator interface {
// installing a resolver only for specific DNS suffixes. If false,
// the configurator can only set a global resolver.
SupportsSplitDNS() bool
// GetBaseConfig returns the OS's "base" configuration, i.e. the
// resolver settings the OS would use without Tailscale
// contributing any configuration.
// GetBaseConfig must return the tailscale-free base config even
// after SetDNS has been called to set a Tailscale configuration.
// Only works when SupportsSplitDNS=false.
GetBaseConfig() (OSConfig, error)
// Close removes Tailscale-related DNS configuration from the OS.
Close() error
}

@ -142,6 +142,11 @@ func (m resolvconfManager) SupportsSplitDNS() bool {
return false
}
func (m resolvconfManager) GetBaseConfig() (OSConfig, error) {
// TODO
return OSConfig{}, nil
}
func (m resolvconfManager) Close() error {
var cmd *exec.Cmd
switch m.impl {

@ -157,6 +157,11 @@ func (m resolvedManager) SupportsSplitDNS() bool {
return false
}
func (m resolvedManager) GetBaseConfig() (OSConfig, error) {
// TODO
return OSConfig{}, nil
}
func (m resolvedManager) Close() error {
ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout)
defer cancel()

@ -49,6 +49,11 @@ func (r *CallbackRouter) SupportsSplitDNS() bool {
return r.SplitDNS
}
func (r *CallbackRouter) GetBaseConfig() (dns.OSConfig, error) {
// TODO
return dns.OSConfig{}, nil
}
func (r *CallbackRouter) Close() error {
return r.SetBoth(nil, nil) // TODO: check if makes sense
}

Loading…
Cancel
Save