newdns: Index | Files | Directories

package newdns

import ""


Package Files

record.go server.go set.go tools.go type.go zone.go


const (
    // A records return IPV4 addresses.
    A   = Type(dns.TypeA)

    // AAAA records return IPV6 addresses.
    AAAA = Type(dns.TypeAAAA)

    // CNAME records return other DNS names.
    CNAME = Type(dns.TypeCNAME)

    // MX records return mails servers with their priorities. The target mail
    // servers must itself be returned with an A or AAAA record.
    MX  = Type(dns.TypeMX)

    // TXT records return arbitrary text data.
    TXT = Type(dns.TypeTXT)

func InZone Uses

func InZone(zone, name string) bool

InZone returns whether the provided name is part of the provided zone. Will always return false if the provided domains are not valid.

func IsDomain Uses

func IsDomain(name string, fqdn bool) bool

IsDomain returns whether the name is a valid domain and if requested also fully qualified.

func NormalizeDomain Uses

func NormalizeDomain(name string, lower, makeFQDN, removeFQDN bool) string

NormalizeDomain will normalize the provided domain name by removing space around the name and lowercase it if request.

func Query Uses

func Query(proto, addr, name, typ string, fn func(*dns.Msg)) (*dns.Msg, error)

Query can be used to query a DNS server over the provided protocol on its address fot the specified name and type. The supplied function can be set to mutate the sent request.

func SplitDomain Uses

func SplitDomain(name string, hierarchical bool) []string

SplitDomain will split the provided domain either in separate labels or hierarchical labels. The late allows walking a domain up to the root.

func TransferCase Uses

func TransferCase(source, destination string) string

TransferCase will transfer the case from the source name to the destination. For for the source "" and destination "" the function will return "". The source must be either a child or the same as the destination.

func TrimZone Uses

func TrimZone(zone, name string) string

TrimZone will remove the zone from the specified name.

type Config Uses

type Config struct {
    // The buffer size used if EDNS is enabled by a client.
    // Default: 1220.
    BufferSize int

    // Handler is the callback that returns a zone for the specified name.
    Handler func(name string) (*Zone, error)

    // Reporter is the callback called with request errors.
    Logger func(e Event, msg *dns.Msg, err error, reason string)

Config provides configuration for a DNS server.

type Event Uses

type Event int

Event denotes an event type emitted to the logger.

const (
    // Ignored are requests that haven been dropped by leaving the connection
    // hanging to mitigate attacks. Inspect the reason for more information.
    Ignored Event = iota

    // Request is emitted for every accepted request. For every request event
    // a finish event fill follow. You can inspect the message to see the
    // complete request sent by the client.
    Request Event = iota

    // Refused are requests that received an error due to some incompatibility.
    // Inspect the reason for more information.
    Refused Event = iota

    // BackendError is emitted with errors returned by the callback and
    // validation functions. Inspect the error for more information.
    BackendError Event = iota

    // NetworkError is emitted with errors returned by the connection. Inspect
    // the error for more information.
    NetworkError Event = iota

    // Response is emitted with the final response to the client. You can inspect
    // the message to see the complete response to the client.
    Response Event = iota

    // Finish is emitted when a request has been processed.
    Finish Event = iota

func (Event) String Uses

func (e Event) String() string

String will return the name of the event.

type Record Uses

type Record struct {
    // The target address for A, AAAA, CNAME and MX records.
    Address string

    // The priority for MX records.
    Priority int

    // The data for TXT records.
    Data []string

Record holds a single DNS record.

func (*Record) Validate Uses

func (r *Record) Validate(typ Type) error

Validate will validate the record.

type Server Uses

type Server struct {
    // contains filtered or unexported fields

Server is a DNS server.

func NewServer Uses

func NewServer(config Config) *Server

NewServer creates and returns a new DNS server.

func (*Server) Close Uses

func (s *Server) Close()

Close will close the server.

func (*Server) Run Uses

func (s *Server) Run(addr string) error

Run will run a udp and tcp server on the specified address. It will return on the first accept error and close all servers.

type Set Uses

type Set struct {
    // The FQDN of the set.
    Name string

    // The type of the record.
    Type Type

    // The records in the set.
    Records []Record

    // The TTL of the set.
    // Default: 5m.
    TTL time.Duration

Set is a set of records.

func (*Set) Validate Uses

func (s *Set) Validate() error

Validate will validate the set and ensure defaults.

type Type Uses

type Type uint16

Type denotes the DNS record type.

type Zone Uses

type Zone struct {
    // The FQDN of the zone e.g. "".
    Name string

    // The FQDN of the master mame server responsible for this zone. The FQDN
    // must be returned as A and AAAA record by the parent zone.
    MasterNameServer string

    // A list of FQDNs to all authoritative name servers for this zone. The
    // FQDNs must be returned as A and AAAA records by the parent zone. It is
    // required to announce at least two distinct name servers per zone.
    AllNameServers []string

    // The email address of the administrator e.g. "".
    // Default: "hostmaster@NAME".
    AdminEmail string

    // The refresh interval.
    // Default: 6h.
    Refresh time.Duration

    // The retry interval for the zone.
    // Default: 1h.
    Retry time.Duration

    // The expiration interval of the zone.
    // Default: 72h.
    Expire time.Duration

    // The TTl for the SOA record.
    // Default: 15m.
    SOATTL time.Duration

    // The TTl for NS records.
    // Default: 48h.
    NSTTL time.Duration

    // The minimum TTL for all records. Either this value, or the SOATTL if lower,
    // is used to determine the "negative caching TTL" which is the duration
    // caches are allowed to cache missing records (NXDOMAIN).
    // Default: 5min.
    MinTTL time.Duration

    // The handler that responds to requests for this zone.
    Handler func(name string) ([]Set, error)

Zone describes a single authoritative DNS zone.

func (*Zone) Lookup Uses

func (z *Zone) Lookup(name string, needle ...Type) ([]Set, bool, error)

Lookup will lookup the specified name in the zone and return results for the specified record types. If no results are returned, the second return value indicates if there are other results for the specified name.

func (*Zone) Validate Uses

func (z *Zone) Validate() error

Validate will validate the zone and ensure the documented defaults.



Package newdns imports 8 packages (graph) and is imported by 1 packages. Updated 2019-08-06. Refresh now. Tools for package owners.