magna

package module
v0.0.0-...-2c2a1c5 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: MIT Imports: 5 Imported by: 0

README

Magna

Documentation

Overview

Package magna implements DNS message encoding/decoding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type A

type A struct {
	Address net.IP
}

A represents a 32 bit Internet Address.

func (*A) Decode

func (a *A) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*A) Encode

func (a *A) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (A) String

func (a A) String() string

type BufferOverflowError

type BufferOverflowError struct {
	Length int
	Offset int
}

BufferOverflowError represents an error when there is a buffer overflow.

func (*BufferOverflowError) Error

func (e *BufferOverflowError) Error() string

type CNAME

type CNAME struct {
	CName string
}

CNAME represents the canonical name for the owner.

func (*CNAME) Decode

func (c *CNAME) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*CNAME) Encode

func (c *CNAME) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (CNAME) String

func (c CNAME) String() string

type DNSClass

type DNSClass uint16

A DNSClass specifies the class of the query.

const (
	IN DNSClass = iota + 1
	CS
	CH
	HS

	ANY = 255
)

func (DNSClass) String

func (c DNSClass) String() string

type DNSType

type DNSType uint16

A DNSType specifies the type of the query.

const (
	AType DNSType = iota + 1
	NSType
	MDType
	MFType
	CNAMEType
	SOAType
	MBType
	MGType
	MRType
	NULLType
	WKSType
	PTRType
	HINFOType
	MINFOType
	MXType
	TXTType

	AXFRType  = 252
	MAILBType = 253
	MAILAType = 254
	AllType   = 255
)

func (DNSType) String

func (t DNSType) String() string

type DomainCompressionError

type DomainCompressionError struct{}

DomainCompressionError represents an error related to domain compression.

func (*DomainCompressionError) Error

func (e *DomainCompressionError) Error() string

type HINFO

type HINFO struct {
	CPU string // CPU specifies the CPU type.
	OS  string // OS specifies the operating system.
}

HINFO represents the general information about a server.

func (*HINFO) Decode

func (hinfo *HINFO) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*HINFO) Encode

func (hinfo *HINFO) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (HINFO) String

func (hinfo HINFO) String() string
type Header struct {
	ID      uint16 // ID is a 16 bit identifier.
	QR      bool   // QR (query response) specifies if the packet is a query (false) or response (true).
	OPCode  OPCode // OPCode is a 4bit value that specifies the kind of the query.
	AA      bool   // AA (Authoritative Answer) specifies if the responding name server is the authoritative server.
	TC      bool   // TC (Truncation) specifies if the packet was truncated due to length.
	RD      bool   // RD (Recursion Desired) specifies that the client wants to recurse.
	RA      bool   // RA (Recursion Available) specifies that the server is available to recurse.
	Z       uint8  // Z  Reserved for future use
	RCode   RCode  // RCode is a 4 bit field representing the response error.
	QDCount uint16 // QDCount specifies number of entries in the Question slice.
	ANCount uint16 // ANCount specifies number of entries in the Answer slice.
	NSCount uint16 // NSCount specifies number of entries in the Authority slice.
	ARCount uint16 // ARCount specifies number of entries in the Additional slice.
}

A Header represents the metadata information of a DNS packet.

func (*Header) Decode

func (h *Header) Decode(buf []byte, offset int) (int, error)

Decode decodes the header from the bytes.

func (*Header) Encode

func (h *Header) Encode() []byte

Encode encodes the header packet to the byte representation.

type InvalidLabelError

type InvalidLabelError struct {
	Length int
}

InvalidLabelError represents an error when an invalid label length is encountered.

func (*InvalidLabelError) Error

func (e *InvalidLabelError) Error() string

type MB

type MB struct {
	MADName string
}

MB represents the host with a specified mailbox.

func (*MB) Decode

func (mb *MB) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*MB) Encode

func (mb *MB) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (MB) String

func (mb MB) String() string

type MD

type MD struct {
	MADName string
}

MD represents the mail agent for a domain. XXX: Obsolete

func (*MD) Decode

func (md *MD) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*MD) Encode

func (md *MD) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (MD) String

func (md MD) String() string

type MF

type MF struct {
	MADName string
}

MF represents a host which has a mail agent for a domain. XXX: Obsolete

func (*MF) Decode

func (mf *MF) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*MF) Encode

func (mf *MF) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (MF) String

func (mf MF) String() string

type MG

type MG struct {
	MGMName string
}

MG represents a mailbox which is configured for MGMName.

func (*MG) Decode

func (mg *MG) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*MG) Encode

func (mg *MG) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (MG) String

func (mg MG) String() string

type MINFO

type MINFO struct {
	RMailBx string // RMailBx specifies the mailbox for a mailing list.
	EMailBx string // EMailBx specifes a mailbox for receiving errors.
}

MINFO represents mailing list information.

func (*MINFO) Decode

func (minfo *MINFO) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*MINFO) Encode

func (minfo *MINFO) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (MINFO) String

func (minfo MINFO) String() string

type MR

type MR struct {
	NEWName string
}

MR specifies the proper rename of a mailbox.

func (*MR) Decode

func (mr *MR) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*MR) Encode

func (mr *MR) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (MR) String

func (mr MR) String() string

type MX

type MX struct {
	Preference uint16 // Preference specifies the preference with lower values being prefered.
	Exchange   string // Exchange specifies host acting for the name.
}

MX represents a host acting as a mail exchange.

func (*MX) Decode

func (mx *MX) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*MX) Encode

func (mx *MX) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (MX) String

func (mx MX) String() string

type MagnaError

type MagnaError struct {
	Message string
}

MagnaError represents a generic error with a custom message.

func (*MagnaError) Error

func (e *MagnaError) Error() string

type Message

type Message struct {
	Header     Header           // Header contains metadata about the message.
	Question   []Question       // Question contains a slice of questions.
	Answer     []ResourceRecord // Answer contains a slice of resource records.
	Authority  []ResourceRecord // Authority contains a slice of resource records.
	Additional []ResourceRecord // Additional contains a slice of resource records.
	// contains filtered or unexported fields
}

A Message represents the single format supported by the DNS protocol.

func CreateRequest

func CreateRequest(op OPCode, rd bool) *Message

func (*Message) AddQuestion

func (m *Message) AddQuestion(q Question) *Message

func (*Message) CreateReply

func (m *Message) CreateReply(req *Message) *Message

func (*Message) Decode

func (m *Message) Decode(buf []byte) (err error)

Decode decodes a DNS packet.

func (*Message) Encode

func (m *Message) Encode() []byte

Encode encodes a message to a DNS packet. TODO: set truncation bit if over 512 and udp is protocol

func (*Message) SetRCode

func (m *Message) SetRCode(rc RCode) *Message

type NS

type NS struct {
	NSDName string
}

NS represents

func (*NS) Decode

func (ns *NS) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*NS) Encode

func (ns *NS) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (NS) String

func (ns NS) String() string

type NULL

type NULL struct {
	Anything []byte
}

NULL can be anything as long as its under 65535 octets.

func (*NULL) Decode

func (null *NULL) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*NULL) Encode

func (null *NULL) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (NULL) String

func (null NULL) String() string

type OPCode

type OPCode int

An OPCode specifies the kind of query.

const (
	QUERY OPCode = iota
	IQUERY
	STATUS
)

func (OPCode) String

func (op OPCode) String() string

type PTR

type PTR struct {
	PTRDName string
}

PTR specifies to a location in the domain name space.

func (*PTR) Decode

func (ptr *PTR) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*PTR) Encode

func (ptr *PTR) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (PTR) String

func (ptr PTR) String() string

type Question

