Documentation
¶
Overview ¶
Package util provides DNS protocol utilities for SDNS.
Package util provides DNS protocol utilities for SDNS.
Package util provides DNS protocol utilities for SDNS.
Package util provides DNS protocol utilities for SDNS.
Index ¶
- Constants
- func CalculateCacheTTL(msg *dns.Msg, respType ResponseType) time.Duration
- func CheckReverseName(name string) int
- func ClearDNSSEC(msg *dns.Msg) *dns.Msg
- func ClearOPT(msg *dns.Msg) *dns.Msg
- func ErrorToEDE(err error) (uint16, string)
- func Exchange(ctx context.Context, req *dns.Msg, addr string, net string, client *dns.Client) (*dns.Msg, error)
- func GenerateServerCookie(secret, remoteip, cookie string) string
- func GetEDE(msg *dns.Msg) *dns.EDNS0_EDE
- func IPFromReverseName(name string) string
- func NotSupported(w dns.ResponseWriter, req *dns.Msg) error
- func SetEDE(msg *dns.Msg, code uint16, extraText string)
- func SetEdns0(req *dns.Msg) (*dns.OPT, int, string, bool, bool)
- func SetRcode(req *dns.Msg, rcode int, do bool) *dns.Msg
- func SetRcodeWithEDE(req *dns.Msg, rcode int, do bool, edeCode uint16, extraText string) *dns.Msg
- type ResponseType
Constants ¶
const ( // MinCacheTTL is the minimum time to cache any response. MinCacheTTL = 5 * time.Second // MaxCacheTTL is the maximum time to cache any response. MaxCacheTTL = 24 * time.Hour )
const ( // ReverseDomainV4 is the reverse DNS domain for IPv4 addresses. ReverseDomainV4 = ".in-addr.arpa." // ReverseDomainV6 is the reverse DNS domain for IPv6 addresses. ReverseDomainV6 = ".ip6.arpa." )
const (
// DefaultMsgSize EDNS0 message size.
DefaultMsgSize = 1232
)
Variables ¶
This section is empty.
Functions ¶
func CalculateCacheTTL ¶
func CalculateCacheTTL(msg *dns.Msg, respType ResponseType) time.Duration
CalculateCacheTTL determines the appropriate cache duration for a DNS response. It scans all resource records and returns the minimum TTL found, with bounds checking. For DNSSEC-signed responses, it also considers RRSIG expiration times.
func CheckReverseName ¶
CheckReverseName checks if a domain name is in a reverse DNS zone. Returns: - 0: not a reverse domain - 1: IPv4 reverse domain (.in-addr.arpa.) - 2: IPv6 reverse domain (.ip6.arpa.)
func ClearDNSSEC ¶
ClearDNSSEC removes RRSIG, NSEC and NSEC3 records from Answer and Ns sections in place. Short-circuits when the sections already hold nothing to strip (typical for non-DNSSEC responses), and reuses the slice backing array when a filter is actually needed.
func ClearOPT ¶
ClearOPT removes every OPT record from msg.Extra in place. No copy is made when the Extra section has no OPT (the common case for responses synthesised without EDNS).
func ErrorToEDE ¶
ErrorToEDE maps errors to Extended DNS Error codes efficiently.
func Exchange ¶
func Exchange(ctx context.Context, req *dns.Msg, addr string, net string, client *dns.Client) (*dns.Msg, error)
Exchange exchange dns request with TCP fallback.
func GenerateServerCookie ¶
GenerateServerCookie return generated edns server cookie.
func IPFromReverseName ¶
IPFromReverseName extracts an IP address from a PTR record name. For example: - "54.119.58.176.in-addr.arpa." returns "176.58.119.54" - "b.a.9.8.7.6.5.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa." returns "2001:db8::567:89ab" Returns empty string if the name is not a valid PTR record.
func NotSupported ¶
func NotSupported(w dns.ResponseWriter, req *dns.Msg) error
NotSupported response to writer an empty notimplemented message.
func SetEdns0 ¶
SetEdns0 returns replaced or new opt rr and if request has do.
The function inspects the client's OPT record to harvest NSID / COOKIE signalling, strips every option before forwarding (ECS in particular, per RFC 7871 privacy guidance), and normalises the UDP size. Inspection uses typed pointer assertions so we avoid the allocating option.String() path, and the stripping reuses opt.Option's backing storage via opt.Option = nil rather than allocating an empty slice.
Types ¶
type ResponseType ¶
type ResponseType int
ResponseType represents the classification of a DNS response.
const ( // TypeSuccess indicates a positive response with answers. TypeSuccess ResponseType = iota // TypeNXDomain indicates the queried domain does not exist (NXDOMAIN). TypeNXDomain // TypeNoRecords indicates the domain exists but has no records of the requested type (NODATA). TypeNoRecords // TypeReferral indicates a delegation to another nameserver. TypeReferral // TypeMetaQuery indicates zone transfer or notification queries. TypeMetaQuery // TypeDynamicUpdate indicates a dynamic DNS update message. TypeDynamicUpdate // TypeServerFailure indicates a server error occurred. TypeServerFailure // TypeNotCacheable indicates responses that should not be cached. TypeNotCacheable // TypeExpiredSignature indicates DNSSEC signatures have expired. TypeExpiredSignature )
func ClassifyResponse ¶
ClassifyResponse analyzes a DNS message and determines its type. It also returns the OPT record if present for EDNS0 processing. The time parameter is used for checking DNSSEC signature expiration.