msg

package
v0.0.0-...-bcdc67c Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2015 License: BSD-3-Clause, BSD-3-Clause Imports: 11 Imported by: 0

README

This is a goinstall-able mirror of modified code already published at:
http://git.nic.cz/redmine/projects/godns/repository/show/msg

Online godoc documentation for this package (should be) available at:
http://gopkgdoc.appspot.com/pkg/github.com/cznic/dns/msg

Documentation

Overview

Package msg handles DNS messages.

Index

Constants

View Source
const (
	QTYPE_TLSA = 65468 // Experimental, DANE WG, see: http://tools.ietf.org/wg/dane/
)

Variables

This section is empty.

Functions

func GenID

func GenID() uint16

GenID returns a new pseudo random message ID. GenID is safe for concurrent access.

func ReceiveWire

func ReceiveWire(conn net.Conn, rxbuf []byte) (n int, addr *net.UDPAddr, err error)

ReceiveWire reads a DNS packet from conn, copying the payload into rxbuf. It returns the number of bytes copied into rxbuf. If conn is a net.TCPConn then a 2 byte msg len prefix is expected firstly and those two prefix bytes are not reflected in the returned size n. If conn is a net.UPConn then the originating address is returned in addr, otherwise addr will be nil. ReceiveWire can hang forever if the conn doesn't have appropriate read timeout already set.

func SendWire

func SendWire(conn net.Conn, w []byte) (err error)

SendWire sends w through conn and returns an Error of any. If the conn is a *net.TCPConn then the 2 byte msg len is prepended.

Types

type ExchangeChan

type ExchangeChan chan ExchangeReply

ExchangeChan is the type of the channel used to report ExchangeReply from GoExchangeBuf and GoExchange.

type ExchangeReply

type ExchangeReply struct {
	*Message
	// contains filtered or unexported fields
}

ExchangeReply is the type of the ExchangeChan.

type Header struct {
	// A 16 bit identifier assigned by the program that
	// generates 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.
	ID uint16
	// Field that specifies whether this message is a
	// query (false), or a response (true).
	QR bool
	// A four bit field that specifies kind of query in this
	// message.  This value is set by the originator of a query
	// and copied into the response.
	Opcode
	// Authoritative Answer - this bit is valid in responses,
	// and specifies that the responding name server is an
	// authority for the domain name in question section.
	// Note that the contents of the answer section may have
	// multiple owner names because of aliases.  The AA bit
	// corresponds to the name which matches the query name, or
	// the first owner name in the answer section.
	AA bool
	// TrunCation - specifies that this message was truncated
	// due to length greater than that permitted on the
	// transmission channel.
	TC bool
	// Recursion Desired - this bit may be set in a query and
	// is copied into the response.  If RD is set, it directs
	// the name server to pursue the query recursively.
	// Recursive query support is optional.
	RD bool
	// Recursion Available - this be is set or cleared in a
	// response, and denotes whether recursive query support is
	// available in the name server.
	RA bool
	// Reserved for future use.  Must be zero in all queries
	// and responses.
	Z bool
	// rfc2535: The AD (authentic data) bit indicates
	// in a response that all the data included in the answer and authority
	// portion of the response has been authenticated by the server
	// according to the policies of that server.
	AD bool
	// The CD (checking disabled)
	// bit indicates in a query that Pending (non-authenticated) data is
	// acceptable to the resolver sending the query.
	CD bool
	// Response code - this 4 bit field is set as part of
	// responses.
	RCODE
	// An unsigned 16 bit integer specifying the number of
	// entries in the question section.
	QDCOUNT uint16
	// An unsigned 16 bit integer specifying the number of
	// resource records in the answer section.
	ANCOUNT uint16
	// An unsigned 16 bit integer specifying the number of name
	// server resource records in the authority records
	// section.
	NSCOUNT uint16
	// An unsigned 16 bit integer specifying the number of
	// resource records in the additional records section.
	ARCOUNT uint16
}

Header is the header section of a DNS message.

func (*Header) Decode

func (m *Header) Decode(b []byte, pos *int, sniffer dns.WireDecodeSniffer) (err error)

Implementation of dns.Wirer

func (*Header) Encode

func (m *Header) Encode(b *dns.Wirebuf)

Implementation of dns.Wirer

func (*Header) String

func (h *Header) String() string

type Message

type Message struct {
	Header
	Question          // the question for the name server
	Answer     rr.RRs // RRs answering the question
	Authority  rr.RRs // RRs pointing toward an authority
	Additional rr.RRs // RRs holding additional information
}

Message is a DNS message. (RFC 1035, Chapter 4, RFC2535)

func ExchangeWire

func ExchangeWire(conn net.Conn, w, rxbuf []byte) (n int, reply *Message, err error)

ExchangeWire exchanges a msg 'w' already in wire format through conn and returns a reply or an Error if any. ExchangeBuf uses rxbuf for receiving the reply. ExchangeWire can hang forever if the conn doesn't have appropriate read and/or write timeouts already set. Returned n reflects the number of bytes revecied to rxbuf.

func New

func New() *Message

New returns a newly created Message. Initialized fields of Message are:

Header.ID

func (*Message) Decode

func (m *Message) Decode(b []byte, pos *int, sniffer dns.WireDecodeSniffer) (err error)

Implementation of dns.Wirer

func (*Message) Encode

func (m *Message) Encode(b *dns.Wirebuf)

Implementation of dns.Wirer

func (*Message) Exchange

func (m *Message) Exchange(conn net.Conn, rxbufsize int) (reply *Message, err error)

Exchange invokes ExchangeBuf with a private rxbuf of rxbufsize bytes.

func (*Message) ExchangeBuf

func (m *Message) ExchangeBuf(conn net.Conn, rxbuf []byte) (n int, reply *Message, err error)

ExchangeBuf exchanges m through conn and returns a reply or an Error if any. ExchangeBuf uses rxbuf for receiving the reply. ExchangeBuf can hang forever if the conn doesn't have appropriate read and/or write timeouts already set. Returned n reflects the number of bytes revecied to rxbuf.

func (*Message) GoExchange

func (m *Message) GoExchange(conn net.Conn, rxbufsize int, reply ExchangeChan) ExchangeChan

GoExchange invokes GoExchangeBuf with a private rxbuf of rxbufsize bytes.

func (*Message) GoExchangeBuf

func (m *Message) GoExchangeBuf(conn net.Conn, rxbuf []byte, reply ExchangeChan) ExchangeChan

GoExchangeBuf invokes ExchangeBuf in a separate goroutine and reports the result back using the supplied reply channel. The goroutine returns after sending the result. The reply channel may be nil on invocation, then it is created by this method (buffered with a default size).

func (*Message) Receive

func (m *Message) Receive(conn net.Conn, rxbuf []byte) (n int, addr *net.UDPAddr, err error)

Receive reads a DNS message from conn, copying the packet into rxbuf. It returns the number of bytes copied into rxbuf and the originating address of the packet if conn is a net.UDPConn, nil otherwise. Receive can hang forever if the conn doesn't have appropriate read timeout already set.

func (*Message) ReceiveTCP

func (m *Message) ReceiveTCP(conn *net.TCPConn, rxbuf []byte) (n int, err error)

ReceiveTCP attempts to read a DNS message m through conn and returns an Error if any. ReceiveTCP uses rxbuf for receiving the message. ReceiveTCP can hang forever if the conn doesn't have appropriate read timeout already set. Returned n reflects the number of bytes revecied to rxbuf. The 2 byte msg len prefix is expected firstly. The two prefix bytes are not reflected in the returned size 'n'.

func (*Message) ReceiveUDP

func (m *Message) ReceiveUDP(conn *net.UDPConn, rxbuf []byte) (n int, addr *net.UDPAddr, err error)

ReceiveUDP reads a UDP packet from conn, copying the payload into rxbuf. It returns the number of bytes copied into rxbuf and the originating address of the packet. ReceiveUDP can hang forever if the conn doesn't have appropriate read timeout already set.

func (*Message) Send

func (m *Message) Send(conn net.Conn) (err error)

Send sends m through conn and returns an Error of any. If the conn is a *net.TCPConn then the 2 byte msg len is prepended.

func (*Message) String

func (m *Message) String() string

type Opcode

type Opcode byte

Opcode is the type of the Opcode field in a Header.

const (
	QUERY  Opcode = iota // 0: a standard query (QUERY)
	IQUERY               // 1: an inverse query (IQUERY)
	STATUS               // 2: a server status request (STATUS)

	NOTIFY // 4: Notify [RFC1996]
)

Header.Opcode values.

func (Opcode) String

func (o Opcode) String() string

type QType

type QType uint16

QTYPE fields appear in the question part of a query. QTYPES are a superset of rr.TYPEs, hence all TYPEs are valid QTYPEs.

