resutil

package
v0.75.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package resutil provides shared DNS resolution utilities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractEDE added in v0.73.2

func ExtractEDE(msg *dns.Msg) (*dns.EDNS0_EDE, bool)

ExtractEDE returns the first Extended DNS Error (RFC 8914) option carried in the message, if present.

func FormatAnswers

func FormatAnswers(answers []dns.RR) string

FormatAnswers formats DNS resource records for logging.

func GenerateRequestID

func GenerateRequestID() string

GenerateRequestID creates a random 8-character hex string for request tracing.

func GetRequestID

func GetRequestID(w dns.ResponseWriter) string

GetRequestID extracts a request ID from the ResponseWriter if available, otherwise generates a new one.

func IPsToRRs

func IPsToRRs(name string, ips []netip.Addr, ttl uint32) []dns.RR

IPsToRRs converts a slice of IP addresses to DNS resource records. IPv4 addresses become A records, IPv6 addresses become AAAA records.

func LookupRecords added in v0.74.0

func LookupRecords(ctx context.Context, r RecordResolver, name string, qtype uint16, ttl uint32) ([]dns.RR, int)

LookupRecords resolves a non-address DNS record type through the host resolver and returns the resource records and the DNS rcode. Types the host resolver cannot answer (anything not covered by the net.Resolver Lookup* methods) yield NODATA so that a routed name is never poisoned with NXDOMAIN for an unsupported type.

func NetworkForQtype

func NetworkForQtype(qtype uint16) string

NetworkForQtype returns the network string ("ip4" or "ip6") for a DNS query type. Returns empty string for unsupported types.

func SetMeta

func SetMeta(w dns.ResponseWriter, key, value string)

SetMeta sets metadata on the ResponseWriter if it supports it.

func StripOPT added in v0.73.2

func StripOPT(msg *dns.Msg)

StripOPT removes any OPT pseudo-RRs from the message's Extra section. Per RFC 6891 a responder must not include an OPT RR toward a client that did not advertise EDNS0.

Types

type LookupResult

type LookupResult struct {
	IPs   []netip.Addr
	Rcode int
	Err   error // Original error for caller's logging needs
}

LookupResult contains the result of an external DNS lookup

func LookupIP

func LookupIP(ctx context.Context, r resolver, network, host string, qtype uint16) LookupResult

LookupIP performs a DNS lookup and determines the appropriate rcode.

type RecordResolver added in v0.74.0

type RecordResolver interface {
	LookupMX(ctx context.Context, name string) ([]*net.MX, error)
	LookupTXT(ctx context.Context, name string) ([]string, error)
	LookupNS(ctx context.Context, name string) ([]*net.NS, error)
	LookupSRV(ctx context.Context, service, proto, name string) (string, []*net.SRV, error)
	LookupCNAME(ctx context.Context, host string) (string, error)
	LookupAddr(ctx context.Context, addr string) ([]string, error)
}

RecordResolver is the host resolver surface used to forward non-address record queries. net.DefaultResolver satisfies it.

Jump to

Keyboard shortcuts

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