resolver

package
v1.14.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2021 License: BSD-3-Clause Imports: 24 Imported by: 6

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

View Source
var ErrClosed = errors.New("closed")

ErrClosed indicates that the resolver has been closed and readers should exit.

Functions

func WriteIPPorts added in v1.12.0

func WriteIPPorts(w *bufio.Writer, vv []netaddr.IPPort)

WriteIPPorts writes vv to w.

func WriteRoutes added in v1.12.0

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

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][]netaddr.IPPort
	// LocalHosts is a map of FQDNs to corresponding IPs.
	Hosts map[dnsname.FQDN][]netaddr.IP
	// 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 added in v1.12.0

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 added in v1.10.0

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(netaddr.IP) (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, linkMon *monitor.Mon, linkSel ForwardLinkSelector) *Resolver

New returns a new resolver. linkMon optionally specifies a link 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) EnqueueRequest

func (r *Resolver) EnqueueRequest(bs []byte, from netaddr.IPPort) error

EnqueueRequest places the given DNS request in the resolver's queue. It takes ownership of the payload and does not block. If the queue is full, the request will be dropped and an error will be returned.

func (*Resolver) NextResponse

func (r *Resolver) NextResponse() (packet []byte, to netaddr.IPPort, err error)

NextResponse returns a DNS response to a previously enqueued request. It blocks until a response is available and gives up ownership of the response payload.

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