const (
	QTYPE_A          QType //  1 a host address                              [RFC1035]
	QTYPE_NS               //  2 an authoritative name server                [RFC1035]
	QTYPE_MD               //  3 a mail destination (Obsolete - use MX)      [RFC1035]
	QTYPE_MF               //  4 a mail forwarder (Obsolete - use MX)        [RFC1035]
	QTYPE_CNAME            //  5 the canonical name for an alias             [RFC1035]
	QTYPE_SOA              //  6 marks the start of a zone of authority      [RFC1035]
	QTYPE_MB               //  7 a mailbox domain name (EXPERIMENTAL)        [RFC1035]
	QTYPE_MG               //  8 a mail group member (EXPERIMENTAL)          [RFC1035]
	QTYPE_MR               //  9 a mail rename domain name (EXPERIMENTAL     [RFC1035]
	QTYPE_NULL             // 10 a null RR (EXPERIMENTAL)                    [RFC1035]
	QTYPE_WKS              // 11 a well known service description            [RFC1035]
	QTYPE_PTR              // 12 a domain name pointer                       [RFC1035]
	QTYPE_HINFO            // 13 host information                            [RFC1035]
	QTYPE_MINFO            // 14 mailbox or mail list information            [RFC1035]
	QTYPE_MX               // 15 mail exchange                               [RFC1035]
	QTYPE_TXT              // 16 text strings                                [RFC1035]
	QTYPE_RP               // 17 for Responsible Person                      [RFC1183]
	QTYPE_AFSDB            // 18 for AFS Data Base location                  [RFC1183][RFC5864]
	QTYPE_X25              // 19 for X.25 PSDN address                       [RFC1183]
	QTYPE_ISDN             // 20 for ISDN address                            [RFC1183]
	QTYPE_RT               // 21 for Route Through                           [RFC1183]
	QTYPE_NSAP             // 22 for NSAP address, NSAP style A record       [RFC1706]
	QTYPE_NSAP_PTR         // 23 for domain name pointer, NSAP style         [RFC1348]
	QTYPE_SIG              // 24 for security signature                      [RFC4034][RFC3755][RFC2535]
	QTYPE_KEY              // 25 for security key                            [RFC4034][RFC3755][RFC2535]
	QTYPE_PX               // 26 X.400 mail mapping information              [RFC2163]
	QTYPE_GPOS             // 27 Geographical Position                       [RFC1712]
	QTYPE_AAAA             // 28 IP6 Address                                 [RFC3596]
	QTYPE_LOC              // 29 Location Information                        [RFC1876]
	QTYPE_NXT              // 30 Next Domain - OBSOLETE                      [RFC3755][RFC2535]
	QTYPE_EID              // 31 Endpoint Identifier                         [Patton]
	QTYPE_NIMLOC           // 32 Nimrod Locator                              [Patton]
	QTYPE_SRV              // 33 Server Selection                            [RFC2782]
	QTYPE_ATMA             // 34 ATM Address                                 [ATMDOC]
	QTYPE_NAPTR            // 35 Naming Authority Pointer                    [RFC2915][RFC2168][RFC3403]
	QTYPE_KX               // 36 Key Exchanger                               [RFC2230]
	QTYPE_CERT             // 37 CERT                                        [RFC4398]
	QTYPE_A6               // 38 A6 (Experimental)                           [RFC3226][RFC2874]
	QTYPE_DNAME            // 39 DNAME                                       [RFC2672]
	QTYPE_SINK             // 40 SINK                                        [Eastlake]
	QTYPE_OPT              // 41 OPT                                         [RFC2671]
	QTYPE_APL              // 42 APL                                         [RFC3123]
	QTYPE_DS               // 43 Delegation Signer                           [RFC4034][RFC3658]
	QTYPE_SSHFP            // 44 SSH Key Fingerprint                         [RFC4255]
	QTYPE_IPSECKEY         // 45 IPSECKEY                                    [RFC4025]
	QTYPE_RRSIG            // 46 RRSIG                                       [RFC4034][RFC3755]
	QTYPE_NSEC             // 47 NSEC                                        [RFC4034][RFC3755]
	QTYPE_DNSKEY           // 48 DNSKEY                                      [RFC4034][RFC3755]
	QTYPE_DHCID            // 49 DHCID                                       [RFC4701]
	QTYPE_NSEC3            // 50 NSEC3                                       [RFC5155]
	QTYPE_NSEC3PARAM       // 51 NSEC3PARAM                                  [RFC5155]
)

QTYPE codes

