dns

package module
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 Imports: 11 Imported by: 0

README

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

Packages in this repository:

Install: $ go get github.com/cznic/dns
Godocs: http://godoc.org/github.com/cznic/dns

Install: $ go get github.com/cznic/dns/cache
Godocs: http://godoc.org/github.com/cznic/dns/cache

Install: $ go get github.com/cznic/dns/hosts
Godocs: http://godoc.org/github.com/cznic/dns/hosts

Install: $ go get github.com/cznic/dns/msg
Godocs: http://godoc.org/github.com/cznic/dns/msg

Install: $ go get github.com/cznic/dns/named
Godocs: http://godoc.org/github.com/cznic/dns/named

Install: $ go get github.com/cznic/dns/pcat
Godocs: http://godoc.org/github.com/cznic/dns/pcat

Install: $ go get github.com/cznic/dns/resolv
Godocs: http://godoc.org/github.com/cznic/dns/resolv

Install: $ go get github.com/cznic/dns/resolver
Godocs: http://godoc.org/github.com/cznic/dns/resolver

Install: $ go get github.com/cznic/dns/rr
Godocs: http://godoc.org/github.com/cznic/dns/rr

Install: $ go get github.com/cznic/dns/xfr
Godocs: http://godoc.org/github.com/cznic/dns/xfr

Install: $ go get github.com/cznic/dns/zdb
Godocs: http://godoc.org/github.com/cznic/dns/zdb

Install: $ go get github.com/cznic/dns/zone
Godocs: http://godoc.org/github.com/cznic/dns/zone

Documentation

Overview

Package dns collects some DNS common stuff.

Index

Constants

This section is empty.

Variables

View Source
var NoLogger = &Logger{log.New(devNull{}, "", 0), 0}

NoLogger doesn't log anything.

Functions

func DefaultLocalNameServer

func DefaultLocalNameServer() net.IP

DefaultLocalNameServer return the IP of the default local DNS server

func Host2domain

func Host2domain(hostname string) (domainname string)

func IsRooted

func IsRooted(name string) bool

IsRooted returns true if name ends in a '.'.

func Labels

func Labels(name string) (labels []string, err error)

Labels returns a domain name labels or an Error if any.

func MatchCount

func MatchCount(namea, nameb string) (n int, err error)

MatchCount returns the number of labels that namea and nameb have in common or an Error if any. The counting starts at the root label, so any two valid rooted domain names have match count at least one == the root domain.

func RevLookupName

func RevLookupName(ip net.IP) string

RevLookupName returns a domain name for the DNS reverse lookup or "" if ip is not a valid IP address.

func RootedName

func RootedName(name string) string

Rooted name enforces name to end with a ".".

func Seconds2String

func Seconds2String(epochSecs int64) string

Seconds2String converts epoch seconds to a string with the YYYYMMDDHHmmSS format.

func String2Seconds

func String2Seconds(s string) (secs int64, err error)

String2Seconds converts s to epoch seconds. Input string s must be in the YYYYMMDDHHmmSS format or a plain unsigned decadic number < 2^32.

Types

type CharString

type CharString string

CharString is a DNS <character-string> (RFC 1035) implementing Wirer.

func (*CharString) Decode

func (s *CharString) Decode(b []byte, pos *int, sniffer WireDecodeSniffer) (err error)

Implementation of Wirer

func (CharString) Encode

func (s CharString) Encode(b *Wirebuf)

Implementation of Wirer

func (CharString) Quoted

func (s CharString) Quoted() string

Quoted returns s with `"` escaped as `\"`

type DomainName

type DomainName string

DomainName is a DNS <domain-name> (RFC 1035) implementing Wirer.

func (*DomainName) Decode

func (s *DomainName) Decode(b []byte, pos *int, sniffer WireDecodeSniffer) (err error)

Implementation of Wirer

func (DomainName) Encode

func (s DomainName) Encode(b *Wirebuf)

Implementation of Wirer

type GoTree

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

GoTree is a concurrent access safe version of Tree.

func NewGoTree

func NewGoTree() *GoTree

NewGoTree returns a newly created GoTree.

func (*GoTree) Add

