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 (
"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
}

@ -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{}
}

@ -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)
}

@ -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()
}

@ -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()
}
}

@ -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()
}
}

@ -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()
}

@ -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,
}
}

@ -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,
}
}

@ -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{}
}

@ -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,

@ -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{}
}

@ -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
}

@ -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
}

@ -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
}

@ -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,

Loading…
Cancel
Save