dns

package
v0.0.0-...-1201bab Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: BSD-3-Clause Imports: 7 Imported by: 6

Documentation

Overview

Code generated by "stringer" command for the types within this file; DO NOT EDIT. and then joined together to keep directory clean. The functions have also been modified to avoid heap allocations. - //go:generate stringer -type=Class -trimprefix=Class -output=string_class.go - //go:generate stringer -type=Type -trimprefix=Type -output=string_type.go - //go:generate stringer -type=OpCode -trimprefix=OpCode -output=string_opcode.go

Index

Constants

View Source
const (
	// SizeHeader is the length (in bytes) of a DNS header.
	// A header is comprised of 6 uint16s and no padding.
	SizeHeader = 6 * 2
	// The Internet supports name server access using TCP [RFC-9293] on server
	// port 53 (decimal) as well as datagram access using UDP [RFC-768] on UDP port 53 (decimal).
	ServerPort = 53
	ClientPort = 53
	// Messages carried by UDP are restricted to 512 bytes (not counting the IP
	// or UDP headers).  Longer messages are truncated and the TC bit is set in the header.
	MaxSizeUDP = 512
)

Global parameters.

Variables

This section is empty.

Functions

This section is empty.

Types

type Class

type Class uint16

A Class is a type of network.

const (
	// ResourceHeader.Class and Question.Class
	ClassINET   Class = 1
	ClassCSNET  Class = 2
	ClassCHAOS  Class = 3
	ClassHESIOD Class = 4

	// Question.Class
	ClassANY Class = 255
)

func (Class) String

func (i Class) String() string
type Header struct {
	// Generated for any kind of query.  This identifier is copied
	// the corresponding reply and can be used by the requester to
	// match up replies to outstanding queries.
	TransactionID uint16      // 0:2
	Flags         HeaderFlags // 2:4
	// number of entries in the question section.
	QDCount uint16 // 4:6
	// number of resource records in the answer section.
	ANCount uint16 // 6:8
	// number of name server resource records in the authority records section.
	NSCount uint16 // 8:10
	// number of resource records in the additional records section.
	ARCount uint16 // 10:12
}

func DecodeHeader

func DecodeHeader(b []byte) (dhdr Header)

func (*Header) Put

func (dhdr *Header) Put(b []byte)

type HeaderFlags

type HeaderFlags uint16

HeaderFlags gathers the flags in bits 16..31 of the header.

func NewClientHeaderFlags

func NewClientHeaderFlags(op OpCode, enableRecursion bool) HeaderFlags

NewClientHeaderFlags creates the header flags for a client request.

func (HeaderFlags) IsAuthorativeAnswer

func (flags HeaderFlags) IsAuthorativeAnswer() bool

IsAuthorativeAnswer returns AA bit which specifies that the responding name server is an authority for the domain name in question section.

func (HeaderFlags) IsRecursionAvailable

func (flags HeaderFlags) IsRecursionAvailable() bool

IsRecursionAvailable returns RA bit which specifies whether recursive query support is available by the server.

func (HeaderFlags) IsRecursionDesired

func (flags HeaderFlags) IsRecursionDesired() bool

IsRecursionDesired returns RD bit which specifies whether recursive query support is desired by the client. Is optionally set by client.

func (HeaderFlags) IsResponse

func (flags HeaderFlags) IsResponse() bool

IsResponse returns QR bit which specifies whether this message is a query (0), or a response (1).

func (HeaderFlags) IsTruncated

func (flags HeaderFlags) IsTruncated() bool

IsTruncated returns TC bit which specifies that this message was truncated due to length greater than that permitted on the transmission channel.

func (HeaderFlags) OpCode

func (flags HeaderFlags) OpCode() OpCode

OpCode returns the 4-bit opcode.

func (HeaderFlags) ResponseCode

func (flags HeaderFlags) ResponseCode() RCode

ResponseCode returns the 4-bit response code set as part of responses.

func (HeaderFlags) String

func (flags HeaderFlags) String() string

type Message

type Message struct {
	Header
	Questions   []Question
	Answers     []Resource
	Authorities []Resource
	Additionals []Resource
}

func (*Message) AddQuestions

func (m *Message) AddQuestions(questions []Question)

func (*Message) AppendTo

func (m *Message) AppendTo(buf []byte) (_ []byte, err error)

func (*Message) Decode

func (m *Message) Decode(msg []byte) (_ uint16, incompleteButOK bool, err error)

Decode decodes the DNS message in b into m. It returns the number of bytes consumed from b (0 if no bytes were consumed) and any error encountered. If the message was not completely parsed due to LimitResourceDecoding, incompleteButOK is true and an error is returned, though the message is still usable.

func (*Message) Len

func (m *Message) Len() uint16

func (*Message) LimitResourceDecoding

func (m *Message) LimitResourceDecoding(maxQ, maxAns, maxAuth, maxAdd uint16)

