dns
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package dns contains code to configure and manage DNS settings.
Index¶
- Variables
- func CleanUp(logf logger.Logf, netMon *netmon.Monitor, bus *eventbus.Bus, ...)
- func Clone(dst, src any) bool
- func NewNoopManager() (noopManager, error)
- type Config
- type ConfigView
- func (v ConfigView) AsStruct() *Config
- func (v ConfigView) DefaultResolvers() views.SliceView[*dnstype.Resolver, dnstype.ResolverView]
- func (v ConfigView) Equal(v2 ConfigView) bool
- func (v ConfigView) Hosts() views.MapSlice[dnsname.FQDN, netip.Addr]
- func (v ConfigView) MarshalJSON() ([]byte, error)
- func (v ConfigView) MarshalJSONTo(enc *jsontext.Encoder) error
- func (v ConfigView) OnlyIPv6() bool
- func (v ConfigView) Routes() ...
- func (v ConfigView) SearchDomains() views.Slice[dnsname.FQDN]
- func (v *ConfigView) UnmarshalJSON(b []byte) error
- func (v *ConfigView) UnmarshalJSONFrom(dec *jsontext.Decoder) error
- func (v ConfigView) Valid() bool
- type HostEntry
- type Manager
- func (m *Manager) Down() error
- func (m *Manager) FlushCaches() error
- func (m *Manager) GetBaseConfig() (OSConfig, error)
- func (m *Manager) HandleTCPConn(conn net.Conn, srcAddr netip.AddrPort)
- func (m *Manager) Query(ctx context.Context, bs []byte, family string, from netip.AddrPort) ([]byte, error)
- func (m *Manager) RecompileDNSConfig() error
- func (m *Manager) Resolver() *resolver.Resolver
- func (m *Manager) Set(cfg Config) error
- type OSConfig
- type OSConfigurator
Constants¶
This section is empty.
Variables¶
var ErrGetBaseConfigNotSupported =errors.New("getting OS base config is not supported")ErrGetBaseConfigNotSupported is the errorOSConfigurator.GetBaseConfig returns when the OSConfiguratordoesn't support reading the underlying configuration out of the OS.
var (// ErrNoDNSConfig is returned by RecompileDNSConfig when the Manager// has no existing DNS configuration.ErrNoDNSConfig =errors.New("no DNS configuration"))
var HookWatchFilefeature.Hook[func(ctxcontext.Context, dir, filenamestring, cb func())error]HookWatchFile is a hook for watching file changes, for platforms that support it.The function is called with a directory and filename to watch, and a callbackto call when the file changes. It returns an error if the watch could not be set up.
Functions¶
funcCleanUp¶added inv1.64.0
func CleanUp(logflogger.Logf, netMon *netmon.Monitor, bus *eventbus.Bus, health *health.Tracker, interfaceNamestring)
CleanUp restores the system DNS configuration to its original statein case the Tailscale daemon terminated without closing the router.No other state needs to be instantiated before this runs.
health must not be nil
funcClone¶added inv1.90.0
Clone duplicates src into dst and reports whether it succeeded.To succeed, <src, dst> must be of types <*T, *T> or <*T, **T>,where T is one of Config.
funcNewNoopManager¶
func NewNoopManager() (noopManager,error)
Types¶
typeConfig¶
type Config struct {// DefaultResolvers are the DNS resolvers to use for DNS names// which aren't covered by more specific per-domain routes below.// If empty, the OS's default resolvers (the ones that predate// Tailscale altering the configuration) are used.DefaultResolvers []*dnstype.Resolver// Routes maps a DNS suffix to the resolvers that should be used// for queries that fall within that suffix.// If a query doesn't match any entry in Routes, the// DefaultResolvers are used.// A Routes entry with no resolvers means the route should be// authoritatively answered using the contents of Hosts.Routes map[dnsname.FQDN][]*dnstype.Resolver// SearchDomains are DNS suffixes to try when expanding// single-label queries.SearchDomains []dnsname.FQDN// Hosts maps DNS FQDNs to their IPs, which can be a mix of IPv4// and IPv6.// Queries matching entries in Hosts are resolved locally by// 100.100.100.100 without leaving the machine.// Adding an entry to Hosts merely creates the record. If you want// it to resolve, you also need to add appropriate routes to// Routes.Hosts map[dnsname.FQDN][]netip.Addr// OnlyIPv6, if true, uses the IPv6 service IP (for MagicDNS)// instead of the IPv4 version (100.100.100.100).OnlyIPv6bool}Config is a DNS configuration.
func (*Config)Clone¶added inv1.90.0
Clone makes a deep copy of Config.The result aliases no memory with the original.
func (*Config)View¶added inv1.90.0
func (p *Config) View()ConfigView
View returns a read-only view of Config.
func (*Config)WriteToBufioWriter¶added inv1.12.0
WriteToBufioWriter write a debug version of c for logs to w, omittingspammy stuff like *.arpa entries and replacing it with a total count.
typeConfigView¶added inv1.90.0
type ConfigView struct {// contains filtered or unexported fields}ConfigView provides a read-only view over Config.
Its methods should only be called if `Valid()` returns true.
func (ConfigView)AsStruct¶added inv1.90.0
func (vConfigView) AsStruct() *Config
AsStruct returns a clone of the underlying value which aliases no memory withthe original.
func (ConfigView)DefaultResolvers¶added inv1.90.0
func (vConfigView) DefaultResolvers()views.SliceView[*dnstype.Resolver,dnstype.ResolverView]
DefaultResolvers are the DNS resolvers to use for DNS nameswhich aren't covered by more specific per-domain routes below.If empty, the OS's default resolvers (the ones that predateTailscale altering the configuration) are used.
func (ConfigView)Equal¶added inv1.90.0
func (vConfigView) Equal(v2ConfigView)bool
func (ConfigView)Hosts¶added inv1.90.0
Hosts maps DNS FQDNs to their IPs, which can be a mix of IPv4and IPv6.Queries matching entries in Hosts are resolved locally by100.100.100.100 without leaving the machine.Adding an entry to Hosts merely creates the record. If you wantit to resolve, you also need to add appropriate routes toRoutes.
func (ConfigView)MarshalJSON¶added inv1.90.0
func (vConfigView) MarshalJSON() ([]byte,error)
MarshalJSON implementsjsonv1.Marshaler.
func (ConfigView)MarshalJSONTo¶added inv1.90.0
func (vConfigView) MarshalJSONTo(enc *jsontext.Encoder)error
MarshalJSONTo implementsjsonv2.MarshalerTo.
func (ConfigView)OnlyIPv6¶added inv1.90.0
func (vConfigView) OnlyIPv6()bool
OnlyIPv6, if true, uses the IPv6 service IP (for MagicDNS)instead of the IPv4 version (100.100.100.100).
func (ConfigView)Routes¶added inv1.90.0
func (vConfigView) Routes()views.MapFn[dnsname.FQDN, []*dnstype.Resolver,views.SliceView[*dnstype.Resolver,dnstype.ResolverView]]
Routes maps a DNS suffix to the resolvers that should be usedfor queries that fall within that suffix.If a query doesn't match any entry in Routes, theDefaultResolvers are used.A Routes entry with no resolvers means the route should beauthoritatively answered using the contents of Hosts.
func (ConfigView)SearchDomains¶added inv1.90.0
func (vConfigView) SearchDomains()views.Slice[dnsname.FQDN]
SearchDomains are DNS suffixes to try when expandingsingle-label queries.
func (*ConfigView)UnmarshalJSON¶added inv1.90.0
func (v *ConfigView) UnmarshalJSON(b []byte)error
UnmarshalJSON implementsjsonv1.Unmarshaler.
func (*ConfigView)UnmarshalJSONFrom¶added inv1.90.0
func (v *ConfigView) UnmarshalJSONFrom(dec *jsontext.Decoder)error
UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.
func (ConfigView)Valid¶added inv1.90.0
func (vConfigView) Valid()bool
Valid reports whether v's underlying value is non-nil.
typeManager¶
type Manager struct {// contains filtered or unexported fields}Manager manages system DNS settings.
funcNewManager¶
func NewManager(logflogger.Logf, oscfgOSConfigurator, health *health.Tracker, dialer *tsdial.Dialer, linkSelresolver.ForwardLinkSelector, knobs *controlknobs.Knobs, goosstring) *Manager
NewManagers created a new manager from the given config.
knobs may be nil.
func (*Manager)FlushCaches¶added inv1.16.0
func (*Manager)GetBaseConfig¶added inv1.74.0
GetBaseConfig returns the current base OS DNS configuration as provided by the OSConfigurator.
func (*Manager)HandleTCPConn¶added inv1.26.0
HandleTCPConn implements magicDNS over TCP, taking a connection andservicing DNS requests sent down it.
func (*Manager)Query¶added inv1.26.0
func (m *Manager) Query(ctxcontext.Context, bs []byte, familystring, fromnetip.AddrPort) ([]byte,error)
Query executes a DNS query received from the given address. The query isprovided in bs as a wire-encoded DNS query without any transport header.This method is called for requests arriving over UDP and TCP.
The "family" parameter should indicate what type of DNS query this is:either "tcp" or "udp".
func (*Manager)RecompileDNSConfig¶added inv1.82.0
RecompileDNSConfig recompiles the last attempted DNS configuration, which hasthe side effect of re-querying the OS's interface nameservers. This should be usedon platforms where the interface nameservers can change. Darwin, for example,where the nameservers aren't always available when we process a major interfacechange event, or platforms where the nameservers may change while tunnel is up.
This should be called if it is determined that [OSConfigurator.GetBaseConfig] maygive a better or different result than whenManager.Set was last called. Thelogic for making that determination is up to the caller.
It returnsErrNoDNSConfig ifManager.Set has never been called.
typeOSConfig¶
type OSConfig struct {// 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// Nameservers are the IP addresses of the nameservers to use.Nameservers []netip.Addr// 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.SearchDomains []dnsname.FQDN// 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.MatchDomains []dnsname.FQDN}OSConfig is an OS DNS configuration.
func (OSConfig)Format¶added inv1.32.0
Format implements the fmt.Formatter interface to ensure that Hosts isprinted correctly (i.e. not as a bunch of pointers).
func (*OSConfig)WriteToBufioWriter¶added inv1.50.0
typeOSConfigurator¶
type OSConfigurator interface {// SetDNS updates the OS's DNS configuration to match cfg.// If cfg is the zero value, all Tailscale-related DNS// configuration is removed.// SetDNS must not be called after Close.// SetDNS takes ownership of cfg.SetDNS(cfgOSConfig)error// 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// Implementations that don't support getting the base config must// return ErrGetBaseConfigNotSupported.GetBaseConfig() (OSConfig,error)// Close removes Tailscale-related DNS configuration from the OS.Close()error}An OSConfigurator applies DNS settings to the operating system.
funcNewOSConfigurator¶
func NewOSConfigurator(logflogger.Logf, health *health.Tracker, _policyclient.Client, _ *controlknobs.Knobs, interfaceNamestring) (retOSConfigurator, errerror)
NewOSConfigurator created a new OS configurator.
The health tracker may be nil; the knobs may be nil and are ignored on this platform.
Source Files¶
Directories¶
| Path | Synopsis |
|---|---|
Package publicdns contains mapping and helpers for working with public DNS providers. | Package publicdns contains mapping and helpers for working with public DNS providers. |
Package resolvconffile parses & serializes /etc/resolv.conf-style files. | Package resolvconffile parses & serializes /etc/resolv.conf-style files. |
Package resolver implements a stub DNS resolver that can also serve records out of an internal local zone. | Package resolver implements a stub DNS resolver that can also serve records out of an internal local zone. |