dns

package
v0.7.61 Latest Latest
Warning

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

Go to latest
Published: May 28, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	AlgRSASHA1   uint8 = 5
	AlgRSASHA256 uint8 = 8
	AlgRSASHA512 uint8 = 10
	AlgECDSAP256 uint8 = 13
	AlgECDSAP384 uint8 = 14
	AlgED25519   uint8 = 15
	AlgED448     uint8 = 16
)

DNSSEC algorithm numbers (RFC 8624).

View Source
const (
	// DigestReserved (0) is the IANA-reserved DS digest type. RFC 4509
	// §2.4 / RFC 8624 §3.3 say a DS RR carrying digest type 0 MUST NOT
	// be used to authenticate the corresponding DNSKEY. If the parent
	// publishes ONLY digest-type-0 DS records for a delegation, the
	// delegation has no usable DS — RFC 4035 §5.2 treats that the same
	// as no DS at all and the validator falls through to Insecure.
	DigestReserved uint8 = 0
	DigestSHA1     uint8 = 1
	DigestSHA256   uint8 = 2
	DigestSHA384   uint8 = 4
)

DNSSEC digest types (RFC 8624).

View Source
const (
	AlgRSAMD5       uint8 = 1
	AlgDSA          uint8 = 3
	AlgDSANSEC3SHA1 uint8 = 6
	AlgRSASHA1NSEC3 uint8 = 7
)

DNSSEC algorithm numbers that this resolver explicitly does NOT validate. The verify-switch in dnssec/verify.go falls through to "unsupported" for any algorithm not enumerated above, so listing these as named constants is for spec-completeness and pin-test readability — never for acceptance.

  • RSAMD5 (1): MD5 is cryptographically broken (RFC 6151) and MUST NOT be used for new signatures (RFC 6944).
  • DSA (3): DSA-SHA1 is deprecated and dropped from the Internet root signing key rollover (RFC 8624 §3.1).
  • DSA-NSEC3 (6): Same DSA constraints, NSEC3 variant.
  • RSASHA1-NSEC3 (7):RSA/SHA-1 in any form is deprecated; we honour the validator's allowSHA1 gate via algorithm 5 only when explicitly opted in. Algorithm 7 is legacy and we leave it strictly off.
View Source
const (
	EDECodeOtherError              uint16 = 0
	EDECodeUnsupportedDNSKEYAlgo   uint16 = 1
	EDECodeUnsupportedDSDigestType uint16 = 2
	EDECodeStaleAnswer             uint16 = 3
	EDECodeForgedAnswer            uint16 = 4
	EDECodeDNSSECIndeterminate     uint16 = 5
	EDECodeDNSSECBogus             uint16 = 6
	EDECodeSignatureExpired        uint16 = 7
	EDECodeSignatureNotYetValid    uint16 = 8
	EDECodeDNSKEYMissing           uint16 = 9
	EDECodeRRSIGsMissing           uint16 = 10
	EDECodeNoZoneKeyBitSet         uint16 = 11
	EDECodeNSECMissing             uint16 = 12
	EDECodeCachedError             uint16 = 13
	EDECodeNotReady                uint16 = 14
	EDECodeBlocked                 uint16 = 15
	EDECodeCensored                uint16 = 16
	EDECodeFiltered                uint16 = 17
	EDECodeProhibited              uint16 = 18
	EDECodeStaleNXDOMAINAnswer     uint16 = 19
	EDECodeNotAuthoritative        uint16 = 20
	EDECodeNotSupported            uint16 = 21
	EDECodeNoReachableAuthority    uint16 = 22
	EDECodeNetworkError            uint16 = 23
	EDECodeInvalidData             uint16 = 24
	// EDECodeSignatureExpiredBeforeValid — RFC 9606. The signer
	// produced an RRSIG whose Expiration timestamp is earlier than
	// its Inception timestamp; under no clock could it ever validate.
	// Distinct from a normal "expired" (7) because this is a signer
	// bug rather than a clock-skew situation.
	EDECodeSignatureExpiredBeforeValid uint16 = 25
	// EDECodeTooEarly — RFC 9539. Used by upstreams that observed
	// the resolver send a 0-RTT query before the TLS handshake
	// completed in a way they could not safely replay. Lets the
	// client know to retry once handshake completes.
	EDECodeTooEarly uint16 = 26
	// EDECodeUnsupportedNSEC3IterationsValue — RFC 9276 §3.2. The
	// resolver refused to walk an NSEC3 chain because its iteration
	// count exceeded the local cap (MaxNSEC3Iterations); the response
	// is reported Insecure rather than Bogus so the client knows to
	// trust it for non-DNSSEC purposes.
	EDECodeUnsupportedNSEC3IterationsValue uint16 = 27
	// EDECodeUnableToConformToPolicy — IANA EDE 28. Signals that the
	// upstream did not return an answer the resolver considers
	// policy-acceptable (e.g. an unsigned answer when the operator
	// requires DO=1 + AD=1). Distinct from "filtered" (17) which is
	// the resolver's OWN policy refusing to forward; code 28 covers
	// the case where the upstream's response itself violates a local
	// policy gate the resolver enforces post-receipt.
	EDECodeUnableToConformToPolicy uint16 = 28
	// EDECodeSynthesized — IANA EDE 29. Signals that the answer was
	// synthesized by the resolver (DNS64 AAAA synthesis, RFC 8198
	// aggressive NSEC NXDOMAIN/NODATA, NSEC3-aggressive synthesis)
	// rather than fetched as-is from the authoritative. Clients that
	// need a verifiable upstream answer can re-query with synthesis
	// disabled or take corrective action.
	EDECodeSynthesized uint16 = 29
)

