dns

package module
v0.0.0-...-904e322 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2011 License: BSD-3-Clause Imports: 25 Imported by: 0

README

Alternative (more granular) approach to a DNS library.

Completely usable DNS library. Most widely used Resource Records are supported. DNSSEC types too. EDNS0 is (see edns.go), UDP/TCP queries, TSIG, AXFR (and IXFR probably) too. Both client and server side programming is supported.

Sample programs can be found in the _examples directory. They can be build with: make examples (after the dns package has been installed)

The major omission at the moment is parsing Resource Records from strings. (i.e. supporting the RFC 1035 zone file format).

Everything else should be present and working. If not, drop me an email.

Have fun!

Miek Gieben - 2010, 2011 - miek@miek.nl

Supported RFCs and features include:

  • 103{4,5} - DNS standard
  • 1982 - Serial Arithmetic
  • 1876 - LOC record (incomplete)
  • 1995 - IXFR
  • 1996 - DNS notify
  • 2181 - RRset definition
  • 2537 - RSAMD5 DNS keys
  • 2065 - DNSSEC (updated in later RFCs)
  • 2671 - EDNS
  • 2782 - SRV
  • 2845 - TSIG
  • 2915 - NAPTR
  • 3110 - RSASHA1 DNS keys
  • 3225 - DO bit (DNSSEC OK)
  • 340{1,2,3} - NAPTR
  • 3597 - Unkown RRs
  • 403{3,4,5} - DNSSEC + validation functions
  • 4255 - SSHFP
  • 4408 - SPF
  • 4509 - SHA256 Hash in DS
  • 4635 - HMAC SHA TSIG
  • 5001 - NSID
  • 5155 - NSEC
  • 5936 - AXFR

Loosely based upon:

  • ldns
  • NSD
  • Net::DNS
  • GRONG

Documentation

Overview

Package dns implements a full featured interface to the DNS. The package allows complete control over what is send out to the DNS.

Resource records are native types. They are not stored in wire format. Basic usage pattern for creating a new resource record:

r := new(RR_TXT)
r.Hdr = RR_Header{Name: "a.miek.nl", Rrtype: TypeTXT, Class: ClassINET, Ttl: 3600}
r.TXT = "This is the content of the TXT record"

The package dns supports (async) querying/replying, incoming/outgoing Axfr/Ixfr, TSIG, EDNS0, dynamic updates, notifies and DNSSEC validation/signing.

In the DNS messages are exchanged. Use pattern for creating one:

m := new(Msg)
m.SetQuestion("miek.nl.", dns.TypeMX)
// Set the desired options.
m.MsgHdr.RecursionDesired = true

Basic use pattern for synchronize querying of the DNS:

c := dns.NewClient()
in := c.Exchange(m, "127.0.0.1:53")

Index

Constants

View Source
const (
	Year68         = 2 << (32 - 1) // For RFC1982 (Serial Arithmetic) calculations in 32 bits.
	DefaultMsgSize = 4096          // A standard default for larger than 512 packets.
	MaxMsgSize     = 65536         // Largest possible DNS packet.
	DefaultTTL     = 3600          // Default Ttl.
)
View Source
const (
	AlgRSAMD5    = 1
	AlgDH        = 2
	AlgDSA       = 3
	AlgECC       = 4
	AlgRSASHA1   = 5
	AlgRSASHA256 = 8
	AlgRSASHA512 = 10
	AlgECCGOST   = 12
)

DNSSEC encryption algorithm codes.

View Source
const (
	HashSHA1
	HashSHA256
	HashGOST94
)

DNSSEC hashing codes.

View Source
const (
	KSK    = 1
	ZSK    = 1 << 8
	REVOKE = 1 << 7
)

DNSKEY flags values.

View Source
const (
	OptionCodeLLQ  // not used
	OptionCodeUL   // not used
	OptionCodeNSID // NSID, RFC5001

)

EDNS0 Option codes.

View Source
const (
	HmacMD5    = "hmac-md5.sig-alg.reg.int."
	HmacSHA1   = "hmac-sha1."
	HmacSHA256 = "hmac-sha256."
)

HMAC hashing codes. These are transmitted as domain names.

