dnsclient

package module
v0.0.0-...-103a051 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DNSErrToString = map[DNSErr]string{
	DNSErrRcodeNotSuccess:   "RCODE was not SUCCESS",
	DNSErrMissingAnswer:     "DNS response does not answer the query",
	DNSErrInvalidAnswer:     "DNS response has an answer that matches neither the qname nor one of its aliases",
	DNSErrInvalidCNAMEChain: "DNS response contains an invalid CNAME chain",
	DNSErrMaxCNAMEs:         "query followed max number of CNAMEs",
}

Functions

func EnumerateServiceInstances

func EnumerateServiceInstances(c Client, domain, service string) ([]string, error)

func EnumerateServices

func EnumerateServices(c Client, domain string) ([]string, error)

func GetAllServiceBrowserDomains

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

func GetDefaultServiceBrowserDomain

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

func GetIP4s

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

func GetIP6s

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

func GetIPs

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

func GetLegacyServiceBrowserDomain

func GetLegacyServiceBrowserDomain(c Client, domain string) (string, error)

func GetServiceBrowserDomains

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

func GetServiceInstanceInfo

func GetServiceInstanceInfo(c Client, domain string) error

func NewMsg

func NewMsg(config *Config, name string, qtype uint16) *dns.Msg

func Query

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

Return an error if:

  • there was some sort of network error
  • DNS returned a valid response but Rcode is not SUCCESS
  • DNS returned Rcode SUCCESS, but the response doesn't have the record we requested
  • The config is set to follow CNAMES, but we encountered some sort of malformed CNAME (namely, an invalid CNAME chain in an answer; this should be rare)
  • The config is set to follow CNAMES, and we reached MaxCNAMEs without getting an answer

In other words, if we ergonomics are such that if the caller invokes:

resp, err != dnsquery.Query(c, name, type)

Then err == nil iff resp actually returns a positive response for the query. If err != nil, then err will store the response message (if there was one) as well as indicate the reason for the failure (basically, one of the above categories above. The whole point is to make it so the caller doesn't have to inspect the msg to see if the query succeeded; if the caller wants the nitty-gritty details of why the query didn't get an answer, it can inspect the error value.

Types

type Client

type Client interface {
	GetConfig() *Config
	Dial() error
	Close() error
	Query(name string, qtype uint16) (*dns.Msg, error)
}

type Config

type Config struct {
	IdFunc           func() uint16
	RecursionDesired bool
	Timeout          time.Duration
	MaxCNAMEs        int
	DNSSEC           bool
}

This is configuration that applies to all typs of clients -- it deals purely with the handling of the DNS requests and responses

type DNSErr

type DNSErr int
const (
	DNSErrRcodeNotSuccess DNSErr = iota
	DNSErrMissingAnswer
	DNSErrInvalidAnswer
	DNSErrInvalidCNAMEChain
	DNSErrMaxCNAMEs
)

type DNSError

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

func NewDNSError

func NewDNSError(reason DNSErr, response *dns.Msg) *DNSError

func (*DNSError) Error

func (e *DNSError) Error() string

type Do53Client

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

func NewDo53Client

func NewDo53Client(config *Do53Config) *Do53Client

func (*Do53Client) Close

func (c *Do53Client) Close() error

func (*Do53Client) Dial

func (c *Do53Client) Dial() error

func (*Do53Client) GetConfig

func (c *Do53Client) GetConfig() *Config

func (*Do53Client) Query

func (c *Do53Client) Query(name string, qtype uint16) (*dns.Msg, error)

type Do53Config

type Do53Config struct {
	Config
	UseTCP       bool
	RetryWithTCP bool
	Server       string
}

type DoHClient

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

func NewDoHClient

func NewDoHClient(config *DoHConfig) *DoHClient

func (*DoHClient) Close

func (c *DoHClient) Close() error

func (*DoHClient) Dial

func (c *DoHClient) Dial() error

func (*DoHClient) GetConfig

func (c *DoHClient) GetConfig() *Config

func (*DoHClient) Query

func (c *DoHClient) Query(name string, qtype uint16) (*dns.Msg, error)

Raw Query

type DoHConfig

type DoHConfig struct {
	Config
	URL string
}

type DoTClient

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

func NewDoTClient

func NewDoTClient(config *DoTConfig) *DoTClient

func (*DoTClient) Close

func (c *DoTClient) Close() error

func (*DoTClient) Dial

func (c *DoTClient) Dial() error

func (*DoTClient) GetConfig

func (c *DoTClient) GetConfig() *Config

func (*DoTClient) Query

func (c *DoTClient) Query(name string, qtype uint16) (*dns.Msg, error)

type DoTConfig

type DoTConfig struct {
	Config
	TLSConfig *tls.Config
	Server    string
}

type NameServer

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

func GetNameServers

func GetNameServers(c Client, name string) ([]*NameServer, error)

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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