Documentation
¶
Overview ¶
Package resutil provides shared DNS resolution utilities
Index ¶
- func ExtractEDE(msg *dns.Msg) (*dns.EDNS0_EDE, bool)
- func FormatAnswers(answers []dns.RR) string
- func GenerateRequestID() string
- func GetRequestID(w dns.ResponseWriter) string
- func IPsToRRs(name string, ips []netip.Addr, ttl uint32) []dns.RR
- func LookupRecords(ctx context.Context, r RecordResolver, name string, qtype uint16, ttl uint32) ([]dns.RR, int)
- func NetworkForQtype(qtype uint16) string
- func SetMeta(w dns.ResponseWriter, key, value string)
- func StripOPT(msg *dns.Msg)
- type LookupResult
- type RecordResolver
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractEDE ¶ added in v0.73.2
ExtractEDE returns the first Extended DNS Error (RFC 8914) option carried in the message, if present.
func FormatAnswers ¶
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 ¶
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 ¶
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.
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
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.