View Source
const (
	// valid RR_Header.Rrtype and Question.qtype
	TypeA     = 1
	TypeNS    = 2
	TypeMD    = 3
	TypeMF    = 4
	TypeCNAME = 5
	TypeSOA   = 6
	TypeMB    = 7
	TypeMG    = 8
	TypeMR    = 9
	TypeNULL  = 10
	TypeWKS   = 11
	TypePTR   = 12
	TypeHINFO = 13
	TypeMINFO = 14
	TypeMX    = 15
	TypeTXT   = 16
	TypeAAAA  = 28
	TypeLOC   = 29
	TypeSRV   = 33
	TypeNAPTR = 35
	TypeKX    = 36
	TypeCERT  = 37
	TypeDNAME = 39

	// EDNS
	TypeOPT = 41

	TypeSIG        = 24
	TypeKEY        = 25
	TypeNXT        = 30
	TypeDS         = 43
	TypeSSHFP      = 44
	TypeIPSECKEY   = 45 // No type implemented
	TypeRRSIG      = 46
	TypeNSEC       = 47
	TypeDNSKEY     = 48
	TypeDHCID      = 49
	TypeNSEC3      = 50
	TypeNSEC3PARAM = 51
	TypeTALINK     = 58
	TypeSPF        = 99

	TypeTKEY = 249
	TypeTSIG = 250
	// valid Question.Qtype only
	TypeIXFR  = 251
	TypeAXFR  = 252
	TypeMAILB = 253
	TypeMAILA = 254
	TypeALL   = 255
	// newly defined types
	TypeURI = 256

	TypeTA  = 32768
	TypeDLV = 32769

	// valid Question.Qclass
	ClassINET   = 1
	ClassCSNET  = 2
	ClassCHAOS  = 3
	ClassHESIOD = 4
	ClassNONE   = 254
	ClassANY    = 255

	// Msg.rcode
	RcodeSuccess        = 0
	RcodeFormatError    = 1
	RcodeServerFailure  = 2
	RcodeNameError      = 3
	RcodeNotImplemented = 4
	RcodeRefused        = 5
	RcodeYXDomain       = 6
	RcodeYXRrset        = 7
	RcodeNXRrset        = 8
	RcodeNotAuth        = 9
	RcodeNotZone        = 10
	RcodeBadSig         = 16 // TSIG
	RcodeBadKey         = 17
	RcodeBadTime        = 18
	RcodeBadMode        = 19 // TKEY
	RcodeBadName        = 20
	RcodeBadAlg         = 21
	RcodeBadTrunc       = 22 // TSIG

	// Opcode
	OpcodeQuery  = 0
	OpcodeIQuery = 1
	OpcodeStatus = 2
	// There is no 3
	OpcodeNotify = 4
	OpcodeUpdate = 5
)

Wire constants and supported types.

Variables

View Source
var (
	ErrUnpack    os.Error = &Error{Error: "unpacking failed"}
	ErrPack      os.Error = &Error{Error: "packing failed"}
	ErrId        os.Error = &Error{Error: "id mismatch"}
	ErrShortRead os.Error = &Error{Error: "short read"}
	ErrConn      os.Error = &Error{Error: "conn holds both UDP and TCP connection"}
	ErrConnEmpy  os.Error = &Error{Error: "conn has no connection"}
	ErrServ      os.Error = &Error{Error: "no servers could be reached"}
	ErrKey       os.Error = &Error{Error: "bad key"}
	ErrPrivKey   os.Error = &Error{Error: "bad private key"}
	ErrKeySize   os.Error = &Error{Error: "bad key size"}
	ErrAlg       os.Error = &Error{Error: "bad algorithm"}
	ErrTime      os.Error = &Error{Error: "bad time"}
	ErrNoSig     os.Error = &Error{Error: "no signature found"}
	ErrSig       os.Error = &Error{Error: "bad signature"}
	ErrSigGen    os.Error = &Error{Error: "bad signature generation"}
	ErrAuth      os.Error = &Error{Error: "bad authentication"}
	ErrXfrSoa    os.Error = &Error{Error: "no SOA seen"}
	ErrHandle    os.Error = &Error{Error: "handle is nil"}
	ErrChan      os.Error = &Error{Error: "channel is nil"}
)
View Source
var (
	// Request an async query by sending to this channel.
	QueryRequest chan *Query
	// Listen for replies to previously sent queries on this channel.
	QueryReply chan *Query
)

These channels are global so that all parts of the application can send queries (or even pick them up).

View Source
var Class_str = map[uint16]string{
	ClassINET:   "IN",
	ClassCSNET:  "CS",
	ClassCHAOS:  "CH",
	ClassHESIOD: "HS",
	ClassANY:    "ANY",
}

Map of strings for each CLASS wire type.

View Source
var DefaultQueryChan = newQueryChan()
View Source
var DefaultQueryMux = NewQueryMux()

DefaultQueryMux is the default QueryMux used by Query.

View Source
var DefaultReplyChan = newQueryChanSlice()

Default channel to use for the resolver

View Source
var DefaultServeMux = NewServeMux()

DefaultServeMux is the default ServeMux used by Serve.