func (t *GoTree) Add(owner string, data interface{}, updater func(interface{}) interface{})

Add will add data to GoTree. If the owner node has no data yet, the data will be simply inserted in that node. If the updater is not nil and the owner node already has some existing data then the value returned by updater(existing_data) is inserted into the owner node.

func (*GoTree) Delete

func (t *GoTree) Delete(owner string)

Delete deletes data associated with owner, if any.

func (*GoTree) Enum

func (t *GoTree) Enum(root string, handler func(path []string, data interface{}) bool)

Enum enumerates all data in the tree starting at root and all of its childs. On every datum found the handler is invoked. If the handler returns false the tree traversing stops.

func (*GoTree) Get

func (t *GoTree) Get(owner string) interface{}

Get returns the data associated with owner or nil if there are none.

func (*GoTree) Match

func (t *GoTree) Match(owner string) interface{}

Match returns the data associated with the largest part of owner or nil if there are none. See also Tree.Match for details.

func (*GoTree) Put

func (t *GoTree) Put(owner string, data interface{})

Put will put data to Tree. If the owner node already has some existing data they will be overwritten by the new data.

type LogLevel

type LogLevel int
const (
	LOG_NONE   LogLevel = iota // no logging
	LOG_ERRORS                 // only error events
	LOG_EVENTS                 // + non error events
	LOG_TRACE                  // + requests & results
	LOG_DEBUG                  // everything
)

type Logger

type Logger struct {
	Logger *log.Logger
	Level  LogLevel
}

The Logger type supports simple/simplified logging based on a log.Logger and dns.LogLevel.

func NewLogger

func NewLogger(logger *log.Logger, level LogLevel) *Logger

NewLogger returns a newly created Logger initialized with logger and level. If the logger is nil and level != LOG_NONE then a defualt log.New logger is provided.

func (*Logger) Log

func (l *Logger) Log(format string, v ...interface{})

func (*Logger) Output

func (l *Logger) Output(calldepth int, s string) (err error)

If l.Logger != nil then Output invokes l.Logger.Output. If s contains newlines it is splitted to multiple Outputs.

type Octet

type Octet byte

Octet is a byte implementing Wirer.

func (*Octet) Decode

func (o *Octet) Decode(b []byte, pos *int, sniffer WireDecodeSniffer) (err error)

Implementation of Wirer

func (Octet) Encode

func (o Octet) Encode(b *Wirebuf)

Implementation of Wirer

type Octets2

type Octets2 uint16

Octets2 is an uint16 implementing Wirer.

func (*Octets2) Decode

func (n *Octets2) Decode(b []byte, pos *int, sniffer WireDecodeSniffer) (err error)

Implementation of Wirer

func (Octets2) Encode

func (n Octets2) Encode(b *Wirebuf)

Implementation of Wirer

type Octets4

type Octets4 uint32

Octets4 is an uint32 implementing Wirer.

func (*Octets4) Decode

func (n *Octets4) Decode(b []byte, pos *int, sniffer WireDecodeSniffer) (err error)

Implementation of Wirer

func (Octets4) Encode

func (n Octets4) Encode(b *Wirebuf)

Implementation of Wirer

type Tree

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

Tree implements a hierarchical tree of any data (interface{}). The hierarchy is based on case insensitive labels of a rooted domain name. Tree is *not* concurrent access safe.

func NewTree

func NewTree() *Tree

NewTree returns a newly created Tree.

func (*Tree) Add

func (t *Tree) Add(owner string, data interface{}, updater func(interface{}) interface{})

Add will add data to Tree. If the owner node has no data yet, the data will be simply inserted in that node. If the updater is not nil and the owner node already has some existing data then the value returned by updater(existing_data) is inserted into the owner node.

func (*Tree) Delete

func (t *Tree) Delete(owner string)

Delete deletes data associated with owner, if any.

func (*Tree) Enum

func (t *Tree) Enum(root string, handler func(path []string, data interface{}) bool)

Enum enumerates all data in the tree starting at root and all of its childs. On every datum found the handler is invoked. If the handler returns false the tree traversing stops.

func (*Tree) Get

