util

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 12 Imported by: 0

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

View Source
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
)
View Source
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."
)
View Source
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

func CheckReverseName(name string) int

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

func ClearDNSSEC(msg *dns.Msg) *dns.Msg

ClearDNSSEC returns cleared RRSIG and NSECx message.

func ClearOPT

func ClearOPT(msg *dns.Msg) *dns.Msg

ClearOPT returns cleared opt message.

func ErrorToEDE

func ErrorToEDE(err error) (uint16, string)

ErrorToEDE maps errors to Extended DNS Error codes efficiently.

func Exchange

func Exchange(ctx context.Context, req *dns.Msg, addr string, net string) (*dns.Msg, error)

Exchange exchange dns request with TCP fallback.

func ExchangeInternal

func ExchangeInternal(ctx context.Context, r *dns.Msg) (*dns.Msg, error)

ExchangeInternal exchange dns request internal.

func GenerateServerCookie

func GenerateServerCookie(secret, remoteip, cookie string) string

GenerateServerCookie return generated edns server cookie.

func GetEDE

func GetEDE(msg *dns.Msg) *dns.EDNS0_EDE

GetEDE extracts Extended DNS Error from a message if present.

func IPFromReverseName

func IPFromReverseName(name string) string

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

func ParsePurgeQuestion(req *dns.Msg) (qname string, qtype uint16, ok bool)

ParsePurgeQuestion can parse query for purge questions.

func SetEDE

func SetEDE(msg *dns.Msg, code uint16, extraText string)

SetEDE adds an Extended DNS Error to the response.

func SetEdns0

func SetEdns0(req *dns.Msg) (*dns.OPT, int, string, bool, bool)

SetEdns0 returns replaced or new opt rr and if request has do.

func SetRcode

func SetRcode(req *dns.Msg, rcode int, do bool) *dns.Msg

SetRcode returns message specified with rcode.

func SetRcodeWithEDE

func SetRcodeWithEDE(req *dns.Msg, rcode int, do bool, edeCode uint16, extraText string) *dns.Msg

SetRcodeWithEDE returns message with specified rcode and Extended DNS Error.

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

func ClassifyResponse(msg *dns.Msg, now time.Time) (ResponseType, *dns.OPT)

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.

Jump to

Keyboard shortcuts

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