Documentation ¶
Overview ¶
Package unbound implements a wrapper for libunbound(3). Unbound is a DNSSEC aware resolver, see https://unbound.net/ for more information. It's up to the caller to configure Unbound with trust anchors. With these anchors a DNSSEC answer can be validated.
The method's documentation can be found in libunbound(3). The names of the methods are in sync with the names used in unbound, but the underscores are removed and they are in camel-case, e.g. ub_ctx_resolv_conf becomes u.ResolvConf. Except for ub_ctx_create() and ub_ctx_delete(), which become: New() and Destroy() to be more in line with the standard Go practice.
Basic use pattern:
u := unbound.New() defer u.Destroy() u.ResolvConf("/etc/resolv.conf") u.AddTaFile("trustanchor") r, e := u.Resolve("miek.nl.", dns.TypeA, dns.ClassINET)
The asynchronous functions are implemented using goroutines. This means the following functions are not useful in Go and therefor not implemented: ub_fd, ub_wait, ub_poll, ub_process and ub_cancel.
Unbound's ub_result (named Result in the package) has been modified. An extra field has been added, 'Rr', which is a []dns.RR.
The Lookup* functions of the net package are re-implemented in this package.
Index ¶
- type Error
- type Result
- type ResultError
- type Unbound
- func (u *Unbound) AddTa(ta string) error
- func (u *Unbound) AddTaFile(fname string) error
- func (u *Unbound) AddTaRR(ta dns.RR) error
- func (u *Unbound) Config(fname string) error
- func (u *Unbound) DataAdd(data string) error
- func (u *Unbound) DataAddRR(data dns.RR) error
- func (u *Unbound) DataRemove(data string) error
- func (u *Unbound) DataRemoveRR(data dns.RR) error
- func (u *Unbound) DebugLevel(d int) error
- func (u *Unbound) DebugOut(out *os.File) error
- func (u *Unbound) Destroy()
- func (u *Unbound) GetOption(opt string) (string, error)
- func (u *Unbound) Hosts(fname string) error
- func (u *Unbound) LookupAddr(addr string) (name []string, err error)
- func (u *Unbound) LookupCNAME(name string) (cname string, err error)
- func (u *Unbound) LookupHost(host string) (addrs []string, err error)
- func (u *Unbound) LookupIP(host string) (addrs []net.IP, err error)
- func (u *Unbound) LookupMX(name string) (mx []*dns.MX, err error)
- func (u *Unbound) LookupNS(name string) (ns []*dns.NS, err error)
- func (u *Unbound) LookupSRV(service, proto, name string) (cname string, srv []*dns.SRV, err error)
- func (u *Unbound) LookupTLSA(service, proto, name string) (tlsa []*dns.TLSA, err error)
- func (u *Unbound) LookupTXT(name string) (txt []string, err error)
- func (u *Unbound) ResolvConf(fname string) error
- func (u *Unbound) Resolve(name string, rrtype, rrclass uint16) (*Result, error)
- func (u *Unbound) ResolveAsync(name string, rrtype, rrclass uint16, c chan *ResultError)
- func (u *Unbound) SetFwd(addr string) error
- func (u *Unbound) SetOption(opt, val string) error
- func (u *Unbound) TrustedKeys(fname string) error
- func (u *Unbound) Version() (version [3]int)
- func (u *Unbound) ZoneAdd(zoneName, zoneType string) error
- func (u *Unbound) ZoneRemove(zoneName string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct { Err string // contains filtered or unexported fields }
Error is an error returned from Unbound, it wraps both the return code and the error string as returned by ub_strerror.
type Result ¶
type Result struct { Qname string // Text string, original question Qtype uint16 // Type code asked for Qclass uint16 // Class code asked for Data [][]byte // Slice of rdata items formed from the reply Rr []dns.RR // The RR encoded from Data, Qclass, Qtype, Qname and Ttl (not in Unbound) CanonName string // Canonical name of result Rcode int // Additional error code in case of no data AnswerPacket *dns.Msg // Full answer packet HaveData bool // True if there is data NxDomain bool // True if the name does not exist Secure bool // True if the result is secure Bogus bool // True if a security failure happened WhyBogus string // String with error when bogus Ttl uint32 // TTL for the result in seconds (0 for unbound versions < 1.4.20) Rtt time.Duration // Time the query took (not in Unbound) }
Result is Unbound's ub_result adapted for Go.
type ResultError ¶
ResultError encapsulates a *Result and an error. This is used to communicate with unbound over a channel.
type Unbound ¶
type Unbound struct {
// contains filtered or unexported fields
}
Unbound wraps the C structures and performs the resolving of names.
func (*Unbound) AddTaRR ¶
AddTaRR calls AddTa, but allows to directly use an dns.RR. This method is not found in Unbound.
func (*Unbound) DataAddRR ¶
DataAddRR calls DataAdd, but allows to directly use an dns.RR. This method is not found in Unbound.
func (*Unbound) DataRemove ¶
DataRemove wraps Unbound's ub_ctx_data_remove.
func (*Unbound) DataRemoveRR ¶
DataRemoveRR calls DataRemove, but allows to directly use an dns.RR. This method is not found in Unbound.
func (*Unbound) DebugLevel ¶
DebugLevel wraps Unbound's ub_ctx_data_level.
func (*Unbound) LookupAddr ¶
LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address.
func (*Unbound) LookupCNAME ¶
LookupCNAME returns the canonical DNS host for the given name. Callers that do not care about the canonical name can call LookupHost or LookupIP directly; both take care of resolving the canonical name as part of the lookup.
func (*Unbound) LookupHost ¶
LookupHost looks up the given host using Unbound. It returns an array of that host's addresses.
func (*Unbound) LookupIP ¶
LookupIP looks up host using Unbound. It returns an array of that host's IPv4 and IPv6 addresses. The A and AAAA lookups are performed in parallel.
func (*Unbound) LookupMX ¶
LookupMX returns the DNS MX records for the given domain name sorted by preference.
func (*Unbound) LookupSRV ¶
LookupSRV tries to resolve an SRV query of the given service, protocol, and domain name. The proto is "tcp" or "udp". The returned records are sorted by priority and randomized by weight within a priority.
LookupSRV constructs the DNS name to look up following RFC 2782. That is, it looks up _service._proto.name. To accommodate services publishing SRV records under non-standard names, if both service and proto are empty strings, LookupSRV looks up name directly.
func (*Unbound) LookupTLSA ¶
LookupTLSA returns the DNS DANE records for the given domain service, protocol and domainname.
LookupTLSA constructs the DNS name to look up following RFC 6698. That is, it looks up _port._proto.name.
func (*Unbound) ResolvConf ¶
ResolvConf wraps Unbound's ub_ctx_resolvconf.
func (*Unbound) ResolveAsync ¶
func (u *Unbound) ResolveAsync(name string, rrtype, rrclass uint16, c chan *ResultError)
ResolveAsync does *not* wrap the Unbound function, instead it utilizes Go's goroutines and channels to implement the asynchronous behavior Unbound implements. As a result the function signature is different. The result (or an error) is returned on the channel c. Also the ub_cancel, ub_wait_, ub_fd, ub_process are not implemented.
func (*Unbound) TrustedKeys ¶
TrustedKeys wraps Unbound's ub_ctx_trustedkeys.
func (*Unbound) Version ¶
Version wrap Ubounds's ub_version. Return the version of the Unbound library in as integers [major, minor, patch]
func (*Unbound) ZoneRemove ¶
ZoneRemove wraps Unbound's ub_ctx_zone_remove.