View Source
var Rr_str = map[uint16]string{
	TypeCNAME:      "CNAME",
	TypeHINFO:      "HINFO",
	TypeMB:         "MB",
	TypeMG:         "MG",
	TypeMINFO:      "MINFO",
	TypeMR:         "MR",
	TypeMX:         "MX",
	TypeNS:         "NS",
	TypePTR:        "PTR",
	TypeSOA:        "SOA",
	TypeTXT:        "TXT",
	TypeSRV:        "SRV",
	TypeNAPTR:      "NAPTR",
	TypeKX:         "KX",
	TypeCERT:       "CERT",
	TypeDNAME:      "DNAME",
	TypeA:          "A",
	TypeAAAA:       "AAAA",
	TypeLOC:        "LOC",
	TypeOPT:        "OPT",
	TypeDS:         "DS",
	TypeDHCID:      "DHCID",
	TypeIPSECKEY:   "IPSECKEY",
	TypeSSHFP:      "SSHFP",
	TypeRRSIG:      "RRSIG",
	TypeNSEC:       "NSEC",
	TypeDNSKEY:     "DNSKEY",
	TypeNSEC3:      "NSEC3",
	TypeNSEC3PARAM: "NSEC3PARAM",
	TypeTALINK:     "TALINK",
	TypeSPF:        "SPF",
	TypeTKEY:       "TKEY",
	TypeTSIG:       "TSIG",
	TypeAXFR:       "AXFR",
	TypeIXFR:       "IXFR",
	TypeALL:        "ANY",
	TypeURI:        "URI",
	TypeTA:         "TA",
	TypeDLV:        "DLV",
}

Map of strings for each RR wire type.

View Source
var Str_rr = reverse(Rr_str)

Reverse of Rr_str (needed for string parsing).

Functions

func Handle

func Handle(pattern string, handler Handler)

Handle register the handler the given pattern in the DefaultServeMux. The documentation for ServeMux explains how patters are matched.

func HandleFunc

func HandleFunc(pattern string, handler func(ResponseWriter, *Msg))

func HandleQuery

func HandleQuery(d *Conn, i *Msg)

HandleQuery can be used as a default query handler. It fires of the querie, wait for a response and sends the response back on the QueryReply channel. HandleQuery closes d.

func HandleQueryFunc

func HandleQueryFunc(pattern string, handler func(RequestWriter, *Msg))

func Id

func Id() uint16

Return a 16 bits random number to be used as a message id. The random provided should be good enough.

func InitQueryChannels

func InitQueryChannels()

Initialize the QueryRequest and QueryReply channels. This is only required when async. queries are wanted.

func ListenAndQuery

func ListenAndQuery(c chan *Request, handler QueryHandler)

func ListenAndServe

func ListenAndServe(addr string, network string, handler Handler) os.Error

func QueryAndServeTCP

func QueryAndServeTCP(f func(*Conn, *Msg)) os.Error

QueryAndServeTCP listens for incoming requests on channel in and then calls f. The function f is executed in a seperate goroutine and performs the actual TCP query and should return the result on the QueryReply channel.

func QueryAndServeUDP

func QueryAndServeUDP(f func(*Conn, *Msg)) os.Error

QueryAndServeUDP listens for incoming requests on channel in and then calls f. The function f is executed in a seperate goroutine and performs the actual UDP query and should return the result on the QueryReply channel.

func Refused

func Refused(w ResponseWriter, r *Msg)

func ServeTCP

func ServeTCP(l *net.TCPListener, handler Handler) os.Error

Serve accepts incoming DNS request on the TCP listener l, creating a new service thread for each. The service threads read requests and then call handler to reply to them. Handler is typically nil, in which case the DefaultServeMux is used.

func ServeUDP

func ServeUDP(l *net.UDPConn, handler Handler) os.Error

Serve accepts incoming DNS request on the UDP Conn l, creating a new service thread for each. The service threads read requests and then call handler to reply to them. Handler is typically nil, in which case the DefaultServeMux is used.

func TsigVerify

func TsigVerify(msg []byte, secret, requestMAC string, timersOnly bool) (bool, os.Error)

Verify a TSIG on a message. If the signature does not validate err contains the error. If the it validates err is nil

Types

type Client

type Client struct {
	Net          string            // if "tcp" a TCP query will be initiated, otherwise an UDP one
	Addr         string            // address to call
	Attempts     int               // number of attempts
	Retry        bool              // retry with TCP
	ChannelQuery chan *Request     // read DNS request from this channel
	ChannelReply chan []*Msg       // read DNS request from this channel
	ReadTimeout  int64             // the net.Conn.SetReadTimeout value for new connections
	WriteTimeout int64             // the net.Conn.SetWriteTimeout value for new connections
	TsigSecret   map[string]string // secret(s) for Tsig map[<zonename>]<base64 secret>
}

TODO add: LocalAddr

func NewClient

func NewClient() *Client

func (*Client) Do

func (c *Client) Do(m *Msg, a string)

Do performs an asynchronize query. The result is returned on the channel set in the c.

func (*Client) Exchange

func (c *Client) Exchange(m *Msg, a string) *Msg

A sync query

func (*Client) XfrReceive

func (c *Client) XfrReceive(q *Msg, a string) ([]*Msg, os.Error)

Perform an incoming Ixfr or Axfr. If the message q's question section contains an AXFR type an Axfr is performed. If q's question section contains an IXFR type an Ixfr is performed.

type ClientConfig

type ClientConfig struct {
	Servers  []string // servers to use
	Search   []string // suffixes to append to local name
	Port     string   // what port to use
	Ndots    int      // number of dots in name to trigger absolute lookup
	Timeout  int      // seconds before giving up on packet
	Attempts int      // lost packets before giving up on server
}

Wrap the contents of the /etc/resolv.conf.

