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) (*dns.Msg, error)
- func ExchangeInternal(ctx context.Context, r *dns.Msg) (*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 ParsePurgeQuestion(req *dns.Msg) (qname string, qtype uint16, ok bool)
- 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 returns cleared RRSIG and NSECx message.
func ErrorToEDE ¶
ErrorToEDE maps errors to Extended DNS Error codes efficiently.
func ExchangeInternal ¶
ExchangeInternal exchange dns request internal.
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 ParsePurgeQuestion ¶
ParsePurgeQuestion can parse query for purge questions.
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.