resolv

package module
v0.0.0-...-4dd4c21 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

README

Go package that implements a variety of DNS clients, including DNS-over-TLS and DNS-over-HTTPs.

resolv

Documentation

Index

Constants

View Source
const (
	MinUDPBufSize = 0
	MaxUDPBufSize = 65535

	MinMaxCNAMEs = 0
	MaxMaxCNAMEs = 10

	DefaultDoTPort      = "853"
	DefaultDoQPort      = "853"
	DefaultHTTPEndpoint = "/dns-query"
	DefaultTimeout      = 5 * time.Second
	DefaultUDPBufSize   = 4096 // in the EDNS0 opt record
)

Variables

View Source
var (
	// ErrRcode indicates that the DNS response has an RCODE that is not
	// NOERROR ([github.com/miekg/dns.RcodeSuccess]).
	ErrRcode error = &Error{err: "response rcode is not success"} // DNS response's rcode is something other than Sucess

	// ErrNoData represents the NODATA pseudo RCODE.  NODATA is not a real
	// RCODE, but rather describes a response with an RCODE of NOERROR and zero
	// answers.  A DNS server sends such a response when it has records for the
	// domain, but not of the type the client requested.
	ErrNoData error = &Error{err: "response has a NODATA pseudo RCODE"}

	// ErrInvalidCNAMEChain indicates that the response's answer contains
	// an invalid set of CNAMEs.  There are several ways that the CNAME(s)
	// could be invalid, such as if the CNAMEs cannot be ordered to form a
	// logical chain, or if the first CNAME record's name does not match
	// the query's QNAME.  This type of error should be rare.
	ErrInvalidCNAMEs error = &Error{err: "response contains an invalid CNAME chain"}

	// ErrBadName indicates that the response's answer contains records that
	// match the query's QTYPE, but none of the records match the QNAME or one
	// of the QNAME's CNAME aliases.  This type of error should be rare.
	ErrBadName error = &Error{err: "response has an answer that matches neither the qname nor one of its aliases"}

	// ErrBadAnswer indicates that the response's answer contains data that does not conform to
	// its RR type.  This type of error should be rare.
	ErrBadData error = &Error{err: "response has an answer the data does not conform to the RR type"}

	// ErrMaxCNAMEs indicates that the client followed its configurd maximum number of
	// CNAMEs without resolving the query.
	ErrMaxCNAMEs error = &Error{err: "query followed max number of CNAMEs"}
)

These are errors that a client's Exchange method may return.

Functions

func AddEDNS0NSID

func AddEDNS0NSID(m *dns.Msg)

func AddEDNS0Subnet

func AddEDNS0Subnet(m *dns.Msg, prefix netip.Prefix)

func CollectRRs

func CollectRRs[T dns.RR](rrs []dns.RR) []T

CollectRRs takes a slice of [github.com/miekg/dns.RR]s and returns a slice of with the [github.com/miekg/dns.RR]s of type T. If not such records exist, the function returns a zero-length slice.

func OrderCNAMEs

func OrderCNAMEs(a []*dns.CNAME) bool

func ParseInstanceServiceDomain

func ParseInstanceServiceDomain(name string) (instance string, service string, domain string)

Types

type Client

type Client struct {
	// Set the AD ("authentic data") bit in queries. Note that DNS only uses
	// this bit in responses; setting the bit in a query is undefined, though
	// harmless.  Per RFC 3655, a response sets the AD if the DNS server
	// successfully validated the response as per DNSSEC.  If the server did
	// not attempt to validate the records in the response, or validation
	// failed, the bit is 0.
	AD bool

	// Set the CD ("checking disabled") bit in queries.  If the CD bit is set,
	// then the DNS server may omit DNSSEC validation.  A client would
	// generally set the CD bit when it intends to perform DNSSEC validation
	// itself.  If the query clears the bit, the server may perform perform
	// DNSSEC validation.
	CD bool

	// Set the DO ("DNSSEC OK") bit in queries.  The DO bit indicates that the
	// client is DNSSEC-aware and it is OK for the DNS server to return DNSSEC
	// records in a response.  If the bit is cleared, and the server  should
	// not return DNSSEC records in the response.
	DO bool // DNSSEC

	// Set the RD ("recursion deisred") bit in queries.  This indicates that
	// the DNS server should follow all delegations and resolve the query on
	// behalf of the client.
	RD bool

	// Send an EDNS0 Client Subnet option (RFC 7871) in queries.  Either
	// clients or recursive resolvers may add this option.  A prefix with
	// length 0 is indicates a client opt-opt: the recursive resolvers must not
	// add the this option when serviving the client's request.
	ClientSubnet netip.Prefix

	// Send the ENDS0 Name Server Identifier (NSID) option (RFC 5001) in
	// queries.  If a server supports the option, it will return its unique
	// server identifer in the response.  Per RFC 5001, "The semantics of an
	// NSID request are not transitive.  That is: the presence of an NSID
	// option in a query is a request that the name server which receives the
	// query identify itself."
	NSID bool

	// The maximum number of times the client may issue a new query when
	// resolving a chain of CNAMEs.  The client always inspects the CNAMES in a
	// given response to determine if these CNAMEs resolve to the requested record
	// type.  If the chain of CNAMEs in a response terminates in a CNAME
	// record, only then does the client re-issue the query, replacing the
	// original QNAME with the last CNAME target in the chain.
	MaxCNAMEs int

	// The underlying tranport (e.g., [Do53UDP], [Do53TCP], [DoT], [DoH])
	Transport Transport
}