func ClientConfigFromFile

func ClientConfigFromFile(conf string) (*ClientConfig, os.Error)

See resolv.conf(5) on a Linux machine. Parse a /etc/resolv.conf like file and return a filled out ClientConfig. Note that all nameservers will have the port number appendend (:53)

type Error

type Error struct {
	Error   string
	Name    string
	Server  net.Addr
	Timeout bool
}

Error represents a DNS error

func (*Error) String

func (e *Error) String() string

type Handler

type Handler interface {
	ServeDNS(w ResponseWriter, r *Msg)
}

func RefusedHandler

func RefusedHandler() Handler

RefusedHandler return a REFUSED answer

type HandlerFunc

type HandlerFunc func(ResponseWriter, *Msg)

The HandlerFunc type is an adapter to allow the use of ordinary functions as DNS handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler object that calls f.

func (HandlerFunc) ServeDNS

func (f HandlerFunc) ServeDNS(w ResponseWriter, r *Msg)

ServerDNS calls f(w, reg)

type HandlerQueryFunc

type HandlerQueryFunc func(RequestWriter, *Msg)

The HandlerQueryFunc type is an adapter to allow the use of ordinary functions as DNS query handlers. If f is a function with the appropriate signature, HandlerQueryFunc(f) is a QueryHandler object that calls f.

func (HandlerQueryFunc) QueryDNS

func (f HandlerQueryFunc) QueryDNS(w RequestWriter, r *Msg)

QueryDNS calls f(w, reg)

type Header struct {
	Id                                 uint16
	Bits                               uint16
	Qdcount, Ancount, Nscount, Arcount uint16
}

The wire format for the DNS packet header.

type Msg

type Msg struct {
	MsgHdr
	Question []Question
	Answer   []RR
	Ns       []RR
	Extra    []RR
}

The layout of a DNS message.

func SimpleQuery

func SimpleQuery(n string, d *Conn, m *Msg) (*Msg, os.Error)

SimpleQuery performs a query and waits for the reply before returning.

func TsigGenerate

func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) (*Msg, os.Error)

Add a Tsig to an message. // Must return the mac

func (*Msg) IsAxfr

func (dns *Msg) IsAxfr() (ok bool)

Is the message a valid axfr request packet?

func (*Msg) IsIxfr

func (dns *Msg) IsIxfr() (ok bool)

Is the message a valid ixfr request packet?

func (*Msg) IsNotify

func (dns *Msg) IsNotify() (ok bool)

Is the message a valid notify packet?

func (*Msg) IsTsig

func (dns *Msg) IsTsig() (ok bool)

Has a message a TSIG record as the last record?

func (*Msg) IsUpdate

func (dns *Msg) IsUpdate() (ok bool)

Is the message a dynamic update packet?

func (*Msg) Pack

func (dns *Msg) Pack() (msg []byte, ok bool)

Pack a msg: convert it to wire format.

func (*Msg) SetAxfr

func (dns *Msg) SetAxfr(z string)

Create a dns msg suitable for requesting an axfr.

func (*Msg) SetIxfr

func (dns *Msg) SetIxfr(z string, serial uint32)

Create a dns msg suitable for requesting an ixfr.

func (*Msg) SetNotify

func (dns *Msg) SetNotify(z string)

Create a notify packet.

func (*Msg) SetQuestion

func (dns *Msg) SetQuestion(z string, t uint16)

func (*Msg) SetReply

func (dns *Msg) SetReply(request *Msg)

Create a reply packet from a request message.

func (*Msg) SetTsig

func (dns *Msg) SetTsig(z, algo string, fudge uint16, timesigned uint64)

func (*Msg) String

func (dns *Msg) String() string

Convert a complete message to a string with dig-like output.

func (*Msg) Unpack

func (dns *Msg) Unpack(msg []byte) bool

Unpack a binary message to a Msg structure.

type MsgHdr

type MsgHdr struct {
	Id                 uint16
	Response           bool
	Opcode             int
	Authoritative      bool
	Truncated          bool
	RecursionDesired   bool
	RecursionAvailable bool
	Zero               bool
	AuthenticatedData  bool
	CheckingDisabled   bool
	Rcode              int
}

A manually-unpacked version of (id, bits). This is in its own struct for easy printing.

func (*MsgHdr) String

func (h *MsgHdr) String() string

Convert a MsgHdr to a string, mimic the way Dig displays headers: ;; opcode: QUERY, status: NOERROR, id: 48404 ;; flags: qr aa rd ra;

type Option

type Option struct {
	Code uint16
	Data string "hex"
}

An ENDS0 option rdata element.

type PrivateKey

type PrivateKey interface{}

Empty interface that is used as a wrapper around all possible private key implementations from the crypto package.

type Query

type Query struct {
	// The query message which is to be send.
	Query *Msg

	// Any reply message that came back from the wire.
	Reply *Msg

	// It is only required to fill out Conn.RemoteAddr.
	// Optionally you may set Conn.Tsig if TSIG is required.
	// The rest of the structure is filled by the Query functions.
	Conn *Conn

	// If there are any errors there Err is not nil
	Err os.Error
}

Query is used to communicate with the Query* functions.

func (*Query) ListenAndQuery

func (q *Query) ListenAndQuery() os.Error

func (*Query) Query

func (q *Query) Query() os.Error

type QueryHandler

type QueryHandler interface {
	QueryDNS(w RequestWriter, q *Msg)
}

type QueryMux

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

QueryMux is an DNS request multiplexer. It matches the zone name of each incoming request against a list of registered patterns add calls the handler for the pattern that most closely matches the zone name.

func NewQueryMux

func NewQueryMux() *QueryMux

NewQueryMux allocates and returns a new QueryMux.

func (*QueryMux) Handle

func (mux *QueryMux) Handle(pattern string, handler QueryHandler)

func (*QueryMux) HandleQueryFunc

func (mux *QueryMux) HandleQueryFunc(pattern string, handler func(RequestWriter, *Msg))

func (*QueryMux) QueryDNS

func (mux *QueryMux) QueryDNS(w RequestWriter, r *Msg)

type Question

type Question struct {
	Name   string "domain-name" // "domain-name" specifies encoding
	Qtype  uint16
	Qclass uint16
}

DNS queries.

func (*Question) String

func (q *Question) String() string

type RR

type RR interface {
	Header() *RR_Header
	String() string
}

type RR_A

type RR_A struct {
	Hdr RR_Header
	A   net.IP "A"
}

func (*RR_A) Header

func (rr *RR_A) Header() *RR_Header

func (*RR_A) String

func (rr *RR_A) String() string

type RR_AAAA

type RR_AAAA struct {
	Hdr  RR_Header
	AAAA net.IP "AAAA"
}

func (*RR_AAAA) Header

func (rr *RR_AAAA) Header() *RR_Header

func (*RR_AAAA) String

func (rr *RR_AAAA) String() string

type RR_CERT

type RR_CERT struct {
	Hdr         RR_Header
	Type        uint16
	KeyTag      uint16
	Algorithm   uint8
	Certificate string "base64"
}

See RFC 4398.

func (*RR_CERT) Header

func (rr *RR_CERT) Header() *RR_Header

func (*RR_CERT) String

func (rr *RR_CERT) String() string

type RR_CNAME

type RR_CNAME struct {
	Hdr   RR_Header
	Cname string "domain-name"
}

func (*RR_CNAME) Header

func (rr *RR_CNAME) Header() *RR_Header

func (*RR_CNAME) String

func (rr *RR_CNAME) String() string

type RR_DHCID

type RR_DHCID struct {
	Hdr    RR_Header
	Digest string "base64"
}

func (*RR_DHCID) Header

func (rr *RR_DHCID) Header() *RR_Header

func (*RR_DHCID) String

func (rr *RR_DHCID) String() string

type RR_DLV

type RR_DLV struct {
	Hdr        RR_Header
	KeyTag     uint16
	Algorithm  uint8
	DigestType uint8
	Digest     string "hex"
}

func (*RR_DLV) Header

func (rr *RR_DLV) Header() *RR_Header

func (*RR_DLV) String

func (rr *RR_DLV) String() string

type RR_DNAME

type RR_DNAME struct {
	Hdr    RR_Header
	Target string "domain-name"
}

See RFC 2672.

func (*RR_DNAME) Header

func (rr *RR_DNAME) Header() *RR_Header

func (*RR_DNAME) String

func (rr *RR_DNAME) String() string

type RR_DNSKEY

type RR_DNSKEY struct {
	Hdr       RR_Header
	Flags     uint16
	Protocol  uint8
	Algorithm uint8
	PublicKey string "base64"
}

func (*RR_DNSKEY) Generate

func (r *RR_DNSKEY) Generate(bits int) (PrivateKey, os.Error)

Generate a key of the given bit size. The public part is put inside the DNSKEY record. The Algorithm in the key must be set as this will define what kind of DNSKEY will be generated.

func (*RR_DNSKEY) Header

func (rr *RR_DNSKEY) Header() *RR_Header

func (*RR_DNSKEY) KeyTag

func (k *RR_DNSKEY) KeyTag() uint16

Calculate the keytag of the DNSKEY.

func (*RR_DNSKEY) PrivateKeyString

func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string)

Convert a PrivateKey to a string. This string has the same format as the private-key-file of BIND9 (Private-key-format: v1.3). It needs some info from the key (hashing, keytag), so its a method of the RR_DNSKEY.

func (*RR_DNSKEY) ReadPrivateKey

func (k *RR_DNSKEY) ReadPrivateKey(q io.Reader) (PrivateKey, os.Error)

Read a private key (file) string and create a public key. Return the private key.

func (*RR_DNSKEY) String

func (rr *RR_DNSKEY) String() string

func (*RR_DNSKEY) ToDS

func (k *RR_DNSKEY) ToDS(h int) *RR_DS

Convert an DNSKEY record to a DS record.

type RR_DS

