2021-04-02 08:39:52 +00:00
|
|
|
// Copyright (c) 2021 Tailscale Inc & AUTHORS All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package dns
|
|
|
|
|
2021-04-07 22:39:26 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
"net/netip"
|
2021-04-07 22:39:26 +00:00
|
|
|
|
2021-04-09 22:24:47 +00:00
|
|
|
"tailscale.com/util/dnsname"
|
2021-04-07 22:39:26 +00:00
|
|
|
)
|
2021-04-02 08:39:52 +00:00
|
|
|
|
|
|
|
// An OSConfigurator applies DNS settings to the operating system.
|
|
|
|
type OSConfigurator interface {
|
2021-04-03 03:15:54 +00:00
|
|
|
// SetDNS updates the OS's DNS configuration to match cfg.
|
2021-04-03 01:44:02 +00:00
|
|
|
// If cfg is the zero value, all Tailscale-related DNS
|
2021-04-02 08:39:52 +00:00
|
|
|
// configuration is removed.
|
2021-04-03 03:15:54 +00:00
|
|
|
// SetDNS must not be called after Close.
|
2022-07-22 19:49:18 +00:00
|
|
|
// SetDNS takes ownership of cfg.
|
2021-04-03 03:15:54 +00:00
|
|
|
SetDNS(cfg OSConfig) error
|
2021-04-05 20:05:47 +00:00
|
|
|
// SupportsSplitDNS reports whether the configurator is capable of
|
|
|
|
// installing a resolver only for specific DNS suffixes. If false,
|
|
|
|
// the configurator can only set a global resolver.
|
|
|
|
SupportsSplitDNS() bool
|
2021-04-07 07:31:31 +00:00
|
|
|
// GetBaseConfig returns the OS's "base" configuration, i.e. the
|
|
|
|
// resolver settings the OS would use without Tailscale
|
|
|
|
// contributing any configuration.
|
|
|
|
// GetBaseConfig must return the tailscale-free base config even
|
|
|
|
// after SetDNS has been called to set a Tailscale configuration.
|
|
|
|
// Only works when SupportsSplitDNS=false.
|
2021-04-07 22:39:26 +00:00
|
|
|
|
|
|
|
// Implementations that don't support getting the base config must
|
|
|
|
// return ErrGetBaseConfigNotSupported.
|
2021-04-07 07:31:31 +00:00
|
|
|
GetBaseConfig() (OSConfig, error)
|
2021-04-02 08:39:52 +00:00
|
|
|
// Close removes Tailscale-related DNS configuration from the OS.
|
|
|
|
Close() error
|
|
|
|
}
|
2021-04-05 20:05:47 +00:00
|
|
|
|
2022-08-19 17:19:50 +00:00
|
|
|
// HostEntry represents a single line in the OS's hosts file.
|
|
|
|
type HostEntry struct {
|
|
|
|
Addr netip.Addr
|
|
|
|
Hosts []string
|
|
|
|
}
|
|
|
|
|
2021-04-05 20:05:47 +00:00
|
|
|
// OSConfig is an OS DNS configuration.
|
|
|
|
type OSConfig struct {
|
2022-08-19 17:19:50 +00:00
|
|
|
// Hosts is a map of DNS FQDNs to their IPs, which should be added to the
|
|
|
|
// OS's hosts file. Currently, (2022-08-12) it is only populated for Windows
|
|
|
|
// in SplitDNS mode and with Smart Name Resolution turned on.
|
|
|
|
Hosts []*HostEntry
|
2021-04-05 20:05:47 +00:00
|
|
|
// Nameservers are the IP addresses of the nameservers to use.
|
all: convert more code to use net/netip directly
perl -i -npe 's,netaddr.IPPrefixFrom,netip.PrefixFrom,' $(git grep -l -F netaddr.)
perl -i -npe 's,netaddr.IPPortFrom,netip.AddrPortFrom,' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPrefix,netip.Prefix,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPPort,netip.AddrPort,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IP\b,netip.Addr,g' $(git grep -l -F netaddr. )
perl -i -npe 's,netaddr.IPv6Raw\b,netip.AddrFrom16,g' $(git grep -l -F netaddr. )
goimports -w .
Then delete some stuff from the net/netaddr shim package which is no
longer neeed.
Updates #5162
Change-Id: Ia7a86893fe21c7e3ee1ec823e8aba288d4566cd8
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2022-07-26 04:14:09 +00:00
|
|
|
Nameservers []netip.Addr
|
2021-04-06 22:21:32 +00:00
|
|
|
// SearchDomains are the domain suffixes to use when expanding
|
|
|
|
// single-label name queries. SearchDomains is additive to
|
|
|
|
// whatever non-Tailscale search domains the OS has.
|
2021-04-09 22:24:47 +00:00
|
|
|
SearchDomains []dnsname.FQDN
|
2021-04-06 22:21:32 +00:00
|
|
|
// MatchDomains are the DNS suffixes for which Nameservers should
|
|
|
|
// be used. If empty, Nameservers is installed as the "primary" resolver.
|
|
|
|
// A non-empty MatchDomains requests a "split DNS" configuration
|
|
|
|
// from the OS, which will only work with OSConfigurators that
|
|
|
|
// report SupportsSplitDNS()=true.
|
2021-04-09 22:24:47 +00:00
|
|
|
MatchDomains []dnsname.FQDN
|
2021-04-05 20:05:47 +00:00
|
|
|
}
|
2021-04-07 22:39:26 +00:00
|
|
|
|
2021-04-20 22:51:14 +00:00
|
|
|
func (o OSConfig) IsZero() bool {
|
|
|
|
return len(o.Nameservers) == 0 && len(o.SearchDomains) == 0 && len(o.MatchDomains) == 0
|
|
|
|
}
|
|
|
|
|
2021-04-14 00:10:30 +00:00
|
|
|
func (a OSConfig) Equal(b OSConfig) bool {
|
|
|
|
if len(a.Nameservers) != len(b.Nameservers) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if len(a.SearchDomains) != len(b.SearchDomains) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if len(a.MatchDomains) != len(b.MatchDomains) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range a.Nameservers {
|
|
|
|
if a.Nameservers[i] != b.Nameservers[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := range a.SearchDomains {
|
|
|
|
if a.SearchDomains[i] != b.SearchDomains[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := range a.MatchDomains {
|
|
|
|
if a.MatchDomains[i] != b.MatchDomains[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2021-04-07 22:39:26 +00:00
|
|
|
// 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")
|