diff --git a/net/dns/config.go b/net/dns/config.go index 884d9284c..5ac08a666 100644 --- a/net/dns/config.go +++ b/net/dns/config.go @@ -6,8 +6,6 @@ package dns import ( "inet.af/netaddr" - - "tailscale.com/types/logger" ) // Config is the set of parameters that uniquely determine @@ -54,13 +52,3 @@ func (lhs Config) Equal(rhs Config) bool { return true } - -// ManagerConfig is the set of parameters from which -// a manager implementation is chosen and initialized. -type ManagerConfig struct { - // Logf is the logger for the manager to use. - // It is wrapped with a "dns: " prefix. - Logf logger.Logf - // InterfaceName is the name of the interface with which DNS settings should be associated. - InterfaceName string -} diff --git a/net/dns/direct.go b/net/dns/direct.go index bd1c03b9d..c5ff2cc09 100644 --- a/net/dns/direct.go +++ b/net/dns/direct.go @@ -110,7 +110,7 @@ func isResolvedRunning() bool { // or as cleanup if the program terminates unexpectedly. type directManager struct{} -func newDirectManager(mconfig ManagerConfig) managerImpl { +func newDirectManager() managerImpl { return directManager{} } diff --git a/net/dns/manager.go b/net/dns/manager.go index 60a790bb0..94494e0d5 100644 --- a/net/dns/manager.go +++ b/net/dns/manager.go @@ -37,17 +37,15 @@ type Manager struct { impl managerImpl - config Config - mconfig ManagerConfig + config Config } // NewManagers created a new manager from the given config. -func NewManager(mconfig ManagerConfig) *Manager { - mconfig.Logf = logger.WithPrefix(mconfig.Logf, "dns: ") +func NewManager(logf logger.Logf, interfaceName string) *Manager { + logf = logger.WithPrefix(logf, "dns: ") m := &Manager{ - logf: mconfig.Logf, - impl: newManager(mconfig), - mconfig: mconfig, + logf: logf, + impl: newManager(logf, interfaceName), } m.logf("using %T", m.impl) @@ -91,11 +89,7 @@ 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) { - mconfig := ManagerConfig{ - Logf: logf, - InterfaceName: interfaceName, - } - dns := NewManager(mconfig) + dns := NewManager(logf, interfaceName) if err := dns.Down(); err != nil { logf("dns down: %v", err) } diff --git a/net/dns/manager_default.go b/net/dns/manager_default.go index 04c8bb811..013a957f9 100644 --- a/net/dns/manager_default.go +++ b/net/dns/manager_default.go @@ -6,9 +6,11 @@ package dns -func newManager(mconfig ManagerConfig) managerImpl { +import "tailscale.com/types/logger" + +func newManager(logger.Logf, string) managerImpl { // 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(mconfig) + return newNoopManager() } diff --git a/net/dns/manager_freebsd.go b/net/dns/manager_freebsd.go index 232635f7e..bde838412 100644 --- a/net/dns/manager_freebsd.go +++ b/net/dns/manager_freebsd.go @@ -4,11 +4,13 @@ package dns -func newManager(mconfig ManagerConfig) managerImpl { +import "tailscale.com/types/logger" + +func newManager(logf logger.Logf, _ string) managerImpl { switch { case isResolvconfActive(): - return newResolvconfManager(mconfig) + return newResolvconfManager(logf) default: - return newDirectManager(mconfig) + return newDirectManager() } } diff --git a/net/dns/manager_linux.go b/net/dns/manager_linux.go index 51841219c..9d3771874 100644 --- a/net/dns/manager_linux.go +++ b/net/dns/manager_linux.go @@ -4,15 +4,17 @@ package dns -func newManager(mconfig ManagerConfig) managerImpl { +import "tailscale.com/types/logger" + +func newManager(logf logger.Logf, interfaceName string) managerImpl { switch { case isResolvedActive(): - return newResolvedManager(mconfig) + return newResolvedManager() case isNMActive(): - return newNMManager(mconfig) + return newNMManager(interfaceName) case isResolvconfActive(): - return newResolvconfManager(mconfig) + return newResolvconfManager(logf) default: - return newDirectManager(mconfig) + return newDirectManager() } } diff --git a/net/dns/manager_openbsd.go b/net/dns/manager_openbsd.go index 228e3cca5..48f365e65 100644 --- a/net/dns/manager_openbsd.go +++ b/net/dns/manager_openbsd.go @@ -4,6 +4,8 @@ package dns -func newManager(mconfig ManagerConfig) managerImpl { - return newDirectManager(mconfig) +import "tailscale.com/types/logger" + +func newManager(logger.Logf, string) managerImpl { + return newDirectManager() } diff --git a/net/dns/manager_windows.go b/net/dns/manager_windows.go index 5940404e7..9589e93b8 100644 --- a/net/dns/manager_windows.go +++ b/net/dns/manager_windows.go @@ -25,10 +25,10 @@ type windowsManager struct { guid string } -func newManager(mconfig ManagerConfig) managerImpl { +func newManager(logf logger.Logf, interfaceName string) managerImpl { return windowsManager{ - logf: mconfig.Logf, - guid: mconfig.InterfaceName, + logf: logf, + guid: interfaceName, } } diff --git a/net/dns/nm.go b/net/dns/nm.go index a597fa60d..5d744b276 100644 --- a/net/dns/nm.go +++ b/net/dns/nm.go @@ -53,9 +53,9 @@ type nmManager struct { interfaceName string } -func newNMManager(mconfig ManagerConfig) managerImpl { +func newNMManager(interfaceName string) managerImpl { return nmManager{ - interfaceName: mconfig.InterfaceName, + interfaceName: interfaceName, } } diff --git a/net/dns/noop.go b/net/dns/noop.go index 1cdffefc3..51c7920c9 100644 --- a/net/dns/noop.go +++ b/net/dns/noop.go @@ -14,6 +14,6 @@ func (m noopManager) Up(Config) error { return nil } // Down implements managerImpl. func (m noopManager) Down() error { return nil } -func newNoopManager(mconfig ManagerConfig) managerImpl { +func newNoopManager() managerImpl { return noopManager{} } diff --git a/net/dns/resolvconf.go b/net/dns/resolvconf.go index 8bf97ee88..2a82e8aa5 100644 --- a/net/dns/resolvconf.go +++ b/net/dns/resolvconf.go @@ -12,6 +12,8 @@ import ( "fmt" "os" "os/exec" + + "tailscale.com/types/logger" ) // isResolvconfActive indicates whether the system appears to be using resolvconf. @@ -99,9 +101,9 @@ type resolvconfManager struct { impl resolvconfImpl } -func newResolvconfManager(mconfig ManagerConfig) managerImpl { +func newResolvconfManager(logf logger.Logf) managerImpl { impl := getResolvconfImpl() - mconfig.Logf("resolvconf implementation is %s", impl) + logf("resolvconf implementation is %s", impl) return resolvconfManager{ impl: impl, diff --git a/net/dns/resolved.go b/net/dns/resolved.go index 9d8c40d90..467bfe63d 100644 --- a/net/dns/resolved.go +++ b/net/dns/resolved.go @@ -77,7 +77,7 @@ func isResolvedActive() bool { // resolvedManager uses the systemd-resolved DBus API. type resolvedManager struct{} -func newResolvedManager(mconfig ManagerConfig) managerImpl { +func newResolvedManager() managerImpl { return resolvedManager{} } diff --git a/wgengine/router/router_linux.go b/wgengine/router/router_linux.go index 311681ab0..ea4132b65 100644 --- a/wgengine/router/router_linux.go +++ b/wgengine/router/router_linux.go @@ -146,11 +146,6 @@ func newUserspaceRouter(logf logger.Logf, tunDev tun.Device) (Router, error) { func newUserspaceRouterAdvanced(logf logger.Logf, tunname string, netfilter4, netfilter6 netfilterRunner, cmd commandRunner, supportsV6, supportsV6NAT bool) (Router, error) { ipRuleAvailable := (cmd.run("ip", "rule") == nil) - mconfig := dns.ManagerConfig{ - Logf: logf, - InterfaceName: tunname, - } - return &linuxRouter{ logf: logf, tunname: tunname, @@ -163,7 +158,7 @@ func newUserspaceRouterAdvanced(logf logger.Logf, tunname string, netfilter4, ne ipt4: netfilter4, ipt6: netfilter6, cmd: cmd, - dns: dns.NewManager(mconfig), + dns: dns.NewManager(logf, tunname), }, nil } diff --git a/wgengine/router/router_openbsd.go b/wgengine/router/router_openbsd.go index a6dbf9282..68ea13fcf 100644 --- a/wgengine/router/router_openbsd.go +++ b/wgengine/router/router_openbsd.go @@ -36,15 +36,10 @@ func newUserspaceRouter(logf logger.Logf, tundev tun.Device) (Router, error) { return nil, err } - mconfig := dns.ManagerConfig{ - Logf: logf, - InterfaceName: tunname, - } - return &openbsdRouter{ logf: logf, tunname: tunname, - dns: dns.NewManager(mconfig), + dns: dns.NewManager(logf, tunname), }, nil } diff --git a/wgengine/router/router_userspace_bsd.go b/wgengine/router/router_userspace_bsd.go index 79a81de03..9d69473c4 100644 --- a/wgengine/router/router_userspace_bsd.go +++ b/wgengine/router/router_userspace_bsd.go @@ -34,15 +34,10 @@ func newUserspaceBSDRouter(logf logger.Logf, tundev tun.Device) (Router, error) return nil, err } - mconfig := dns.ManagerConfig{ - Logf: logf, - InterfaceName: tunname, - } - return &userspaceBSDRouter{ logf: logf, tunname: tunname, - dns: dns.NewManager(mconfig), + dns: dns.NewManager(logf, tunname), }, nil } diff --git a/wgengine/router/router_windows.go b/wgengine/router/router_windows.go index 2e2a87e62..2a1aa2729 100644 --- a/wgengine/router/router_windows.go +++ b/wgengine/router/router_windows.go @@ -50,15 +50,10 @@ func newUserspaceRouter(logf logger.Logf, tundev tun.Device) (Router, error) { return nil, err } - mconfig := dns.ManagerConfig{ - Logf: logf, - InterfaceName: guid.String(), - } - return &winRouter{ logf: logf, nativeTun: nativeTun, - dns: dns.NewManager(mconfig), + dns: dns.NewManager(logf, guid.String()), firewall: &firewallTweaker{ logf: logger.WithPrefix(logf, "firewall: "), tunGUID: *guid,