func (*Message) Reset

func (m *Message) Reset()

type Name

type Name struct {
	// contains filtered or unexported fields
}

func MustNewName

func MustNewName(s string) Name

func NewName

func NewName(domain string) (Name, error)

NewName parses a domain name and returns a new Name.

func (*Name) AddLabel

func (n *Name) AddLabel(label string)

AddLabel adds a label to the name. If n.CanAddLabel(label) returns false, it panics.

func (*Name) AppendDottedTo

func (n *Name) AppendDottedTo(b []byte) []byte

AppendDottedTo appends the Name to b in dotted format and returns the resulting slice.

func (*Name) AppendTo

func (n *Name) AppendTo(b []byte) ([]byte, error)

AppendTo appends the Name to b in wire format and returns the resulting slice.

func (*Name) CanAddLabel

func (n *Name) CanAddLabel(label string) bool

CanAddLabel reports whether the label can be added to the name.

func (*Name) CloneFrom

func (n *Name) CloneFrom(ex Name)

func (*Name) Decode

func (n *Name) Decode(b []byte, off uint16) (uint16, error)

Decode resets internal Name buffer and reads raw wire data from buffer, returning any error encountered.

func (*Name) Len

func (n *Name) Len() uint16

Len returns the length over-the-wire of the encoded Name.

func (*Name) Reset

func (n *Name) Reset()

Reset resets the Name labels to be empty and reuses buffer.

func (*Name) String

func (n *Name) String() string

String returns a string representation of the name in dotted format.

func (*Name) VisitLabels

func (n *Name) VisitLabels(fn func(label []byte)) error

type OpCode

type OpCode uint16

An OpCode is a DNS operation code which specifies the type of query.

const (
	OpCodeQuery        OpCode = 0 // Standard query.
	OpCodeInverseQuery OpCode = 1 // Inverse query.
	OpCodeStatus       OpCode = 2 // Server status request.
)

func (OpCode) String

func (i OpCode) String() string

type Question

type Question struct {
	Name  Name
	Type  Type
	Class Class
}

func (*Question) Decode

func (q *Question) Decode(msg []byte, off uint16) (uint16, error)

func (*Question) Len

func (q *Question) Len() uint16

Len returns Question's length over-the-wire.

func (*Question) Reset

func (q *Question) Reset()

func (*Question) String

func (q *Question) String() string

String returns a string representation of the Question with the Name in dotted format.

type RCode

type RCode uint16

An RCode is a DNS response status code.

const (
	RCodeSuccess        RCode = 0 // No error condition.
	RCodeFormatError    RCode = 1 // Format error - The name server was unable to interpret the query.
	RCodeServerFailure  RCode = 2 // Server failure - The name server was unable to process this query due to a	problem with the name server.
	RCodeNameError      RCode = 3 // Name Error - Meaningful only for responses from an authoritative name server, this code signifies that the	domain name referenced in the query does not exist.
	RCodeNotImplemented RCode = 4 // Not implemented - The name server does not support the requested kind of query.
	RCodeRefused        RCode = 5 // Refused - The name server refuses to perform the specified operation for policy reasons. For example, a name server may not wish to provide the information to the particular requester, or a name server may not wish to perform a particular operation (e.g., zone transfer) for particular data.
)

/go:generate stringer -type=RCode -trimprefix=RCode -output=rcode_string.go

func (RCode) String

func (i RCode) String() string

type Resource

type Resource struct {
	Header ResourceHeader
	// contains filtered or unexported fields
}

func (*Resource) Decode

func (r *Resource) Decode(b []byte, off uint16) (uint16, error)

func (*Resource) Len

func (r *Resource) Len() uint16

func (*Resource) RawData

func (r *Resource) RawData() []byte

func (*Resource) Reset

func (r *Resource) Reset()

type ResourceHeader

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

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.

func (*ResourceHeader) Decode

func (rhdr *ResourceHeader) Decode(msg []byte, off uint16) (uint16, error)

func (*ResourceHeader) Reset

func (r *ResourceHeader) Reset()

func (*ResourceHeader) String

func (h *ResourceHeader) String() string

String returns a string representation of the header.

type Type

type Type uint16

Type is a type of DNS request and response.

const (
	// ResourceHeader.Type and Question.Type
	TypeA     Type = 1
	TypeNS    Type = 2
	TypeCNAME Type = 5
	TypeSOA   Type = 6
	TypePTR   Type = 12
	TypeMX    Type = 15
	TypeTXT   Type = 16
	TypeAAAA  Type = 28
	TypeSRV   Type = 33
	TypeOPT   Type = 41

	// Question.Type
	TypeWKS   Type = 11
	TypeHINFO Type = 13
	TypeMINFO Type = 14
	TypeAXFR  Type = 252
	TypeALL   Type = 255
)

func (Type) String

func (i Type) String() string

Jump to

Keyboard shortcuts

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