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 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 )
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 )
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", }
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 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) 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 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.
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.