bdns

package
v0.20251216.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MPL-2.0 Imports: 21 Imported by: 136

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewStaticProvider

func NewStaticProvider(servers []string) (*staticProvider, error)

func ParseTarget

func ParseTarget(target, defaultPort string) (host, port string, err error)

ParseTarget takes the user input target string and default port, returns formatted host and port info. If target doesn't specify a port, set the port to be the defaultPort. If target is in IPv6 format and host-name is enclosed in square brackets, brackets are stripped when setting the host.

Examples:

  • target: "www.google.com" defaultPort: "443" returns host: "www.google.com", port: "443"
  • target: "ipv4-host:80" defaultPort: "443" returns host: "ipv4-host", port: "80"
  • target: "[ipv6-host]" defaultPort: "443" returns host: "ipv6-host", port: "443"
  • target: ":80" defaultPort: "443" returns host: "localhost", port: "80"

This function is copied from: https://github.com/grpc/grpc-go/blob/master/internal/resolver/dns/dns_resolver.go It has been minimally modified to fit our code style.

func StartDynamicProvider

func StartDynamicProvider(c *cmd.DNSProvider, refresh time.Duration, proto string) (*dynamicProvider, error)

StartDynamicProvider constructs a new dynamicProvider and starts its auto-update goroutine. The auto-update process queries DNS for SRV records at refresh intervals and uses the resulting IP/port combos to populate the list returned by Addrs. The update process ignores the Priority and Weight attributes of the SRV records.

`proto` is the IP protocol (tcp or udp) to look up SRV records for.

Types

type Client

type Client interface {
	LookupA(context.Context, string) (*Result[*dns.A], string, error)
	LookupAAAA(context.Context, string) (*Result[*dns.AAAA], string, error)
	LookupCAA(context.Context, string) (*Result[*dns.CAA], string, error)
	LookupTXT(context.Context, string) (*Result[*dns.TXT], string, error)
}

Client can make A, AAAA, CAA, and TXT queries. The second return value of each method is the address of the resolver used to conduct the query, and should be populated even when returning an error.

func New

func New(
	readTimeout time.Duration,
	servers ServerProvider,
	stats prometheus.Registerer,
	clk clock.Clock,
	maxTries int,
	userAgent string,
	log blog.Logger,
	tlsConfig *tls.Config,
) Client

New constructs a new DNS resolver object that utilizes the provided list of DNS servers for resolution, and the provided tlsConfig to speak DoH to those servers.

type Error

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

Error wraps a DNS error with various relevant information

func (Error) Error

func (d Error) Error() string

type MockClient

type MockClient struct{}

MockClient is a mock

func (*MockClient) LookupA added in v0.20251216.0

func (mock *MockClient) LookupA(_ context.Context, hostname string) (*Result[*dns.A], string, error)

LookupA is a fake

func (*MockClient) LookupAAAA added in v0.20251216.0

func (mock *MockClient) LookupAAAA(_ context.Context, hostname string) (*Result[*dns.AAAA], string, error)

LookupAAAA is a fake

func (*MockClient) LookupCAA

func (mock *MockClient) LookupCAA(_ context.Context, domain string) (*Result[*dns.CAA], string, error)

LookupCAA is a fake

func (*MockClient) LookupTXT

func (mock *MockClient) LookupTXT(_ context.Context, hostname string) (*Result[*dns.TXT], string, error)

LookupTXT is a mock

type Result added in v0.20251216.0

type Result[R dns.RR] struct {
	*dns.Msg
	CNames []*dns.CNAME
	Final  []R
}

Result is a wrapper around miekg/dns.Msg, but with all Resource Records from the Answer section which match the parameterized record type already pulled out for convenient access.

type ServerProvider

type ServerProvider interface {
	Addrs() ([]string, error)
	Stop()
}

ServerProvider represents a type which can provide a list of addresses for the bdns to use as DNS resolvers. Different implementations may provide different strategies for providing addresses, and may provide different kinds of addresses (e.g. host:port combos vs IP addresses).

Jump to

Keyboard shortcuts

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