Documentation ¶
Index ¶
- Constants
- Variables
- func Parse(msg []byte) (Parser, Header, error)
- type AddressFamily
- type Bit
- type Builder
- func (b *Builder) Bytes() []byte
- func (b *Builder) Header() Header
- func (b *Builder) Length() int
- func (b *Builder) LimitMessageSize(size int)
- func (b *Builder) Question(q Question) error
- func (b *Builder) RDBuilder(hdr ResourceHeader) (RDBuilder, error)
- func (b *Builder) RawResourceTXT(hdr ResourceHeader, txt RawResourceTXT) error
- func (b *Builder) Reset(buf []byte, id uint16, flags Flags)
- func (b *Builder) ResourceA(hdr ResourceHeader, a ResourceA) error
- func (b *Builder) ResourceAAAA(hdr ResourceHeader, aaaa ResourceAAAA) error
- func (b *Builder) ResourceCNAME(hdr ResourceHeader, cname ResourceCNAME) error
- func (b *Builder) ResourceMX(hdr ResourceHeader, mx ResourceMX) error
- func (b *Builder) ResourceNS(hdr ResourceHeader, ns ResourceNS) error
- func (b *Builder) ResourceOPT(hdr ResourceHeader, opt ResourceOPT) error
- func (b *Builder) ResourceOPTBuilder(hdr ResourceHeader) (ResourceOPTBuilder, error)
- func (b *Builder) ResourcePTR(hdr ResourceHeader, ptr ResourcePTR) error
- func (b *Builder) ResourceSOA(hdr ResourceHeader, soa ResourceSOA) error
- func (b *Builder) ResourceTXT(hdr ResourceHeader, txt ResourceTXT) error
- func (b *Builder) SetFlags(flags Flags)
- func (b *Builder) SetID(id uint16)
- func (b *Builder) StartAdditionals()
- func (b *Builder) StartAnswers()
- func (b *Builder) StartAuthorities()
- type Class
- type Compression
- type EDNS0ClientSubnet
- type EDNS0Cookie
- type EDNS0ExtendedDNSError
- type EDNS0Header
- type EDNS0Option
- type EDNS0OptionBuilder
- func (b *EDNS0OptionBuilder) Bytes(raw []byte) error
- func (b *EDNS0OptionBuilder) End()
- func (b *EDNS0OptionBuilder) Length() uint16
- func (b *EDNS0OptionBuilder) Name(name Name, compress bool) error
- func (b *EDNS0OptionBuilder) Remove()
- func (b *EDNS0OptionBuilder) Uint16(val uint16) error
- func (b *EDNS0OptionBuilder) Uint32(val uint32) error
- func (b *EDNS0OptionBuilder) Uint64(val uint64) error
- func (b *EDNS0OptionBuilder) Uint8(val uint8) error
- type EDNS0OptionCode
- type EDNS0OptionParser
- func (p *EDNS0OptionParser) AllBytes() []byte
- func (p *EDNS0OptionParser) Bytes(n int) ([]byte, error)
- func (p *EDNS0OptionParser) End() error
- func (p *EDNS0OptionParser) Length() uint16
- func (p *EDNS0OptionParser) Name() (Name, error)
- func (p *EDNS0OptionParser) Uint16() (uint16, error)
- func (p *EDNS0OptionParser) Uint32() (uint32, error)
- func (p *EDNS0OptionParser) Uint64() (uint64, error)
- func (p *EDNS0OptionParser) Uint8() (uint8, error)
- type ExtendedDNSErrorCode
- type ExtendedFlags
- type ExtendedRCode
- type Flags
- func (f Flags) Bit(bit Bit) bool
- func (f Flags) OpCode() OpCode
- func (f Flags) Query() bool
- func (f Flags) RCode() RCode
- func (f Flags) Response() bool
- func (f *Flags) SetBit(bit Bit, val bool)
- func (f *Flags) SetOpCode(o OpCode)
- func (f *Flags) SetQuery()
- func (f *Flags) SetRCode(r RCode)
- func (f *Flags) SetResponse()
- type Header
- type Name
- type OpCode
- type Parser
- func (p *Parser) End() error
- func (m *Parser) Question() (Question, error)
- func (m *Parser) RDParser() (RDParser, error)
- func (m *Parser) RawResourceTXT() (RawResourceTXT, error)
- func (m *Parser) ResourceA() (ResourceA, error)
- func (m *Parser) ResourceAAAA() (ResourceAAAA, error)
- func (m *Parser) ResourceCNAME() (ResourceCNAME, error)
- func (m *Parser) ResourceHeader() (ResourceHeader, error)
- func (m *Parser) ResourceMX() (ResourceMX, error)
- func (m *Parser) ResourceNS() (ResourceNS, error)
- func (p *Parser) ResourceOPT() (ResourceOPT, error)
- func (m *Parser) ResourceOPTParser() (ResourceOPTParser, error)
- func (m *Parser) ResourcePTR() (ResourcePTR, error)
- func (m *Parser) ResourceSOA() (ResourceSOA, error)
- func (p *Parser) SkipQuestions() error
- func (m *Parser) SkipResourceData() error
- func (p *Parser) SkipResources() error
- func (p *Parser) StartAdditionals() error
- func (p *Parser) StartAnswers() error
- func (p *Parser) StartAuthorities() error
- type PartialExtendedRCode
- type Question
- type RCode
- type RDBuilder
- func (b *RDBuilder) Bytes(raw []byte) error
- func (b *RDBuilder) End()
- func (b *RDBuilder) Length() uint16
- func (b *RDBuilder) Name(name Name, compress bool) error
- func (b *RDBuilder) Remove()
- func (b *RDBuilder) Uint16(val uint16) error
- func (b *RDBuilder) Uint32(val uint32) error
- func (b *RDBuilder) Uint64(val uint64) error
- func (b *RDBuilder) Uint8(val uint8) error
- type RDParser
- func (p *RDParser) AllBytes() []byte
- func (p *RDParser) Bytes(n int) ([]byte, error)
- func (p *RDParser) End() error
- func (p *RDParser) Length() uint16
- func (p *RDParser) Name() (Name, error)
- func (p *RDParser) Uint16() (uint16, error)
- func (p *RDParser) Uint32() (uint32, error)
- func (p *RDParser) Uint64() (uint64, error)
- func (p *RDParser) Uint8() (uint8, error)
- type RawResourceTXT
- type ResourceA
- type ResourceAAAA
- type ResourceCNAME
- type ResourceHeader
- type ResourceMX
- type ResourceNS
- type ResourceOPT
- type ResourceOPTBuilder
- func (b *ResourceOPTBuilder) ClientSubnet(opt EDNS0ClientSubnet) error
- func (b *ResourceOPTBuilder) Cookie(opt EDNS0Cookie) error
- func (b *ResourceOPTBuilder) End()
- func (b *ResourceOPTBuilder) ExtendedDNSError(opt EDNS0ExtendedDNSError) error
- func (b *ResourceOPTBuilder) Length() uint16
- func (b *ResourceOPTBuilder) OptionBuilder(code EDNS0OptionCode) (EDNS0OptionBuilder, error)
- func (b *ResourceOPTBuilder) Remove()
- type ResourceOPTParser
- func (p *ResourceOPTParser) ClientSubnet() (EDNS0ClientSubnet, error)
- func (p *ResourceOPTParser) Code() (EDNS0OptionCode, error)
- func (p *ResourceOPTParser) Cookie() (EDNS0Cookie, error)
- func (p *ResourceOPTParser) ExtendedDNSError() (EDNS0ExtendedDNSError, error)
- func (p *ResourceOPTParser) OptionParser() (EDNS0OptionParser, error)
- func (p *ResourceOPTParser) Skip() error
- type ResourcePTR
- type ResourceSOA
- type ResourceTXT
- type Type
Constants ¶
const ( // EDNS0HeaderEncodingLength is a length required to encode a resource with a resource header // created by [EDNS0Header.AsResourceHeader] and zero-length resource data. EDNS0HeaderEncodingLength = 1 + 10 // ResourceOPTOptionMetadataLength represents the size of an "metadata" // (option code and length).of an EDNS(0) options. ResourceOPTOptionMetadataLength = 4 )
Variables ¶
var ( // ErrSectionDone is returned by [Parser.Question] and [Parser.ResourceHeader] when // no more questions/resources are available to parse in the current section. ErrSectionDone = errors.New("parsing of current section done") )
var ( // ErrTruncated is an error returned by [Builder] when appending questions or resources to the message // is not possible due to reaching the maximum size limit set by [Builder.LimitMessageSize]. // When this error occurs, it indicates that the total size of the DNS message, has reached or exceeded // the specified size limit. // // The DNS message, upon encountering the ErrTruncated error, remains valid, and shorter resources can still be appended // to the message. The error serves as a notification that the message has reached its size limit and indicates that the // application may need to handle this condition appropriately. Two common approaches to handle this situation // include setting the TC (Truncated) bit or sending fewer resources (RFC 2181, Section 9). ErrTruncated = errors.New("message size limit reached") )
Functions ¶
Types ¶
type AddressFamily ¶
type AddressFamily uint8
AddressFamily is an address family, currently used by EDNS0ClientSubnet.
Defined in Address_Family_Numbers.
const ( AddressFamilyIPv4 AddressFamily = 1 AddressFamilyIPv6 AddressFamily = 2 )
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is an incremental DNS message builder.
Internally the Builder contains a building section field, that can be changed using one of these methods: Builder.StartAnswers, Builder.StartAuthorities, Builder.StartAdditionals. By default the building section is set to questions, it allows appending questions by the use of the Builder.Question method. After changing the building section (using one of the Start* methods described above) the resource building methods: Builder.ResourceA, Builder.ResourceAAAA, Builder.ResourceNS, Builder.ResourceCNAME, Builder.ResourceSOA, Builder.ResourcePTR, Builder.ResourceMX, Builder.RawResourceTXT, Builder.ResourceTXT or Builder.RDBuilder can be used to append DNS resources.
The zero value of this type shouldn't be used.
func StartBuilder ¶
StartBuilder creates a new DNS builder. The message is going to be appended to the provided byte slice (buf).
func (*Builder) Bytes ¶
Bytes returns the built DNS message.
Note: Calling this method multiple times may result in invalid results, as it only returns the current state of the DNS message. Any previous calls to Bytes() should be considered invalid.
func (*Builder) Length ¶
Length returns the number of bytes that have been appended to the DNS message up to this point.
func (*Builder) LimitMessageSize ¶
LimitMessageSize sets the upper limit on the size of the DNS message that can be built using the Builder. It allows you to restrict the message size to a specified value, preventing it from exceeding the threshold. If the total size of the message reaches or exceeds the given size, any subsequent appending of questions or resources will result in an error ErrTruncated. Despite encountering the ErrTruncated error, the DNS message remains valid, and shorter resources can still be appended.
Note: The message size will not be reduced if it is already larger than the specified limit.
func (*Builder) Question ¶
Question appends a single question. It errors when the amount of questions is equal to 65535.
The building section must be set to questions, otherwise it panics.
func (*Builder) RDBuilder ¶
func (b *Builder) RDBuilder(hdr ResourceHeader) (RDBuilder, error)
RDBuilder craeates a new RDBuilder, used for building custom resource data. It errors when the amount of resources in the current section is equal to 65535.
Note: The returned RDBuilder should not be used after creating any new resource in b. Once a resource is created using the RDBuilder, attempting to use the same RDBuilder again might lead to panics.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) RawResourceTXT ¶
func (b *Builder) RawResourceTXT(hdr ResourceHeader, txt RawResourceTXT) error
RawResourceTXT appends a single TXT resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) Reset ¶
Reset restes the DNS builder. The message is going to be appended to the provided byte slice (buf).
func (*Builder) ResourceA ¶
func (b *Builder) ResourceA(hdr ResourceHeader, a ResourceA) error
ResourceA appends a single A resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourceAAAA ¶
func (b *Builder) ResourceAAAA(hdr ResourceHeader, aaaa ResourceAAAA) error
ResourceAAAA appends a single AAAA resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourceCNAME ¶
func (b *Builder) ResourceCNAME(hdr ResourceHeader, cname ResourceCNAME) error
ResourceCNAME appends a single CNAME resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourceMX ¶
func (b *Builder) ResourceMX(hdr ResourceHeader, mx ResourceMX) error
ResourceMX appends a single MX resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourceNS ¶
func (b *Builder) ResourceNS(hdr ResourceHeader, ns ResourceNS) error
ResourceNS appends a single NS resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourceOPT ¶
func (b *Builder) ResourceOPT(hdr ResourceHeader, opt ResourceOPT) error
ResourceOPT appends a single OPT resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourceOPTBuilder ¶
func (b *Builder) ResourceOPTBuilder(hdr ResourceHeader) (ResourceOPTBuilder, error)
ResourceOPTBuilder creates a new instance of ResourceOPTBuilder. It errors when the amount of resources in the current section is equal to 65535.
After creating the ResourceOPTBuilder, all resource appending methods shouldn't be used on the Builder until you call ResourceOPTBuilder.End or ResourceOPTBuilder.Remove.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourcePTR ¶
func (b *Builder) ResourcePTR(hdr ResourceHeader, ptr ResourcePTR) error
ResourcePTR appends a single PTR resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourceSOA ¶
func (b *Builder) ResourceSOA(hdr ResourceHeader, soa ResourceSOA) error
ResourceSOA appends a single SOA resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) ResourceTXT ¶
func (b *Builder) ResourceTXT(hdr ResourceHeader, txt ResourceTXT) error
ResourceTXT appends a single TXT resource. It errors when the amount of resources in the current section is equal to 65535.
The building section must NOT be set to questions, otherwise it panics.
func (*Builder) StartAdditionals ¶
func (b *Builder) StartAdditionals()
StartAuthorities changes the building section from authorities to additionals.
It Panics when the current building section is not additionals.
func (*Builder) StartAnswers ¶
func (b *Builder) StartAnswers()
StartAnswers changes the building section from question to answers.
It Panics when the current building section is not questions.
func (*Builder) StartAuthorities ¶
func (b *Builder) StartAuthorities()
StartAuthorities changes the building section from answers to authorities.
It Panics when the current building section is not answers.
type Compression ¶
type Compression uint8
const ( CompressionWhenPossible Compression = 0 // compress when RFC permits compression CompressionNever Compression = 1 // never compress CompressionNotCompressed Compression = 128 // name was not compressed CompressionCompressed Compression = 64 // name was compressed )
type EDNS0ClientSubnet ¶
type EDNS0ClientSubnet struct { Family AddressFamily SourcePrefixLength uint8 ScopePrefixLength uint8 Address []byte }
EDNS0ClientSubnet ia an EDNS(0) option defined in RFC 7871.
func (*EDNS0ClientSubnet) EncodingLength ¶
func (o *EDNS0ClientSubnet) EncodingLength() int
EncodingLength return the encoding length of the option.
Note: It does not include the "metadata" (option code and length).
type EDNS0Cookie ¶
type EDNS0Cookie struct { ClientCookie [8]byte ServerCookie [32]byte // ServerCookieAdditionalLength represents the amount of additional ServerCookie bytes // that are used as an server cookie. When set to 0, only 8 leading bytes are used. // The maximum value of ServerCookieAdditionalLength is 24, which implies that all bytes // in ServerCookie are used as a server cookie. ServerCookieAdditionalLength uint8 }
EDNS0Cookie ia an EDNS(0) option defined in RFC 7873.
func (*EDNS0Cookie) EncodingLength ¶
func (o *EDNS0Cookie) EncodingLength() int
EncodingLength return the encoding length of the option.
Note: It does not include the "metadata" (option code and length).
type EDNS0ExtendedDNSError ¶
type EDNS0ExtendedDNSError struct { InfoCode ExtendedDNSErrorCode ExtraText []byte }
EDNS0ExtendedDNSError is an EDNS(0) option defined in RFC 8914.
func (*EDNS0ExtendedDNSError) EncodingLength ¶
func (o *EDNS0ExtendedDNSError) EncodingLength() int
EncodingLength return the encoding length of the option.
Note: It does not include the "metadata" (option code and length).
type EDNS0Header ¶
type EDNS0Header struct { Payload uint16 PartialExtendedRCode PartialExtendedRCode Version uint8 ExtendedFlags ExtendedFlags }
EDNS0Header represents a ResourceHeader interpreted as an EDNS(0) header.
func (EDNS0Header) AsResourceHeader ¶
func (e EDNS0Header) AsResourceHeader() ResourceHeader
AsResourceHeader converts EDNS0Header into a ResourceHeader.
type EDNS0Option ¶
type EDNS0Option interface {
// contains filtered or unexported methods
}
type EDNS0OptionBuilder ¶
type EDNS0OptionBuilder struct {
// contains filtered or unexported fields
}
ResourceOPTBuilder is a builder for building OPT resource option.
Once the entire resource data has been created, the EDNS0OptionBuilder.End method needs to be called.
func (*EDNS0OptionBuilder) Bytes ¶
func (b *EDNS0OptionBuilder) Bytes(raw []byte) error
Bytes appends a raw byte slice to the option.
func (*EDNS0OptionBuilder) End ¶
func (b *EDNS0OptionBuilder) End()
End finalizes the building process and reflects the changes made using the EDNS0OptionBuilder in the ResourceOPTBuilder. This method must be called after writing the entire resource data is done. Attempting to use the EDNS0OptionBuilder after calling End might lead to panics.
func (*EDNS0OptionBuilder) Length ¶
func (b *EDNS0OptionBuilder) Length() uint16
Length returns the current length of the option in bytes.
func (*EDNS0OptionBuilder) Name ¶
func (b *EDNS0OptionBuilder) Name(name Name, compress bool) error
Name appends a DNS name to the option.
func (*EDNS0OptionBuilder) Remove ¶
func (b *EDNS0OptionBuilder) Remove()
Remove removes the resource from the message. Attempting to use the ResourceOPTBuilder after calling Remove might lead to panics.
func (*EDNS0OptionBuilder) Uint16 ¶
func (b *EDNS0OptionBuilder) Uint16(val uint16) error
Uint16 appends a single uint16 value to the option in Big-Endian format.
func (*EDNS0OptionBuilder) Uint32 ¶
func (b *EDNS0OptionBuilder) Uint32(val uint32) error
Uint32 appends a single uint32 value to the option in Big-Endian format.
func (*EDNS0OptionBuilder) Uint64 ¶
func (b *EDNS0OptionBuilder) Uint64(val uint64) error
Uint64 appends a single uint64 value to the option in Big-Endian format.
func (*EDNS0OptionBuilder) Uint8 ¶
func (b *EDNS0OptionBuilder) Uint8(val uint8) error
Uint8 appends a single uint8 value to the option.
type EDNS0OptionCode ¶
type EDNS0OptionCode uint16
EDNS0OptionCode is an option code of an EDNS(0) option.
const ( EDNS0OptionCodeClientSubnet EDNS0OptionCode = 8 EDNS0OptionCodeCookie EDNS0OptionCode = 10 EDNS0OptionCodeExtendedDNSError EDNS0OptionCode = 15 )
type EDNS0OptionParser ¶
type EDNS0OptionParser struct {
// contains filtered or unexported fields
}
EDNS0OptionParser is a option parser used to parse custom OPT options.
func (*EDNS0OptionParser) AllBytes ¶
func (p *EDNS0OptionParser) AllBytes() []byte
AllBytes returns all remaining bytes in p. The length of the byte slice is equal to EDNS0OptionParser.Length.
The returned slice references the underlying message pased to Parse.
func (*EDNS0OptionParser) Bytes ¶
func (p *EDNS0OptionParser) Bytes(n int) ([]byte, error)
Bytes returns a n-length slice, errors when [EDNS0OptionParser.Length} < n.
The returned slice references the underlying message pased to Parse.
func (*EDNS0OptionParser) End ¶
func (p *EDNS0OptionParser) End() error
End checks if there is any remaining data in the option data being parsed. It is used to ensure that the entire option data has been successfully parsed and no unexpected data remains.
func (*EDNS0OptionParser) Length ¶
func (p *EDNS0OptionParser) Length() uint16
Length returns the remaining bytes in the option data.
func (*EDNS0OptionParser) Name ¶
func (p *EDNS0OptionParser) Name() (Name, error)
Name parses a single DNS name.
func (*EDNS0OptionParser) Uint16 ¶
func (p *EDNS0OptionParser) Uint16() (uint16, error)
Uint16 parses a single Big-Endian uint16 value. It requires at least two bytes to be available in the EDNS0OptionParser to successfully parse.
func (*EDNS0OptionParser) Uint32 ¶
func (p *EDNS0OptionParser) Uint32() (uint32, error)
Uint32 parses a single Big-Endian uint32 value. It requires at least four bytes to be available in the EDNS0OptionParser to successfully parse.
func (*EDNS0OptionParser) Uint64 ¶
func (p *EDNS0OptionParser) Uint64() (uint64, error)
Uint64 parses a single Big-Endian uint64 value. It requires at least eight bytes to be available in the EDNS0OptionParser to successfully parse.
func (*EDNS0OptionParser) Uint8 ¶
func (p *EDNS0OptionParser) Uint8() (uint8, error)
Uint8 parses a single uint8 value. It requires at least one byte to be available in the EDNS0OptionParser to successfully parse.
type ExtendedDNSErrorCode ¶
type ExtendedDNSErrorCode uint16
type ExtendedRCode ¶
type ExtendedRCode uint16
ExtendedRCode is an extended RCode. To create an ExtendedRCode from PartialExtendedRCode and RCode use NewExtendedRCode.
func NewExtendedRCode ¶
func NewExtendedRCode(partial PartialExtendedRCode, rcode RCode) ExtendedRCode
NewExtendedRCode combines the PartialExtendedRCode and RCode into an ExtendedRCode
func (ExtendedRCode) PartialExtendedRCode ¶
func (e ExtendedRCode) PartialExtendedRCode() PartialExtendedRCode
PartialExtendedRCode returns the part of the ExtendedRCode used in EDNS0Header
func (ExtendedRCode) RCode ¶
func (e ExtendedRCode) RCode() RCode
PartialExtendedRCode returns the part of the ExtendedRCode used in Header
type Name ¶
type Name struct { Name [255]byte Length uint8 // When [Name] is used with a [Builder], the field should be set to // - [CompressionWhenPossible] - (default, zero value) name will be compressed // when the RFC permits compression // - [CompressionNever] - name will never be compressed // // [Parser] produces [Name]s with: // - [CompressonNotCompressed] - name used DNS compression // - [CompressionCompressed] - name did not use DNS compression // // [Builder] also permits [Name]s producted by the [Parser] with this field set to // [CompressionNotCompressed] or [CompressionCompressed], it treats them as [CompressionWhenPossible]. // // This field should only be set to the constants mentioned before. Compression Compression // contains filtered or unexported fields }
func MustParseName ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is an incremental DNS message parser.
Internally the Parser contains a parsing section field, that can be changed using one of these methods: Parser.StartAnswers, Parser.StartAuthorities, Parser.StartAdditionals. By default the parsing section is set to questions, this allows parsing the questions section by the use of the Parser.Question method. After changing the parsing section (using one of the Start* methods described above) the Parser.ResourceHeader method in conjunction with resource parsing methods Parser.ResourceA, Parser.ResourceAAAA, Parser.ResourceNS, Parser.ResourceCNAME, Parser.ResourceSOA, Parser.ResourcePTR Parser.ResourceMX, Parser.RawResourceTXT, Parser.SkipResourceData or Parser.RDParser can be used to parse the resource data.
Parser can be copied to preserve the current parsing state.
func (*Parser) End ¶
End should be called after parsing every question and resource. It returns an error when there are remaining bytes after the end of the message.
This method should only be called when parsing of all sections is completed, when there is nothing left to parse.
func (*Parser) Question ¶
Question parses a single question. Returns ErrSectionDone when no more questions are available to parse.
The parsing section must be set to questions.
func (*Parser) RawResourceTXT ¶
func (m *Parser) RawResourceTXT() (RawResourceTXT, error)
RawResourceTXT parses a single TXT resouce data.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeTXT.
func (*Parser) ResourceA ¶
ResourceA parses a single A resouce data.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeA.
func (*Parser) ResourceAAAA ¶
func (m *Parser) ResourceAAAA() (ResourceAAAA, error)
ResourceAAAA parses a single AAAA resouce data.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeAAAA.
func (*Parser) ResourceCNAME ¶
func (m *Parser) ResourceCNAME() (ResourceCNAME, error)
ResourceCNAME parses a single CNAME resouce data.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeCNAME.
func (*Parser) ResourceHeader ¶
func (m *Parser) ResourceHeader() (ResourceHeader, error)
ResourceHeader parses a single header of a resource record.
Every call to ResourceHeader must be followed by a appropriate Resource Data parsing method (Parser.ResourceA, Parser.ResourceAAAA, Parser.ResourceCNAME, Parser.ResourceMX, Parser.RawResourceTXT) depending on the returned ResourceHeader Type field or skipped by Parser.SkipResourceData (even when the ResourceHeader Length field is equal to zero).
Returns ErrSectionDone when no more resources are available to parse in the current section.
The parsing section must not be set to questions.
func (*Parser) ResourceMX ¶
func (m *Parser) ResourceMX() (ResourceMX, error)
ResourceMX parses a single MX resouce data.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeMX.
func (*Parser) ResourceNS ¶
func (m *Parser) ResourceNS() (ResourceNS, error)
ResourceNS parses a single NS resouce data.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeNS.
func (*Parser) ResourceOPT ¶
func (p *Parser) ResourceOPT() (ResourceOPT, error)
ResourceOPT parses a single OPT resource.
Only known (supported by this package) options are parsed, unsupported options are skipped.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeOPT.
func (*Parser) ResourceOPTParser ¶
func (m *Parser) ResourceOPTParser() (ResourceOPTParser, error)
ResourceOPTParser creates a single ResourceOPTParser.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeOPT.
func (*Parser) ResourcePTR ¶
func (m *Parser) ResourcePTR() (ResourcePTR, error)
ResourcePTR parses a single PTR resouce data.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypePTR.
func (*Parser) ResourceSOA ¶
func (m *Parser) ResourceSOA() (ResourceSOA, error)
ResourceSOA parses a single SOA resouce data.
This method can only be used after Parser.ResourceHeader returns a ResourceHeader with a Type field equal to TypeSOA.
func (*Parser) SkipQuestions ¶
SkipQuestions skips all questions.
The parsing section must be set to questions.
func (*Parser) SkipResourceData ¶
SkipResourceData skips the resource data, without parsing it in any way.
This method can only be called after calling the Parser.ResourceHeader method.
func (*Parser) SkipResources ¶
SkipResources skips all resources in the current parsing section.
The parsing section must not be set to questions.
func (*Parser) StartAdditionals ¶
StartAdditionals changes the parsing section from authorities to additionals.
Returns error when the parsing of the current section is not yet completed.
func (*Parser) StartAnswers ¶
StartAnswers changes the parsing section from questions to answers.
Returns error when the parsing of the current section is not yet completed.
func (*Parser) StartAuthorities ¶
StartAuthorities changes the parsing section from answers to authorities.
Returns error when the parsing of the current section is not yet completed.
type PartialExtendedRCode ¶
type PartialExtendedRCode uint8
PartialExtendedRCode represents a part of an ExtendedRCode used by EDNS0Header. It can be combined with RCode using the NewExtendedRCode to create an ExtendedRCode.
type RDBuilder ¶
type RDBuilder struct {
// contains filtered or unexported fields
}
RDParser is a resource data builder used to build custom resources.
Once the entire resource data has been created, the RDBuilder.End method needs to be called.
Note: The returned RDBuilder should not be used after creating any new resource in the Builder. Once a resource is created using the RDBuilder, attempting to use the same RDBuilder might lead to panics.
func (*RDBuilder) Bytes ¶
Bytes appends a raw byte slice to the resource data.
If the resource data exceeds the maximum allowed size of 64 KiB or the message limit size is reached (Builder.LimitMessageSize), an error will be returned. Note: In case of an error, the resource is not removed, and you can still use the RDBuilder safely. The Resource can be removed via the RDBuilder.Remove method.
func (*RDBuilder) End ¶
func (b *RDBuilder) End()
End finalizes the resource data building process and reflects the changes made using the RDBuilder in the Builder. This method must be called after writing the entire resource data is done. Attempting to use the RDBuilder after calling End might lead to panics.
func (*RDBuilder) Name ¶
Name appends a DNS name to the resource data.
If the resource data exceeds the maximum allowed size of 64 KiB or the message limit size is reached (Builder.LimitMessageSize), an error will be returned. Note: In case of an error, the resource is not removed, and you can still use the RDBuilder safely. The Resource can be removed via the RDBuilder.Remove method.
func (*RDBuilder) Remove ¶
func (b *RDBuilder) Remove()
Remove removes the resource from the message. Attempting to use the RDBuilder after calling Remove might lead to panics.
func (*RDBuilder) Uint16 ¶
Uint16 appends a single uint16 value to the resource data in Big-Endian format.
If the resource data exceeds the maximum allowed size of 64 KiB or the message limit size is reached (Builder.LimitMessageSize), an error will be returned. Note: In case of an error, the resource is not removed, and you can still use the RDBuilder safely. The Resource can be removed via the RDBuilder.Remove method.
func (*RDBuilder) Uint32 ¶
Uint32 appends a single uint16 value to the resource data in Big-Endian format.
If the resource data exceeds the maximum allowed size of 64 KiB or the message limit size is reached (Builder.LimitMessageSize), an error will be returned. Note: In case of an error, the resource is not removed, and you can still use the RDBuilder safely. The Resource can be removed via the RDBuilder.Remove method.
func (*RDBuilder) Uint64 ¶
Uint64 appends a single uint16 value to the resource data in Big-Endian format.
If the resource data exceeds the maximum allowed size of 64 KiB or the message limit size is reached (Builder.LimitMessageSize), an error will be returned. Note: In case of an error, the resource is not removed, and you can still use the RDBuilder safely. The Resource can be removed via the RDBuilder.Remove method.
func (*RDBuilder) Uint8 ¶
Uint8 appends a single uint8 value to the resource data.
If the resource data exceeds the maximum allowed size of 64 KiB or the message limit size is reached (Builder.LimitMessageSize), an error will be returned. Note: In case of an error, the resource is not removed, and you can still use the RDBuilder safely. The Resource can be removed via the RDBuilder.Remove method.
type RDParser ¶
type RDParser struct {
// contains filtered or unexported fields
}
RDParser is a resource data parser used to parse custom resources.
func (*RDParser) AllBytes ¶
AllBytes returns all remaining bytes in p. The length of the byte slice is equal to RDParser.Length.
The returned slice references the underlying message pased to Parse.
func (*RDParser) Bytes ¶
Bytes returns a n-length slice, errors when [RDParser.Length} < n.
The returned slice references the underlying message pased to Parse.
func (*RDParser) End ¶
End checks if there is any remaining data in the resource data being parsed. It is used to ensure that the entire resource data has been successfully parsed and no unexpected data remains.
func (*RDParser) Uint16 ¶
Uint16 parses a single Big-Endian uint16 value. It requires at least two bytes to be available in the RDParser to successfully parse.
func (*RDParser) Uint32 ¶
Uint32 parses a single Big-Endian uint32 value. It requires at least four bytes to be available in the RDParser to successfully parse.
type RawResourceTXT ¶
type RawResourceTXT struct { // TXT is as defined by RFC 1035 a "One or more <character-string>s" // so it is a one or more byte-length prefixed data TXT []byte }
func (RawResourceTXT) Concat ¶
func (r RawResourceTXT) Concat() []byte
func (RawResourceTXT) String ¶
func (r RawResourceTXT) String() string
func (RawResourceTXT) ToResourceTXT ¶
func (r RawResourceTXT) ToResourceTXT() ResourceTXT
type ResourceAAAA ¶
type ResourceAAAA struct {
AAAA [16]byte
}
type ResourceCNAME ¶
type ResourceCNAME struct {
CNAME Name
}
type ResourceHeader ¶
func (*ResourceHeader) AsEDNS0Header ¶
func (h *ResourceHeader) AsEDNS0Header() (EDNS0Header, error)
AsEDNS0Header parses the ResourceHeader into an EDNS0Header.
This function should only be called when the h.Type is equal to TypeOPT.
type ResourceMX ¶
type ResourceNS ¶
type ResourceNS struct {
NS Name
}
type ResourceOPT ¶
type ResourceOPT struct {
Options []EDNS0Option
}
func (*ResourceOPT) EncodingLength ¶
func (r *ResourceOPT) EncodingLength() int
EncodingLength returns the DNS encoding length of the resource.
Note: The length does not include the resource header size, the size of the resource header is most likely to be equal to EDNS0HeaderEncodingLength.
type ResourceOPTBuilder ¶
type ResourceOPTBuilder struct {
// contains filtered or unexported fields
}
ResourceOPTBuilder is a builder for building OPT resource options.
Once the entire resource data has been created, the ResourceOPTBuilder.End method needs to be called.
func (*ResourceOPTBuilder) ClientSubnet ¶
func (b *ResourceOPTBuilder) ClientSubnet(opt EDNS0ClientSubnet) error
ClientSubnet append a single client subnet option to the OPT resource.
func (*ResourceOPTBuilder) Cookie ¶
func (b *ResourceOPTBuilder) Cookie(opt EDNS0Cookie) error
Cookie append a single cookie option to the OPT resource.
func (*ResourceOPTBuilder) End ¶
func (b *ResourceOPTBuilder) End()
End finalizes the resource data building process and reflects the changes made using the ResourceOPTBuilder in the Builder. This method must be called after writing the entire resource data is done. Attempting to use the ResourceOPTBuilder after calling End might lead to panics.
func (*ResourceOPTBuilder) ExtendedDNSError ¶
func (b *ResourceOPTBuilder) ExtendedDNSError(opt EDNS0ExtendedDNSError) error
ExtendedDNSError appends a single extended dns error option to the OPT resource.
func (*ResourceOPTBuilder) Length ¶
func (b *ResourceOPTBuilder) Length() uint16
Length returns the current length of the resource data in bytes.
func (*ResourceOPTBuilder) OptionBuilder ¶
func (b *ResourceOPTBuilder) OptionBuilder(code EDNS0OptionCode) (EDNS0OptionBuilder, error)
OptionBuilder creates a new EDNS0OptionBuilder used for building custom OPT options.
After creating the EDNS0OptionBuilder, all option appending methods shouldn`t be used on the ResourceOPTBuilder until you call EDNS0OptionBuilder.End or EDNS0OptionBuilder.Remove.
func (*ResourceOPTBuilder) Remove ¶
func (b *ResourceOPTBuilder) Remove()
Remove removes the resource from the message. Attempting to use the ResourceOPTBuilder after calling Remove might lead to panics.
type ResourceOPTParser ¶
type ResourceOPTParser struct {
// contains filtered or unexported fields
}
ResourceOPTParser is an incremental parser of an OPT resource.
func (*ResourceOPTParser) ClientSubnet ¶
func (p *ResourceOPTParser) ClientSubnet() (EDNS0ClientSubnet, error)
ClientSubnet parses a single EDNS0ClientSubnet option.
Note: This function should only be called when the ResourceOPTParser.Code method returns a EDNS0OptionCodeClientSubnet code.
func (*ResourceOPTParser) Code ¶
func (p *ResourceOPTParser) Code() (EDNS0OptionCode, error)
Code parses the header of a OPT option and returns a EDNS0OptionCode.
func (*ResourceOPTParser) Cookie ¶
func (p *ResourceOPTParser) Cookie() (EDNS0Cookie, error)
Cookie parses a single EDNS0Cookie option.
Note: This function should only be called when the ResourceOPTParser.Code method returns a EDNS0OptionCodeCookie code.
func (*ResourceOPTParser) ExtendedDNSError ¶
func (p *ResourceOPTParser) ExtendedDNSError() (EDNS0ExtendedDNSError, error)
ExtendedDNSError parses a single EDNS0ExtendedDNSError option.
Note: This function should only be called when the ResourceOPTParser.Code method returns a EDNS0OptionCodeExtendedDNSError code.
func (*ResourceOPTParser) OptionParser ¶
func (p *ResourceOPTParser) OptionParser() (EDNS0OptionParser, error)
OptionParser creates a single EDNS0OptionParser which can be used for parsing custom options.
func (*ResourceOPTParser) Skip ¶
func (p *ResourceOPTParser) Skip() error
Skip skips the option data.
type ResourcePTR ¶
type ResourcePTR struct {
PTR Name
}
type ResourceSOA ¶
type ResourceTXT ¶
type ResourceTXT struct {
TXT [][]byte
}