Documentation
¶
Index ¶
- Constants
- Variables
- func BuildPlainName(name string) []byte
- func DecodeName(msg []byte, offset int) (string, int, error)
- func EncodeName(w *wireWriter, name string) error
- func EncodeNameToBytes(name string) ([]byte, error)
- func Pack(msg *Message, buf []byte) ([]byte, error)
- func ParseA(rdata []byte) (net.IP, error)
- func ParseAAAA(rdata []byte) (net.IP, error)
- func ParseCNAME(msg []byte, rdataOffset int) (string, error)
- func ParseCookieOption(data []byte) (clientCookie []byte, serverCookie []byte)
- func ParseDNAME(msg []byte, rdataOffset int) (string, error)
- func ParseEDEOption(data []byte) (infoCode uint16, extraText string, err error)
- func ParseNS(msg []byte, rdataOffset int) (string, error)
- func ParsePTR(msg []byte, rdataOffset int) (string, error)
- func ParseTXT(rdata []byte) ([]string, error)
- func TruncateIP(ip net.IP, prefixLen uint8) net.IP
- type DNSKEYRecord
- type DSRecord
- type ECSOption
- type EDNS0
- type EDNSOption
- type FlagBuilder
- func (fb *FlagBuilder) Build() uint16
- func (fb *FlagBuilder) SetAA(v bool) *FlagBuilder
- func (fb *FlagBuilder) SetAD(v bool) *FlagBuilder
- func (fb *FlagBuilder) SetCD(v bool) *FlagBuilder
- func (fb *FlagBuilder) SetOpcode(v uint8) *FlagBuilder
- func (fb *FlagBuilder) SetQR(v bool) *FlagBuilder
- func (fb *FlagBuilder) SetRA(v bool) *FlagBuilder
- func (fb *FlagBuilder) SetRCODE(v uint8) *FlagBuilder
- func (fb *FlagBuilder) SetRD(v bool) *FlagBuilder
- func (fb *FlagBuilder) SetTC(v bool) *FlagBuilder
- type Header
- func (h *Header) AA() bool
- func (h *Header) AD() bool
- func (h *Header) CD() bool
- func (h *Header) Opcode() uint8
- func (h *Header) Pack(w *wireWriter) error
- func (h *Header) QR() bool
- func (h *Header) RA() bool
- func (h *Header) RCODE() uint8
- func (h *Header) RD() bool
- func (h *Header) TC() bool
- func (h *Header) Unpack(r *wireReader) error
- type MXRecord
- type Message
- type NSEC3Record
- type NSECRecord
- type Question
- type RRSIGRecord
- type ResourceRecord
- type SOARecord
- type SRVRecord
Constants ¶
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).
const ( DigestSHA1 uint8 = 1 DigestSHA256 uint8 = 2 DigestSHA384 uint8 = 4 )
DNSSEC digest types (RFC 8624).
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 )
EDE info codes (RFC 8914).
const ( EDNSOptionCodeECS uint16 = 8 EDNSOptionCodeCookie uint16 = 10 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.
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 // 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
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
const ( OpcodeQuery uint8 = 0 OpcodeIQuery uint8 = 1 OpcodeStatus uint8 = 2 )
Opcodes
const (
ClassIN uint16 = 1
)
Classes
Variables ¶
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.
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", TypeANY: "ANY", TypeSVCB: "SVCB", TypeHTTPS: "HTTPS", TypeCAA: "CAA", }
TypeToString maps type values to human-readable names.
Functions ¶
func BuildPlainName ¶
BuildPlainName encodes a domain name as uncompressed wire-format label sequence. Exported for use in tests and delegation handling.
func DecodeName ¶
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 ¶
EncodeName writes a domain name in wire format with optional compression.
func EncodeNameToBytes ¶ added in v0.6.15
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 ParseCNAME ¶
ParseCNAME extracts the canonical name from CNAME record RDATA.
func ParseCookieOption ¶
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 ¶
ParseDNAME extracts the delegation name from DNAME record RDATA (RFC 6672).
func ParseEDEOption ¶
ParseEDEOption parses an Extended DNS Error option from EDNS0 option data. Returns the info code and extra text.
Types ¶
type DNSKEYRecord ¶
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) KeyTag ¶
func (k *DNSKEYRecord) KeyTag() uint16
KeyTag computes the key tag per RFC 4034 Appendix B.
type DSRecord ¶
DSRecord holds parsed DS RDATA fields (RFC 4034 Section 5).
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
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 (*ECSOption) CacheKey ¶ added in v0.6.9
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 ¶
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.
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 ¶
type Header struct {
ID uint16
Flags uint16
QDCount uint16
ANCount uint16
NSCount uint16
ARCount uint16
}
Header represents the fixed 12-byte DNS message header.
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.
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 ¶
NSECRecord holds parsed NSEC RDATA fields (RFC 4034 Section 4).
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.