file

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2022 License: Apache-2.0 Imports: 23 Imported by: 280

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 contained RFC 1035 styled data. 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 plugin 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... ] {
    reload DURATION
}
  • 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.

If you need outgoing zone transfers, take a look at the transfer plugin.

Examples

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

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

Where db.example.org would contain RRSets (https://tools.ietf.org/html/rfc7719#section-4) in the (text) presentation format from RFC 1035:

$ORIGIN example.org.
@	3600 IN	SOA sns.dns.icann.org. noc.dns.icann.org. 2017042745 7200 3600 1209600 3600
	3600 IN NS a.iana-servers.net.
	3600 IN NS b.iana-servers.net.

www     IN A     127.0.0.1
        IN AAAA  ::1

Or use a single zone file for multiple zones:

. {
    file example.org.signed example.org example.net
    transfer example.org example.net {
        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
}

See Also

See the loadbalance plugin if you need simple record shuffling. And the transfer plugin for zone transfers. Lastly the root plugin can help you specify the location of the zone files.

See RFC 1035 for more info on how to structure zone files.

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
	// contains filtered or unexported fields
}

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.

func (File) Transfer added in v1.8.0

func (f File) Transfer(zone string, serial uint32) (<-chan []dns.RR, error)

Transfer implements the transfer.Transfer 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 Zone

type Zone struct {
	*tree.Tree
	Apex
	Expired bool

	sync.RWMutex

	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) 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(t *transfer.Transfer) error

Reload reloads a zone when it is changed on disk. If z.ReloadInterval is zero, 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) Transfer added in v1.8.0

func (z *Zone) Transfer(serial uint32) (<-chan []dns.RR, error)

Transfer transfers a zone with serial in the returned channel and implements IXFR fallback, by just sending a single SOA record.

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