resolver

package module
v0.7.8 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 12 Imported by: 6

README

Darvaza DNS Resolver

Go Reference Codebeat Score

a dns resolver

Documentation

Overview

Package resolver provides DNS lookup functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsServerAddress added in v0.2.0

func AsServerAddress(server string) (string, error)

AsServerAddress validates and optionally appends :53 port if it wasn't specified already

func Decanonize added in v0.4.5

func Decanonize(qname string) string

Decanonize removes the trailing . if present, unless it's the root dot

func ForEachAnswer added in v0.1.3

func ForEachAnswer[T dns.RR](msg *dns.Msg, fn func(v T))

ForEachAnswer calls a function for each answer of the specified type.

func GetFirstAnswer added in v0.7.1

func GetFirstAnswer[T dns.RR](msg *dns.Msg) T

GetFirstAnswer returns the first answer for a specified type

func HasAnswerType added in v0.7.7

func HasAnswerType(msg *dns.Msg, qType uint16) bool

HasAnswerType checks if a dns.Msg contains answers of the specified type.

func HasNsType added in v0.7.7

func HasNsType(msg *dns.Msg, qType uint16) bool

HasNsType checks if a dns.Msg contains Ns entries of the specified type

func SystemResolver added in v0.0.3

func SystemResolver(preferGo bool) *net.Resolver

SystemResolver returns a standard net.Resolver configured to preferGo or not

func SystemResolverWithDialer added in v0.0.3

func SystemResolverWithDialer(preferGo bool, dialer DialerFunc) *net.Resolver

SystemResolverWithDialer returns a standard net.Resolver configured to preferGo or not and use the given Dialer instead of the default

Types

type DialerFunc added in v0.0.3

type DialerFunc func(ctx context.Context, network, address string) (net.Conn, error)

A DialerFunc is a function that establishes TCP or UDP connection

type Exchanger added in v0.6.0

type Exchanger interface {
	Exchange(ctx context.Context, q *dns.Msg) (*dns.Msg, error)
}

Exchanger performs a Lookup using a pre-assembled dns.Msg question.

type ExchangerFunc added in v0.6.2

type ExchangerFunc func(context.Context, *dns.Msg) (*dns.Msg, error)

ExchangerFunc is a function that implements the Exchanger interface

func (ExchangerFunc) Exchange added in v0.6.2

func (fn ExchangerFunc) Exchange(ctx context.Context, msg *dns.Msg) (*dns.Msg, error)

Exchange implements the Exchanger interface

func (ExchangerFunc) Lookup added in v0.6.2

func (fn ExchangerFunc) Lookup(ctx context.Context, qName string, qType uint16) (*dns.Msg, error)

Lookup implements the Lookuper interface using an Exchanger function

type LookupResolver added in v0.0.3

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

LookupResolver uses a Lookuper to implement the Resolver inteface

func NewResolver added in v0.0.3

func NewResolver(h Lookuper) *LookupResolver

NewResolver returns a Resolver using the provided Lookuper

func NewRootResolver added in v0.4.9

func NewRootResolver(start string) (*LookupResolver, error)

NewRootResolver creates a LookupResolver using iterative lookup from a given root-server, or random if the argument is ""

func (LookupResolver) LookupAddr added in v0.0.3

func (LookupResolver) LookupAddr(_ context.Context,
	name string,
) ([]string, error)

LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address

func (LookupResolver) LookupCNAME added in v0.0.3

func (r LookupResolver) LookupCNAME(ctx context.Context,
	host string) (string, error)

LookupCNAME returns the final canonical name after following zero or more CNAME records

func (LookupResolver) LookupHost added in v0.0.3

func (LookupResolver) LookupHost(_ context.Context,
	name string,
) (addrs []string, err error)

LookupHost returns a slice of the host's addresses

func (LookupResolver) LookupIP added in v0.0.3

func (r LookupResolver) LookupIP(ctx context.Context,
	network, host string) (s []net.IP, err error)

LookupIP returns the IP addresses of a host in the form of a slice of net.IP. The network must be one of "ip", "ip4" or "ip6".

func (LookupResolver) LookupIPAddr added in v0.0.3

func (r LookupResolver) LookupIPAddr(ctx context.Context,
	host string) ([]net.IPAddr, error)

LookupIPAddr returns the IP addresses of a host in the form of a slice of net.IPAddr

func (LookupResolver) LookupMX added in v0.0.3

func (r LookupResolver) LookupMX(ctx context.Context,
	name string) ([]*net.MX, error)

LookupMX returns the DNS MX records for the given domain name sorted by preference

func (LookupResolver) LookupNS added in v0.0.3

func (LookupResolver) LookupNS(_ context.Context,
	name string,
) ([]*net.NS, error)

LookupNS returns the DNS NS records for the given domain name

func (LookupResolver) LookupNetIP added in v0.0.3

func (r LookupResolver) LookupNetIP(ctx context.Context,
	network, host string) ([]netip.Addr, error)

LookupNetIP looks up host using the assigned Lookuper. It returns a slice of that host's IP addresses of the type specified by network. The network must be one of "ip", "ip4" or "ip6".

func (LookupResolver) LookupSRV added in v0.0.3

func (r LookupResolver) LookupSRV(ctx context.Context,
	service, proto, name string) (string, []*net.SRV, error)

LookupSRV returns the DNS SRV for _service._proto.domain

func (LookupResolver) LookupTXT added in v0.0.3

func (r LookupResolver) LookupTXT(ctx context.Context,
	name string) ([]string, error)

LookupTXT returns the DNS TXT records for the given domain name

type Lookuper added in v0.0.3

type Lookuper interface {
	Lookup(ctx context.Context, qName string, qType uint16) (*dns.Msg, error)
}

Lookuper is the interface that wraps the basic iterative Lookup method.

type LookuperFunc added in v0.6.2

type LookuperFunc func(context.Context, string, uint16) (*dns.Msg, error)

LookuperFunc is a function that implements the Lookuper interface

func (LookuperFunc) Exchange added in v0.6.2

func (fn LookuperFunc) Exchange(ctx context.Context, msg *dns.Msg) (*dns.Msg, error)

Exchange implements the Exchanger interface using a Lookuper function

func (LookuperFunc) Lookup added in v0.6.2

func (fn LookuperFunc) Lookup(ctx context.Context, qName string, qType uint16) (*dns.Msg, error)

Lookup implements the Lookuper interface

type MultiLookuper added in v0.2.0

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

MultiLookuper queries multiple Lookupers in parallel and takes the first non-error answer

func NewMultiLookuper added in v0.2.0

func NewMultiLookuper(lookupers ...Lookuper) *MultiLookuper

NewMultiLookuper creates a new Multilookuper using the given Lookupers

func NewMultiLookuperAddresses added in v0.2.0

func NewMultiLookuperAddresses(servers ...string) (*MultiLookuper, error)

NewMultiLookuperAddresses creates a new Multilookuper composing SingleLookupers for each given address

func (MultiLookuper) Lookup added in v0.2.0

func (r MultiLookuper) Lookup(ctx context.Context,
	qName string, qType uint16) (*dns.Msg, error)

Lookup queries all Lookupers in parallel and returns the quickest to answer

type Resolver added in v0.0.3

type Resolver interface {
	// LookupIPAddr looks up host using the assigned Lookuper.
	// It returns a slice of that host's IPv4 and IPv6 addresses.
	LookupIPAddr(ctx context.Context, host string) ([]net.IPAddr, error)

	// LookupIP looks up host for the given network using assigned Lookuper
	// It returns a slice of that host's IP addresses of the type specified
	// by network. network must be one of "ip", "ip4" or "ip6".
	LookupIP(ctx context.Context, network, host string) ([]net.IP, error)

	// LookupNetIP looks up host using the assigned Lookuper. It returns a
	// slice of that host's IP addresses of the type specified by network.
	// The network must be one of "ip", "ip4" or "ip6".
	LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)

	// LookupAddr performs a reverse lookup for the given address, returning a list
	// of names mapping to that address.
	//
	// The returned names are validated to be properly formatted presentation-format
	// domain names. If the response contains invalid names, those records are
	// filtered out and an error will be returned alongside the remaining results,
	// if any.
	LookupAddr(ctx context.Context, addr string) ([]string, error)

	// LookupCNAME returns the canonical name for the given host. Callers that do not
	// care about the canonical name can call LookupHost or LookupIP directly; both
	// take care of resolving the canonical name as part of the lookup.
	// A canonical name is the final name after following zero or more CNAME records.
	// LookupCNAME does not return an error if host does not contain DNS "CNAME"
	// records, as long as host resolves to address records.
	// The returned canonical name is validated to be a properly formatted
	// presentation-format domain name.
	LookupCNAME(ctx context.Context, host string) (string, error)

	// LookupHost looks up the given host using the assigned Lookuper. It returns a
	// slice of that host's addresses.
	LookupHost(ctx context.Context, host string) (addrs []string, err error)

	// LookupMX returns the DNS MX records for the given domain name sorted by
	// preference.
	// The returned mail server names are validated to be properly formatted
	// presentation-format domain names. If the response contains invalid names,
	// those records are filtered out and an error will be returned alongside
	// the remaining results, if any.
	LookupMX(ctx context.Context, name string) ([]*net.MX, error)

	// LookupNS returns the DNS NS records for the given domain name.
	// The returned name server names are validated to be properly formatted
	// presentation-format domain names. If the response contains invalid names,
	// those records are filtered out and an error will be returned alongside
	// the remaining results, if any.
	LookupNS(ctx context.Context, name string) ([]*net.NS, error)

	// LookupSRV tries to resolve an SRV query of the given service, protocol,
	// and domain name. The proto is "tcp" or "udp". The returned records are
	// sorted by priority and randomized by weight within a priority.
	//
	// LookupSRV constructs the DNS name to look up following RFC 2782. That is,
	// it looks up _service._proto.name. To accommodate services publishing SRV
	// records under non-standard names, if both service and proto are empty
	// strings, LookupSRV looks up name directly.
	//
	// The returned service names are validated to be properly formatted
	// presentation-format domain names. If the response contains invalid names,
	// those records are filtered out and an error will be returned alongside
	// the remaining results, if any.
	LookupSRV(ctx context.Context, service, proto, name string) (cname string,
		addrs []*net.SRV, err error)

	// LookupTXT returns the DNS TXT records for the given domain name.
	LookupTXT(ctx context.Context, name string) ([]string, error)
}