func (t *Tree) Get(owner string) interface{}

Get returns the data associated with owner or nil if there are none.

func (*Tree) Match

func (t *Tree) Match(owner string) interface{}

Match returns the data associated with the largest part of owner or nil if there are none.

If the tree "map" contains

"www.example.com.": "www-example-com"
"example.org.": "www-example-org"

then

t.Match(".") == nil
t.Match("com.") == nil
t.Match("example.com.") == nil
t.Match("www.example.com.") == "www-example-com"
t.Match("ns.www.example.com.") == "www-example-com"
t.Match("org.") == nil
t.Match("example.org.") == "www-example-org"
t.Match("www.example.org.") == "www-example-org"

In other words, Match returns the most recent (last seen) data item present in the tree when walking the DNS name hiearchy.

func (*Tree) Put

func (t *Tree) Put(owner string, data interface{})

Put will put data to Tree. If the owner node already has some existing data they will be overwritten by the new data.

type WireDecodeSniffed

type WireDecodeSniffed int

WireDecodeSniffed tags data passed to WireDecodeSniffer

const (
	SniffCharString      WireDecodeSniffed // A domain name label
	SniffClass                             // A CLASS
	SniffDomainName                        // A domain name
	SniffEXT_RCODE                         // An EXT_RCODE
	SniffHeader                            // A DNS message header
	SniffIPV4                              // An IP V4 address
	SniffIPV6                              // An IP V6 address
	SniffMessage                           // A DNS message
	SniffOPT_DATA                          // OPT resource record attr/value pair
	SniffOctet                             // An octet
	SniffOctets2                           // Two octets
	SniffOctets4                           // Four octets
	SniffQuestion                          // A DNS message question
	SniffQuestionItem                      // A DNS message question item
	SniffRData                             // Resource record data
	SniffRDataA                            // A resource record data
	SniffRDataAAAA                         // AAAA resource record data
	SniffRDataAFSDB                        // AFSDB resource record data
	SniffRDataCERT                         // CERT resource record data
	SniffRDataCNAME                        // CNAME resource record data
	SniffRDataDHCID                        // DHCID resource record data
	SniffRDataDLV                          // DLV resource record data
	SniffRDataDNAME                        // DNAME resource record data
	SniffRDataDNSKEY                       // DNSKEY resource record data
	SniffRDataDS                           // DS resource record data
	SniffRDataGPOS                         // GPOS resource record data
	SniffRDataHINFO                        // HINFO resource record data
	SniffRDataHIP                          // HIP resource record data
	SniffRDataIPSECKEY                     // IPSECKEY resource record data
	SniffRDataISDN                         // ISDN resource record data
	SniffRDataKEY                          // KEY resource record data
	SniffRDataKX                           // KX resource record data
	SniffRDataLOC                          // LOC resource record data
	SniffRDataMB                           // MB resource record data
	SniffRDataMD                           // MD resource record data
	SniffRDataMF                           // MF resource record data
	SniffRDataMG                           // MG resource record data
	SniffRDataMINFO                        // MINFO resource record data
	SniffRDataMR                           // MR resource record data
	SniffRDataMX                           // MX resource record data
	SniffRDataNAPTR                        // NAPTR pseudo resource record data
	SniffRDataNODATA                       // NODATA pseudo resource record data
	SniffRDataNS                           // NS resource record data
	SniffRDataNSAP                         // NSAP resource record data
	SniffRDataNSAP_PTR                     // NSAP-PTR resource record data
	SniffRDataNSEC                         // NSEC resource record data
	SniffRDataNSEC3                        // NSEC3 resource record data
	SniffRDataNSEC3PARAM                   // NSEC3PARAM resource record data
	SniffRDataNULL                         // NULL resource record data
	SniffRDataOPT                          // OPT resource record data
	SniffRDataPTR                          // PTR resource record data
	SniffRDataPX                           // PX resource record data
	SniffRDataRT                           // RT resource record data
	SniffRDataRP                           // RP resource record data
	SniffRDataRRSIG                        // RRSIG resource record data
	SniffRDataSIG                          // SIG resource record data
	SniffRDataSOA                          // SOA resource record data
	SniffRDataSPF                          // SPF resource record data
	SniffRDataSRV                          // SRV resource record data
	SniffRDataSSHFP                        // SSHFP resource record data
	SniffRDataTA                           // TA resource record data
	SniffRDataTALINK                       // TALINK resource record data
	SniffRDataTKEY                         // TKEY resource record data
	SniffRDataTLSA                         // TLSA resource record data
	SniffRDataTSIG                         // TSIG resource record data
	SniffRDataTXT                          // TXT resource record data
	SniffRDataURI                          // URI resource record data
	SniffRDataWKS                          // WKS resource record data
	SniffRDataX25                          // X25 resource record data
	SniffRR                                // Any or unknown/unsupported type resource record
	SniffType                              // A TYPE
)

