database

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2023 License: BSD-2-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package database provides a hierarchical DNS lookup mechanism. LookupRR() requires a class, type and FQDN and returns a set of RRs or an NXDOMAIN indication.

Once the database has been handed to a Getter() only Lookup() calls can be made as there is no internal concurrency protection.

Expected usage is:

db := database.NewDatabase(config)
for {
    db.AddRR(dns.RR)
}

fmt.Println("Size", db.Count())
for {
    rrset, nxDomain := db.LookupRR(...)
}

database.Getter exists to assist with switching databases atomically.

For compatibility purpose, the older ptr database interfaces are also supported in compat.go. These are Add() to add a PTR and Lookup() to look up PTRs given just an ip address. These functions will presumably disappear once autoreverse is fully migrated over to the newer interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database is constructed with NewDatabase() - using a default construction will result in a panic due to unconstructed maps.

func NewDatabase

func NewDatabase() *Database

NewDatabase *must* be used to construct a new database

func (*Database) AddRR added in v1.2.0

func (t *Database) AddRR(rr dns.RR) bool

AddRR into the map. Return true if it was added. Return false it's a duplicate or an impossible RR (which should never be the case).

func (*Database) Count

func (t *Database) Count() int

Count returns the total count of all RRs in the database.

func (*Database) Dump added in v1.2.0

func (t *Database) Dump()

Dump is a test/debug function only.

func (*Database) LookupRR added in v1.2.0

func (t *Database) LookupRR(qClass, qType uint16, qName string) (ans []dns.RR, nxDomain bool)

LookupRR returns an array of copies of matching RRs. Copies are important as we know caller are likely to modify the results, particularly TTL. nxDomain is true if there is no node for the qName. Note a node is only every created when there is something to add into it so the presence of a node implies RRs or children.

type Getter

type Getter struct {
	// contains filtered or unexported fields
}

Getter supports atomically switching databases on the fly - this occurs most often due to expired zone reloads. All database access for each request should go via Getter.Current() and go-routines should not hold on to the returned values of Getter() for longer than a single set of related accesses (such as an SOA query which might access SOA, NS and address RRs).

The Getter exists because the database is read-only once populated and rather than having update capabilities they are simply replaced. Getter makes that easier.

func NewGetter

func NewGetter() *Getter

NewGetter creates a Getter with valid databases. This ensures Getter.Current() always returns valid pointers to database structs. After a Getter is created, all access functions are mutex protected to ensure concurrent access is ok.

func (*Getter) Current

func (t *Getter) Current() *Database

Current returns the current database pointers under mutex protection.

func (*Getter) Replace

func (t *Getter) Replace(newDB *Database)

Replace the current database. The old database will eventually garbage collect out of existence once the go-routines re-get via Current(). Replace can be called with a nil replacement pointer, in which case Replace() does nothing.

The replacement occurs under the protection of a mutex making it concurrency safe.

Jump to

Keyboard shortcuts

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