dnszone

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package implement a DNS zone, held in a binary tree. Each RR(set) that gets inserted will need to create any empty non-terminals (ENT) it possesses. I.e. inserting www.example.org into example.org is easy, but when www.a.b.c.example.org inserts we need to make sure that 'c.example.org', 'b.c.example.org' and 'a.b.c.example.org' also exist and are ENTs (have no actual RRs). For deleted the opposite must happen. As an example from RFC 4592, the record: sub.*.example. TXT "this is not a wildcard" is a fun one. As this means the '*.example' ENT exists meaning that bogus.example. gets a NODATA response instead of NXDOMAIN.

Doing this on insert sucks a bit, but makes the lookup code much more simple (and correct), which is more important for a DNS server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Canonical

func Canonical(z Interface, r *dns.Msg, encloser Node, re *Restart) *dns.Msg

Canonical follows the cname chain.

func Less

func Less(a, b Node) bool

Less compares nodes a, b by Name and returns true if a is less than b.

func MsgFound

func MsgFound(z Interface, r *dns.Msg, encloser Node, hint Hint, re *Restart) *dns.Msg

func Retrieve

func Retrieve(z Interface, m *dns.Msg, re *Restart) *dns.Msg

Retrieve looks up the qname and qtype in the Zone z. It returns a message with the RRs (if found) in the correct places. In case of NXDOMAIN or NODATA response the message will also contain the correct information. The optional Restart is used to generate the correct CNAME chains. When calling Retrieve for the first time re should be nil.

func Synthesize

func Synthesize(z Interface, r *dns.Msg, sosynthesis, encloser Node, re *Restart) *dns.Msg

Synthesize handles all wildcard responses, we are only called when we hit a wildcard and didn't find any more specific. I.e. original qname did not exist. Now we need to assemble the answer plus adding the NSECs that validte the answer. If sosynthesis.Name != encloser.Name, those two NSECs need to be added.

func TransferOut added in v0.5.2

func TransferOut(z Interface, ctx context.Context, w dns.ResponseWriter, r *dns.Msg) error

Types

type Hint

type Hint int

Hints give a hint to the functions here on what type of answer we got. This could be (mostly?) be done in retreive, but requires redoing work already done, easier to just notify what we have.

type Interface

type Interface interface {
	// Load loads a zone.
	Load() error
	// Get returns the node under key. The boolean is true when something is found.
	Get(string) (Node, bool)
	// Previous returns the previous node for string. If the node under key exists that one is returned.
	Previous(string) Node
	// Set sets a node in the zone. It must take care to also fill out any empty non-terminals that are
	// needed.
	Set(Node) string
	// Apex returns the apex of the zone.
	Apex() Node
	// Origin returns the origin of the zone as string.
	Origin() string
	// Labels returns the number of labels from the origin. This is method to allow the implementation some
	// head room for optimizations.
	Labels() int
	// Walk walks the entire walk starting at the apex.
	Walk(func(Node) bool)
	// AuthoritativeWalk walks the entire zone starting at the apex, but skips non-authoritative records:
	// delegated (or should have been delegated) and glue recors.
	AuthoritativeWalk(func(Node, bool) bool)
}

Interface defines the methods for each db* implementation. This is currently unused, and if used this needs to live in the pkg/db or something, not tucked away here.

This is the interface dbfile implements on top of the b-tree. And dbsqlite on top of an SQLite database.

type Node

type Node struct {
	Name string
	RRs  []dns.RR // all the rrs with owner name 'name'.
}

A Node is a DNS node in the tree.

func (Node) String

func (n Node) String() string

type Restart

type Restart struct {
	Answer []dns.RR // current set of RRs that need to go in the final response
	I      int      // break recursion at I > 7
}

Restart is used in the (recursive) calling of Retrieve to complete a CNAME chain. The i index is used to avoid loops in the recursion and we break at 8.

Jump to

Keyboard shortcuts

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