Movatterモバイル変換


[0]ホーム

URL:


dns

package
v1.92.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:54Imported by:36

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package dns contains code to configure and manage DNS settings.

Index

Constants

This section is empty.

Variables

View Source
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.

View Source
var (// ErrNoDNSConfig is returned by RecompileDNSConfig when the Manager// has no existing DNS configuration.ErrNoDNSConfig =errors.New("no DNS configuration"))
View Source
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

funcCleanUpadded 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

funcCloneadded inv1.90.0

func Clone(dst, srcany)bool

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)Cloneadded inv1.90.0

func (src *Config) Clone() *Config

Clone makes a deep copy of Config.The result aliases no memory with the original.

func (*Config)Equaladded inv1.90.0

func (c *Config) Equal(o *Config)bool

func (*Config)Viewadded inv1.90.0

func (p *Config) View()ConfigView

View returns a read-only view of Config.

func (*Config)WriteToBufioWriteradded inv1.12.0

func (c *Config) WriteToBufioWriter(w *bufio.Writer)

WriteToBufioWriter write a debug version of c for logs to w, omittingspammy stuff like *.arpa entries and replacing it with a total count.

typeConfigViewadded 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)AsStructadded inv1.90.0

func (vConfigView) AsStruct() *Config

AsStruct returns a clone of the underlying value which aliases no memory withthe original.

func (ConfigView)DefaultResolversadded inv1.90.0

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)Equaladded inv1.90.0

func (vConfigView) Equal(v2ConfigView)bool

func (ConfigView)Hostsadded 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)MarshalJSONadded inv1.90.0

func (vConfigView) MarshalJSON() ([]byte,error)

MarshalJSON implementsjsonv1.Marshaler.

func (ConfigView)MarshalJSONToadded inv1.90.0

func (vConfigView) MarshalJSONTo(enc *jsontext.Encoder)error

MarshalJSONTo implementsjsonv2.MarshalerTo.

func (ConfigView)OnlyIPv6added 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)Routesadded inv1.90.0

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)SearchDomainsadded inv1.90.0

func (vConfigView) SearchDomains()views.Slice[dnsname.FQDN]

SearchDomains are DNS suffixes to try when expandingsingle-label queries.

func (*ConfigView)UnmarshalJSONadded inv1.90.0

func (v *ConfigView) UnmarshalJSON(b []byte)error

UnmarshalJSON implementsjsonv1.Unmarshaler.

func (*ConfigView)UnmarshalJSONFromadded inv1.90.0

func (v *ConfigView) UnmarshalJSONFrom(dec *jsontext.Decoder)error

UnmarshalJSONFrom implementsjsonv2.UnmarshalerFrom.

func (ConfigView)Validadded inv1.90.0

func (vConfigView) Valid()bool

Valid reports whether v's underlying value is non-nil.

typeHostEntryadded inv1.30.0

type HostEntry struct {Addrnetip.AddrHosts []string}

HostEntry represents a single line in the OS's hosts file.

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)Down

func (m *Manager) Down()error

func (*Manager)FlushCachesadded inv1.16.0

func (m *Manager) FlushCaches()error

func (*Manager)GetBaseConfigadded inv1.74.0

func (m *Manager) GetBaseConfig() (OSConfig,error)

GetBaseConfig returns the current base OS DNS configuration as provided by the OSConfigurator.

func (*Manager)HandleTCPConnadded inv1.26.0

func (m *Manager) HandleTCPConn(connnet.Conn, srcAddrnetip.AddrPort)

HandleTCPConn implements magicDNS over TCP, taking a connection andservicing DNS requests sent down it.

func (*Manager)Queryadded 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)RecompileDNSConfigadded inv1.82.0

func (m *Manager) RecompileDNSConfig()error

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.

func (*Manager)Resolveradded inv1.20.0

func (m *Manager) Resolver() *resolver.Resolver

Resolver returns the Manager's DNS Resolver.

func (*Manager)Set

func (m *Manager) Set(cfgConfig)error

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)Equal

func (aOSConfig) Equal(bOSConfig)bool

func (OSConfig)Formatadded inv1.32.0

func (aOSConfig) Format(ffmt.State, verbrune)

Format implements the fmt.Formatter interface to ensure that Hosts isprinted correctly (i.e. not as a bunch of pointers).

Fixeshttps://github.com/tailscale/tailscale/issues/5669

func (OSConfig)IsZero

func (oOSConfig) IsZero()bool

func (*OSConfig)WriteToBufioWriteradded inv1.50.0

func (o *OSConfig) WriteToBufioWriter(w *bufio.Writer)

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

View all Source files

Directories

PathSynopsis
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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp