Involved Source Files Package dnsmessage provides a mostly RFC 1035 compliant implementation of
DNS message packing and unpacking.
The package also supports messages with Extension Mechanisms for DNS
(EDNS(0)) as defined in RFC 6891.
This implementation is designed to minimize heap allocations and avoid
unnecessary packing and unpacking as much as possible.svcb.go
Package-Level Type Names (total 32, in which 29 are exported)
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. compression is a mapping from name suffixes to their starting index
in msg. header keeps track of what should go in the header when Finish is
called. msg is the storage for the message being built. section keeps track of the current section being built. start is the starting index of the bytes allocated in msg for header. AAAAResource adds a single AAAAResource. AResource adds a single AResource. CNAMEResource adds a single CNAMEResource. 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. Finish ends message building and generates a binary message. HTTPSResource adds a single HTTPSResource. MXResource adds a single MXResource. NSResource adds a single NSResource. OPTResource adds a single OPTResource. PTRResource adds a single PTRResource. Question adds a single Question. SOAResource adds a single SOAResource. SRVResource adds a single SRVResource. SVCBResource adds a single SVCBResource. StartAdditionals prepares the builder for packing Additionals. StartAnswers prepares the builder for packing Answers. StartAuthorities prepares the builder for packing Authorities. StartQuestions prepares the builder for packing Questions. TXTResource adds a single TXTResource. UnknownResource adds a single UnknownResource.(*Builder) checkResourceSection() error genericSVCBResource is the generic implementation for adding SVCB-like resources.(*Builder) incrementSectionCount() error(*Builder) startCheck(s section) error
func NewBuilder(buf []byte, h Header) Builder
An HTTPSResource is an HTTPS Resource record.
It has the same format as the SVCB record. Alias for SVCB resource record. // Must be in strict increasing order by Key.SVCBResource.Priorityuint16SVCBResource.TargetName DeleteParam deletes a parameter by key.
It returns true if the parameter was present. GetParam returns a parameter value by key. GoString implements fmt.GoStringer.GoString. SetParam sets a parameter value by key.
The Params list is kept sorted by key.(*HTTPSResource) pack(msg []byte, _ map[string]uint16, _ int) ([]byte, error)(*HTTPSResource) realType() Type
*HTTPSResource : ResourceBody
*HTTPSResource : fmt.GoStringer
func (*Parser).HTTPSResource() (HTTPSResource, error)
func (*Builder).HTTPSResource(h ResourceHeader, r HTTPSResource) error
A Name is a non-encoded and non-escaped domain name. It is used instead of strings to avoid
allocations.Data[255]byteLengthuint8 GoString implements fmt.GoStringer.GoString. String implements fmt.Stringer.String.
Note: characters inside the labels are not escaped in any way. 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. unpack unpacks a domain name.
*Name : fmt.GoStringer
Name : fmt.Stringer
Name : context.stringer
Name : runtime.stringer
func MustNewName(name string) Name
func NewName(name string) (Name, error)
func net.(*Resolver).goLookupIPCNAMEOrder(ctx context.Context, network, name string, order net.hostLookupOrder, conf *net.dnsConfig) (addrs []net.IPAddr, cname Name, err error)
func net.equalASCIIName(x, y Name) bool
An OpCode is a DNS operation code. GoString implements fmt.GoStringer.GoString.
OpCode : fmt.GoStringer
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. // option codeData[]byte GoString implements fmt.GoStringer.GoString.
*Option : fmt.GoStringer
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.headerheaderindexintmsg[]byteoffintresHeaderLengthuint16resHeaderOffsetintresHeaderTypeTyperesHeaderValidboolsectionsection AAAAResource parses a single AAAAResource.
One of the XXXHeader methods must have been called before calling this
method. AResource parses a single AResource.
One of the XXXHeader methods must have been called before calling this
method. Additional parses a single Additional Resource. AdditionalHeader parses a single Additional ResourceHeader. AllAdditionals parses all Additional Resources. AllAnswers parses all Answer Resources. AllAuthorities parses all Authority Resources. AllQuestions parses all Questions. Answer parses a single Answer Resource. AnswerHeader parses a single Answer ResourceHeader. Authority parses a single Authority Resource. AuthorityHeader parses a single Authority ResourceHeader. CNAMEResource parses a single CNAMEResource.
One of the XXXHeader methods must have been called before calling this
method. HTTPSResource parses a single HTTPSResource.
One of the XXXHeader methods must have been called before calling this
method. MXResource parses a single MXResource.
One of the XXXHeader methods must have been called before calling this
method. NSResource parses a single NSResource.
One of the XXXHeader methods must have been called before calling this
method. OPTResource parses a single OPTResource.
One of the XXXHeader methods must have been called before calling this
method. PTRResource parses a single PTRResource.
One of the XXXHeader methods must have been called before calling this
method. Question parses a single Question. SOAResource parses a single SOAResource.
One of the XXXHeader methods must have been called before calling this
method. SRVResource parses a single SRVResource.
One of the XXXHeader methods must have been called before calling this
method. SVCBResource parses a single SVCBResource.
One of the XXXHeader methods must have been called before calling this
method. 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. SkipAllAdditionals skips all Additional Resources. SkipAllAnswers skips all Answer Resources. SkipAllAuthorities skips all Authority Resources. SkipAllQuestions skips all Questions. 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. 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. SkipQuestion skips a single Question. Start parses the header and enables the parsing of Questions. TXTResource parses a single TXTResource.
One of the XXXHeader methods must have been called before calling this
method. UnknownResource parses a single UnknownResource.
One of the XXXHeader methods must have been called before calling this
method.(*Parser) checkAdvance(sec section) error genericSVCBResource parses a single Resource Record compatible with SVCB.(*Parser) resource(sec section) (Resource, error)(*Parser) resourceHeader(sec section) (ResourceHeader, error)(*Parser) skipResource(sec section) error
func net.dnsPacketRoundTrip(c net.Conn, id uint16, query Question, b []byte) (Parser, Header, error)
func net.dnsStreamRoundTrip(c net.Conn, id uint16, query Question, b []byte) (Parser, Header, error)
func net.(*Resolver).exchange(ctx context.Context, server string, q Question, timeout time.Duration, useTCP, ad bool) (Parser, Header, error)
func net.(*Resolver).lookup(ctx context.Context, name string, qtype Type, conf *net.dnsConfig) (Parser, string, error)
func net.(*Resolver).tryOneName(ctx context.Context, cfg *net.dnsConfig, name string, qtype Type) (Parser, string, error)
func net.checkHeader(p *Parser, h Header) error
func net.extractExtendedRCode(p Parser, hdr Header) (RCode, bool)
func net.skipToAnswer(p *Parser, qtype Type) error
Package-Level Functions (total 41, in which 3 are exported)
MustNewName creates a new Name from a string and panics on 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.
NewName creates a new Name from a string.
packBytes appends the wire format of field to msg.
packClass appends the wire format of field to msg.
packText appends the wire format of field to msg.
packType appends the wire format of field to msg.
packUint16 appends the wire format of field to msg.
packUint32 appends the wire format of field to msg.
Package-Level Variables (total 27, in which 2 are exported)
ErrNotStarted indicates that the prerequisite information isn't
available yet because the previous records haven't been appropriately
parsed, skipped or finished.
ErrSectionDone indicated that all records in the section have been
parsed or finished.
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.
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.