type RR_DS struct {
	Hdr        RR_Header
	KeyTag     uint16
	Algorithm  uint8
	DigestType uint8
	Digest     string "hex"
}

func (*RR_DS) Header

func (rr *RR_DS) Header() *RR_Header

func (*RR_DS) String

func (rr *RR_DS) String() string

type RR_HINFO

type RR_HINFO struct {
	Hdr RR_Header
	Cpu string
	Os  string
}

func (*RR_HINFO) Header

func (rr *RR_HINFO) Header() *RR_Header

func (*RR_HINFO) String

func (rr *RR_HINFO) String() string

type RR_Header

type RR_Header struct {
	Name     string "domain-name"
	Rrtype   uint16
	Class    uint16
	Ttl      uint32
	Rdlength uint16 // length of data after header
}

DNS resource records. There are many types of messages, but they all share the same header.

func (*RR_Header) Header

func (h *RR_Header) Header() *RR_Header

func (*RR_Header) String

func (h *RR_Header) String() string

type RR_KX

type RR_KX struct {
	Hdr        RR_Header
	Preference uint16
	Exchanger  string "domain-name"
}

func (*RR_KX) Header

func (rr *RR_KX) Header() *RR_Header

func (*RR_KX) String

func (rr *RR_KX) String() string

type RR_LOC

type RR_LOC struct {
	Hdr       RR_Header
	Version   uint8
	Size      uint8
	HorizPre  uint8
	VertPre   uint8
	Latitude  uint32
	Longitude uint32
	Altitude  uint32
}

func (*RR_LOC) Header

func (rr *RR_LOC) Header() *RR_Header

func (*RR_LOC) String

func (rr *RR_LOC) String() string

type RR_MB

type RR_MB struct {
	Hdr RR_Header
	Mb  string "domain-name"
}

func (*RR_MB) Header

func (rr *RR_MB) Header() *RR_Header

func (*RR_MB) String

func (rr *RR_MB) String() string

type RR_MG

type RR_MG struct {
	Hdr RR_Header
	Mg  string "domain-name"
}

func (*RR_MG) Header

func (rr *RR_MG) Header() *RR_Header

func (*RR_MG) String

func (rr *RR_MG) String() string

type RR_MINFO

type RR_MINFO struct {
	Hdr   RR_Header
	Rmail string "domain-name"
	Email string "domain-name"
}

func (*RR_MINFO) Header

func (rr *RR_MINFO) Header() *RR_Header

func (*RR_MINFO) String

func (rr *RR_MINFO) String() string

type RR_MR

type RR_MR struct {
	Hdr RR_Header
	Mr  string "domain-name"
}

func (*RR_MR) Header

func (rr *RR_MR) Header() *RR_Header

func (*RR_MR) String

func (rr *RR_MR) String() string

type RR_MX

type RR_MX struct {
	Hdr  RR_Header
	Pref uint16
	Mx   string "domain-name"
}

func (*RR_MX) Header

func (rr *RR_MX) Header() *RR_Header

func (*RR_MX) String

func (rr *RR_MX) String() string

type RR_NAPTR

type RR_NAPTR struct {
	Hdr         RR_Header
	Order       uint16
	Preference  uint16
	Flags       string
	Service     string
	Regexp      string
	Replacement string "domain-name"
}

func (*RR_NAPTR) Header

func (rr *RR_NAPTR) Header() *RR_Header

func (*RR_NAPTR) String

func (rr *RR_NAPTR) String() string

type RR_NS

type RR_NS struct {
	Hdr RR_Header
	Ns  string "domain-name"
}

func (*RR_NS) Header

func (rr *RR_NS) Header() *RR_Header

func (*RR_NS) String

func (rr *RR_NS) String() string

type RR_NSEC

type RR_NSEC struct {
	Hdr        RR_Header
	NextDomain string   "domain-name"
	TypeBitMap []uint16 "NSEC"
}

func (*RR_NSEC) Header

func (rr *RR_NSEC) Header() *RR_Header

func (*RR_NSEC) String

func (rr *RR_NSEC) String() string

type RR_NSEC3

type RR_NSEC3 struct {
	Hdr        RR_Header
	Hash       uint8
	Flags      uint8
	Iterations uint16
	SaltLength uint8
	Salt       string "size-hex"
	HashLength uint8
	NextDomain string   "size-base32"
	TypeBitMap []uint16 "NSEC"
}

func (*RR_NSEC3) HashNames

func (nsec3 *RR_NSEC3) HashNames()

Hash the ownername and the next owner name in an NSEC3 record according to RFC 5155. Use the parameters from the NSEC3 itself.

func (*RR_NSEC3) Header

func (rr *RR_NSEC3) Header() *RR_Header

func (*RR_NSEC3) String

func (rr *RR_NSEC3) String() string

type RR_NSEC3PARAM

type RR_NSEC3PARAM struct {
	Hdr        RR_Header
	Hash       uint8
	Flags      uint8
	Iterations uint16
	SaltLength uint8
	Salt       string "hex"
}

func (*RR_NSEC3PARAM) Header

