resolver

package
v3.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: BSD-3-Clause Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// PaddingDesiredBlockSize is the size that the padded query should be multiple of
	PaddingDesiredBlockSize = 128

	// EDNS0MaxResponseSize is the maximum response size for EDNS0
	EDNS0MaxResponseSize = 4096

	// DNSSECEnabled turns on support for DNSSEC when using EDNS0
	DNSSECEnabled = true
)

Variables

This section is empty.

Functions

func IsBogon

func IsBogon(address string) bool

IsBogon returns whether if an IP address is bogon. Passing to this function a non-IP address causes it to return bogon.

Types

type AddressResolver

type AddressResolver struct {
	Resolver
}

AddressResolver is a resolver that knows how to correctly resolve IP addresses to themselves.

func (AddressResolver) LookupHost

func (r AddressResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost implements Resolver.LookupHost

type BogonResolver

type BogonResolver struct {
	Resolver
}

BogonResolver is a bogon aware resolver. When a bogon is encountered in a reply, this resolver will return an error.

func (BogonResolver) LookupHost

func (r BogonResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost implements Resolver.LookupHost

type CacheResolver

type CacheResolver struct {
	ReadOnly bool
	Resolver
	// contains filtered or unexported fields
}

CacheResolver is a resolver that caches successful replies.

func (*CacheResolver) Get

func (r *CacheResolver) Get(domain string) []string

Get gets the currently configured entry for domain, or nil

func (*CacheResolver) LookupHost

func (r *CacheResolver) LookupHost(
	ctx context.Context, hostname string) ([]string, error)

LookupHost implements Resolver.LookupHost

func (*CacheResolver) Set

func (r *CacheResolver) Set(domain string, addresses []string)

Set allows to pre-populate the cache

type ChainResolver

type ChainResolver struct {
	Primary   Resolver
	Secondary Resolver
}

ChainResolver is a chain resolver. The primary resolver is used first and, if that fails, we then attempt with the secondary resolver.

func (ChainResolver) Address

func (c ChainResolver) Address() string

Address implements Resolver.Address

func (ChainResolver) LookupHost

func (c ChainResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost implements Resolver.LookupHost

func (ChainResolver) Network

func (c ChainResolver) Network() string

Network implements Resolver.Network

type DNSOverHTTPS

type DNSOverHTTPS struct {
	Do           func(req *http.Request) (*http.Response, error)
	URL          string
	HostOverride string
}

DNSOverHTTPS is a DNS over HTTPS RoundTripper. Requests are submitted over an HTTP/HTTPS channel provided by URL using the Do function.

func NewDNSOverHTTPS

func NewDNSOverHTTPS(client *http.Client, URL string) DNSOverHTTPS

NewDNSOverHTTPS creates a new DNSOverHTTP instance from the specified http.Client and URL, as a convenience.

func NewDNSOverHTTPSWithHostOverride

func NewDNSOverHTTPSWithHostOverride(client *http.Client, URL, hostOverride string) DNSOverHTTPS

NewDNSOverHTTPSWithHostOverride is like NewDNSOverHTTPS except that it's creating a resolver where we use the specified host.

func (DNSOverHTTPS) Address

func (t DNSOverHTTPS) Address() string

Address returns the upstream server address.

func (DNSOverHTTPS) Network

func (t DNSOverHTTPS) Network() string

Network returns the transport network (e.g., doh, dot)

func (DNSOverHTTPS) RequiresPadding

func (t DNSOverHTTPS) RequiresPadding() bool

RequiresPadding returns true for DoH according to RFC8467

func (DNSOverHTTPS) RoundTrip

func (t DNSOverHTTPS) RoundTrip(ctx context.Context, query []byte) ([]byte, error)

RoundTrip implements RoundTripper.RoundTrip.

type DNSOverTCP

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

DNSOverTCP is a DNS over TCP/TLS RoundTripper. Use NewDNSOverTCP and NewDNSOverTLS to create specific instances that use plaintext queries or encrypted queries over TLS.

As a known bug, this implementation always creates a new connection for each incoming query, thus increasing the response delay.

func NewDNSOverTCP

func NewDNSOverTCP(dial DialContextFunc, address string) DNSOverTCP

NewDNSOverTCP creates a new DNSOverTCP transport.

func NewDNSOverTLS

func NewDNSOverTLS(dial DialContextFunc, address string) DNSOverTCP

NewDNSOverTLS creates a new DNSOverTLS transport.

func (DNSOverTCP) Address

func (t DNSOverTCP) Address() string

Address returns the upstream server address.

func (DNSOverTCP) Network

func (t DNSOverTCP) Network() string

Network returns the transport network (e.g., doh, dot)

func (DNSOverTCP) RequiresPadding

func (t DNSOverTCP) RequiresPadding() bool

RequiresPadding returns true for DoT and false for TCP according to RFC8467.

func (DNSOverTCP) RoundTrip

func (t DNSOverTCP) RoundTrip(ctx context.Context, query []byte) ([]byte, error)

RoundTrip implements RoundTripper.RoundTrip.

type DNSOverUDP

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

DNSOverUDP is a DNS over UDP RoundTripper.

func NewDNSOverUDP

func NewDNSOverUDP(dialer Dialer, address string) DNSOverUDP

NewDNSOverUDP creates a DNSOverUDP instance.

func (DNSOverUDP) Address

func (t DNSOverUDP) Address() string

Address returns the upstream server address.

func (DNSOverUDP) Network

func (t DNSOverUDP) Network() string

Network returns the transport network (e.g., doh, dot)

func (DNSOverUDP) RequiresPadding

func (t DNSOverUDP) RequiresPadding() bool

RequiresPadding returns false for UDP according to RFC8467

func (DNSOverUDP) RoundTrip

func (t DNSOverUDP) RoundTrip(ctx context.Context, query []byte) ([]byte, error)

RoundTrip implements RoundTripper.RoundTrip.

type Decoder

type Decoder interface {
	Decode(qtype uint16, data []byte) ([]string, error)
}

The Decoder decodes a DNS reply into A or AAAA entries. It will use the provided qtype and only look for mathing entries. It will return error if there are no entries for the requested qtype inside the reply.

type DialContextFunc

type DialContextFunc func(context.Context, string, string) (net.Conn, error)

DialContextFunc is a generic function for dialing a connection.

type Dialer

type Dialer interface {
	DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

Dialer is the network dialer interface assumed by this package.

type EmitterResolver

type EmitterResolver struct {
	Resolver
}

EmitterResolver is a resolver that emits events

func (EmitterResolver) LookupHost

func (r EmitterResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost returns the IP addresses of a host

type EmitterTransport

type EmitterTransport struct {
	RoundTripper
}

EmitterTransport is a RoundTripper that emits events when they occur.

func (EmitterTransport) RoundTrip

func (txp EmitterTransport) RoundTrip(ctx context.Context, querydata []byte) ([]byte, error)

RoundTrip implements RoundTripper.RoundTrip

type Encoder

type Encoder interface {
	Encode(domain string, qtype uint16, padding bool) ([]byte, error)
}

The Encoder encodes DNS queries to bytes

type ErrorWrapperResolver

type ErrorWrapperResolver struct {
	Resolver
}

ErrorWrapperResolver is a Resolver that knows about wrapping errors.

func (ErrorWrapperResolver) LookupHost

func (r ErrorWrapperResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost implements Resolver.LookupHost

type IDNAResolver

type IDNAResolver struct {
	Resolver
}

IDNAResolver is to support resolving Internationalized Domain Names. See RFC3492 for more information.

func (IDNAResolver) Address

func (r IDNAResolver) Address() string

Address implements Resolver.Address.

func (IDNAResolver) LookupHost

func (r IDNAResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost implements Resolver.LookupHost

func (IDNAResolver) Network

func (r IDNAResolver) Network() string

Network implements Resolver.Network.

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
	Debug(message string)
}

Logger is the logger assumed by this package

type LoggingResolver

type LoggingResolver struct {
	Resolver
	Logger Logger
}

LoggingResolver is a resolver that emits events

func (LoggingResolver) LookupHost

func (r LoggingResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost returns the IP addresses of a host

type MiekgDecoder

type MiekgDecoder struct{}

MiekgDecoder uses github.com/miekg/dns to implement the Decoder.

func (MiekgDecoder) Decode

func (d MiekgDecoder) Decode(qtype uint16, data []byte) ([]string, error)

Decode implements Decoder.Decode.

type MiekgEncoder

type MiekgEncoder struct{}

MiekgEncoder uses github.com/miekg/dns to implement the Encoder.

func (MiekgEncoder) Encode

func (e MiekgEncoder) Encode(domain string, qtype uint16, padding bool) ([]byte, error)

Encode implements Encoder.Encode

type Resolver

type Resolver interface {
	// LookupHost resolves a hostname to a list of IP addresses.
	LookupHost(ctx context.Context, hostname string) (addrs []string, err error)

	// Network returns the network being used by the resolver
	Network() string

	// Address returns the address being used by the resolver
	Address() string
}

Resolver is a DNS resolver. The *net.Resolver used by Go implements this interface, but other implementations are possible.

type RoundTripper

type RoundTripper interface {
	// RoundTrip sends a DNS query and receives the reply.
	RoundTrip(ctx context.Context, query []byte) (reply []byte, err error)

	// RequiresPadding return true for DoH and DoT according to RFC8467
	RequiresPadding() bool

	// Network is the network of the round tripper (e.g. "dot")
	Network() string

	// Address is the address of the round tripper (e.g. "1.1.1.1:853")
	Address() string
}

RoundTripper represents an abstract DNS transport.

type SaverDNSTransport

type SaverDNSTransport struct {
	RoundTripper
	Saver *trace.Saver
}

SaverDNSTransport is a DNS transport that saves events

func (SaverDNSTransport) RoundTrip

func (txp SaverDNSTransport) RoundTrip(ctx context.Context, query []byte) ([]byte, error)

RoundTrip implements RoundTripper.RoundTrip

type SaverResolver

type SaverResolver struct {
	Resolver
	Saver *trace.Saver
}

SaverResolver is a resolver that saves events

func (SaverResolver) LookupHost

func (r SaverResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost implements Resolver.LookupHost

type SerialResolver

type SerialResolver struct {
	Encoder     Encoder
	Decoder     Decoder
	NumTimeouts *atomicx.Int64
	Txp         RoundTripper
}

SerialResolver is a resolver that first issues an A query and then issues an AAAA query for the requested domain.

func NewSerialResolver

func NewSerialResolver(t RoundTripper) SerialResolver

NewSerialResolver creates a new OONI Resolver instance.

func (SerialResolver) Address

func (r SerialResolver) Address() string

Address implements Resolver.Address

func (SerialResolver) LookupHost

func (r SerialResolver) LookupHost(ctx context.Context, hostname string) ([]string, error)

LookupHost implements Resolver.LookupHost.

func (SerialResolver) Network

func (r SerialResolver) Network() string

Network implements Resolver.Network

func (SerialResolver) Transport

func (r SerialResolver) Transport() RoundTripper

Transport returns the transport being used.

type SystemResolver

type SystemResolver = selfcensor.SystemResolver

SystemResolver is the system resolver. It is implemented using selfcensor.SystemResolver so that we can perform integration testing by forcing the code to return specific responses.

Jump to

Keyboard shortcuts

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