recursor

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: BSD-2-Clause Imports: 22 Imported by: 0

Documentation

Overview

Package recursor performs iterative DNS recursion for lookup helpers.

Index

Constants

This section is empty.

Variables

View Source
var ErrRaceLost = errors.New("recursor: parallel race lost")

ErrRaceLost is the cause attached to the cancellation of a parallel fan-out's batch context when one goroutine has already produced a usable answer and the rest are being cancelled.

Callers that observe context cancellation in code paths that may be reached via parallel recursion can distinguish a race-loss cancellation from a job-level cancellation by inspecting context.Cause(ctx).

Functions

func IgnoreCNAMEError added in v1.4.10

func IgnoreCNAMEError(err error) error

IgnoreCNAMEError returns nil if err is a *CNAMEError, and err otherwise.

Types

type CNAMEError added in v1.4.10

type CNAMEError struct {
	Reason CNAMEReason
	Name   string
	Target string
	Detail string
}

CNAMEError is returned by Recurse when CNAME handling fails.

func (*CNAMEError) Error added in v1.4.10

func (e *CNAMEError) Error() string

type CNAMEReason added in v1.4.10

type CNAMEReason int

CNAMEReason identifies which CNAME-handling failure the recursor hit.

const (
	// CNAMETooMany covers per-answer cardinality and chain-walk inside one answer.
	CNAMETooMany CNAMEReason = iota + 1
	// CNAMEChainTooLong is the chain-depth bound across recursion hops.
	CNAMEChainTooLong
	// CNAMEUnresolved is "target can't be reached": loop, broken chain, qtype mismatch.
	CNAMEUnresolved
)

func (CNAMEReason) String added in v1.4.10

func (r CNAMEReason) String() string

type CacheEntry added in v1.3.2

type CacheEntry struct {
	Name        string
	QType       string
	QClass      string
	Nameservers []NameserverRef
	Message     []byte
}

CacheEntry is a portable representation of a single recursor cache record.

type NameserverRef added in v1.3.2

type NameserverRef struct {
	Name    string
	Address string
}

NameserverRef identifies a nameserver host+address pair.

type Recursor

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

Recursor holds root hints and fake delegations.

func New

func New() (*Recursor, error)

New creates a Recursor and initializes it with root hints.

func (*Recursor) AddFakeAddresses

func (r *Recursor) AddFakeAddresses(domain string, data map[string][]string) error

AddFakeAddresses stores fake addresses for a domain.

func (*Recursor) ClearCache

func (r *Recursor) ClearCache()

ClearCache clears the recursive cache.

func (*Recursor) Client

func (r *Recursor) Client() *transport.Client

Client returns the transport client used by the recursor.

func (*Recursor) ExportCacheEntries added in v1.3.2

func (r *Recursor) ExportCacheEntries() ([]CacheEntry, error)

ExportCacheEntries returns a deterministic snapshot of the recursor cache.

func (*Recursor) GetAddressesFor

func (r *Recursor) GetAddressesFor(ctx context.Context, name string) ([]netip.Addr, error)

GetAddressesFor resolves A and AAAA addresses for a nameserver name.

func (*Recursor) GetFakeAddresses

func (r *Recursor) GetFakeAddresses(domain string, nsname string) []netip.Addr

GetFakeAddresses returns fake addresses for a domain and nameserver name.

func (*Recursor) GetFakeNames

func (r *Recursor) GetFakeNames(domain string) []string

GetFakeNames returns fake nameserver names for a domain.

func (*Recursor) HasFakeAddresses

func (r *Recursor) HasFakeAddresses(domain string) bool

HasFakeAddresses reports whether a domain has fake address data.

func (*Recursor) ImportCacheEntries added in v1.3.2

func (r *Recursor) ImportCacheEntries(entries []CacheEntry) error

ImportCacheEntries populates the recursor cache from the supplied entries.

func (*Recursor) Parent

func (r *Recursor) Parent(ctx context.Context, name string) (string, packet.Packet, error)

Parent resolves the parent zone name for a domain.

func (*Recursor) PrimeCacheError added in v1.4.10

func (r *Recursor) PrimeCacheError(name, qtype string, err error)

PrimeCacheError stores err so the next Recurse for (name, qtype, IN) against root returns it. For tests and saved-cache replay.

func (*Recursor) Recurse

func (r *Recursor) Recurse(ctx context.Context, name string, qtype string, qclass string) (packet.Packet, error)

Recurse performs a recursive lookup using root servers.

func (*Recursor) RecurseWithNameservers

func (r *Recursor) RecurseWithNameservers(ctx context.Context, name string, qtype string, qclass string, ns []nameserver.Nameserver) (packet.Packet, error)

RecurseWithNameservers performs a recursive lookup using a specific nameserver set.

func (*Recursor) RemoveFakeAddresses

func (r *Recursor) RemoveFakeAddresses(domain string)

RemoveFakeAddresses deletes fake address data for a domain.

func (*Recursor) RootServers

func (r *Recursor) RootServers(ctx context.Context) ([]nameserver.Nameserver, error)

RootServers returns nameservers initialized from root hints.

func (*Recursor) SetNegativeCacheTTL added in v1.4.5

func (r *Recursor) SetNegativeCacheTTL(ttl time.Duration)

SetNegativeCacheTTL controls the lifetime of cached "no answer" entries. Zero (default) disables negative caching.

Directories

Path Synopsis
Package recursortest provides test-only helpers for driving the recursor's cache directly, without simulating an upstream walk.
Package recursortest provides test-only helpers for driving the recursor's cache directly, without simulating an upstream walk.

Jump to

Keyboard shortcuts

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