net/dns: remove ManagerConfig, pass relevant args directly.

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/1644/head
David Anderson 3 years ago
parent 0ca04f1e01
commit fcfc0d3a08

@ -6,8 +6,6 @@ package dns
import ( import (
"inet.af/netaddr" "inet.af/netaddr"
"tailscale.com/types/logger"
) )
// Config is the set of parameters that uniquely determine // Config is the set of parameters that uniquely determine
@ -54,13 +52,3 @@ func (lhs Config) Equal(rhs Config) bool {
return true 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
}

@ -110,7 +110,7 @@ func isResolvedRunning() bool {
// or as cleanup if the program terminates unexpectedly. // or as cleanup if the program terminates unexpectedly.
type directManager struct{} type directManager struct{}
func newDirectManager(mconfig ManagerConfig) managerImpl { func newDirectManager() managerImpl {
return directManager{} return directManager{}
} }

@ -37,17 +37,15 @@ type Manager struct {
impl managerImpl impl managerImpl
config Config config Config
mconfig ManagerConfig
} }
// NewManagers created a new manager from the given config. // NewManagers created a new manager from the given config.
func NewManager(mconfig ManagerConfig) *Manager { func NewManager(logf logger.Logf, interfaceName string) *Manager {
mconfig.Logf = logger.WithPrefix(mconfig.Logf, "dns: ") logf = logger.WithPrefix(logf, "dns: ")
m := &Manager{ m := &Manager{
logf: mconfig.Logf, logf: logf,
impl: newManager(mconfig), impl: newManager(logf, interfaceName),
mconfig: mconfig,
} }
m.logf("using %T", m.impl) 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. // in case the Tailscale daemon terminated without closing the router.
// No other state needs to be instantiated before this runs. // No other state needs to be instantiated before this runs.
func Cleanup(logf logger.Logf, interfaceName string) { func Cleanup(logf logger.Logf, interfaceName string) {
mconfig := ManagerConfig{ dns := NewManager(logf, interfaceName)
Logf: logf,
InterfaceName: interfaceName,
}
dns := NewManager(mconfig)
if err := dns.Down(); err != nil { if err := dns.Down(); err != nil {
logf("dns down: %v", err) logf("dns down: %v", err)
} }

@ -6,9 +6,11 @@
package dns 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. // 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, // This is currently not implemented. Editing /etc/resolv.conf does not work,
// as most applications use the system resolver, which disregards it. // as most applications use the system resolver, which disregards it.
return newNoopManager(mconfig) return newNoopManager()
} }

@ -4,11 +4,13 @@
package dns package dns
func newManager(mconfig ManagerConfig) managerImpl { import "tailscale.com/types/logger"
func newManager(logf logger.Logf, _ string) managerImpl {
switch { switch {
case isResolvconfActive(): case isResolvconfActive():
return newResolvconfManager(mconfig) return newResolvconfManager(logf)
default: default:
return newDirectManager(mconfig) return newDirectManager()
} }
} }

@ -4,15 +4,17 @@
package dns package dns
func newManager(mconfig ManagerConfig) managerImpl { import "tailscale.com/types/logger"
func newManager(logf logger.Logf, interfaceName string) managerImpl {
switch { switch {
case isResolvedActive(): case isResolvedActive():
return newResolvedManager(mconfig) return newResolvedManager()
case isNMActive(): case isNMActive():
return newNMManager(mconfig) return newNMManager(interfaceName)
case isResolvconfActive(): case isResolvconfActive():
return newResolvconfManager(mconfig) return newResolvconfManager(logf)
default: default:
return newDirectManager(mconfig) return newDirectManager()
} }
} }

@ -4,6 +4,8 @@
package dns package dns
func newManager(mconfig ManagerConfig) managerImpl { import "tailscale.com/types/logger"
return newDirectManager(mconfig)
func newManager(logger.Logf, string) managerImpl {
return newDirectManager()
} }

@ -25,10 +25,10 @@ type windowsManager struct {
guid string guid string
} }
func newManager(mconfig ManagerConfig) managerImpl { func newManager(logf logger.Logf, interfaceName string) managerImpl {
return windowsManager{ return windowsManager{
logf: mconfig.Logf, logf: logf,
guid: mconfig.InterfaceName, guid: interfaceName,
} }
} }

@ -53,9 +53,9 @@ type nmManager struct {
interfaceName string interfaceName string
} }
func newNMManager(mconfig ManagerConfig) managerImpl { func newNMManager(interfaceName string) managerImpl {
return nmManager{ return nmManager{
interfaceName: mconfig.InterfaceName, interfaceName: interfaceName,
} }
} }

