dnsserver

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2018 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package dnsserver implements a simple, authoritative DNS server. It is built upon https://github.com/miekg/dns.

See the top-level package for general documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DotSuffix

func DotSuffix(name string) string

DotSuffix ensures that the string has a dot at the end, unless it is empty.

func EmailMbox

func EmailMbox(email string) (mbox string, err error)

EmailMbox converts “admin@example.org” to “admin.example.org.”, but rejects “user.name@example.org”. Empty string is passed through.

func Serve

func Serve(ctx context.Context, resolver Resolver, serverConfig *Config) (err error)

Serve DNS requests for the duration of the context. Resolver implementation effectively defines the zones. Configuration is optional.

Types

type Config

type Config struct {
	Addr  string // Defaults to ":dns"
	NoTCP bool
	NoUDP bool

	ErrorLog Logger // Defaults to log package's standard logger
	DebugLog Logger // Defaults to nothingness

	// If provided, this channel will be closed once all listeners are ready.
	Ready chan struct{}

	// If the NS field of SOA is set, the name server will be authoritative and
	// NS and SOA records are returned.
	SOA SOA
}

Config of DNS server.

type Logger

type Logger interface {
	Printf(fmt string, args ...interface{})
}

Logger is a subset of log.Logger.

type Resolver

type Resolver interface {
	// ResolveRecords copies a host's records.  It should return empty node
	// name if and only if the host name doesn't fall into any known zone:
	// unknown node names in known zones should be returned without records.
	//
	// The filter parameter selects a single record type, or all records if
	// dns.TypeAny is specified.  Unknown values must be handled by returning
	// an empty record set.
	//
	// serial is the current serial number of the node's zone.  It is non-zero
	// for known zones, and zero if zone wasn't found.
	ResolveRecords(hostname string, filter dns.RecordType) (node string, rs dns.Records, serial uint32)

	// TransferZone copies the contents of a domain.  The apex node must be
	// first, if present.
	//
	// serial is the current serial number of the zone.  It is non-zero if the
	// zone was found, and zero if not.
	TransferZone(domain string) (zone []dns.NodeRecords, serial uint32)
}

Resolver can dump host and zone records. It must be instantaneous.

type SOA

type SOA struct {
	NS   string // Name of this name server (like "ns1.example.net.")
	Mbox string // Email mailbox (like "hostmaster.example.net.")

	Refresh uint32 // Defaults to a reasonable value
	Retry   uint32 // Defaults to a reasonable value
	Expire  uint32 // Defaults to a reasonable value
	TTL     uint32 // Defaults to a reasonable value
}

SOA and primary NS record information. NS and Mbox fields must both be specified or empty. If they are specified, the server is authoritative for all zones (which are specified elsewhere).

TTL is used for SOA and NS records' TTL and MINIMUM values.

Jump to

Keyboard shortcuts

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