From 8af9d770cffa7aa79cd825cbecf1e8b9b799f832 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 1 Apr 2021 23:42:58 -0700 Subject: [PATCH] net/dns: rename Config to OSConfig. Making way for a new higher level config struct. Signed-off-by: David Anderson --- internal/deepprint/deepprint_test.go | 2 +- ipn/ipnlocal/local.go | 2 +- net/dns/config.go | 7 +++---- net/dns/direct.go | 6 +++--- net/dns/manager.go | 6 +++--- net/dns/manager_windows.go | 4 ++-- net/dns/nm.go | 4 ++-- net/dns/noop.go | 2 +- net/dns/resolvconf.go | 2 +- net/dns/resolved.go | 2 +- wgengine/router/router.go | 2 +- 11 files changed, 19 insertions(+), 20 deletions(-) diff --git a/internal/deepprint/deepprint_test.go b/internal/deepprint/deepprint_test.go index c7e2031f2..33847e27f 100644 --- a/internal/deepprint/deepprint_test.go +++ b/internal/deepprint/deepprint_test.go @@ -46,7 +46,7 @@ func getVal() []interface{} { }, }, &router.Config{ - DNS: dns.Config{ + DNS: dns.OSConfig{ Nameservers: []netaddr.IP{netaddr.IPv4(8, 8, 8, 8)}, Domains: []string{"tailscale.net"}, }, diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 62056b048..1455d9fd4 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -1449,7 +1449,7 @@ func (b *LocalBackend) authReconfig() { b.logf("[unexpected] dns proxied but no nameservers") proxied = false } - rcfg.DNS = dns.Config{ + rcfg.DNS = dns.OSConfig{ Nameservers: nm.DNS.Nameservers, Domains: nm.DNS.Domains, Proxied: proxied, diff --git a/net/dns/config.go b/net/dns/config.go index 5ac08a666..6286d97ef 100644 --- a/net/dns/config.go +++ b/net/dns/config.go @@ -8,9 +8,8 @@ "inet.af/netaddr" ) -// Config is the set of parameters that uniquely determine -// the state to which a manager should bring system DNS settings. -type Config struct { +// OSConfig is an OS DNS configuration. +type OSConfig struct { // Nameservers are the IP addresses of the nameservers to use. Nameservers []netaddr.IP // Domains are the search domains to use. @@ -22,7 +21,7 @@ type Config struct { // Equal determines whether its argument and receiver // represent equivalent DNS configurations (then DNS reconfig is a no-op). -func (lhs Config) Equal(rhs Config) bool { +func (lhs OSConfig) Equal(rhs OSConfig) bool { if lhs.Proxied != rhs.Proxied { return false } diff --git a/net/dns/direct.go b/net/dns/direct.go index c5ff2cc09..5c89b4274 100644 --- a/net/dns/direct.go +++ b/net/dns/direct.go @@ -48,8 +48,8 @@ func writeResolvConf(w io.Writer, servers []netaddr.IP, domains []string) { } // readResolvConf reads DNS configuration from /etc/resolv.conf. -func readResolvConf() (Config, error) { - var config Config +func readResolvConf() (OSConfig, error) { + var config OSConfig f, err := os.Open("/etc/resolv.conf") if err != nil { @@ -115,7 +115,7 @@ func newDirectManager() managerImpl { } // Up implements managerImpl. -func (m directManager) Up(config Config) error { +func (m directManager) Up(config OSConfig) error { // Write the tsConf file. buf := new(bytes.Buffer) writeResolvConf(buf, config.Nameservers, config.Domains) diff --git a/net/dns/manager.go b/net/dns/manager.go index 94494e0d5..f56c89c06 100644 --- a/net/dns/manager.go +++ b/net/dns/manager.go @@ -25,7 +25,7 @@ type managerImpl interface { // Up updates system DNS settings to match the given configuration. - Up(Config) error + Up(OSConfig) error // Down undoes the effects of Up. // It is idempotent and performs no action if Up has never been called. Down() error @@ -37,7 +37,7 @@ type Manager struct { impl managerImpl - config Config + config OSConfig } // NewManagers created a new manager from the given config. @@ -52,7 +52,7 @@ func NewManager(logf logger.Logf, interfaceName string) *Manager { return m } -func (m *Manager) Set(config Config) error { +func (m *Manager) Set(config OSConfig) error { if config.Equal(m.config) { return nil } diff --git a/net/dns/manager_windows.go b/net/dns/manager_windows.go index 9589e93b8..5744a47c1 100644 --- a/net/dns/manager_windows.go +++ b/net/dns/manager_windows.go @@ -64,7 +64,7 @@ func (m windowsManager) setDomains(basePath string, domains []string) error { return setRegistryString(path, "SearchList", value) } -func (m windowsManager) Up(config Config) error { +func (m windowsManager) Up(config OSConfig) error { var ipsv4 []string var ipsv6 []string @@ -114,5 +114,5 @@ func (m windowsManager) Up(config Config) error { } func (m windowsManager) Down() error { - return m.Up(Config{Nameservers: nil, Domains: nil}) + return m.Up(OSConfig{Nameservers: nil, Domains: nil}) } diff --git a/net/dns/nm.go b/net/dns/nm.go index 5d744b276..0dbe52f71 100644 --- a/net/dns/nm.go +++ b/net/dns/nm.go @@ -62,7 +62,7 @@ func newNMManager(interfaceName string) managerImpl { type nmConnectionSettings map[string]map[string]dbus.Variant // Up implements managerImpl. -func (m nmManager) Up(config Config) error { +func (m nmManager) Up(config OSConfig) error { ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout) defer cancel() @@ -201,5 +201,5 @@ func (m nmManager) Up(config Config) error { // Down implements managerImpl. func (m nmManager) Down() error { - return m.Up(Config{Nameservers: nil, Domains: nil}) + return m.Up(OSConfig{Nameservers: nil, Domains: nil}) } diff --git a/net/dns/noop.go b/net/dns/noop.go index 51c7920c9..a1b2eaa24 100644 --- a/net/dns/noop.go +++ b/net/dns/noop.go @@ -9,7 +9,7 @@ type noopManager struct{} // Up implements managerImpl. -func (m noopManager) Up(Config) error { return nil } +func (m noopManager) Up(OSConfig) error { return nil } // Down implements managerImpl. func (m noopManager) Down() error { return nil } diff --git a/net/dns/resolvconf.go b/net/dns/resolvconf.go index 2a82e8aa5..7806ad621 100644 --- a/net/dns/resolvconf.go +++ b/net/dns/resolvconf.go @@ -116,7 +116,7 @@ func newResolvconfManager(logf logger.Logf) managerImpl { const resolvconfConfigName = "tun-tailscale.inet" // Up implements managerImpl. -func (m resolvconfManager) Up(config Config) error { +func (m resolvconfManager) Up(config OSConfig) error { stdin := new(bytes.Buffer) writeResolvConf(stdin, config.Nameservers, config.Domains) // dns_direct.go diff --git a/net/dns/resolved.go b/net/dns/resolved.go index 467bfe63d..46aa4f754 100644 --- a/net/dns/resolved.go +++ b/net/dns/resolved.go @@ -82,7 +82,7 @@ func newResolvedManager() managerImpl { } // Up implements managerImpl. -func (m resolvedManager) Up(config Config) error { +func (m resolvedManager) Up(config OSConfig) error { ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout) defer cancel() diff --git a/wgengine/router/router.go b/wgengine/router/router.go index e164ef13b..5d05ee811 100644 --- a/wgengine/router/router.go +++ b/wgengine/router/router.go @@ -58,7 +58,7 @@ type Config struct { // this node has chosen to use. Routes []netaddr.IPPrefix - DNS dns.Config + DNS dns.OSConfig // Linux-only things below, ignored on other platforms.