dnsmsg

package module
v0.0.0-...-c6b8576 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 25, 2023 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
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

View Source
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")
)
View Source
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

func Parse

func Parse(msg []byte) (Parser, Header, error)

Parse starts parsing a DNS message.

This function sets the parsing section of the Parser to questions.

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 Bit

type Bit uint8
const (
	BitAA Bit = 10
	BitTC Bit = 9
	BitRD Bit = 8
	BitRA Bit = 7
	BitAD Bit = 5
	BitCD Bit = 4
)

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

func StartBuilder(buf []byte, id uint16, flags Flags) Builder

StartBuilder creates a new DNS builder. The message is going to be appended to the provided byte slice (buf).

func (*Builder) Bytes

func (b *Builder) Bytes() []byte

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) Header

func (b *Builder) Header() Header

Header returns the current state of the builder's header.

func (*Builder) Length

func (b *Builder) Length() int

Length returns the number of bytes that have been appended to the DNS message up to this point.

func (*Builder) LimitMessageSize

func (b *Builder) LimitMessageSize(size int)

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

func (b *Builder) Question(q Question) error

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

func (b *Builder) Reset(buf []byte, id uint16, flags Flags)

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) SetFlags

func (b *Builder) SetFlags(flags Flags)

SetFlags updates the flags in the header.

func (*Builder) SetID

func (b *Builder) SetID(id uint16)

SetID updates the id in the header.

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 Class

type Class uint16
const (
	ClassIN Class = 1
)

func (Class) String

func (t Class) String() string

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 ExtendedFlags

type ExtendedFlags uint16

ExtendedFlags are an extended flags used in EDNS(0).

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 Flags

type Flags uint16

func (Flags) Bit

func (f Flags) Bit(bit Bit) bool

func (Flags) OpCode

func (f Flags) OpCode() OpCode

func (Flags) Query

func (f Flags) Query() bool

func (Flags) RCode

func (f Flags) RCode() RCode

func (Flags) Response

func (f Flags) Response() bool

func (*Flags) SetBit

func (f *Flags) SetBit(bit Bit, val bool)

func (*Flags) SetOpCode

func (f *Flags) SetOpCode(o OpCode)

func (*Flags) SetQuery

func (f *Flags) SetQuery()

func (*Flags) SetRCode

func (f *Flags) SetRCode(r RCode)

func (*Flags) SetResponse

func (f *Flags) SetResponse()
type Header struct {
	ID      uint16
	Flags   Flags
	QDCount uint16
	ANCount uint16
	NSCount uint16
	ARCount uint16
}

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

func MustParseName(name string) Name

func ParseName

func ParseName(name string) (Name, error)

func (*Name) Equal

func (n *Name) Equal(other *Name) bool

Equal return true when n and other represents the same name (case-insensitively).

func (*Name) String

func (n *Name) String() string

type OpCode

type OpCode uint8
const (
	OpCodeQuery OpCode = 0
)

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

func (p *Parser) End() error

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

func (m *Parser) Question() (Question, error)

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) RDParser

func (m *Parser) RDParser() (RDParser, error)

RDParser craeates a new RDParser, used for parsing custom resource data.

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

func (m *Parser) ResourceA() (ResourceA, error)

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

func (p *Parser) SkipQuestions() error

SkipQuestions skips all questions.

The parsing section must be set to questions.

func (*Parser) SkipResourceData

func (m *Parser) SkipResourceData() error

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

func (p *Parser) SkipResources() error

SkipResources skips all resources in the current parsing section.

The parsing section must not be set to questions.

func (*Parser) StartAdditionals

func (p *Parser) StartAdditionals() error

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

func (p *Parser) StartAnswers() error

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

func (p *Parser) StartAuthorities() error

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 Question

type Question struct {
	Name  Name
	Type  Type
	Class Class
}

type RCode

type RCode uint8
const (
	RCodeSuccess RCode = iota
	RCodeFormatError
	RCodeServerFail
	RCodeNameError
	RCodeNotImpl
	RCodeRefused
)

func (RCode) String

func (r RCode) String() string

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

func (b *RDBuilder) Bytes(raw []byte) error

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) Length

func (b *RDBuilder) Length() uint16

Length returns the current length of the resource data in bytes.

func (*RDBuilder) Name

func (b *RDBuilder) Name(name Name, compress bool) error

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

func (b *RDBuilder) Uint16(val uint16) error

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

func (b *RDBuilder) Uint32(val uint32) error

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

func (b *RDBuilder) Uint64(val uint64) error

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

func (b *RDBuilder) Uint8(val uint8) error

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

func (p *RDParser) AllBytes() []byte

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

func (p *RDParser) Bytes(n int) ([]byte, error)

Bytes returns a n-length slice, errors when [RDParser.Length} < n.

The returned slice references the underlying message pased to Parse.

func (*RDParser) End

func (p *RDParser) End() error

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) Length

func (p *RDParser) Length() uint16

Length returns the remaining bytes in the resource data.

func (*RDParser) Name

func (p *RDParser) Name() (Name, error)

Name parses a single DNS name.

func (*RDParser) Uint16

func (p *RDParser) Uint16() (uint16, error)

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

func (p *RDParser) Uint32() (uint32, error)

Uint32 parses a single Big-Endian uint32 value. It requires at least four bytes to be available in the RDParser to successfully parse.

func (*RDParser) Uint64

func (p *RDParser) Uint64() (uint64, error)

Uint64 parses a single Big-Endian uint64 value. It requires at least eight bytes to be available in the RDParser to successfully parse.

func (*RDParser) Uint8

func (p *RDParser) Uint8() (uint8, error)

Uint8 parses a single uint8 value. It requires at least one byte 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 ResourceA

type ResourceA struct {
	A [4]byte
}

type ResourceAAAA

type ResourceAAAA struct {
	AAAA [16]byte
}

type ResourceCNAME

type ResourceCNAME struct {
	CNAME Name
}

type ResourceHeader

type ResourceHeader struct {
	Name   Name
	Type   Type
	Class  Class
	TTL    uint32
	Length uint16
}

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 ResourceMX struct {
	MX   Name
	Pref uint16
}

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

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 ResourceSOA struct {
	NS      Name
	Mbox    Name
	Serial  uint32
	Refresh uint32
	Retry   uint32
	Expire  uint32
	Minimum uint32
}

type ResourceTXT

type ResourceTXT struct {
	TXT [][]byte
}

type Type

type Type uint16
const (
	TypeA     Type = 1
	TypeNS    Type = 2
	TypeCNAME Type = 5
	TypeSOA   Type = 6
	TypePTR   Type = 12
	TypeMX    Type = 15
	TypeTXT   Type = 16
	TypeAAAA  Type = 28
	TypeOPT   Type = 41
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL