dns

package
v0.0.0-...-5abfbfe Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Header struct {
	ID                 uint16      // ID
	IsQuery            bool        // QR
	OpCode             opcode.Code // OPCODE
	Authoritative      bool        // AA
	Truncated          bool        // TC
	RecursionDesired   bool        // RD
	RecursionAvailable bool        // RA
	Zero               bool        // Z
	RCode              rcode.Code  // RCODE
	QDCount            uint16      // Question count
	ANCount            uint16      // Answer count
	NSCount            uint16      // Authority count
	ARCount            uint16      // Additional record count
}

Header describes the header data of a message. This header format enables easy access to all header fields. The RawHeader in comparison stores raw data directly from the "wire". See https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.1

func NewHeader

func NewHeader(id uint16) Header

func (*Header) ToRaw

func (h *Header) ToRaw() RawHeader

ToRaw converts a header to a raw header by applying bitmasks to shift data to the correct positions

type Message

type Message struct {
	Header     Header
	Question   []Question
	Answer     []rr.RR
	Authority  []rr.RR
	Additional []rr.RR

	// Compression keeps track of compression pointers
	// and domain names
	Compression compression.Map
}

Message describes a complete DNS message describes in RFC 1035 Section 4. See https://datatracker.ietf.org/doc/html/rfc1035#section-4

func NewMessage

func NewMessage() *Message

NewMessage returns a new empty (default value) DNS message

func NewMessageWith

func NewMessageWith(h Header) *Message

NewMessageWith returns a new empty (default value) DNS message with the provided header

func (*Message) AddAdditional

func (m *Message) AddAdditional(record rr.RR)

AddAdditional adds a resource record to the additional section

func (*Message) AddAnswer

func (m *Message) AddAnswer(record rr.RR)

AddAnswer adds a resource record to the answer section of the message

func (*Message) AddAnswers

func (m *Message) AddAnswers(records []rr.RR)

AddAnswers adds multiple resource record sto the answer section of the message

func (*Message) AddAuthority

func (m *Message) AddAuthority(record rr.RR)

AddAuthority adds a resource record to the authoritative name server section

func (*Message) AddQuestion

func (m *Message) AddQuestion(question Question)

AddQuestion adds a question to the question section of the message

func (*Message) AddRecords

func (m *Message) AddRecords(answer, authority, additional []rr.RR)

AddRecords adds multiple answerm authority and additional RRs to the appropriate sections in the message

func (*Message) IsEDNS

func (m *Message) IsEDNS() bool

IsEDNS returns if the message has an EDNS OPT record

func (*Message) IsSOA

func (m *Message) IsSOA() bool

IsSOA returns if the message has a SOA record

func (*Message) Len

func (m *Message) Len() int

Len returns the length of the message in octets

func (Message) MarshalLogObject

func (m Message) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject marshals the DNS message as a zap log object

func (*Message) Q

func (m *Message) Q() (string, uint16, uint16)

Q returns Name, Class and Type of the question

func (*Message) SetIsResponse

func (m *Message) SetIsResponse()

SetIsResponse sets the QR bit of the DNS header to 1

func (*Message) SetRecursionAvailable

func (m *Message) SetRecursionAvailable(ra bool)

SetRecursionAvailable sets the RA bit in the DNS header to 1

type Question

type Question struct {
	Name  string
	Type  uint16
	Class uint16
}

Questions holds a DNS question. The RFC allows multiple questions per message, but most DNS servers only accpet one and multiple questions often result in errors. See https://datatracker.ietf.org/doc/html/rfc1035#section-4.1.2

func (Question) MarshalLogObject

func (q Question) MarshalLogObject(enc zapcore.ObjectEncoder) error

MarshalLogObject marshals a DNS question as a zap log object

type RawHeader

type RawHeader struct {
	ID      uint16 // ID
	Flags   uint16 // Various flags, see above
	QDCount uint16 // QDCOUNT
	ANCount uint16 // ANCOUNT
	NSCount uint16 // NSCOUNT
	ARCount uint16 // ARCOUNT
}

RawHeader describes the raw header data of a message directly from the "wire". The data gets unpacked by splitting the message into six 16 bit (2 octet) chunks. The second chunk "flags" carries data like QR, OPCODE, etc. which gets split up further by bit masks

func (*RawHeader) ToHeader

func (h *RawHeader) ToHeader() Header

ToHeader converts a raw header to a header by applying bitmasks to split DNS header flags

type Session

type Session struct {
	AddrPort   netip.AddrPort
	Additional []byte
}

Session holds the remote IP address, remote port and optional additional data of a UDP "connection"

Jump to

Keyboard shortcuts

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