Documentation
¶
Index ¶
- Constants
- Variables
- func AcquireBuffer() *[]byte
- func DecodeDomain(domain []byte) []byte
- func EncodeDomain(dst []byte, domain string) []byte
- func ReleaseBuffer(b *[]byte)
- func ReleaseRequest(msg *Request)
- func ReleaseResponse(msg *Response)
- func UnpackDomainName(msg []byte, off int) ([]byte, int, error)
- type A
- type AAAA
- type CNAME
- type Class
- type Error
- type Header
- func (h *Header) AuthenticatedData() bool
- func (h *Header) Authoritative() bool
- func (h *Header) CheckingDisabled() bool
- func (h *Header) OpCode() Opcode
- func (h *Header) Pack() [headerSize]byte
- func (h *Header) Rcode() Rcode
- func (h *Header) RecursionAvailable() bool
- func (h *Header) RecursionDesired() bool
- func (h *Header) Response() bool
- func (h *Header) SetAuthenticatedData()
- func (h *Header) SetAuthoritative()
- func (h *Header) SetCheckingDisabled()
- func (h *Header) SetOpCode(op Opcode)
- func (h *Header) SetRcode(rcode Rcode)
- func (h *Header) SetRecursionAvailable()
- func (h *Header) SetRecursionDesired()
- func (h *Header) SetResponse()
- func (h *Header) SetTruncated()
- func (h *Header) SetZero()
- func (h *Header) String() string
- func (h *Header) Truncated() bool
- func (h *Header) Unpack(b []byte) error
- func (h *Header) Zero() bool
- type MX
- type NS
- type Name
- type OPT
- type Opcode
- type Option
- type OptionCode
- type PTR
- type Question
- type RFC3597
- type RR
- type RR_Header
- type Rcode
- type Request
- func (r *Request) Reset()
- func (r *Request) SetEDNS0(maxSize uint16, do bool)
- func (r *Request) SetEDNS0Chain(chain []byte)
- func (r *Request) SetEDNS0ClientSubnet(clientSubnet netip.Prefix) error
- func (r *Request) SetEDNS0Cookie(cookie []byte)
- func (r *Request) SetEDNS0Keepalive(timeout uint16)
- func (r *Request) SetEDNS0NSID(nsid string)
- func (r *Request) SetEDNS0Padding(size int)
- func (r *Request) SetQuestion(domain string, typ Type, class Class)
- func (r *Request) Unpack(payload []byte) error
- type Response
- type SOA
- type SRV
- type TXT
- type Type
Constants ¶
const ( TypeNone Type = 0 TypeA Type = 1 TypeNS Type = 2 TypeMD Type = 3 TypeMF Type = 4 TypeCNAME Type = 5 TypeSOA Type = 6 TypeMB Type = 7 TypeMG Type = 8 TypeMR Type = 9 TypeNULL Type = 10 TypePTR Type = 12 TypeHINFO Type = 13 TypeMINFO Type = 14 TypeMX Type = 15 TypeTXT Type = 16 TypeRP Type = 17 TypeAFSDB Type = 18 TypeX25 Type = 19 TypeISDN Type = 20 TypeRT Type = 21 TypeNSAPPTR Type = 23 TypeSIG Type = 24 TypeKEY Type = 25 TypePX Type = 26 TypeGPOS Type = 27 TypeAAAA Type = 28 TypeLOC Type = 29 TypeNXT Type = 30 TypeEID Type = 31 TypeNIMLOC Type = 32 TypeSRV Type = 33 TypeATMA Type = 34 TypeNAPTR Type = 35 TypeKX Type = 36 TypeCERT Type = 37 TypeDNAME Type = 39 TypeOPT Type = 41 // EDNS TypeAPL Type = 42 TypeDS Type = 43 TypeSSHFP Type = 44 TypeIPSECKEY Type = 45 TypeRRSIG Type = 46 TypeNSEC Type = 47 TypeDNSKEY Type = 48 TypeDHCID Type = 49 TypeNSEC3 Type = 50 TypeNSEC3PARAM Type = 51 TypeTLSA Type = 52 TypeSMIMEA Type = 53 TypeHIP Type = 55 TypeNINFO Type = 56 TypeRKEY Type = 57 TypeTALINK Type = 58 TypeCDS Type = 59 TypeCDNSKEY Type = 60 TypeOPENPGPKEY Type = 61 TypeCSYNC Type = 62 TypeZONEMD Type = 63 TypeSVCB Type = 64 TypeHTTPS Type = 65 TypeSPF Type = 99 TypeUINFO Type = 100 TypeUID Type = 101 TypeGID Type = 102 TypeUNSPEC Type = 103 TypeNID Type = 104 TypeL32 Type = 105 TypeL64 Type = 106 TypeLP Type = 107 TypeEUI48 Type = 108 TypeEUI64 Type = 109 TypeURI Type = 256 TypeCAA Type = 257 TypeAVC Type = 258 TypeAMTRELAY Type = 260 TypeTKEY Type = 249 TypeTSIG Type = 250 // valid Question.Qtype only TypeIXFR Type = 251 TypeAXFR Type = 252 TypeMAILB Type = 253 TypeMAILA Type = 254 TypeANY Type = 255 TypeTA Type = 32768 TypeDLV Type = 32769 TypeReserved Type = 65535 // valid Question.Qclass ClassINET Class = 1 ClassCSNET Class = 2 ClassCHAOS Class = 3 ClassHESIOD Class = 4 ClassNONE Class = 254 ClassANY Class = 255 )
Wire constants and supported types.
Variables ¶
var ( ErrBuf error = errors.New("buffer size too small") // ErrBuf indicates that the buffer used is too small for the message. ErrLongDomain error = fmt.Errorf("domain name exceeded %d wire-format octets", maxDomainNameWireOctets) ErrRdata error = errors.New("dns: invalid rdata in message") )
var ( // ErrInvalidHeader is returned when dns message does not have the expected header size. ErrInvalidHeader = errors.New("dns message does not have the expected header size") // ErrInvalidQuestion is returned when dns message does not have the expected question size. ErrInvalidQuestion = errors.New("dns message does not have the expected question size") // ErrInvalidAnswer is returned when dns message does not have the expected answer size. ErrInvalidAnswer = errors.New("dns message does not have the expected answer size") // ErrInvalidOPT is returned when dns message does not have the expected OPT size. ErrInvalidOPT = errors.New("dns message does not have the expected OPT size") //ErrInvalidRR is returned when dns message does not have the expected RR size. ErrInvalidRR = errors.New("dns message does not have the expected RR size") )
var ClassToString = map[Class]string{ ClassINET: "IN", ClassCSNET: "CS", ClassCHAOS: "CH", ClassHESIOD: "HS", ClassNONE: "NONE", ClassANY: "ANY", }
ClassToString is a maps Classes to strings for each CLASS wire type.
var OpcodeToString = map[Opcode]string{ OpcodeQuery: "QUERY", OpcodeIQuery: "IQUERY", OpcodeStatus: "STATUS", OpcodeNotify: "NOTIFY", OpcodeUpdate: "UPDATE", }
OpcodeToString maps Opcodes to strings.
var RcodeToString = map[Rcode]string{ RcodeSuccess: "NOERROR", RcodeFormatError: "FORMERR", RcodeServerFailure: "SERVFAIL", RcodeNameError: "NXDOMAIN", RcodeNotImplemented: "NOTIMP", RcodeRefused: "REFUSED", RcodeYXDomain: "YXDOMAIN", RcodeYXRrset: "YXRRSET", RcodeNXRrset: "NXRRSET", RcodeNotAuth: "NOTAUTH", RcodeNotZone: "NOTZONE", RcodeBadSig: "BADSIG", RcodeBadKey: "BADKEY", RcodeBadTime: "BADTIME", RcodeBadMode: "BADMODE", RcodeBadName: "BADNAME", RcodeBadAlg: "BADALG", RcodeBadTrunc: "BADTRUNC", RcodeBadCookie: "BADCOOKIE", }
RcodeToString maps Rcodes to strings.
var TypeToRR = map[Type]func() RR{ TypeA: func() RR { return new(A) }, TypeNS: func() RR { return new(NS) }, TypeCNAME: func() RR { return new(CNAME) }, TypeSOA: func() RR { return new(SOA) }, TypePTR: func() RR { return new(PTR) }, TypeMX: func() RR { return new(MX) }, TypeTXT: func() RR { return new(TXT) }, TypeSRV: func() RR { return new(SRV) }, TypeAAAA: func() RR { return new(AAAA) }, TypeOPT: func() RR { return new(OPT) }, }
TypeToRR is a map of constructors for each RR type.
Functions ¶
func DecodeDomain ¶
func EncodeDomain ¶
EncodeDomain encodes domain to dst. If dst has enough capacity, this will be zero-allocation.
func ReleaseRequest ¶
func ReleaseRequest(msg *Request)
ReleaseRequest returnes the dns request to the pool.
func ReleaseResponse ¶
func ReleaseResponse(msg *Response)
ReleaseResponse returnes the dns response to the pool.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents a DNS error.
type Header ¶
type Header struct {
ID uint16
// Flags is an arbitrary 16bit represents QR, Opcode, AA, TC, RD, RA, Z and RCODE.
//
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// |QR| Opcode |AA|TC|RD|RA| Z | RCODE |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
Bits uint16
// Qdcount specifies the number of entries in the question section
// Ancount specifies the number of resource records in the answer section
// Nscount specifies the number of name server resource records in the authority records section
// Arcount specifies the number of resource records in the additional records section
Qdcount, Ancount, Nscount, Arcount uint16
}
Header is the wire format for the DNS packet header.
func (*Header) AuthenticatedData ¶
func (*Header) Authoritative ¶
func (*Header) CheckingDisabled ¶
func (*Header) RecursionAvailable ¶
func (*Header) RecursionDesired ¶
func (*Header) SetAuthenticatedData ¶
func (h *Header) SetAuthenticatedData()
func (*Header) SetAuthoritative ¶
func (h *Header) SetAuthoritative()
func (*Header) SetCheckingDisabled ¶
func (h *Header) SetCheckingDisabled()
func (*Header) SetRecursionAvailable ¶
func (h *Header) SetRecursionAvailable()
func (*Header) SetRecursionDesired ¶
func (h *Header) SetRecursionDesired()
func (*Header) SetResponse ¶
func (h *Header) SetResponse()
func (*Header) SetTruncated ¶
func (h *Header) SetTruncated()
type Name ¶
A Name is a non-encoded and non-escaped domain name. It is used instead of strings to avoid allocations.
type OPT ¶
type OPT struct {
// Name string
// Type Type
// MaxSize uint16
// TTL uint32
// RDLength uint16
Options []Option
Hdr RR_Header
}
func (*OPT) AddOption ¶
func (r *OPT) AddOption(code OptionCode, data []byte)
type Opcode ¶
type Opcode byte
Opcode denotes a 4bit field that specified the query type.
type Option ¶
type Option struct {
Data []byte
Code OptionCode
Length uint16
}
type OptionCode ¶
type OptionCode uint16
OptionCode represents the code of a DNS Option, see RFC6891, section 6.1.2
const ( OptionCodeNSID OptionCode = 3 OptionCodeDAU OptionCode = 5 OptionCodeDHU OptionCode = 6 OptionCodeN3U OptionCode = 7 OptionCodeEDNSClientSubnet OptionCode = 8 OptionCodeEDNSExpire OptionCode = 9 OptionCodeCookie OptionCode = 10 OptionCodeEDNSKeepAlive OptionCode = 11 OptionCodePadding OptionCode = 12 OptionCodeChain OptionCode = 13 OptionCodeEDNSKeyTag OptionCode = 14 OptionCodeEDNSClientTag OptionCode = 16 OptionCodeEDNSServerTag OptionCode = 17 OptionCodeDeviceID OptionCode = 26946 )
OptionCode known values. See IANA
func (OptionCode) String ¶
func (c OptionCode) String() string
type PTR ¶
PTR record (Pointer) RFC 1035, section 3.3.12
type Question ¶
type Question struct {
// Name refers to the raw query name to be resolved in the query.
//
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | |
// / QNAME /
// / /
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
Name []byte
// Type specifies the type of the query to perform.
//
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | QTYPE |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
Type Type
// Class specifies the class of the query to perform.
//
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
// | QCLASS |
// +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
Class Class
}
type RR ¶
type RR interface {
Header() *RR_Header
String() string
// contains filtered or unexported methods
}
type RR_Header ¶
type Rcode ¶
type Rcode uint16
const ( // Message Response Codes, see https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml RcodeSuccess Rcode = 0 // NoError - No Error [DNS] RcodeFormatError Rcode = 1 // FormErr - Format Error [DNS] RcodeServerFailure Rcode = 2 // ServFail - Server Failure [DNS] RcodeNameError Rcode = 3 // NXDomain - Non-Existent Domain [DNS] RcodeNotImplemented Rcode = 4 // NotImp - Not Implemented [DNS] RcodeRefused Rcode = 5 // Refused - Query Refused [DNS] RcodeYXDomain Rcode = 6 // YXDomain - Name Exists when it should not [DNS Update] RcodeYXRrset Rcode = 7 // YXRRSet - RR Set Exists when it should not [DNS Update] RcodeNXRrset Rcode = 8 // NXRRSet - RR Set that should exist does not [DNS Update] RcodeNotAuth Rcode = 9 // NotAuth - Server Not Authoritative for zone [DNS Update] RcodeNotZone Rcode = 10 // NotZone - Name not contained in zone [DNS Update/TSIG] RcodeBadSig Rcode = 16 // BADSIG - TSIG Signature Failure [TSIG] https://www.rfc-editor.org/rfc/rfc6895.html#section-2.3 RcodeBadVers Rcode = 16 // BADVERS - Bad OPT Version [EDNS0] https://www.rfc-editor.org/rfc/rfc6895.html#section-2.3 RcodeBadKey Rcode = 17 // BADKEY - Key not recognized [TSIG] RcodeBadTime Rcode = 18 // BADTIME - Signature out of time window [TSIG] RcodeBadMode Rcode = 19 // BADMODE - Bad TKEY Mode [TKEY] RcodeBadName Rcode = 20 // BADNAME - Duplicate key name [TKEY] RcodeBadAlg Rcode = 21 // BADALG - Algorithm not supported [TKEY] RcodeBadTrunc Rcode = 22 // BADTRUNC - Bad Truncation [TSIG] RcodeBadCookie Rcode = 23 // BADCOOKIE - Bad/missing Server Cookie [DNS Cookies] )
type Request ¶
func (*Request) SetEDNS0Chain ¶
func (*Request) SetEDNS0ClientSubnet ¶
// e.Code = dns.EDNS0SUBNET // by default this is filled in through unpacking OPT packets (unpackDataOpt) // e.Family = 1 // 1 for IPv4 source address, 2 for IPv6 // e.SourceNetmask = 32 // 32 for IPV4, 128 for IPv6 // e.SourceScope = 0 // e.Address = net.ParseIP("127.0.0.1").To4() // for IPv4 // // e.Address = net.ParseIP("2001:7b8:32a::2") // for IPV6
func (*Request) SetEDNS0Cookie ¶
func (*Request) SetEDNS0Keepalive ¶
func (*Request) SetEDNS0NSID ¶
func (*Request) SetEDNS0Padding ¶
type Response ¶
type SOA ¶
type SOA struct {
Hdr RR_Header
Ns string // Primary name server
Mbox string // Responsible mailbox
Serial uint32 // Serial number
Refresh uint32 // Refresh interval
Retry uint32 // Retry interval
Expire uint32 // Expire limit
Minttl uint32 // Minimum TTL
}
SOA record (Start of Authority) RFC 1035, section 3.3.13
type SRV ¶
type SRV struct {
Hdr RR_Header
Priority uint16 // Priority
Weight uint16 // Weight
Port uint16 // Port
Target string // Target domain name
}
SRV record (Service) RFC 2782