EDE info codes (RFC 8914).

View Source
const (
	EDNSOptionCodeECS          uint16 = 8
	EDNSOptionCodeCookie       uint16 = 10
	EDNSOptionCodeTCPKeepalive uint16 = 11
	EDNSOptionCodePadding      uint16 = 12
	EDNSOptionCodeEDE          uint16 = 15
	// EDNSOptionCodeDAU is the "DNSSEC Algorithm Understood" option
	// (RFC 6975 §3). The option data is the list of DNSKEY/RRSIG
	// algorithm numbers the resolver can validate. Multi-signed zones
	// (a zone published with multiple algorithms during a rollover)
	// use this to decide which signature to return; without DAU they
	// must send all signatures, wasting bandwidth and amplification.
	EDNSOptionCodeDAU uint16 = 5
	// EDNSOptionCodeDHU is the "DS Hash Understood" option. Same idea
	// but for DS digest types (RFC 6975 §3, option code 6).
	EDNSOptionCodeDHU uint16 = 6
	// EDNSOptionCodeN3U is the "NSEC3 Hash Understood" option. NSEC3
	// hash algorithms — only SHA-1 (algorithm 1) is currently defined
	// (RFC 6975 §3, option code 7).
	EDNSOptionCodeN3U uint16 = 7
)

EDNS option codes.

View Source
const (
	TypeA     uint16 = 1
	TypeNS    uint16 = 2
	TypeCNAME uint16 = 5
	TypeSOA   uint16 = 6
	TypePTR   uint16 = 12
	TypeMX    uint16 = 15
	TypeTXT   uint16 = 16
	TypeAAAA  uint16 = 28
	TypeSRV   uint16 = 33
	TypeHINFO uint16 = 13
	TypeDNAME uint16 = 39
	TypeOPT   uint16 = 41
	TypeANY   uint16 = 255

	// DNSSEC types
	TypeDS         uint16 = 43
	TypeRRSIG      uint16 = 46
	TypeNSEC       uint16 = 47
	TypeDNSKEY     uint16 = 48
	TypeNSEC3      uint16 = 50
	TypeNSEC3PARAM uint16 = 51
	// RFC 7344 — child-published DS/DNSKEY records the parent zone uses
	// to update the child's delegation. CDS RDATA is byte-identical to
	// DS; CDNSKEY RDATA is byte-identical to DNSKEY. Distinct types
	// only at the owner-side semantics: present at the apex of the
	// CHILD zone, signed by the child's keys, instructing the parent.
	TypeCDS     uint16 = 59
	TypeCDNSKEY uint16 = 60

	// Modern service-discovery types. We do not parse their RDATA into
	// rich Go structs (the wire layer treats them as opaque, which is
	// the right behaviour for a forwarding recursive resolver per RFC
	// 3597 — pass unknown RDATA through verbatim so signatures remain
	// verifiable downstream). But registering them in TypeToString so
	// logs, the queries UI, and DNSSEC trace events show "HTTPS" and
	// "SVCB" instead of "TYPE65"/"TYPE64" is important for operators
	// chasing real-world traffic on networks where these dominate
	// (Apple devices, HTTP/3 / QUIC clients, ECH-enabled browsers).
	TypeSVCB  uint16 = 64 // RFC 9460 §2.1 — service binding
	TypeHTTPS uint16 = 65 // RFC 9460 §9   — HTTPS specialisation of SVCB
	// RFC 8659 (obsoletes 6844). DNS-based authorization for X.509
	// issuance — every CA on the public PKI MUST honour CAA, so
	// resolvers that mangle this RDATA can silently break cert renewal.
	TypeCAA uint16 = 257
)