const (
	QTYPE_HIP    QType // 55 Host Identity Protocol                      [RFC5205]
	QTYPE_NINFO        // 56 NINFO                                       [Reid]
	QTYPE_RKEY         // 57 RKEY                                        [Reid]
	QTYPE_TALINK       // 58 Trust Anchor LINK                           [Wijngaards]
	QTYPE_CDS          // 59 Child DS                                    [Barwood]
)
const (
	QTYPE_SPF    QType //  99                                             [RFC4408]
	QTYPE_UINFO        // 100                                             [IANA-Reserved]
	QTYPE_UID          // 101                                             [IANA-Reserved]
	QTYPE_GID          // 102                                             [IANA-Reserved]
	QTYPE_UNSPEC       // 103                                             [IANA-Reserved]
)
const (
	QTYPE_TKEY  QType // 249 Transaction Key                            [RFC2930]
	QTYPE_TSIG        // 250 Transaction Signature                      [RFC2845]
	QTYPE_IXFR        // 251 incremental transfer                       [RFC1995]
	QTYPE_AXFR        // 252 transfer of an entire zone                 [RFC1035][RFC5936]
	QTYPE_MAILB       // 253 mailbox-related RRs (MB, MG or MR)         [RFC1035]
	QTYPE_MAILA       // 254 mail agent RRs (Obsolete - see MX)         [RFC1035]
	QTYPE_STAR        // 255 A request for all records                  [RFC1035]
	QTYPE_URI         // 256 URI                                        [Faltstrom]
	QTYPE_CAA         // 257 Certification Authority Authorization      [Hallam-Baker]
)
const (
	QTYPE_TA  QType // 32768   DNSSEC Trust Authorities               [Weiler]           2005-12-13
	QTYPE_DLV       // 32769   DNSSEC Lookaside Validation            [RFC4431]
)
const (
	QTYPE_NODATA QType // A pseudo type in the "reserved for private use" area
	QTYPE_NXDOMAIN
)

func (QType) String

func (n QType) String() (s string)

type Question

type Question []*QuestionItem

Question is the question section of a DNS message.

func (*Question) A

func (q *Question) A(qname string, qclass rr.Class)

func (*Question) AAAA

func (q *Question) AAAA(qname string, qclass rr.Class)

func (*Question) Append

func (q *Question) Append(qname string, qtype QType, qclass rr.Class)

func (Question) Decode

func (q Question) Decode(b []byte, pos *int, sniffer dns.WireDecodeSniffer) (err error)

Implementation of dns.Wirer

func (*Question) NS

func (q *Question) NS(qname string, qclass rr.Class)

func (*Question) PTR

func (q *Question) PTR(qname string, qclass rr.Class)

func (*Question) STAR

func (q *Question) STAR(qname string, qclass rr.Class)

func (*Question) String

func (q *Question) String() string

func (*Question) TXT

func (q *Question) TXT(qname string, qclass rr.Class)

type QuestionItem

type QuestionItem struct {
	// A domain name represented as a sequence of labels, where
	// each label consists of a length octet followed by that
	// number of octets.  The domain name terminates with the
	// zero length octet for the null label of the root.  Note
	// that this field may be an odd number of octets; no
	// padding is used.
	QNAME string
	// A two octet code which specifies the type of the query.
	// The values for this field include all codes valid for a
	// TYPE field, together with some more general codes which
	// can match more than one type of RR.
	QTYPE QType
	// A two octet code that specifies the class of the query.
	// For example, the QCLASS field is IN for the Internet.
	QCLASS rr.Class
}

QuestionItem is an item of the question section of a DNS message.

func (*QuestionItem) Decode

func (m *QuestionItem) Decode(b []byte, pos *int, sniffer dns.WireDecodeSniffer) (err error)

Implementation of dns.Wirer

func (*QuestionItem) Encode

func (m *QuestionItem) Encode(b *dns.Wirebuf)

Implementation of dns.Wirer

func (*QuestionItem) String

func (m *QuestionItem) String() string

type RCODE

type RCODE byte

RCODE is the type of the RCODE field in a Header.

const (
	// 0               No error condition
	RC_NO_ERROR RCODE = iota
	// 1               Format error - The name server was
	//                 unable to interpret the query.
	RC_FORMAT_ERROR
	// 2               Server failure - The name server was
	//                 unable to process this query due to a
	//                 problem with the name server.
	RC_SERVER_FAILURE
	// 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.
	RC_NAME_ERROR
	// 4               Not Implemented - The name server does
	//                 not support the requested kind of query.
	RC_NOT_IMPLEMENETD
	// 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.
	RC_REFUSED
)

RCODE values.

func (RCODE) String

func (r RCODE) String() string

Jump to

Keyboard shortcuts

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