net/dns: some post-review cleanups.

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/1677/head
David Anderson 4 years ago committed by Dave Anderson
parent 720c1ad0f0
commit 4a64d2a603

@ -164,8 +164,7 @@ func (m directManager) SupportsSplitDNS() bool {
} }
func (m directManager) GetBaseConfig() (OSConfig, error) { func (m directManager) GetBaseConfig() (OSConfig, error) {
// TODO return OSConfig{}, ErrGetBaseConfigNotSupported
return OSConfig{}, nil
} }
func (m directManager) Close() error { func (m directManager) Close() error {

@ -71,11 +71,6 @@ func forceSplitDNSForTesting(cfg *Config) {
func (m *Manager) Set(cfg Config) error { func (m *Manager) Set(cfg Config) error {
m.logf("Set: %+v", cfg) m.logf("Set: %+v", cfg)
if false {
// Temporary, for danderson to test things.
forceSplitDNSForTesting(&cfg)
}
rcfg, ocfg, err := m.compileConfig(cfg) rcfg, ocfg, err := m.compileConfig(cfg)
if err != nil { if err != nil {
return err return err
@ -168,8 +163,6 @@ func (m *Manager) compileConfig(cfg Config) (resolver.Config, OSConfig, error) {
// If the OS can't do native split-dns, read out the underlying // If the OS can't do native split-dns, read out the underlying
// resolver config and blend it into our config. // resolver config and blend it into our config.
// TODO: for now, use quad-8 as the upstream until more plumbing
// is done.
if m.os.SupportsSplitDNS() { if m.os.SupportsSplitDNS() {
ocfg.MatchDomains = cfg.matchDomains() ocfg.MatchDomains = cfg.matchDomains()
} else { } else {
@ -187,7 +180,10 @@ func (m *Manager) compileConfig(cfg Config) (resolver.Config, OSConfig, error) {
func addFQDNDots(domains []string) []string { func addFQDNDots(domains []string) []string {
ret := make([]string, 0, len(domains)) ret := make([]string, 0, len(domains))
for _, dom := range domains { for _, dom := range domains {
ret = append(ret, strings.TrimSuffix(dom, ".")+".") if !strings.HasSuffix(dom, ".") {
dom = dom + "."
}
ret = append(ret, dom)
} }
return ret return ret
} }
@ -198,6 +194,7 @@ func addFQDNDots(domains []string) []string {
// https://github.com/tailscale/tailscale/issues/1666 tracks making // https://github.com/tailscale/tailscale/issues/1666 tracks making
// that not true, if we ever want to. // that not true, if we ever want to.
func toIPsOnly(ipps []netaddr.IPPort) (ret []netaddr.IP) { func toIPsOnly(ipps []netaddr.IPPort) (ret []netaddr.IP) {
ret = make([]netaddr.IP, 0, len(ipps))
for _, ipp := range ipps { for _, ipp := range ipps {
ret = append(ret, ipp.IP) ret = append(ret, ipp.IP)
} }
@ -205,6 +202,7 @@ func toIPsOnly(ipps []netaddr.IPPort) (ret []netaddr.IP) {
} }
func toIPPorts(ips []netaddr.IP) (ret []netaddr.IPPort) { func toIPPorts(ips []netaddr.IP) (ret []netaddr.IPPort) {
ret = make([]netaddr.IPPort, 0, len(ips))
for _, ip := range ips { for _, ip := range ips {
ret = append(ret, netaddr.IPPort{IP: ip, Port: 53}) ret = append(ret, netaddr.IPPort{IP: ip, Port: 53})
} }

@ -301,9 +301,6 @@ func (m windowsManager) Close() error {
} }
func (m windowsManager) GetBaseConfig() (OSConfig, error) { func (m windowsManager) GetBaseConfig() (OSConfig, error) {
if m.nrptWorks {
return OSConfig{}, errors.New("GetBaseConfig not supported")
}
resolvers, err := m.getBasePrimaryResolver() resolvers, err := m.getBasePrimaryResolver()
if err != nil { if err != nil {
return OSConfig{}, err return OSConfig{}, err

@ -203,8 +203,7 @@ func (m nmManager) SetDNS(config OSConfig) error {
func (m nmManager) SupportsSplitDNS() bool { return false } func (m nmManager) SupportsSplitDNS() bool { return false }
func (m nmManager) GetBaseConfig() (OSConfig, error) { func (m nmManager) GetBaseConfig() (OSConfig, error) {
// TODO return OSConfig{}, ErrGetBaseConfigNotSupported
return OSConfig{}, nil
} }
func (m nmManager) Close() error { func (m nmManager) Close() error {

@ -9,7 +9,9 @@ type noopManager struct{}
func (m noopManager) SetDNS(OSConfig) error { return nil } func (m noopManager) SetDNS(OSConfig) error { return nil }
func (m noopManager) SupportsSplitDNS() bool { return false } func (m noopManager) SupportsSplitDNS() bool { return false }
func (m noopManager) Close() error { return nil } func (m noopManager) Close() error { return nil }
func (m noopManager) GetBaseConfig() (OSConfig, error) { return OSConfig{}, nil } func (m noopManager) GetBaseConfig() (OSConfig, error) {
return OSConfig{}, ErrGetBaseConfigNotSupported
}
func NewNoopManager() noopManager { func NewNoopManager() noopManager {
return noopManager{} return noopManager{}

@ -4,7 +4,11 @@
package dns package dns
import "inet.af/netaddr" import (
"errors"
"inet.af/netaddr"
)
// An OSConfigurator applies DNS settings to the operating system. // An OSConfigurator applies DNS settings to the operating system.
type OSConfigurator interface { type OSConfigurator interface {
@ -23,6 +27,9 @@ type OSConfigurator interface {
// GetBaseConfig must return the tailscale-free base config even // GetBaseConfig must return the tailscale-free base config even
// after SetDNS has been called to set a Tailscale configuration. // after SetDNS has been called to set a Tailscale configuration.
// Only works when SupportsSplitDNS=false. // Only works when SupportsSplitDNS=false.
// Implementations that don't support getting the base config must
// return ErrGetBaseConfigNotSupported.
GetBaseConfig() (OSConfig, error) GetBaseConfig() (OSConfig, error)
// Close removes Tailscale-related DNS configuration from the OS. // Close removes Tailscale-related DNS configuration from the OS.
Close() error Close() error
@ -43,3 +50,8 @@ type OSConfig struct {
// report SupportsSplitDNS()=true. // report SupportsSplitDNS()=true.
MatchDomains []string MatchDomains []string
} }
// ErrGetBaseConfigNotSupported is the error
// OSConfigurator.GetBaseConfig returns when the OSConfigurator
// doesn't support reading the underlying configuration out of the OS.
var ErrGetBaseConfigNotSupported = errors.New("getting OS base config is not supported")

@ -143,8 +143,7 @@ func (m resolvconfManager) SupportsSplitDNS() bool {
} }
func (m resolvconfManager) GetBaseConfig() (OSConfig, error) { func (m resolvconfManager) GetBaseConfig() (OSConfig, error) {
// TODO return OSConfig{}, ErrGetBaseConfigNotSupported
return OSConfig{}, nil
} }
func (m resolvconfManager) Close() error { func (m resolvconfManager) Close() error {

@ -158,8 +158,7 @@ func (m resolvedManager) SupportsSplitDNS() bool {
} }
func (m resolvedManager) GetBaseConfig() (OSConfig, error) { func (m resolvedManager) GetBaseConfig() (OSConfig, error) {
// TODO return OSConfig{}, ErrGetBaseConfigNotSupported
return OSConfig{}, nil
} }
func (m resolvedManager) Close() error { func (m resolvedManager) Close() error {

@ -50,8 +50,7 @@ func (r *CallbackRouter) SupportsSplitDNS() bool {
} }
func (r *CallbackRouter) GetBaseConfig() (dns.OSConfig, error) { func (r *CallbackRouter) GetBaseConfig() (dns.OSConfig, error) {
// TODO return dns.OSConfig{}, dns.ErrGetBaseConfigNotSupported
return dns.OSConfig{}, nil
} }
func (r *CallbackRouter) Close() error { func (r *CallbackRouter) Close() error {

Loading…
Cancel
Save