net/dns: rename Config to OSConfig.

Making way for a new higher level config struct.

Signed-off-by: David Anderson <danderson@tailscale.com>
This commit is contained in:
David Anderson 2021-04-01 23:42:58 -07:00 committed by Dave Anderson
parent fcfc0d3a08
commit 8af9d770cf
11 changed files with 19 additions and 20 deletions

View File

@ -46,7 +46,7 @@ func getVal() []interface{} {
}, },
}, },
&router.Config{ &router.Config{
DNS: dns.Config{ DNS: dns.OSConfig{
Nameservers: []netaddr.IP{netaddr.IPv4(8, 8, 8, 8)}, Nameservers: []netaddr.IP{netaddr.IPv4(8, 8, 8, 8)},
Domains: []string{"tailscale.net"}, Domains: []string{"tailscale.net"},
}, },

View File

@ -1449,7 +1449,7 @@ func (b *LocalBackend) authReconfig() {
b.logf("[unexpected] dns proxied but no nameservers") b.logf("[unexpected] dns proxied but no nameservers")
proxied = false proxied = false
} }
rcfg.DNS = dns.Config{ rcfg.DNS = dns.OSConfig{
Nameservers: nm.DNS.Nameservers, Nameservers: nm.DNS.Nameservers,
Domains: nm.DNS.Domains, Domains: nm.DNS.Domains,
Proxied: proxied, Proxied: proxied,

View File

@ -8,9 +8,8 @@
"inet.af/netaddr" "inet.af/netaddr"
) )
// Config is the set of parameters that uniquely determine // OSConfig is an OS DNS configuration.
// the state to which a manager should bring system DNS settings. type OSConfig struct {
type Config struct {
// Nameservers are the IP addresses of the nameservers to use. // Nameservers are the IP addresses of the nameservers to use.
Nameservers []netaddr.IP Nameservers []netaddr.IP
// Domains are the search domains to use. // Domains are the search domains to use.
@ -22,7 +21,7 @@ type Config struct {
// Equal determines whether its argument and receiver // Equal determines whether its argument and receiver
// represent equivalent DNS configurations (then DNS reconfig is a no-op). // 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 { if lhs.Proxied != rhs.Proxied {
return false return false
} }

View File

@ -48,8 +48,8 @@ func writeResolvConf(w io.Writer, servers []netaddr.IP, domains []string) {
} }
// readResolvConf reads DNS configuration from /etc/resolv.conf. // readResolvConf reads DNS configuration from /etc/resolv.conf.
func readResolvConf() (Config, error) { func readResolvConf() (OSConfig, error) {
var config Config var config OSConfig
f, err := os.Open("/etc/resolv.conf") f, err := os.Open("/etc/resolv.conf")
if err != nil { if err != nil {
@ -115,7 +115,7 @@ func newDirectManager() managerImpl {
} }
// Up implements managerImpl. // Up implements managerImpl.
func (m directManager) Up(config Config) error { func (m directManager) Up(config OSConfig) error {
// Write the tsConf file. // Write the tsConf file.
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
writeResolvConf(buf, config.Nameservers, config.Domains) writeResolvConf(buf, config.Nameservers, config.Domains)

View File

@ -25,7 +25,7 @@
type managerImpl interface { type managerImpl interface {
// Up updates system DNS settings to match the given configuration. // Up updates system DNS settings to match the given configuration.
Up(Config) error Up(OSConfig) error
// Down undoes the effects of Up. // Down undoes the effects of Up.
// It is idempotent and performs no action if Up has never been called. // It is idempotent and performs no action if Up has never been called.
Down() error Down() error
@ -37,7 +37,7 @@ type Manager struct {
impl managerImpl impl managerImpl
config Config config OSConfig
} }
// NewManagers created a new manager from the given config. // NewManagers created a new manager from the given config.
@ -52,7 +52,7 @@ func NewManager(logf logger.Logf, interfaceName string) *Manager {
return m return m
} }
func (m *Manager) Set(config Config) error { func (m *Manager) Set(config OSConfig) error {
if config.Equal(m.config) { if config.Equal(m.config) {
return nil return nil
} }

View File

@ -64,7 +64,7 @@ func (m windowsManager) setDomains(basePath string, domains []string) error {
return setRegistryString(path, "SearchList", value) return setRegistryString(path, "SearchList", value)
} }
func (m windowsManager) Up(config Config) error { func (m windowsManager) Up(config OSConfig) error {
var ipsv4 []string var ipsv4 []string
var ipsv6 []string var ipsv6 []string
@ -114,5 +114,5 @@ func (m windowsManager) Up(config Config) error {
} }
func (m windowsManager) Down() error { func (m windowsManager) Down() error {
return m.Up(Config{Nameservers: nil, Domains: nil}) return m.Up(OSConfig{Nameservers: nil, Domains: nil})
} }

View File

@ -62,7 +62,7 @@ func newNMManager(interfaceName string) managerImpl {
type nmConnectionSettings map[string]map[string]dbus.Variant type nmConnectionSettings map[string]map[string]dbus.Variant
// Up implements managerImpl. // Up implements managerImpl.
func (m nmManager) Up(config Config) error { func (m nmManager) Up(config OSConfig) error {
ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout) ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout)
defer cancel() defer cancel()
@ -201,5 +201,5 @@ func (m nmManager) Up(config Config) error {
// Down implements managerImpl. // Down implements managerImpl.
func (m nmManager) Down() error { func (m nmManager) Down() error {
return m.Up(Config{Nameservers: nil, Domains: nil}) return m.Up(OSConfig{Nameservers: nil, Domains: nil})
} }

View File

@ -9,7 +9,7 @@
type noopManager struct{} type noopManager struct{}
// Up implements managerImpl. // Up implements managerImpl.
func (m noopManager) Up(Config) error { return nil } func (m noopManager) Up(OSConfig) error { return nil }
// Down implements managerImpl. // Down implements managerImpl.
func (m noopManager) Down() error { return nil } func (m noopManager) Down() error { return nil }

View File

@ -116,7 +116,7 @@ func newResolvconfManager(logf logger.Logf) managerImpl {
const resolvconfConfigName = "tun-tailscale.inet" const resolvconfConfigName = "tun-tailscale.inet"
// Up implements managerImpl. // Up implements managerImpl.
func (m resolvconfManager) Up(config Config) error { func (m resolvconfManager) Up(config OSConfig) error {
stdin := new(bytes.Buffer) stdin := new(bytes.Buffer)
writeResolvConf(stdin, config.Nameservers, config.Domains) // dns_direct.go writeResolvConf(stdin, config.Nameservers, config.Domains) // dns_direct.go

View File

@ -82,7 +82,7 @@ func newResolvedManager() managerImpl {
} }
// Up implements 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) ctx, cancel := context.WithTimeout(context.Background(), reconfigTimeout)
defer cancel() defer cancel()

View File

@ -58,7 +58,7 @@ type Config struct {
// this node has chosen to use. // this node has chosen to use.
Routes []netaddr.IPPrefix Routes []netaddr.IPPrefix
DNS dns.Config DNS dns.OSConfig
// Linux-only things below, ignored on other platforms. // Linux-only things below, ignored on other platforms.