dnsserver

package
v0.0.0-...-d4f9e80 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

README

tinydnscdb

tinydnscdb enables serving DNS data of a cdb file.

Syntax

tinydnscdb CDBFILE [RELOAD_TIME]
  • CDBFILE the CDB database file to read records from.
  • RELOAD_TIME the interval at which the CDB will be reloaded. 0 do disabled automatic reloading. WARNING: this is currently disabled...

Examples

. {
    tinydnscdb /var/db/data.cdb 10
}

Or to disable reloading

. {
    tinydnscdb /var/db/data.cdb
}

Documentation

Index

Constants

View Source
const (
	ControlFileFullReload    = "switchdb"
	ControlFilePartialReload = "reload"
)

group of control files we watch for to reload DB

View Source
const (
	// TypeToStatsPrefix is the prefix used for creating stats keys
	TypeToStatsPrefix = "DNS_query"

	// DefaultMaxAnswer is the default number of answer returned for A\AAAA query
	DefaultMaxAnswer = 1
)

Variables

This section is empty.

Functions

func GetMaxAnswer

func GetMaxAnswer(ctx context.Context) (int, bool)

GetMaxAnswer is used to get max answer number from context

func MakeOPTWithECS

func MakeOPTWithECS(s string) (*dns.OPT, error)

MakeOPTWithECS returns dns.OPT with a specified subnet EDNS0 option FIXME: Instead of returning a dns.OPT specifically for EDNS0 Make this function more standardized to support all types of options (e.g: ecs, dns cookie..) see: https://tools.ietf.org/html/rfc6891#section-6

func WithMaxAnswer

func WithMaxAnswer(ctx context.Context, masAns int) context.Context

WithMaxAnswer set max ans in context

Types

type CacheConfig

type CacheConfig struct {
	Enabled    bool
	LRUSize    int
	WRSTimeout int64
}

CacheConfig has knobs to modify caching behaviour.

type DBConfig

type DBConfig struct {
	Path           string
	ControlPath    string
	Driver         string
	ReloadInterval int
	ReloadTimeout  time.Duration
	WatchDB        bool
	ValidationKey  []byte
}

DBConfig contains our DNS Database configuration.

type DummyLogger

type DummyLogger struct{}

DummyLogger logs nothing

func (*DummyLogger) Log

func (l *DummyLogger) Log(_ request.Request, _ *dns.Msg, _ *dns.EDNS0_SUBNET)

Log is used to log to an ioWriter.

func (*DummyLogger) LogFailed

func (l *DummyLogger) LogFailed(_ request.Request, _ *dns.Msg, _ *dns.EDNS0_SUBNET)

LogFailed is used to log failures

type FBDNSDB

type FBDNSDB struct {
	ReloadChan chan ReloadSignal

	Next plugin.Handler
	// contains filtered or unexported fields
}

FBDNSDB is the DNS DB handler.

func NewFBDNSDB

func NewFBDNSDB(handlerConfig HandlerConfig, dbConfig DBConfig, cacheConfig CacheConfig, l Logger, s stats.Stats) (t *FBDNSDB, err error)

NewFBDNSDB initialize a new FBDNSDB and set up DB reloading

func NewFBDNSDBBasic

func NewFBDNSDBBasic(handlerConfig HandlerConfig, dbConfig DBConfig, cacheConfig CacheConfig, l Logger, s stats.Stats) (t *FBDNSDB, err error)

NewFBDNSDBBasic initialize a new FBDNSDB. Reloading strategy is left to be set.

func (*FBDNSDB) AcquireReader

func (h *FBDNSDB) AcquireReader() (db.Reader, error)

AcquireReader return a DB reader which increment the refcount to the DB. This makes sure that we can handle DB reloading from other goroutine while providing a consistent view on the DB during a query. The Reader must be `Close`d when not needed anymore.

func (*FBDNSDB) Close

func (h *FBDNSDB) Close()

