wgengine: move DNS configuration out of wgengine/router.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson
2021-04-02 19:24:02 -07:00
committed by Dave Anderson
parent 7183e1f052
commit 4c61ebacf4
15 changed files with 38 additions and 71 deletions
+4 -3
View File
@@ -33,11 +33,11 @@ type Manager struct {
}
// NewManagers created a new manager from the given config.
func NewManager(logf logger.Logf, interfaceName string) *Manager {
func NewManager(logf logger.Logf, oscfg OSConfigurator) *Manager {
logf = logger.WithPrefix(logf, "dns: ")
m := &Manager{
logf: logf,
impl: newManager(logf, interfaceName),
impl: oscfg,
}
m.logf("using %T", m.impl)
@@ -81,7 +81,8 @@ func (m *Manager) Down() error {
// in case the Tailscale daemon terminated without closing the router.
// No other state needs to be instantiated before this runs.
func Cleanup(logf logger.Logf, interfaceName string) {
dns := NewManager(logf, interfaceName)
oscfg := NewOSConfigurator(logf, interfaceName)
dns := NewManager(logf, oscfg)
if err := dns.Down(); err != nil {
logf("dns down: %v", err)
}
+2 -2
View File
@@ -8,9 +8,9 @@ package dns
import "tailscale.com/types/logger"
func newManager(logger.Logf, string) OSConfigurator {
func NewOSConfigurator(logger.Logf, string) OSConfigurator {
// TODO(dmytro): on darwin, we should use a macOS-specific method such as scutil.
// This is currently not implemented. Editing /etc/resolv.conf does not work,
// as most applications use the system resolver, which disregards it.
return newNoopManager()
return NewNoopManager()
}
+1 -1
View File
@@ -6,7 +6,7 @@ package dns
import "tailscale.com/types/logger"
func newManager(logf logger.Logf, _ string) OSConfigurator {
func NewOSConfigurator(logf logger.Logf, _ string) OSConfigurator {
switch {
case isResolvconfActive():
return newResolvconfManager(logf)
+1 -1
View File
@@ -6,7 +6,7 @@ package dns
import "tailscale.com/types/logger"
func newManager(logf logger.Logf, interfaceName string) OSConfigurator {
func NewOSConfigurator(logf logger.Logf, interfaceName string) OSConfigurator {
switch {
// TODO: rework NetworkManager and resolved support.
// case isResolvedActive():
+1 -1
View File
@@ -6,6 +6,6 @@ package dns
import "tailscale.com/types/logger"
func newManager(logger.Logf, string) OSConfigurator {
func NewOSConfigurator(logger.Logf, string) OSConfigurator {
return newDirectManager()
}
+1 -1
View File
@@ -25,7 +25,7 @@ type windowsManager struct {
guid string
}
func newManager(logf logger.Logf, interfaceName string) OSConfigurator {
func NewOSConfigurator(logf logger.Logf, interfaceName string) OSConfigurator {
return windowsManager{
logf: logf,
guid: interfaceName,
+1 -3
View File
@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build !linux,!freebsd,!openbsd,!windows
package dns
type noopManager struct{}
@@ -12,6 +10,6 @@ func (m noopManager) Set(OSConfig) error { return nil }
func (m noopManager) RoutingMode() RoutingMode { return RoutingModeNone }
func (m noopManager) Close() error { return nil }
func newNoopManager() noopManager {
func NewNoopManager() noopManager {
return noopManager{}
}