A Resolver implements the interface of net.Resolver

type RootLookuper added in v0.1.0

type RootLookuper struct {
	Start string
	// contains filtered or unexported fields
}

RootLookuper does iterative lookup using the given root-server as starting point

func NewRootLookuper added in v0.1.1

func NewRootLookuper(start string) (*RootLookuper, error)

NewRootLookuper creates a RootLookuper using the indicated root, or random if the argument is ""

func NewRootLookuperWithClient added in v0.7.3

func NewRootLookuperWithClient(start string, c client.Client) (*RootLookuper, error)

NewRootLookuperWithClient creates a RootLookuper using the indicated root, or random if the argument is "", and uses the given client.Client to connect.

func (RootLookuper) Exchange added in v0.3.0

func (r RootLookuper) Exchange(ctx context.Context, m *dns.Msg) (*dns.Msg, error)

Exchange queries any root server and validates the response

func (RootLookuper) Iterate added in v0.3.0

func (r RootLookuper) Iterate(ctx context.Context, name string,
	qtype uint16, startAt string,
) (*dns.Msg, error)

Iterate is an iterative lookup implementation

func (RootLookuper) IterateMsg added in v0.7.1

func (r RootLookuper) IterateMsg(ctx context.Context, req *dns.Msg,
	startAt string,
) (*dns.Msg, error)

IterateMsg is an iterative exchange implementation

func (RootLookuper) Lookup added in v0.1.0

func (r RootLookuper) Lookup(ctx context.Context, qName string, qType uint16) (*dns.Msg, error)

Lookup performs an iterative lookup

type SingleLookuper added in v0.2.0

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

SingleLookuper asks a single server for a direct answer to the query preventing repetition

func NewCloudflareLookuper added in v0.2.0

func NewCloudflareLookuper() *SingleLookuper

NewCloudflareLookuper creates a Lookuper asking 1.1.1.1 (Cloudflare)

func NewGoogleLookuper added in v0.2.0

func NewGoogleLookuper() *SingleLookuper

NewGoogleLookuper creates a Lookuper asking 8.8.8.8 (Google)

func NewGoogleLookuper2 added in v0.2.0

func NewGoogleLookuper2() *SingleLookuper

NewGoogleLookuper2 creates a Lookuper asking 8.8.4.4 (Google)

func NewQuad9Lookuper added in v0.2.0

func NewQuad9Lookuper() *SingleLookuper

NewQuad9Lookuper creates a Lookuper asking 9.9.9.9 (Quad9.net)

func NewQuad9Lookuper6 added in v0.2.0

func NewQuad9Lookuper6() *SingleLookuper

NewQuad9Lookuper6 creates a Lookuper asking Quad9.net using IPv6

func NewSingleLookuper added in v0.2.0

func NewSingleLookuper(server string, recursive bool) (*SingleLookuper, error)

NewSingleLookuper creates a Lookuper that asks one particular server

func NewSingleLookuperWithClient added in v0.7.3

func NewSingleLookuperWithClient(server string, recursive bool,
	c client.Client) (*SingleLookuper, error)

NewSingleLookuperWithClient creates a lookuper that asks one particular server using the provided DNS client

func (SingleLookuper) Exchange added in v0.2.0

func (r SingleLookuper) Exchange(ctx context.Context,
	msg *dns.Msg) (*dns.Msg, error)

Exchange exchanges a message with a designed server

func (SingleLookuper) Lookup added in v0.2.0

func (r SingleLookuper) Lookup(ctx context.Context,
	qName string, qType uint16) (*dns.Msg, error)

Lookup asks the designed remote to make a DNS Lookup

type ZeroLookuper added in v0.0.3

type ZeroLookuper struct{}

A ZeroLookuper is a Lookuper that never finds anything

func (ZeroLookuper) Lookup added in v0.0.3

func (ZeroLookuper) Lookup(_ context.Context, qName string, _ uint16) (*dns.Msg, error)

Lookup implements Lookuper but always fails

Directories

Path Synopsis
pkg
client
Package client implements DNS client wrappers
Package client implements DNS client wrappers
errors
Package errors aids error handling for [dns.Msg] and darvaza.org/resolver related functions
Package errors aids error handling for [dns.Msg] and darvaza.org/resolver related functions
server
Package server aids writing DNS servers
Package server aids writing DNS servers

Jump to

Keyboard shortcuts

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