Close closes the database. It also takes care of closing the channel used for periodic reloading.

func (*FBDNSDB) Load

func (h *FBDNSDB) Load() (err error)

Load loads a DB file

func (*FBDNSDB) Name

func (h *FBDNSDB) Name() string

Name returns tinydnscdb.

func (*FBDNSDB) PeriodicDBReload

func (h *FBDNSDB) PeriodicDBReload(reloadInt int)

PeriodicDBReload is to enforce db reload in case db watch fails or stuck

func (*FBDNSDB) QuerySingle

func (h *FBDNSDB) QuerySingle(rtype, record, remoteIP, subnet string, maxAns int) (*dnstest.Recorder, error)

QuerySingle queries dns server for a query, returning single answer if possible

func (*FBDNSDB) Reload

func (h *FBDNSDB) Reload(s ReloadSignal) (err error)

Reload reload the db

func (*FBDNSDB) ReportBackendStats

func (h *FBDNSDB) ReportBackendStats()

ReportBackendStats refreshes backend statistics in server stats

func (*FBDNSDB) ServeDNS

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

ServeDNS implements the plugin.Handler interface.

func (*FBDNSDB) ServeDNSWithRCODE

func (h *FBDNSDB) ServeDNSWithRCODE(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

ServeDNSWithRCODE handles a dns query and with return the RCODE and eventual error that happen during processing.

func (*FBDNSDB) ValidateDbKey

func (h *FBDNSDB) ValidateDbKey(dbKey []byte) error

ValidateDbKey checks whether record of certain key is in db

func (*FBDNSDB) WatchControlDirAndReload

func (h *FBDNSDB) WatchControlDirAndReload() error

WatchControlDirAndReload refreshes the data view on control file change. We monitor for two type of reload signals: full reload, when we switch to new file/directory, and partial reload when we try to catch up on WAL if possible. CDB does full reload in both cases as it's immutable.

func (*FBDNSDB) WatchDBAndReload

func (h *FBDNSDB) WatchDBAndReload() error

WatchDBAndReload refreshes the data view on DB file change

type HandlerConfig

type HandlerConfig struct {
	// Controls whether responses are always compressed not depending on response buffer size
	AlwaysCompress bool
}

HandlerConfig contains config used when handling a DNS request.

type Logger

type Logger interface {
	// LogFailed logs a message when we could not construct an answer
	LogFailed(state request.Request, r *dns.Msg, ecs *dns.EDNS0_SUBNET)
	// Log logs a DNS response
	Log(state request.Request, r *dns.Msg, ecs *dns.EDNS0_SUBNET)
}

Logger is an interface for logging messages

type ReloadSignal

type ReloadSignal struct {
	Kind    ReloadType
	Payload string
}

ReloadSignal is a signal we use to tell server that something/someone requested DB reload

func NewFullReloadSignal

func NewFullReloadSignal(newDBPath string) *ReloadSignal

NewFullReloadSignal is a helper to create new ReloadSignal of kind FullReload

func NewPartialReloadSignal

func NewPartialReloadSignal() *ReloadSignal

NewPartialReloadSignal is a helper to create new ReloadSignal of kind PartialReload

type ReloadType

type ReloadType int

ReloadType - how to reload the DB

const (
	// FullReload - close and open DB
	FullReload ReloadType = iota
	// PartialReload - Catch up on WAL
	PartialReload
)

type TextLogger

type TextLogger struct {
	IoWriter io.Writer
}

TextLogger logs to an io.Writer

func (*TextLogger) Log

func (l *TextLogger) Log(state request.Request, _ *dns.Msg, _ *dns.EDNS0_SUBNET)

Log is used to log to an ioWriter.

func (*TextLogger) LogFailed

func (l *TextLogger) LogFailed(state request.Request, r *dns.Msg, ecs *dns.EDNS0_SUBNET)

LogFailed is used to log failures

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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