A Client defines the settings for a DNS client: the tranport, and the query settings that are agnostic to the choice of transport.

A program can modify a Client's settings in between queries. If a program wants to modify the Tranport, it should first call the Client's Close method, modify (or assign a new Transport), and then resume using the Client.

func (*Client) Close

func (c *Client) Close() error

func (*Client) Exchange

func (c *Client) Exchange(req *dns.Msg) (*dns.Msg, error)

Exchange performs a synchronous DNS query: it sends the message req and waits for a response. The client settings (along with the client's transport's settings) determine whether (and how) to retry a query in case of an error response.

If there is a va

func (*Client) GetAllServiceBrowserDomains

func (c *Client) GetAllServiceBrowserDomains(domain string) ([]string, error)

func (*Client) GetDefaultServiceBrowserDomain

func (c *Client) GetDefaultServiceBrowserDomain(domain string) (string, error)

func (*Client) GetIP4s

func (c *Client) GetIP4s(domain string) ([]netip.Addr, error)

func (*Client) GetIP6s

func (c *Client) GetIP6s(domain string) ([]netip.Addr, error)

func (*Client) GetIPs

func (c *Client) GetIPs(name string) ([]netip.Addr, error)

func (*Client) GetLegacyServiceBrowserDomains

func (c *Client) GetLegacyServiceBrowserDomains(domain string) ([]string, error)

func (*Client) GetNameservers

func (c *Client) GetNameservers(name string) ([]*Nameserver, error)

func (*Client) GetServiceBrowserDomains

func (c *Client) GetServiceBrowserDomains(domain string) ([]string, error)

func (*Client) GetServiceInstanceInfo

func (c *Client) GetServiceInstanceInfo(domain string) (*ServiceInstanceInfo, error)

func (*Client) GetServiceInstances

func (c *Client) GetServiceInstances(serviceDomain string) ([]string, error)

func (*Client) GetServices

func (c *Client) GetServices(domain string) ([]string, error)

func (*Client) Lookup

func (c *Client) Lookup(name string, qtype uint16) (*dns.Msg, error)

Lookup is convenience method that creates a new message and then issues a synchronous query with that message.

func (*Client) NewMsg

func (c *Client) NewMsg(name string, qtype uint16) *dns.Msg

NewMsg creates a new *github.com/miekg/dns.Msg based on the client's settings. The name parameter is the query's QNAME (a domainname), and qtype is the query type (e.g., github.com/miekg/dns.TypeA). NewMSG fully-qualifies the name before constructing the query message, if it is not already fully-qualified.

type Do53TCP

type Do53TCP struct {
	Server   string
	IPv4Only bool
	IPv6Only bool
	Timeout  time.Duration
	KeepOpen bool
	// contains filtered or unexported fields
}

func (*Do53TCP) Close

func (t *Do53TCP) Close() error

func (*Do53TCP) Exchange

func (t *Do53TCP) Exchange(req *dns.Msg) (*dns.Msg, error)

type Do53UDP

type Do53UDP struct {
	Server           string
	IPv4Only         bool
	IPv6Only         bool
	Timeout          time.Duration
	UDPBufSize       int
	IgnoreTruncation bool
	// contains filtered or unexported fields
}

func (*Do53UDP) Close

func (t *Do53UDP) Close() error

func (*Do53UDP) Exchange

func (t *Do53UDP) Exchange(req *dns.Msg) (*dns.Msg, error)

type DoH

type DoH struct {
	ServerURL string
	Timeout   time.Duration
	UseGET    bool
	KeepOpen  bool
	TLSConfig *tls.Config
	// contains filtered or unexported fields
}

func (*DoH) Close

func (t *DoH) Close() error

func (*DoH) Exchange

func (t *DoH) Exchange(req *dns.Msg) (*dns.Msg, error)

type DoT

type DoT struct {
	Server    string
	IPv4Only  bool
	IPv6Only  bool
	Timeout   time.Duration
	KeepOpen  bool
	TLSConfig *tls.Config // XXX probably not needed, as dns.Client already has this field
	// contains filtered or unexported fields
}

func (*DoT) Close

func (t *DoT) Close() error

func (*DoT) Exchange

func (t *DoT) Exchange(req *dns.Msg) (*dns.Msg, error)

type Error

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

func (*Error) Error

func (e *Error) Error() string

type Nameserver

type Nameserver struct {
	Name  string
	Addrs []netip.Addr
}

func (*Nameserver) String

func (ns *Nameserver) String() string

type ServiceInstanceInfo

type ServiceInstanceInfo struct {
	Name string

	Priority uint16
	Weight   uint16
	Port     uint16
	Target   string

	Txt []string

	Addrs []netip.Addr
}

aggregation of SRV, TXT, and A/AAAA records

func (*ServiceInstanceInfo) String

func (info *ServiceInstanceInfo) String() string

type Transport

type Transport interface {
	Exchange(*dns.Msg) (*dns.Msg, error)
	Close() error
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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