func (rr *RR_NSEC3PARAM) Header() *RR_Header

func (*RR_NSEC3PARAM) String

func (rr *RR_NSEC3PARAM) String() string

type RR_OPT

type RR_OPT struct {
	Hdr    RR_Header
	Option []Option "OPT" // tag is used in Pack and Unpack
}

Adding an EDNS0 record to a message is done as follows:

opt := new(RR_OPT)
opt.Hdr = dns.RR_Header{Name: "", Rrtype: TypeOPT}
opt.SetVersion(0)       // set version to zero
opt.SetDo()             // set the DO bit
opt.SetUDPSize(4096)    // set the message size
m.Extra = make([]RR, 1)
m.Extra[0] = opt        // add OPT RR to the message

func (*RR_OPT) Do

func (rr *RR_OPT) Do() bool

Get the DO bit.

func (*RR_OPT) Header

func (rr *RR_OPT) Header() *RR_Header

func (*RR_OPT) Nsid

func (rr *RR_OPT) Nsid() string

Return the NSID as hex string.

func (*RR_OPT) SetDo

func (rr *RR_OPT) SetDo()

Set the DO bit.

func (*RR_OPT) SetNsid

func (rr *RR_OPT) SetNsid(hexnsid string)

Set the NSID from a string which is represented as hex characters.

func (*RR_OPT) SetUDPSize

func (rr *RR_OPT) SetUDPSize(size uint16)

Set the UDP buffer size/

func (*RR_OPT) SetVersion

func (rr *RR_OPT) SetVersion(v uint8)

Set the version of EDNS.

func (*RR_OPT) String

func (rr *RR_OPT) String() string

func (*RR_OPT) UDPSize

func (rr *RR_OPT) UDPSize() uint16

Get the UDP buffer size.

func (*RR_OPT) Version

func (rr *RR_OPT) Version() uint8

TODO(mg) Get the EDNS version (always 0 currently).

type RR_PTR

type RR_PTR struct {
	Hdr RR_Header
	Ptr string "domain-name"
}

func (*RR_PTR) Header

func (rr *RR_PTR) Header() *RR_Header

func (*RR_PTR) String

func (rr *RR_PTR) String() string

type RR_RFC3597

type RR_RFC3597 struct {
	Hdr   RR_Header
	Rdata string "hex"
}

Unknown RR representation

func (*RR_RFC3597) Header

func (rr *RR_RFC3597) Header() *RR_Header

func (*RR_RFC3597) String

func (rr *RR_RFC3597) String() string

type RR_RRSIG

type RR_RRSIG struct {
	Hdr         RR_Header
	TypeCovered uint16
	Algorithm   uint8
	Labels      uint8
	OrigTtl     uint32
	Expiration  uint32
	Inception   uint32
	KeyTag      uint16
	SignerName  string "domain-name"
	Signature   string "base64"
}

DNSSEC types

func (*RR_RRSIG) Header

func (rr *RR_RRSIG) Header() *RR_Header

func (*RR_RRSIG) Sign

func (s *RR_RRSIG) Sign(k PrivateKey, rrset RRset) bool

Sign an RRSet. The Signature needs to be filled in with the values: Inception, Expiration, KeyTag, SignerName and Algorithm. The rest is copied from the RRset. Returns true when the signing went OK. The Signature data in the RRSIG is filled by this method. There is no check if RRSet is a proper (RFC 2181) RRSet.

func (*RR_RRSIG) String

func (rr *RR_RRSIG) String() string

func (*RR_RRSIG) ValidityPeriod

func (s *RR_RRSIG) ValidityPeriod() bool

Use RFC1982 to calculate if a signature period is valid.

func (*RR_RRSIG) Verify

func (s *RR_RRSIG) Verify(k *RR_DNSKEY, rrset RRset) bool

Validate an RRSet with the signature and key. This is only the cryptographic test, the signature validity period most be checked separately.

type RR_SOA

type RR_SOA struct {
	Hdr     RR_Header
	Ns      string "domain-name"
	Mbox    string "domain-name"
	Serial  uint32
	Refresh uint32
	Retry   uint32
	Expire  uint32
	Minttl  uint32
}

func (*RR_SOA) Header

func (rr *RR_SOA) Header() *RR_Header

func (*RR_SOA) String

func (rr *RR_SOA) String() string

type RR_SPF

type RR_SPF struct {
	Hdr RR_Header
	Txt string
}

See RFC 4408.

func (*RR_SPF) Header

func (rr *RR_SPF) Header() *RR_Header

func (*RR_SPF) String

func (rr *RR_SPF) String() string

type RR_SRV

type RR_SRV struct {
	Hdr      RR_Header
	Priority uint16
	Weight   uint16
	Port     uint16
	Target   string "domain-name"
}

func (*RR_SRV) Header

func (rr *RR_SRV) Header() *RR_Header

func (*RR_SRV) String

func (rr *RR_SRV) String() string

type RR_SSHFP

type RR_SSHFP struct {
	Hdr         RR_Header
	Algorithm   uint8
	Type        uint8
	FingerPrint string "hex"
}