Record types

View Source
const (
	RCodeNoError  uint8 = 0
	RCodeFormErr  uint8 = 1
	RCodeServFail uint8 = 2
	RCodeNXDomain uint8 = 3
	RCodeNotImp   uint8 = 4
	RCodeRefused  uint8 = 5
	// RCodeBadCookie is the extended RCODE 23 (RFC 7873 §5.2). It must be
	// transmitted using the EDNS0 ExtRCODE split: the low 4 bits (0x07) go
	// into the DNS header RCODE field, the high 8 bits (0x01) go into the
	// OPT pseudo-RR TTL byte 0. See buildBadCookieResponse.
	RCodeBadCookie uint8 = 23
)

Response codes

View Source
const (
	OpcodeQuery  uint8 = 0
	OpcodeIQuery uint8 = 1
	OpcodeStatus uint8 = 2
)

Opcodes

View Source
const (
	ClassIN uint16 = 1
)

Classes

View Source
const PaddingBlockSize = 468

PaddingBlockSize is the recommended response padding block (RFC 8467 §4.1: "the server SHOULD pad the response packet to a multiple of 468 bytes"). The number is empirical: it avoids most common MTUs while still being a single power-of-two-friendly value that hides most short answers in the same length bucket as longer ones.

Variables

View Source
var RCodeToString = map[uint8]string{
	RCodeNoError:   "NOERROR",
	RCodeFormErr:   "FORMERR",
	RCodeServFail:  "SERVFAIL",
	RCodeNXDomain:  "NXDOMAIN",
	RCodeNotImp:    "NOTIMP",
	RCodeRefused:   "REFUSED",
	RCodeBadCookie: "BADCOOKIE",
}

RCodeToString maps response codes to human-readable names.

View Source
var TypeToString = map[uint16]string{
	TypeA: "A", TypeNS: "NS", TypeCNAME: "CNAME", TypeSOA: "SOA",
	TypeHINFO: "HINFO", TypePTR: "PTR", TypeMX: "MX", TypeTXT: "TXT",
	TypeAAAA: "AAAA", TypeSRV: "SRV", TypeDNAME: "DNAME", TypeOPT: "OPT",
	TypeDS: "DS", TypeRRSIG: "RRSIG", TypeNSEC: "NSEC",
	TypeDNSKEY: "DNSKEY", TypeNSEC3: "NSEC3", TypeNSEC3PARAM: "NSEC3PARAM",
	TypeCDS: "CDS", TypeCDNSKEY: "CDNSKEY",
	TypeANY:  "ANY",
	TypeSVCB: "SVCB", TypeHTTPS: "HTTPS", TypeCAA: "CAA",
}

TypeToString maps type values to human-readable names.

Functions

func AddTCPKeepaliveToRawResponse added in v0.6.20

func AddTCPKeepaliveToRawResponse(resp []byte, timeoutUnits100ms uint16) []byte

AddTCPKeepaliveToRawResponse parses a wire-format response and adds an edns-tcp-keepalive option (RFC 7828 §3.1) carrying the server's idle timeout in 100ms units. Used by TCP/DoT/DoH servers when the client signalled keepalive interest. Idempotent — if the response already carries a keepalive option, the original bytes are returned unchanged. Returns the original bytes on any parse/pack error.

func BuildPlainName

func BuildPlainName(name string) []byte

BuildPlainName encodes a domain name as uncompressed wire-format label sequence. Exported for use in tests and delegation handling.

func DecodeName

func DecodeName(msg []byte, offset int) (string, int, error)

DecodeName reads a domain name from the wire format. It returns the decoded name and the number of bytes consumed from the ORIGINAL position (before any pointer jumps).

