unbound

package module
v0.0.0-...-1e72204 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

README

unbound

Name

unbound - resolve names using libunbound.

Description

With unbound you can (recursively) resolve names using the Unbound resolver from NLnet Labs.

Unbound's ub_result has been extended with an slice of dns.RRs, this alleviates the need to parse ub_result.data yourself.

Syntax

Just enable the plugin with:

unbound

A wrapper for Unbound in Go.

Notes

Compilation of this plugin requires CGO, which means the executables will use shared libraries (OpenSSL, ldns and libunbound).

See Also

The website for Unbound is https://unbound.net/, where you can find further documentation. Tested/compiled to work for versions: 1.4.22 and 1.6.0-3+deb9u1 (Debian Stretch).

The tutorials found here are the originals ones adapted to Go.

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

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.

func (*Error) Error

func (e *Error) Error() string

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

type ResultError struct {
	*Result
	Error error
}

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 New

func New() *Unbound

New wraps Unbound's ub_ctx_create.

func (*Unbound) AddTa

func (u *Unbound) AddTa(ta string) error

AddTa wraps Unbound's ub_ctx_add_ta.

func (*Unbound) AddTaFile

func (u *Unbound) AddTaFile(fname string) error

AddTaFile wraps Unbound's ub_ctx_add_ta_file.

func (*Unbound) AddTaRR

func (u *Unbound) AddTaRR(ta dns.RR) error

AddTaRR calls AddTa, but allows to directly use an dns.RR. This method is not found in Unbound.

func (*Unbound) Config

func (u *Unbound) Config(fname string) error

Config wraps Unbound's ub_ctx_config.

func (*Unbound) DataAdd

func (u *Unbound) DataAdd(data string) error

DataAdd wraps Unbound's ub_ctx_data_add.

func (*Unbound) DataAddRR

func (u *Unbound) DataAddRR(data dns.RR) error

DataAddRR calls DataAdd, but allows to directly use an dns.RR. This method is not found in Unbound.

func (*Unbound) DataRemove

func (u *Unbound) DataRemove(data string) error

DataRemove wraps Unbound's ub_ctx_data_remove.

func (*Unbound) DataRemoveRR

func (u *Unbound) DataRemoveRR(data dns.RR) error

DataRemoveRR calls DataRemove, but allows to directly use an dns.RR. This method is not found in Unbound.

func (*Unbound) DebugLevel

func (u *Unbound) DebugLevel(d int) error

DebugLevel wraps Unbound's ub_ctx_data_level.

func (*Unbound) DebugOut

func (u *Unbound) DebugOut(out *os.File) error

DebugOut wraps Unbound's ub_ctx_debugout.

func (*Unbound) Destroy

func (u *Unbound) Destroy()

Destroy wraps Unbound's ub_ctx_delete.

func (*Unbound) GetOption

func (u *Unbound) GetOption(opt string) (string, error)

GetOption wraps Unbound's ub_ctx_get_option.

func (*Unbound) Hosts

func (u *Unbound) Hosts(fname string) error

Hosts wraps Unbound's ub_ctx_hosts.

func (*Unbound) LookupAddr

func (u *Unbound) LookupAddr(addr string) (name []string, err error)

LookupAddr performs a reverse lookup for the given address, returning a list of names mapping to that address.

func (*Unbound) LookupCNAME

func (u *Unbound) LookupCNAME(name string) (cname string, err error)

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

func (u *Unbound) LookupHost(host string) (addrs []string, err error)

LookupHost looks up the given host using Unbound. It returns an array of that host's addresses.

func (*Unbound) LookupIP

func (u *Unbound) LookupIP(host string) (addrs []net.IP, err error)

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

func (u *Unbound) LookupMX(name string) (mx []*dns.MX, err error)

LookupMX returns the DNS MX records for the given domain name sorted by preference.

func (*Unbound) LookupNS

func (u *Unbound) LookupNS(name string) (ns []*dns.NS, err error)

LookupNS returns the DNS NS records for the given domain name.

func (*Unbound) LookupSRV

func (u *Unbound) LookupSRV(service, proto, name string) (cname string, srv []*dns.SRV, err error)

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

func (u *Unbound) LookupTLSA(service, proto, name string) (tlsa []*dns.TLSA, err error)

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) LookupTXT

func (u *Unbound) LookupTXT(name string) (txt []string, err error)

LookupTXT returns the DNS TXT records for the given domain name.

func (*Unbound) ResolvConf

func (u *Unbound) ResolvConf(fname string) error

ResolvConf wraps Unbound's ub_ctx_resolvconf.

func (*Unbound) Resolve

func (u *Unbound) Resolve(name string, rrtype, rrclass uint16) (*Result, error)

Resolve wraps Unbound's ub_resolve.

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) SetFwd

func (u *Unbound) SetFwd(addr string) error

SetFwd wraps Unbound's ub_ctx_set_fwd.

func (*Unbound) SetOption

func (u *Unbound) SetOption(opt, val string) error

SetOption wraps Unbound's ub_ctx_set_option.

func (*Unbound) TrustedKeys

func (u *Unbound) TrustedKeys(fname string) error

TrustedKeys wraps Unbound's ub_ctx_trustedkeys.

func (*Unbound) Version

func (u *Unbound) Version() (version [3]int)

Version wrap Ubounds's ub_version. Return the version of the Unbound library in as integers [major, minor, patch]

func (*Unbound) ZoneAdd

func (u *Unbound) ZoneAdd(zoneName, zoneType string) error

ZoneAdd wraps Unbound's ub_ctx_zone_add.

func (*Unbound) ZoneRemove

func (u *Unbound) ZoneRemove(zoneName string) error

ZoneRemove wraps Unbound's ub_ctx_zone_remove.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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