func (*RR_SSHFP) Header

func (rr *RR_SSHFP) Header() *RR_Header

func (*RR_SSHFP) String

func (rr *RR_SSHFP) String() string

type RR_TA

type RR_TA struct {
	Hdr        RR_Header
	KeyTag     uint16
	Algorithm  uint8
	DigestType uint8
	Digest     string "hex"
}

func (*RR_TA) Header

func (rr *RR_TA) Header() *RR_Header

func (*RR_TA) String

func (rr *RR_TA) String() string
type RR_TALINK struct {
	Hdr          RR_Header
	PreviousName string "domain"
	NextName     string "domain"
}

func (*RR_TALINK) Header

func (rr *RR_TALINK) Header() *RR_Header

func (*RR_TALINK) String

func (rr *RR_TALINK) String() string

type RR_TKEY

type RR_TKEY struct {
	Hdr        RR_Header
	Algorithm  string "domain-name"
	Inception  uint32
	Expiration uint32
	Mode       uint16
	Error      uint16
	KeySize    uint16
	Key        string
	Otherlen   uint16
	OtherData  string
}

func (*RR_TKEY) Header

func (rr *RR_TKEY) Header() *RR_Header

func (*RR_TKEY) String

func (rr *RR_TKEY) String() string

type RR_TSIG

type RR_TSIG struct {
	Hdr        RR_Header
	Algorithm  string "domain-name"
	TimeSigned uint64
	Fudge      uint16
	MACSize    uint16
	MAC        string "size-hex"
	OrigId     uint16
	Error      uint16
	OtherLen   uint16
	OtherData  string "size-hex"
}

RFC 2845.

func (*RR_TSIG) Header

func (rr *RR_TSIG) Header() *RR_Header

func (*RR_TSIG) String

func (rr *RR_TSIG) String() string

TSIG has no official presentation format, but this will suffice.

type RR_TXT

type RR_TXT struct {
	Hdr RR_Header
	Txt string "txt"
}

func (*RR_TXT) Header

func (rr *RR_TXT) Header() *RR_Header

func (*RR_TXT) String

func (rr *RR_TXT) String() string

type RR_URI

type RR_URI struct {
	Hdr      RR_Header
	Priority uint16
	Weight   uint16
	Target   string
}

func (*RR_URI) Header

func (rr *RR_URI) Header() *RR_Header

func (*RR_URI) String

func (rr *RR_URI) String() string

type RRset

type RRset []RR

An RRset is a slice of RRs.

func (RRset) Len

func (r RRset) Len() int

func (RRset) Less

func (r RRset) Less(i, j int) bool

func (RRset) Ok

func (r RRset) Ok() bool

Check if the RRset is RFC 2181 compliant

func (RRset) Swap

func (r RRset) Swap(i, j int)

type Request

type Request struct {
	Request *Msg
	Addr    string
	Client  *Client
}

type RequestWriter

type RequestWriter interface {
	WriteMessages([]*Msg)
	Write(*Msg)
	Send(*Msg) os.Error
	Receive() (*Msg, os.Error)
}

A RequestWriter interface is used by an DNS query handler to construct an DNS request.

type ResponseWriter

type ResponseWriter interface {
	// RemoteAddr returns the address of the client that sent the current request
	RemoteAddr() string

	Write([]byte) (int, os.Error)
}

A ResponseWriter interface is used by an DNS handler to construct an DNS response.

type ServeMux

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

ServeMux is an DNS request multiplexer. It matches the zone name of each incoming request against a list of registered patterns add calls the handler for the pattern that most closely matches the zone name.

func NewServeMux

func NewServeMux() *ServeMux

NewServeMux allocates and returns a new ServeMux.

func (*ServeMux) Handle

func (mux *ServeMux) Handle(pattern string, handler Handler)

func (*ServeMux) HandleFunc

func (mux *ServeMux) HandleFunc(pattern string, handler func(ResponseWriter, *Msg))

func (*ServeMux) ServeDNS

func (mux *ServeMux) ServeDNS(w ResponseWriter, request *Msg)

ServeDNS dispatches the request to the handler whose pattern most closely matches the request message.

type Server

type Server struct {
	Addr         string  // address to listen on, ":dns" if empty
	Net          string  // if "tcp" it will invoke a TCP listener, otherwise an UDP one
	Handler      Handler // handler to invoke, dns.DefaultServeMux if nil
	ReadTimeout  int64   // the net.Conn.SetReadTimeout value for new connections
	WriteTimeout int64   // the net.Conn.SetWriteTimeout value for new connections
}

A Server defines parameters for running an DNS server.

func (*Server) ListenAndServe

func (srv *Server) ListenAndServe() os.Error

Fixes for udp/tcp

func (*Server) ServeTCP

func (srv *Server) ServeTCP(l *net.TCPListener) os.Error

func (*Server) ServeUDP

func (srv *Server) ServeUDP(l *net.UDPConn) os.Error

Directories

Path Synopsis
_examples
mx
q

Jump to

Keyboard shortcuts

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