func EncodeName

func EncodeName(w *wireWriter, name string) error

EncodeName writes a domain name in wire format with optional compression.

func EncodeNameToBytes added in v0.6.15

func EncodeNameToBytes(name string) ([]byte, error)

EncodeNameToBytes returns the uncompressed wire-format encoding of a domain name: a sequence of length-prefixed labels terminated by a zero byte (e.g. "foo.example.com" → 3 'f' 'o' 'o' 7 'e'...'m' 0). Used for callers that need to produce stand-alone RData bytes — DNAME→CNAME synthesis, hand-built test fixtures — without the message-level compression dictionary that EncodeName depends on. Returns an error on labels longer than 63 octets (RFC 1035 §2.3.4) or full names longer than 255 octets including the root terminator.

func HasPaddingOption added in v0.6.20

func HasPaddingOption(e *EDNS0) bool

HasPaddingOption reports whether the parsed EDNS0 record carries a PADDING option (used as the client's signal that it wants the response padded — RFC 8467 §4).

func HasTCPKeepaliveOption added in v0.6.20

func HasTCPKeepaliveOption(e *EDNS0) bool

HasTCPKeepaliveOption reports whether the parsed EDNS0 record carries an edns-tcp-keepalive option — the client's signal that it wants to negotiate a TCP idle timeout (RFC 7828 §3.2). Per the RFC the client form has zero-length data; we accept any length and treat the option's presence alone as the signal.

func Pack

func Pack(msg *Message, buf []byte) ([]byte, error)

Pack serializes a DNS message to wire format.

func PadRawResponse added in v0.6.20

func PadRawResponse(resp []byte, block int) []byte

PadRawResponse parses a wire-format response and adds an EDNS PADDING option (RFC 7830 §3) sized so that the total wire length becomes the next multiple of `block` bytes (RFC 8467 §4.1 recommends 468). Used by DoT/DoH servers when the client signalled padding interest, so a passive observer cannot infer the queried name from response length alone. Returns the original bytes unchanged on any parse/pack error or when `block <= 0`.

Implementation note: we deliberately mutate the existing OPT RR's RData (rather than rebuilding via BuildOPTWithOptions) so OPT TTL bits — ExtRCODE, Version, DO-flag — are preserved verbatim. The caller's resolver may have set ExtRCODE for BADVERS/BADKEY signalling and we must not lose it.

func ParseA

func ParseA(rdata []byte) (net.IP, error)

ParseA extracts an IPv4 address from A record RDATA.

func ParseAAAA

func ParseAAAA(rdata []byte) (net.IP, error)

ParseAAAA extracts an IPv6 address from AAAA record RDATA.

func ParseCNAME

func ParseCNAME(msg []byte, rdataOffset int) (string, error)

ParseCNAME extracts the canonical name from CNAME record RDATA.

func ParseCookieOption

func ParseCookieOption(data []byte) (clientCookie []byte, serverCookie []byte)

ParseCookieOption parses a DNS Cookie option (RFC 7873, option code 10). Returns the client cookie (8 bytes) and optional server cookie (8-32 bytes).

func ParseDNAME

func ParseDNAME(msg []byte, rdataOffset int) (string, error)

ParseDNAME extracts the delegation name from DNAME record RDATA (RFC 6672).

func ParseEDEOption

func ParseEDEOption(data []byte) (infoCode uint16, extraText string, err error)

ParseEDEOption parses an Extended DNS Error option from EDNS0 option data. Returns the info code and extra text.

func ParseNS

func ParseNS(msg []byte, rdataOffset int) (string, error)

ParseNS extracts the nameserver hostname from NS record RDATA.

func ParsePTR

func ParsePTR(msg []byte, rdataOffset int) (string, error)

ParsePTR extracts the pointer domain name from PTR record RDATA.

func ParseTXT

func ParseTXT(rdata []byte) ([]string, error)

ParseTXT extracts character strings from TXT record RDATA.

func TruncateIP

func TruncateIP(ip net.IP, prefixLen uint8) net.IP

TruncateIP truncates an IP address to the given prefix length, zeroing out any bits beyond the prefix.

Types

type DNSKEYRecord

type DNSKEYRecord struct {
	Flags     uint16
	Protocol  uint8
	Algorithm uint8
	PublicKey []byte
}

DNSKEYRecord holds parsed DNSKEY RDATA fields (RFC 4034 Section 2).

func ParseDNSKEY

func ParseDNSKEY(rdata []byte) (*DNSKEYRecord, error)

ParseDNSKEY extracts DNSKEY fields from RDATA.

func (*DNSKEYRecord) IsKSK

func (k *DNSKEYRecord) IsKSK() bool

IsKSK reports whether the key-signing-key flag (SEP bit) is set.

func (*DNSKEYRecord) IsRevoked added in v0.6.13

func (k *DNSKEYRecord) IsRevoked() bool

IsRevoked reports whether the REVOKE flag (RFC 5011 §3, bit 8) is set. A revoked DNSKEY MUST NOT be used to validate signatures or to match DS records — the operator has explicitly disowned that key and the chain must rebuild from the unrevoked siblings. Resolvers that ignore the bit keep accepting signatures from compromised or rolled-out keys.

func (*DNSKEYRecord) IsZoneKey added in v0.6.32

func (k *DNSKEYRecord) IsZoneKey() bool

IsZoneKey reports whether the Zone Key flag (bit 7, value 0x0100) is set. Per RFC 4034 §2.1.1, a DNSKEY whose Zone Key bit is clear holds some other kind of public key (e.g. SIG(0) host keys) and MUST NOT be used to verify RRSIGs that cover RRsets. The validator gates VerifyRRSIG on this.

func (*DNSKEYRecord) KeyTag

func (k *DNSKEYRecord) KeyTag() uint16

KeyTag computes the key tag per RFC 4034 Appendix B.

type DSRecord

type DSRecord struct {
	KeyTag     uint16
	Algorithm  uint8
	DigestType uint8
	Digest     []byte
}

DSRecord holds parsed DS RDATA fields (RFC 4034 Section 5).

func ParseDS

func ParseDS(rdata []byte) (*DSRecord, error)

ParseDS extracts DS fields from RDATA.

type ECSOption

type ECSOption struct {
	Family          uint16 // 1=IPv4, 2=IPv6
	SourcePrefixLen uint8
	ScopePrefixLen  uint8
	Address         net.IP
}

ECSOption represents an EDNS Client Subnet option (RFC 7871, option code 8).

func ExtractECSFromOPT added in v0.6.9

func ExtractECSFromOPT(opt *EDNS0) (*ECSOption, error)

ExtractECSFromOPT walks the OPT record options and returns the first EDNS Client Subnet option found, or nil if none is present. Parse errors are reported so callers can FORMERR-fail a malformed option per RFC 7871 §6 (unrecognized FAMILY → SERVFAIL). Missing-ECS is the common case and returns (nil, nil).

func ParseECS

func ParseECS(data []byte) (*ECSOption, error)

ParseECS parses an EDNS Client Subnet option from EDNS0 option data.

func (*ECSOption) CacheKey added in v0.6.9

func (ecs *ECSOption) CacheKey() string

CacheKey returns the canonical string used to key ECS-scoped cache entries: "<address>/<prefix>" where address is truncated to prefix. Returns "" when ecs is nil or SourcePrefixLen is 0 (global scope), so callers can distinguish global from ECS-scoped entries by emptiness.

type EDNS0

type EDNS0 struct {
	UDPSize  uint16
	ExtRCODE uint8
	Version  uint8
	DOFlag   bool
	Options  []EDNSOption
}

EDNS0 represents parsed EDNS0 extension data.

func ParseOPT

func ParseOPT(rr *ResourceRecord) (*EDNS0, error)

ParseOPT extracts EDNS0 information from an OPT pseudo-record.

type EDNSOption

type EDNSOption struct {
	Code uint16
	Data []byte
}

EDNSOption represents a single EDNS0 option.

func BuildDAUOption added in v0.6.14

func BuildDAUOption(algorithms []uint8) EDNSOption

BuildDAUOption constructs the DNSSEC Algorithm Understood option (RFC 6975) carrying the list of DNSKEY/RRSIG algorithm numbers this resolver can validate. Algorithms we deliberately refuse (RSASHA1 when allowSHA1=false, ED448 until we ship a verifier) are omitted — the spec is explicit that DAU advertises ONLY algorithms the resolver will actually accept.

func BuildDHUOption added in v0.6.14

func BuildDHUOption(digests []uint8) EDNSOption

BuildDHUOption is the DS-hash counterpart of BuildDAUOption.

func BuildECS

func BuildECS(ecs *ECSOption) EDNSOption

BuildECS constructs an EDNS Client Subnet option (RFC 7871, option code 8).

func BuildEDEOption

func BuildEDEOption(infoCode uint16, extraText string) EDNSOption

BuildEDEOption constructs an Extended DNS Error option (RFC 8914, option code 15). infoCode is the EDE info code, extraText is an optional UTF-8 string.

func BuildN3UOption added in v0.6.14

func BuildN3UOption(hashes []uint8) EDNSOption

BuildN3UOption is the NSEC3-hash counterpart of BuildDAUOption.

func BuildPaddingOption added in v0.6.20

func BuildPaddingOption(n int) EDNSOption

BuildPaddingOption constructs an EDNS(0) PADDING option (RFC 7830, option code 12) carrying `n` zero bytes. The option SHOULD be the last option in the OPT RR per RFC 7830 §3 so receivers can ignore trailing zeros without parsing the rest. Only meaningful on encrypted transports (DoT/DoH) — RFC 8467 §6 explicitly disallows padding on plain UDP/TCP since it gives no privacy benefit and wastes bandwidth.

func BuildTCPKeepaliveOption added in v0.6.20

func BuildTCPKeepaliveOption(timeoutUnits100ms uint16) EDNSOption

BuildTCPKeepaliveOption constructs an EDNS(0) edns-tcp-keepalive option (RFC 7828, option code 11). `timeoutUnits100ms` is the idle timeout the server is willing to keep the connection open, expressed in 100-millisecond units (RFC 7828 §3.1). A zero-length data field (length=0) is the client form ("I want to use keepalive"); the server response form MUST carry the 2-byte timeout. This builder produces the server form.

type FlagBuilder

type FlagBuilder struct {
	// contains filtered or unexported fields
}

FlagBuilder provides a builder pattern for constructing DNS header flags.

func NewFlagBuilder

func NewFlagBuilder() *FlagBuilder

func (*FlagBuilder) Build

func (fb *FlagBuilder) Build() uint16

func (*FlagBuilder) SetAA

func (fb *FlagBuilder) SetAA(v bool) *FlagBuilder

func (*FlagBuilder) SetAD

func (fb *FlagBuilder) SetAD(v bool) *FlagBuilder

func (*FlagBuilder) SetCD

func (fb *FlagBuilder) SetCD(v bool) *FlagBuilder

func (*FlagBuilder) SetOpcode

func (fb *FlagBuilder) SetOpcode(v uint8) *FlagBuilder

func (*FlagBuilder) SetQR

func (fb *FlagBuilder) SetQR(v bool) *FlagBuilder

func (*FlagBuilder) SetRA

func (fb *FlagBuilder) SetRA(v bool) *FlagBuilder

func (*FlagBuilder) SetRCODE

func (fb *FlagBuilder) SetRCODE(v uint8) *FlagBuilder

func (*FlagBuilder) SetRD

func (fb *FlagBuilder) SetRD(v bool) *FlagBuilder

func (*FlagBuilder) SetTC

func (fb *FlagBuilder) SetTC(v bool) *FlagBuilder
type Header struct {
	ID      uint16
	Flags   uint16
	QDCount uint16
	ANCount uint16
	NSCount uint16
	ARCount uint16
}

Header represents the fixed 12-byte DNS message header.

func (*Header) AA

func (h *Header) AA() bool

func (*Header) AD

func (h *Header) AD() bool

func (*Header) CD

func (h *Header) CD() bool

func (*Header) Opcode

func (h *Header) Opcode() uint8

func (*Header) Pack

func (h *Header) Pack(w *wireWriter) error

Pack writes the header to a wireWriter.

func (*Header) QR

func (h *Header) QR() bool

func (*Header) RA

func (h *Header) RA() bool

func (*Header) RCODE

func (h *Header) RCODE() uint8

func (*Header) RD

func (h *Header) RD() bool

func (*Header) TC

func (h *Header) TC() bool

func (*Header) Unpack

func (h *Header) Unpack(r *wireReader) error

Unpack reads the header from a wireReader.

type MXRecord

type MXRecord struct {
	Preference uint16
	Exchange   string
}

MXRecord holds parsed MX RDATA fields.

func ParseMX

func ParseMX(msg []byte, rdataOffset int) (*MXRecord, error)

ParseMX extracts preference and exchange from MX record RDATA.

type Message

type Message struct {
	Header     Header
	Questions  []Question
	Answers    []ResourceRecord
	Authority  []ResourceRecord
	Additional []ResourceRecord
	EDNS0      *EDNS0
	// Raw holds the original wire-format bytes (needed for RDATA decompression)
	Raw []byte
}

Message represents a complete DNS message.

func Unpack

func Unpack(buf []byte) (*Message, error)

Unpack parses a DNS message from wire format.

type NSEC3Record

type NSEC3Record struct {
	HashAlgorithm uint8
	Flags         uint8
	Iterations    uint16
	Salt          []byte
	NextHash      []byte
	TypeBitMaps   []uint16
}

NSEC3Record holds parsed NSEC3 RDATA fields (RFC 5155).

func ParseNSEC3

func ParseNSEC3(rdata []byte) (*NSEC3Record, error)

ParseNSEC3 extracts NSEC3 fields from RDATA.

type NSECRecord

type NSECRecord struct {
	NextDomainName string
	TypeBitMaps    []uint16
}

NSECRecord holds parsed NSEC RDATA fields (RFC 4034 Section 4).

func ParseNSEC

func ParseNSEC(rdata []byte, offset int) (*NSECRecord, error)

ParseNSEC extracts NSEC fields from RDATA. The rdata slice must be self-contained (next domain name not compressed). The offset parameter is unused but kept for API consistency; pass 0.

type Question

type Question struct {
	Name  string
	Type  uint16
	Class uint16
}

Question represents a DNS question entry.

func UnpackQuestion

func UnpackQuestion(msg []byte, offset int) (Question, int, error)

UnpackQuestion decodes a question entry from the wire format.

type RRSIGRecord

type RRSIGRecord struct {
	TypeCovered uint16
	Algorithm   uint8
	Labels      uint8
	OrigTTL     uint32
	Expiration  uint32
	Inception   uint32
	KeyTag      uint16
	SignerName  string
	Signature   []byte
}

RRSIGRecord holds parsed RRSIG RDATA fields (RFC 4034 Section 3).

func ParseRRSIG

func ParseRRSIG(rdata []byte, offset int) (*RRSIGRecord, error)

ParseRRSIG extracts RRSIG fields from RDATA. The rdata slice must be self-contained (signer name not compressed). The offset parameter is unused but kept for API consistency with other name-bearing parsers; pass 0.

type ResourceRecord

type ResourceRecord struct {
	Name     string
	Type     uint16
	Class    uint16
	TTL      uint32
	RDLength uint16
	RData    []byte

	// RDataOffset is the offset of this RR's RDATA in the original wire message.
	// Used by type-specific parsers that need the full message for name decompression.
	RDataOffset int
}

ResourceRecord represents a DNS resource record.

func BuildOPT

func BuildOPT(udpSize uint16, doFlag bool) ResourceRecord

BuildOPT creates an OPT pseudo-record for outgoing queries.

func BuildOPTWithOptions

func BuildOPTWithOptions(udpSize uint16, doFlag bool, options []EDNSOption) ResourceRecord

BuildOPTWithOptions creates an OPT pseudo-record with EDNS0 options.

func UnpackRR

func UnpackRR(msg []byte, offset int) (ResourceRecord, int, error)

UnpackRR decodes a resource record from the wire format. For types with compressed domain names in RDATA (NS, CNAME, PTR, MX, SOA, SRV), the names are decompressed during unpack so stored RDATA is self-contained.

type SOARecord

type SOARecord struct {
	MName   string
	RName   string
	Serial  uint32
	Refresh uint32
	Retry   uint32
	Expire  uint32
	Minimum uint32
}

SOARecord holds parsed SOA RDATA fields.

func ParseSOA

func ParseSOA(msg []byte, rdataOffset int) (*SOARecord, error)

ParseSOA extracts all SOA fields from SOA record RDATA.

type SRVRecord

type SRVRecord struct {
	Priority uint16
	Weight   uint16
	Port     uint16
	Target   string
}

SRVRecord holds parsed SRV RDATA fields.

func ParseSRV

func ParseSRV(msg []byte, rdataOffset int) (*SRVRecord, error)

ParseSRV extracts all SRV fields from SRV record RDATA.

Jump to

Keyboard shortcuts

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