@ -14,6 +14,6 @@ func (m noopManager) Up(Config) error { return nil }
// Down implements managerImpl. // Down implements managerImpl.
func (m noopManager) Down() error { return nil } func (m noopManager) Down() error { return nil }
func newNoopManager(mconfig ManagerConfig) managerImpl { func newNoopManager() managerImpl {
return noopManager{} return noopManager{}
} }

@ -12,6 +12,8 @@ import (
"fmt" "fmt"
"os" "os"
"os/exec" "os/exec"
"tailscale.com/types/logger"
) )
// isResolvconfActive indicates whether the system appears to be using resolvconf. // isResolvconfActive indicates whether the system appears to be using resolvconf.
@ -99,9 +101,9 @@ type resolvconfManager struct {
impl resolvconfImpl impl resolvconfImpl
} }
func newResolvconfManager(mconfig ManagerConfig) managerImpl { func newResolvconfManager(logf logger.Logf) managerImpl {
impl := getResolvconfImpl() impl := getResolvconfImpl()
mconfig.Logf("resolvconf implementation is %s", impl) logf("resolvconf implementation is %s", impl)
return resolvconfManager{ return resolvconfManager{
impl: impl, impl: impl,

@ -77,7 +77,7 @@ func isResolvedActive() bool {
// resolvedManager uses the systemd-resolved DBus API. // resolvedManager uses the systemd-resolved DBus API.
type resolvedManager struct{} type resolvedManager struct{}
func newResolvedManager(mconfig ManagerConfig) managerImpl { func newResolvedManager() managerImpl {
return resolvedManager{} return resolvedManager{}
} }

@ -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) { func newUserspaceRouterAdvanced(logf logger.Logf, tunname string, netfilter4, netfilter6 netfilterRunner, cmd commandRunner, supportsV6, supportsV6NAT bool) (Router, error) {
ipRuleAvailable := (cmd.run("ip", "rule") == nil) ipRuleAvailable := (cmd.run("ip", "rule") == nil)
mconfig := dns.ManagerConfig{
Logf: logf,
InterfaceName: tunname,
}
return &linuxRouter{ return &linuxRouter{
logf: logf, logf: logf,
tunname: tunname, tunname: tunname,
@ -163,7 +158,7 @@ func newUserspaceRouterAdvanced(logf logger.Logf, tunname string, netfilter4, ne
ipt4: netfilter4, ipt4: netfilter4,
ipt6: netfilter6, ipt6: netfilter6,
cmd: cmd, cmd: cmd,
dns: dns.NewManager(mconfig), dns: dns.NewManager(logf, tunname),
}, nil }, nil
} }

@ -36,15 +36,10 @@ func newUserspaceRouter(logf logger.Logf, tundev tun.Device) (Router, error) {
return nil, err return nil, err
} }
mconfig := dns.ManagerConfig{
Logf: logf,
InterfaceName: tunname,
}
return &openbsdRouter{ return &openbsdRouter{
logf: logf, logf: logf,
tunname: tunname, tunname: tunname,
dns: dns.NewManager(mconfig), dns: dns.NewManager(logf, tunname),
}, nil }, nil
} }

@ -34,15 +34,10 @@ func newUserspaceBSDRouter(logf logger.Logf, tundev tun.Device) (Router, error)
return nil, err return nil, err
} }
mconfig := dns.ManagerConfig{
Logf: logf,
InterfaceName: tunname,
}
return &userspaceBSDRouter{ return &userspaceBSDRouter{
logf: logf, logf: logf,
tunname: tunname, tunname: tunname,
dns: dns.NewManager(mconfig), dns: dns.NewManager(logf, tunname),
}, nil }, nil
} }

@ -50,15 +50,10 @@ func newUserspaceRouter(logf logger.Logf, tundev tun.Device) (Router, error) {
return nil, err return nil, err
} }
mconfig := dns.ManagerConfig{
Logf: logf,
InterfaceName: guid.String(),
}
return &winRouter{ return &winRouter{
logf: logf, logf: logf,
nativeTun: nativeTun, nativeTun: nativeTun,
dns: dns.NewManager(mconfig), dns: dns.NewManager(logf, guid.String()),
firewall: &firewallTweaker{ firewall: &firewallTweaker{
logf: logger.WithPrefix(logf, "firewall: "), logf: logger.WithPrefix(logf, "firewall: "),
tunGUID: *guid, tunGUID: *guid,

Loading…
Cancel
Save