type Question struct {
	QName  string   // QName domain name being questioned.
	QType  DNSType  // QType specifies the type of the question.
	QClass DNSClass // QClass specifies the class of the question.
}

A Question represent a question in the DNS packet.

func (*Question) Decode

func (q *Question) Decode(buf []byte, offset int) (int, error)

Decode decodes a question from buf at the offset

func (*Question) Encode

func (q *Question) Encode(bytes []byte, offsets *map[string]uint16) []byte

Encode serializes a Question into bytes, using a map to handle domain name compression offsets.

type RCode

type RCode int

A RCode specifies the response code.

const (
	NOERROR RCode = iota
	FORMERR
	SERVFAIL
	NXDOMAIN
	NOTIMP
	REFUSED
)

func (RCode) String

func (r RCode) String() string

type Reserved

type Reserved struct {
	Bytes []byte
}

Reserved represents a record that is not yet implemented.

func (*Reserved) Decode

func (r *Reserved) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*Reserved) Encode

func (r *Reserved) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (Reserved) String

func (r Reserved) String() string

type ResourceRecord

type ResourceRecord struct {
	Name     string             // a domain label
	RType    DNSType            // the type of the record
	RClass   DNSClass           // the class of the record
	TTL      uint32             // the time to live of the record in seconds
	RDLength uint16             // the length of the record in number of bytes
	RData    ResourceRecordData // the data of the record
}

ResourceRecord represents DNS records.

func (*ResourceRecord) Decode

func (r *ResourceRecord) Decode(buf []byte, offset int) (int, error)

Decode decodes a resource record from buf at the offset.

func (*ResourceRecord) Encode

func (r *ResourceRecord) Encode(bytes []byte, offsets *map[string]uint16) []byte

Encode encdoes a resource record and returns the input bytes appened.

type ResourceRecordData

type ResourceRecordData interface {
	Decode([]byte, int, int) (int, error)
	Encode([]byte, *map[string]uint16) []byte
	String() string
}

A ResourceRecordData represents the RDATA field of the resource record. Decode:

[]byte - DNS packet
int    - offset in []byte to start parsing resource record data
int    - length of the resource record field

Encode:

[]byte            - DNS Packet
*map[string]uint8 - map containing labels and offsets for domain name compression

type SOA

type SOA struct {
	MName   string // MName represents the name server that was the original source of data for a zone.
	RName   string // RName represents a mailbox of the person responsible for this zone.
	Serial  uint32 // Serial is a 32 bit version number of the original copy of the zone.
	Refresh uint32 // Refresh is a 32 bit time interval before the zone should be refreshed.
	Retry   uint32 // Retry is a 32 bit time interval that should elapse before a failed refresh is retried.
	Expire  uint32 // Expire is the upper limit on the time interval that can elapse before the zone is no longer authoritative.
	Minimum uint32 // Minimum is the minimum TTL field that should be exported with any RR from this zone.
}

SOA represents

func (*SOA) Decode

func (soa *SOA) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*SOA) Encode

func (soa *SOA) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (SOA) String

func (soa SOA) String() string

type TXT

type TXT struct {
	TxtData string
}

TXT represents one or more character strings.

func (*TXT) Decode

func (txt *TXT) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*TXT) Encode

func (txt *TXT) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (TXT) String

func (txt TXT) String() string

type WKS

type WKS struct {
	Address  net.IP // Address is  a 32 bit Internet address.
	Protocol uint8  // Protocol is a 8 bit IP protocol number.
	BitMap   []byte // BitMap is a variable length bit map must be multiple of 8 bits.
}

WKS specifies well known services supported by a protocol.

func (*WKS) Decode

func (wks *WKS) Decode(buf []byte, offset int, rdlength int) (int, error)

func (*WKS) Encode

func (wks *WKS) Encode(bytes []byte, offsets *map[string]uint16) []byte

func (WKS) String

func (wks WKS) String() string

Jump to

Keyboard shortcuts

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