Values of WireDecodeSniffed

type WireDecodeSniffer

type WireDecodeSniffer func(p0, p *byte, tag WireDecodeSniffed, info interface{})

WireDecodeSniffer is the type of the hook called by Wirer.Decode. p0 points to a wire buffer on entry to Decode, p to the last byte of the buffer used on leaving the same. tag describes what was pulled from the wire buffer and info may optionally carry the just decoded entity (or a pointer to the same when more ćonvenient).

type Wirebuf

type Wirebuf struct {
	Buf []byte // The encoding buffer
	// contains filtered or unexported fields
}

Wirebuf holds data for encoding DNS messages.

func NewWirebuf

func NewWirebuf() *Wirebuf

NewWirebuf returns a newly created Wirebuf ready for use. Compression is enabled by default.

func (*Wirebuf) DisableCompression

func (w *Wirebuf) DisableCompression()

DisableCompression decrements enable of <domain-name> compression (RFC 1034/4.1.4)

func (*Wirebuf) EnableCompression

func (w *Wirebuf) EnableCompression()

EnableCompression increments enable of <domain-name> compression (RFC 1034/4.1.4)

type Wirer

type Wirer interface {
	// Encode appends data in DNS wire format to Wirebuf.Buf.
	// If the buffer has not enough free space available it will be reallocated.
	Encode(*Wirebuf)
	// Decode decodes data from a DNS wire format in b, starting at p.
	// Decode may return a non nil Error if b is not in the correct format.
	// After Decode, p is adjusted to reflect the amount of data consumed from b.
	// If sniffer is not nil it is invoked with a description of the decoded stuff.
	Decode(b []byte, p *int, sniffer WireDecodeSniffer) error
}

Wirer is a DNS wire format encoder/decoder.

Directories

Path Synopsis
Package cache supports caching of DNS resource records.
Package cache supports caching of DNS resource records.
Package hosts supports hosts formatted data (see also `man hosts`).
Package hosts supports hosts formatted data (see also `man hosts`).
Package msg handles DNS messages.
Package msg handles DNS messages.
WIP: Package named supports named.conf formatted data (see also `man named.conf`).
WIP: Package named supports named.conf formatted data (see also `man named.conf`).
Package pcat supports reading files produced by the pcat utility which is a part of the NLnet Labs' ldns project.
Package pcat supports reading files produced by the pcat utility which is a part of the NLnet Labs' ldns project.
Package resolv supports resolv.conf formatted data (see also `man resolv.conf`).
Package resolv supports resolv.conf formatted data (see also `man resolv.conf`).
Package resolver is a simple DNS resolver.
Package resolver is a simple DNS resolver.
Package rr supports DNS resource records (RFC 1035 chapter 3.2).
Package rr supports DNS resource records (RFC 1035 chapter 3.2).
Package xfr supports DNS zone transfers.
Package xfr supports DNS zone transfers.
WIP: Package zdb provides a specialized DB engine for DNS zone(s)/a DNS server, i.e.
WIP: Package zdb provides a specialized DB engine for DNS zone(s)/a DNS server, i.e.
Package zone handles master files which may be textual data formated as per RFC 1035 chapter 5 or binary data produced by Compiler.
Package zone handles master files which may be textual data formated as per RFC 1035 chapter 5 or binary data produced by Compiler.

Jump to

Keyboard shortcuts

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