dns

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLookup             = errors.New("name lookup failed")
	ErrMessageNotResponse = errors.New("message is not a response")
	ErrMessageTruncated   = errors.New("message is truncated")
)

Functions

This section is empty.

Types

type Resolver

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

func NewResolver

func NewResolver(name string, serverAddrPort netip.AddrPort, tcpClient zerocopy.TCPClient, udpClient zerocopy.UDPClient, logger *zap.Logger) *Resolver

func (*Resolver) Lookup

func (r *Resolver) Lookup(ctx context.Context, name string) (Result, error)

Lookup looks up [name] and returns the result.

func (*Resolver) LookupIP added in v1.8.0

func (r *Resolver) LookupIP(ctx context.Context, name string) (netip.Addr, error)

LookupIP implements [SimpleResolver.LookupIP].

func (*Resolver) LookupIPs added in v1.8.0

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

LookupIPs implements [SimpleResolver.LookupIPs].

type ResolverConfig

type ResolverConfig struct {
	// Name is the resolver's name.
	// The name must be unique among all resolvers.
	Name string `json:"name"`

	// Type is the resolver type.
	//
	// Available values:
	// - "plain": Resolve names by sending cleartext DNS queries to the configured upstream server.
	// - "system": Use the system resolver. This does not support custom server addresses or clients.
	//
	// The default value is "plain".
	Type string `json:"type"`

	// AddrPort is the upstream server's address and port.
	AddrPort netip.AddrPort `json:"addrPort"`

	// TCPClientName is the name of the TCPClient to use.
	// Leave empty to disable TCP.
	TCPClientName string `json:"tcpClientName"`

	// UDPClientName is the name of the UDPClient to use.
	// Leave empty to disable UDP.
	UDPClientName string `json:"udpClientName"`
}

ResolverConfig configures a DNS resolver.

func (*ResolverConfig) SimpleResolver added in v1.8.0

func (rc *ResolverConfig) SimpleResolver(tcpClientMap map[string]zerocopy.TCPClient, udpClientMap map[string]zerocopy.UDPClient, logger *zap.Logger) (SimpleResolver, error)

SimpleResolver creates a new SimpleResolver from the config.

type Result

type Result struct {
	IPv4 []netip.Addr
	IPv6 []netip.Addr

	// TTL is the minimum TTL of A and AAAA RRs.
	TTL time.Time
}

Result represents the result of name resolution.

func (*Result) Clone added in v1.8.0

func (r *Result) Clone() Result

Clone returns a deep copy of the result. Modifying values in the address slices will not affect the original result.

type SimpleResolver added in v1.8.0

type SimpleResolver interface {
	// LookupIP looks up [name] and returns one of the associated IP addresses.
	LookupIP(ctx context.Context, name string) (netip.Addr, error)

	// LookupIPs looks up [name] and returns all associated IP addresses.
	LookupIPs(ctx context.Context, name string) ([]netip.Addr, error)
}

SimpleResolver defines methods that only return the resolved IP addresses.

type SystemResolver added in v1.8.0

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

SystemResolver resolves names using net.DefaultResolver. It implements SimpleResolver.

func NewSystemResolver added in v1.8.0

func NewSystemResolver(name string, logger *zap.Logger) *SystemResolver

NewSystemResolver returns a new SystemResolver.

func (*SystemResolver) LookupIP added in v1.8.0

func (r *SystemResolver) LookupIP(ctx context.Context, name string) (netip.Addr, error)

LookupIP implements [SimpleResolver.LookupIP].

func (*SystemResolver) LookupIPs added in v1.8.0

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

LookupIPs implements [SimpleResolver.LookupIPs].

Jump to

Keyboard shortcuts

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