Imports #
"errors"
"errors"
Question.Class
const ClassANY Class = 255
const ClassCHAOS Class = 3
const ClassCSNET Class = 2
const ClassHESIOD Class = 4
ResourceHeader.Class and Question.Class
const ClassINET Class = 1
ErrNotStarted indicates that the prerequisite information isn't available yet because the previous records haven't been appropriately parsed, skipped or finished.
var ErrNotStarted = *ast.CallExpr
ErrSectionDone indicated that all records in the section have been parsed or finished.
var ErrSectionDone = *ast.CallExpr
Header.RCode values.
const RCodeFormatError RCode = 1
Header.RCode values.
const RCodeNameError RCode = 3
Header.RCode values.
const RCodeNotImplemented RCode = 4
Header.RCode values.
const RCodeRefused RCode = 5
Header.RCode values.
const RCodeServerFailure RCode = 2
Header.RCode values.
const RCodeSuccess RCode = 0
ResourceHeader.Type and Question.Type
const TypeA Type = 1
const TypeAAAA Type = 28
const TypeALL Type = 255
const TypeAXFR Type = 252
const TypeCNAME Type = 5
const TypeHINFO Type = 13
const TypeMINFO Type = 14
const TypeMX Type = 15
const TypeNS Type = 2
const TypeOPT Type = 41
const TypePTR Type = 12
const TypeSOA Type = 6
const TypeSRV Type = 33
const TypeTXT Type = 16
Question.Type
const TypeWKS Type = 11
var classNames = map[Class]string{...}
EDNS(0) wire constants.
const edns0DNSSECOK = 0x00008000
EDNS(0) wire constants.
const edns0DNSSECOKMask = 0x00ff8000
EDNS(0) wire constants.
const edns0Version = 0
EDNS(0) wire constants.
const ednsVersionMask = 0x00ff0000
var errBaseLen = *ast.CallExpr
var errCalcLen = *ast.CallExpr
var errInvalidName = *ast.CallExpr
var errInvalidPtr = *ast.CallExpr
var errNameTooLong = *ast.CallExpr
var errNilResouceBody = *ast.CallExpr
var errNonCanonicalName = *ast.CallExpr
var errResTooLong = *ast.CallExpr
var errReserved = *ast.CallExpr
var errResourceLen = *ast.CallExpr
var errSegTooLong = *ast.CallExpr
var errStringTooLong = *ast.CallExpr
var errTooManyAdditionals = *ast.CallExpr
var errTooManyAnswers = *ast.CallExpr
var errTooManyAuthorities = *ast.CallExpr
var errTooManyPtr = *ast.CallExpr
var errTooManyQuestions = *ast.CallExpr
var errZeroSegLen = *ast.CallExpr
const headerBitAA = *ast.BinaryExpr
const headerBitAD = *ast.BinaryExpr
const headerBitCD = *ast.BinaryExpr
const headerBitQR = *ast.BinaryExpr
const headerBitRA = *ast.BinaryExpr
const headerBitRD = *ast.BinaryExpr
const headerBitTC = *ast.BinaryExpr
headerLen is the length (in bytes) of a DNS header. A header is comprised of 6 uint16s and no padding.
const headerLen = *ast.BinaryExpr
const hexDigits = "0123456789abcdef"
const nonEncodedNameMax = 254
packStartingCap is the default initial buffer size allocated during packing. The starting capacity doesn't matter too much, but most DNS responses Will be <= 512 bytes as it is the limit for DNS over UDP.
const packStartingCap = 512
var rCodeNames = map[RCode]string{...}
const sectionAdditionals
const sectionAnswers
const sectionAuthorities
const sectionDone
const sectionHeader
var sectionNames = map[section]string{...}
const sectionNotStarted section = iota
const sectionQuestions
var typeNames = map[Type]string{...}
uint16Len is the length (in bytes) of a uint16.
const uint16Len = 2
uint32Len is the length (in bytes) of a uint32.
const uint32Len = 4
A Class is a type of network.
type Class uint16
An OpCode is a DNS operation code.
type OpCode uint16
An RCode is a DNS response status code.
type RCode uint16
A Type is a type of DNS request and response.
type Type uint16
type section uint8
A ResourceBody is a DNS resource record minus the header.
type ResourceBody interface {
pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
realType() Type
GoString() string
}
An AAAAResource is an AAAA Resource record.
type AAAAResource struct {
AAAA [16]byte
}
An AResource is an A Resource record.
type AResource struct {
A [4]byte
}
A Builder allows incrementally packing a DNS message. Example usage: buf := make([]byte, 2, 514) b := NewBuilder(buf, Header{...}) b.EnableCompression() // Optionally start a section and add things to that section. // Repeat adding sections as necessary. buf, err := b.Finish() // If err is nil, buf[2:] will contain the built bytes.
type Builder struct {
msg []byte
section section
header header
start int
compression map[string]uint16
}
A CNAMEResource is a CNAME Resource record.
type CNAMEResource struct {
CNAME Name
}
Header is a representation of a DNS message header.
type Header struct {
ID uint16
Response bool
OpCode OpCode
Authoritative bool
Truncated bool
RecursionDesired bool
RecursionAvailable bool
AuthenticData bool
CheckingDisabled bool
RCode RCode
}
An MXResource is an MX Resource record.
type MXResource struct {
Pref uint16
MX Name
}
Message is a representation of a DNS message.
type Message struct {
Header
Questions []Question
Answers []Resource
Authorities []Resource
Additionals []Resource
}
An NSResource is an NS Resource record.
type NSResource struct {
NS Name
}
A Name is a non-encoded and non-escaped domain name. It is used instead of strings to avoid allocations.
type Name struct {
Data [255]byte
Length uint8
}
An OPTResource is an OPT pseudo Resource record. The pseudo resource record is part of the extension mechanisms for DNS as defined in RFC 6891.
type OPTResource struct {
Options []Option
}
An Option represents a DNS message option within OPTResource. The message option is part of the extension mechanisms for DNS as defined in RFC 6891.
type Option struct {
Code uint16
Data []byte
}
A PTRResource is a PTR Resource record.
type PTRResource struct {
PTR Name
}
A Parser allows incrementally parsing a DNS message. When parsing is started, the Header is parsed. Next, each Question can be either parsed or skipped. Alternatively, all Questions can be skipped at once. When all Questions have been parsed, attempting to parse Questions will return the [ErrSectionDone] error. After all Questions have been either parsed or skipped, all Answers, Authorities and Additionals can be either parsed or skipped in the same way, and each type of Resource must be fully parsed or skipped before proceeding to the next type of Resource. Parser is safe to copy to preserve the parsing state. Note that there is no requirement to fully skip or parse the message.
type Parser struct {
msg []byte
header header
section section
off int
index int
resHeaderValid bool
resHeaderOffset int
resHeaderType Type
resHeaderLength uint16
}
A Question is a DNS query.
type Question struct {
Name Name
Type Type
Class Class
}
A Resource is a DNS resource record.
type Resource struct {
Header ResourceHeader
Body ResourceBody
}
A ResourceHeader is the header of a DNS resource record. There are many types of DNS resource records, but they all share the same header.
type ResourceHeader struct {
Name Name
Type Type
Class Class
TTL uint32
Length uint16
}
An SOAResource is an SOA Resource record.
type SOAResource struct {
NS Name
MBox Name
Serial uint32
Refresh uint32
Retry uint32
Expire uint32
MinTTL uint32
}
An SRVResource is an SRV Resource record.
type SRVResource struct {
Priority uint16
Weight uint16
Port uint16
Target Name
}
A TXTResource is a TXT Resource record.
type TXTResource struct {
TXT []string
}
An UnknownResource is a catch-all container for unknown record types.
type UnknownResource struct {
Type Type
Data []byte
}
header is the wire format for a DNS message header.
type header struct {
id uint16
bits uint16
questions uint16
answers uint16
authorities uint16
additionals uint16
}
type nestedError struct {
s string
err error
}
AAAAResource parses a single AAAAResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) AAAAResource() (AAAAResource, error)
AAAAResource adds a single AAAAResource.
func (b *Builder) AAAAResource(h ResourceHeader, r AAAAResource) error
AResource parses a single AResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) AResource() (AResource, error)
AResource adds a single AResource.
func (b *Builder) AResource(h ResourceHeader, r AResource) error
Additional parses a single Additional Resource.
func (p *Parser) Additional() (Resource, error)
AdditionalHeader parses a single Additional ResourceHeader.
func (p *Parser) AdditionalHeader() (ResourceHeader, error)
AllAdditionals parses all Additional Resources.
func (p *Parser) AllAdditionals() ([]Resource, error)
AllAnswers parses all Answer Resources.
func (p *Parser) AllAnswers() ([]Resource, error)
AllAuthorities parses all Authority Resources.
func (p *Parser) AllAuthorities() ([]Resource, error)
AllQuestions parses all Questions.
func (p *Parser) AllQuestions() ([]Question, error)
Answer parses a single Answer Resource.
func (p *Parser) Answer() (Resource, error)
AnswerHeader parses a single Answer ResourceHeader.
func (p *Parser) AnswerHeader() (ResourceHeader, error)
AppendPack is like Pack but appends the full Message to b and returns the extended buffer.
func (m *Message) AppendPack(b []byte) ([]byte, error)
Authority parses a single Authority Resource.
func (p *Parser) Authority() (Resource, error)
AuthorityHeader parses a single Authority ResourceHeader.
func (p *Parser) AuthorityHeader() (ResourceHeader, error)
CNAMEResource adds a single CNAMEResource.
func (b *Builder) CNAMEResource(h ResourceHeader, r CNAMEResource) error
CNAMEResource parses a single CNAMEResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) CNAMEResource() (CNAMEResource, error)
DNSSECAllowed reports whether the DNSSEC OK bit is set.
func (h *ResourceHeader) DNSSECAllowed() bool
EnableCompression enables compression in the Builder. Leaving compression disabled avoids compression related allocations, but can result in larger message sizes. Be careful with this mode as it can cause messages to exceed the UDP size limit. According to RFC 1035, section 4.1.4, the use of compression is optional, but all implementations must accept both compressed and uncompressed DNS messages. Compression should be enabled before any sections are added for best results.
func (b *Builder) EnableCompression()
nestedError implements error.Error.
func (e *nestedError) Error() string
ExtendedRCode returns an extended RCode. The provided rcode must be the RCode in DNS message header.
func (h *ResourceHeader) ExtendedRCode(rcode RCode) RCode
Finish ends message building and generates a binary message.
func (b *Builder) Finish() ([]byte, error)
GoString implements fmt.GoStringer.GoString.
func (m *Header) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *AAAAResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (t Type) GoString() string
func (r *Resource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *UnknownResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (h *ResourceHeader) GoString() string
GoString implements fmt.GoStringer.GoString.
func (m *Message) GoString() string
GoString implements fmt.GoStringer.GoString.
func (n *Name) GoString() string
GoString implements fmt.GoStringer.GoString.
func (q *Question) GoString() string
GoString implements fmt.GoStringer.GoString.
func (c Class) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *CNAMEResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *MXResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (o OpCode) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *NSResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *OPTResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *PTRResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *SOAResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *TXTResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *SRVResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r RCode) GoString() string
GoString implements fmt.GoStringer.GoString.
func (r *AResource) GoString() string
GoString implements fmt.GoStringer.GoString.
func (o *Option) GoString() string
MXResource adds a single MXResource.
func (b *Builder) MXResource(h ResourceHeader, r MXResource) error
MXResource parses a single MXResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) MXResource() (MXResource, error)
MustNewName creates a new Name from a string and panics on error.
func MustNewName(name string) Name
NSResource parses a single NSResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) NSResource() (NSResource, error)
NSResource adds a single NSResource.
func (b *Builder) NSResource(h ResourceHeader, r NSResource) error
NewBuilder creates a new builder with compression disabled. Note: Most users will want to immediately enable compression with the EnableCompression method. See that method's comment for why you may or may not want to enable compression. The DNS message is appended to the provided initial buffer buf (which may be nil) as it is built. The final message is returned by the (*Builder).Finish method, which includes buf[:len(buf)] and may return the same underlying array if there was sufficient capacity in the slice.
func NewBuilder(buf []byte, h Header) Builder
NewName creates a new Name from a string.
func NewName(name string) (Name, error)
OPTResource parses a single OPTResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) OPTResource() (OPTResource, error)
OPTResource adds a single OPTResource.
func (b *Builder) OPTResource(h ResourceHeader, r OPTResource) error
PTRResource parses a single PTRResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) PTRResource() (PTRResource, error)
PTRResource adds a single PTRResource.
func (b *Builder) PTRResource(h ResourceHeader, r PTRResource) error
Pack packs a full Message.
func (m *Message) Pack() ([]byte, error)
Question adds a single Question.
func (b *Builder) Question(q Question) error
Question parses a single Question.
func (p *Parser) Question() (Question, error)
SOAResource adds a single SOAResource.
func (b *Builder) SOAResource(h ResourceHeader, r SOAResource) error
SOAResource parses a single SOAResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) SOAResource() (SOAResource, error)
SRVResource parses a single SRVResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) SRVResource() (SRVResource, error)
SRVResource adds a single SRVResource.
func (b *Builder) SRVResource(h ResourceHeader, r SRVResource) error
SetEDNS0 configures h for EDNS(0). The provided extRCode must be an extended RCode.
func (h *ResourceHeader) SetEDNS0(udpPayloadLen int, extRCode RCode, dnssecOK bool) error
SkipAdditional skips a single Additional Resource. It does not perform a complete validation of the resource header, which means it may return a nil error when the [AdditionalHeader] would actually return an error.
func (p *Parser) SkipAdditional() error
SkipAllAdditionals skips all Additional Resources.
func (p *Parser) SkipAllAdditionals() error
SkipAllAnswers skips all Answer Resources.
func (p *Parser) SkipAllAnswers() error
SkipAllAuthorities skips all Authority Resources.
func (p *Parser) SkipAllAuthorities() error
SkipAllQuestions skips all Questions.
func (p *Parser) SkipAllQuestions() error
SkipAnswer skips a single Answer Resource. It does not perform a complete validation of the resource header, which means it may return a nil error when the [AnswerHeader] would actually return an error.
func (p *Parser) SkipAnswer() error
SkipAuthority skips a single Authority Resource. It does not perform a complete validation of the resource header, which means it may return a nil error when the [AuthorityHeader] would actually return an error.
func (p *Parser) SkipAuthority() error
SkipQuestion skips a single Question.
func (p *Parser) SkipQuestion() error
Start parses the header and enables the parsing of Questions.
func (p *Parser) Start(msg []byte) (Header, error)
StartAdditionals prepares the builder for packing Additionals.
func (b *Builder) StartAdditionals() error
StartAnswers prepares the builder for packing Answers.
func (b *Builder) StartAnswers() error
StartAuthorities prepares the builder for packing Authorities.
func (b *Builder) StartAuthorities() error
StartQuestions prepares the builder for packing Questions.
func (b *Builder) StartQuestions() error
String implements fmt.Stringer.String.
func (c Class) String() string
String implements fmt.Stringer.String.
func (r RCode) String() string
String implements fmt.Stringer.String.
func (t Type) String() string
String implements fmt.Stringer.String. Note: characters inside the labels are not escaped in any way.
func (n Name) String() string
TXTResource parses a single TXTResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) TXTResource() (TXTResource, error)
TXTResource adds a single TXTResource.
func (b *Builder) TXTResource(h ResourceHeader, r TXTResource) error
UnknownResource parses a single UnknownResource. One of the XXXHeader methods must have been called before calling this method.
func (p *Parser) UnknownResource() (UnknownResource, error)
UnknownResource adds a single UnknownResource.
func (b *Builder) UnknownResource(h ResourceHeader, r UnknownResource) error
Unpack parses a full Message.
func (m *Message) Unpack(msg []byte) error
func (p *Parser) checkAdvance(sec section) error
func (b *Builder) checkResourceSection() error
func (h *header) count(sec section) uint16
fixLen updates a packed ResourceHeader to include the length of the ResourceBody. lenOff is the offset of the ResourceHeader.Length field in msg. preLen is the length that msg was before the ResourceBody was packed.
func (h *ResourceHeader) fixLen(msg []byte, lenOff int, preLen int) error
func (h *header) header() Header
func (b *Builder) incrementSectionCount() error
pack appends the wire format of the AAAAResource to msg.
func (r *AAAAResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the TXTResource to msg.
func (r *TXTResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the header to msg.
func (h *header) pack(msg []byte) []byte
pack appends the wire format of the AResource to msg.
func (r *AResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the MXResource to msg.
func (r *MXResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the Question to msg.
func (q *Question) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the SRVResource to msg.
func (r *SRVResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the UnknownResource to msg.
func (r *UnknownResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the CNAMEResource to msg.
func (r *CNAMEResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the Resource to msg.
func (r *Resource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the NSResource to msg.
func (r *NSResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the SOAResource to msg.
func (r *SOAResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the Name to msg. Domain names are a sequence of counted strings split at the dots. They end with a zero-length string. Compression can be used to reuse domain suffixes. The compression map will be updated with new domain suffixes. If compression is nil, compression will not be used.
func (n *Name) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
pack appends the wire format of the ResourceHeader to oldMsg. lenOff is the offset in msg where the Length field was packed.
func (h *ResourceHeader) pack(oldMsg []byte, compression map[string]uint16, compressionOff int) (msg []byte, lenOff int, err error)
pack appends the wire format of the PTRResource to msg.
func (r *PTRResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
func (r *OPTResource) pack(msg []byte, compression map[string]uint16, compressionOff int) ([]byte, error)
func (m *Header) pack() (id uint16, bits uint16)
packBytes appends the wire format of field to msg.
func packBytes(msg []byte, field []byte) []byte
packClass appends the wire format of field to msg.
func packClass(msg []byte, field Class) []byte
packText appends the wire format of field to msg.
func packText(msg []byte, field string) ([]byte, error)
packType appends the wire format of field to msg.
func packType(msg []byte, field Type) []byte
packUint16 appends the wire format of field to msg.
func packUint16(msg []byte, field uint16) []byte
packUint32 appends the wire format of field to msg.
func packUint32(msg []byte, field uint32) []byte
func printBool(b bool) string
func printByteSlice(b []byte) string
func printPaddedUint8(i uint8) string
func printString(str []byte) string
func printUint16(i uint16) string
func printUint32(i uint32) string
func printUint8Bytes(buf []byte, i uint8) []byte
func (r *CNAMEResource) realType() Type
func (r *AResource) realType() Type
func (r *OPTResource) realType() Type
func (r *TXTResource) realType() Type
func (r *SOAResource) realType() Type
func (r *NSResource) realType() Type
func (r *SRVResource) realType() Type
func (r *UnknownResource) realType() Type
func (r *AAAAResource) realType() Type
func (r *PTRResource) realType() Type
func (r *MXResource) realType() Type
func (p *Parser) resource(sec section) (Resource, error)
func (p *Parser) resourceHeader(sec section) (ResourceHeader, error)
func skipClass(msg []byte, off int) (int, error)
func skipName(msg []byte, off int) (int, error)
func skipResource(msg []byte, off int) (int, error)
func (p *Parser) skipResource(sec section) error
func skipType(msg []byte, off int) (int, error)
func skipUint16(msg []byte, off int) (int, error)
func skipUint32(msg []byte, off int) (int, error)
func (b *Builder) startCheck(s section) error
func (h *header) unpack(msg []byte, off int) (int, error)
unpack unpacks a domain name.
func (n *Name) unpack(msg []byte, off int) (int, error)
func (h *ResourceHeader) unpack(msg []byte, off int) (int, error)
func unpackAAAAResource(msg []byte, off int) (AAAAResource, error)
func unpackAResource(msg []byte, off int) (AResource, error)
func unpackBytes(msg []byte, off int, field []byte) (int, error)
func unpackCNAMEResource(msg []byte, off int) (CNAMEResource, error)
func unpackClass(msg []byte, off int) (Class, int, error)
func unpackMXResource(msg []byte, off int) (MXResource, error)
func unpackNSResource(msg []byte, off int) (NSResource, error)
func unpackOPTResource(msg []byte, off int, length uint16) (OPTResource, error)
func unpackPTRResource(msg []byte, off int) (PTRResource, error)
func unpackResourceBody(msg []byte, off int, hdr ResourceHeader) (ResourceBody, int, error)
func unpackSOAResource(msg []byte, off int) (SOAResource, error)
func unpackSRVResource(msg []byte, off int) (SRVResource, error)
func unpackTXTResource(msg []byte, off int, length uint16) (TXTResource, error)
func unpackText(msg []byte, off int) (string, int, error)
func unpackType(msg []byte, off int) (Type, int, error)
func unpackUint16(msg []byte, off int) (uint16, int, error)
func unpackUint32(msg []byte, off int) (uint32, int, error)
func unpackUnknownResource(recordType Type, msg []byte, off int, length uint16) (UnknownResource, error)
Generated with Arrow