resolver

package
v0.0.0-...-9d29f1b Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: BSD-3-Clause Imports: 43 Imported by: 0

Documentation

Overview

Package resolver implements a stub DNS resolver that can also serve records out of an internal local zone.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WriteDNSResolver

func WriteDNSResolver(w *bufio.Writer, r *dnstype.Resolver)

WriteDNSResolver writes r to w.

func WriteDNSResolvers

func WriteDNSResolvers(w *bufio.Writer, resolvers []*dnstype.Resolver)

WriteDNSResolvers writes resolvers to w.

func WriteIPPorts

func WriteIPPorts(w *bufio.Writer, vv []netip.AddrPort)

WriteIPPorts writes vv to w.

func WriteRoutes

func WriteRoutes(w *bufio.Writer, routes map[dnsname.FQDN][]*dnstype.Resolver)

WriteRoutes writes routes to w, omitting *.arpa routes and instead summarizing how many of them there were.

Types

type Config

type Config struct {
	// Routes is a map of DNS name suffix to the resolvers to use for
	// queries within that suffix.
	// Queries only match the most specific suffix.
	// To register a "default route", add an entry for ".".
	Routes map[dnsname.FQDN][]*dnstype.Resolver
	// LocalHosts is a map of FQDNs to corresponding IPs.
	Hosts map[dnsname.FQDN][]netip.Addr
	// LocalDomains is a list of DNS name suffixes that should not be
	// routed to upstream resolvers.
	LocalDomains []dnsname.FQDN
}

Config is a resolver configuration. Given a Config, queries are resolved in the following order: If the query is an exact match for an entry in LocalHosts, return that. Else if the query suffix matches an entry in LocalDomains, return NXDOMAIN. Else forward the query to the most specific matching entry in Routes. Else return SERVFAIL.

func (*Config) WriteToBufioWriter

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

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

type ForwardLinkSelector

type ForwardLinkSelector interface {
	// PickLink returns which network device should be used to query
	// the DNS server at the given IP.
	// The empty string means to use an unspecified default.
	PickLink(netip.Addr) (linkName string)
}

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver is a DNS resolver for nodes on the Tailscale network, associating them with domain names of the form <mynode>.<mydomain>.<root>. If it is asked to resolve a domain that is not of that form, it delegates to upstream nameservers if any are set.

func New

func New(logf logger.Logf, netMon *netmon.Monitor, linkSel ForwardLinkSelector, dialer *tsdial.Dialer) *Resolver

New returns a new resolver. netMon optionally specifies a network monitor to use for socket rebinding.

func (*Resolver) Close

func (r *Resolver) Close()

Close shuts down the resolver and ensures poll goroutines have exited. The Resolver cannot be used again after Close is called.

func (*Resolver) HandleExitNodeDNSQuery

func (r *Resolver) HandleExitNodeDNSQuery(ctx context.Context, q []byte, from netip.AddrPort, allowName func(name string) bool) (res []byte, err error)

HandleExitNodeDNSQuery handles a DNS query that arrived from a peer via the peerapi's DoH server. This is only used when the local node is being an exit node.

The provided allowName callback is whether a DNS query for a name (as found by parsing q) is allowed.

In most (all?) cases, err will be nil. A bogus DNS query q will still result in a response DNS packet (saying there's a failure) and a nil error. TODO: figure out if we even need an error result.

func (*Resolver) Query

func (r *Resolver) Query(ctx context.Context, bs []byte, from netip.AddrPort) ([]byte, error)

func (*Resolver) SetConfig

func (r *Resolver) SetConfig(cfg Config) error

func (*Resolver) TestOnlySetHook

func (r *Resolver) TestOnlySetHook(hook func(Config))

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL