file

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2019 License: Apache-2.0 Imports: 22 Imported by: 284

README

file

Name

file - enables serving zone data from an RFC 1035-style master file.

Description

The file plugin is used for an "old-style" DNS server. It serves from a preloaded file that exists on disk. If the zone file contains signatures (i.e., is signed using DNSSEC), correct DNSSEC answers are returned. Only NSEC is supported! If you use this setup you are responsible for re-signing the zonefile.

Syntax

file DBFILE [ZONES...]
  • DBFILE the database file to read and parse. If the path is relative, the path from the root directive will be prepended to it.
  • ZONES zones it should be authoritative for. If empty, the zones from the configuration block are used.

If you want to round-robin A and AAAA responses look at the loadbalance plugin.

file DBFILE [ZONES... ] {
    transfer to ADDRESS...
    reload DURATION
}
  • transfer enables zone transfers. It may be specified multiples times. To or from signals the direction. ADDRESS must be denoted in CIDR notation (e.g., 127.0.0.1/32) or just as plain addresses. The special wildcard * means: the entire internet (only valid for 'transfer to'). When an address is specified a notify message will be sent whenever the zone is reloaded.
  • reload interval to perform a reload of the zone if the SOA version changes. Default is one minute. Value of 0 means to not scan for changes and reload. For example, 30s checks the zonefile every 30 seconds and reloads the zone when serial changes.

Examples

Load the example.org zone from example.org.signed and allow transfers to the internet, but send notifies to 10.240.1.1

example.org {
    file example.org.signed {
        transfer to *
        transfer to 10.240.1.1
    }
}

Or use a single zone file for multiple zones:

. {
    file example.org.signed example.org example.net {
        transfer to *
        transfer to 10.240.1.1
    }
}

Note that if you have a configuration like the following you may run into a problem of the origin not being correctly recognized:

. {
    file db.example.org
}

We omit the origin for the file db.example.org, so this references the zone in the server block, which, in this case, is the root zone. Any contents of db.example.org will then read with that origin set; this may or may not do what you want. It's better to be explicit here and specify the correct origin. This can be done in two ways:

. {
    file db.example.org example.org
}

Or

example.org {
    file db.example.org
}

Also See

See the loadbalance plugin if you need simple record shuffling.

Documentation

Overview

Package file implements a file backend.

Index

Constants

View Source
const MaxSerialIncrement uint32 = 2147483647

MaxSerialIncrement is the maximum difference between two serial numbers. If the difference between two serials is greater than this number, the smaller one is considered greater.

Variables

This section is empty.

Functions

This section is empty.

Types

type Apex

type Apex struct {
	SOA    *dns.SOA
	NS     []dns.RR
	SIGSOA []dns.RR
	SIGNS  []dns.RR
}

Apex contains the apex records of a zone: SOA, NS and their potential signatures.

type File

type File struct {
	Next plugin.Handler
	Zones
}

File is the plugin that reads zone data from disk.

func (File) Name

func (f File) Name() string

Name implements the Handler interface.

func (File) ServeDNS

func (f File) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handle interface.

type Result

type Result int

Result is the result of a Lookup

const (
	// Success is a successful lookup.
	Success Result = iota
	// NameError indicates a nameerror
	NameError
	// Delegation indicates the lookup resulted in a delegation.
	Delegation
	// NoData indicates the lookup resulted in a NODATA.
	NoData
	// ServerFailure indicates a server failure during the lookup.
	ServerFailure
)

type Xfr

type Xfr struct {
	*Zone
}

Xfr serves up an AXFR.

func (Xfr) Name

func (x Xfr) Name() string

Name implements the plugin.Handler interface.

func (Xfr) ServeDNS

func (x Xfr) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNS implements the plugin.Handler interface.

func (Xfr) ServeIxfr added in v1.6.3

func (x Xfr) ServeIxfr(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeIxfr checks if we need to serve a simpler IXFR for the incoming message. See RFC 1995 Section 3: "... and the authority section containing the SOA record of client's version of the zone." and Section 2, paragraph 4 where we only need to echo the SOA record back. This function must be called when the qtype is IXFR. It returns a plugin.ClientWrite(code) == false, when it didn't write anything and we should perform an AXFR.

type Zone

type Zone struct {
	*tree.Tree
	Apex
	Expired bool

	sync.RWMutex

	TransferTo   []string
	StartupOnce  sync.Once
	TransferFrom []string

	ReloadInterval time.Duration

	Upstream *upstream.Upstream // Upstream for looking up external names during the resolution process.
	// contains filtered or unexported fields
}

Zone is a structure that contains all data related to a DNS zone.

func NewZone

func NewZone(name, file string) *Zone

NewZone returns a new zone.

func Parse

func Parse(f io.Reader, origin, fileName string, serial int64) (*Zone, error)

Parse parses the zone in filename and returns a new Zone or an error. If serial >= 0 it will reload the zone, if the SOA hasn't changed it returns an error indicating nothing was read.

func (*Zone) ApexIfDefined added in v1.6.3

func (z *Zone) ApexIfDefined() ([]dns.RR, error)

ApexIfDefined returns the apex nodes from z. The SOA record is the first record, if it does not exist, an error is returned.

func (*Zone) ClosestEncloser

func (z *Zone) ClosestEncloser(qname string) (*tree.Elem, bool)

ClosestEncloser returns the closest encloser for qname.

func (*Zone) Copy

func (z *Zone) Copy() *Zone

Copy copies a zone.

func (*Zone) CopyWithoutApex added in v1.0.5

func (z *Zone) CopyWithoutApex() *Zone

CopyWithoutApex copies zone z without the Apex records.

func (*Zone) File added in v1.2.0

func (z *Zone) File() string

File retrieves the file path in a safe way.

func (*Zone) Insert

func (z *Zone) Insert(r dns.RR) error

Insert inserts r into z.

func (*Zone) Lookup

func (z *Zone) Lookup(ctx context.Context, state request.Request, qname string) ([]dns.RR, []dns.RR, []dns.RR, Result)

Lookup looks up qname and qtype in the zone. When do is true DNSSEC records are included. Three sets of records are returned, one for the answer, one for authority and one for the additional section.

func (*Zone) Notify

func (z *Zone) Notify()

Notify will send notifies to all configured TransferTo IP addresses.

func (*Zone) OnShutdown added in v1.1.0

func (z *Zone) OnShutdown() error

OnShutdown shuts down any running go-routines for this zone.

func (*Zone) Reload

func (z *Zone) Reload() error

Reload reloads a zone when it is changed on disk. If z.NoReload is true, no reloading will be done.

func (*Zone) SOASerialIfDefined

func (z *Zone) SOASerialIfDefined() int64

SOASerialIfDefined returns the SOA's serial if the zone has a SOA record in the Apex, or -1 otherwise.

func (*Zone) SetFile added in v1.2.0

func (z *Zone) SetFile(path string)

SetFile updates the file path in a safe way.

func (*Zone) TransferAllowed

func (z *Zone) TransferAllowed(state request.Request) bool

TransferAllowed checks if incoming request for transferring the zone is allowed according to the ACLs.

func (*Zone) TransferIn

func (z *Zone) TransferIn() error

TransferIn retrieves the zone from the masters, parses it and sets it live.

func (*Zone) Update

func (z *Zone) Update() error

Update updates the secondary zone according to its SOA. It will run for the life time of the server and uses the SOA parameters. Every refresh it will check for a new SOA number. If that fails (for all server) it will retry every retry interval. If the zone failed to transfer before the expire, the zone will be marked expired.

type Zones

type Zones struct {
	Z     map[string]*Zone // A map mapping zone (origin) to the Zone's data
	Names []string         // All the keys from the map Z as a string slice.
}

Zones maps zone names to a *Zone.

Directories

Path Synopsis
Package rrutil provides function to find certain RRs in slices.
Package rrutil provides function to find certain RRs in slices.
Package tree implements Left-Leaning Red Black trees as described by Robert Sedgewick.
Package tree implements Left-Leaning Red Black trees as described by Robert Sedgewick.

Jump to

Keyboard shortcuts

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