ns

package
v0.0.0-...-e5d9080 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrZoneNotFound   = errors.New("zone not found")
	ErrRecordNotFound = errors.New("record not found")
)
View Source
var (
	ErrProtoUnknown = Error{/* contains filtered or unexported fields */}
)
View Source
var (
	// ErrTimeout is returned when request processing did not served
	// within a configured duration.
	ErrTimeout = Error{/* contains filtered or unexported fields */}
)

Functions

func ServeDNS

func ServeDNS(h Handler) dns.Handler

func ServeHTTP

func ServeHTTP(h Handler) http.Handler

func ShutdownAll

func ShutdownAll(ctx context.Context, ss ...Shutdowner) (err error)

ShutdownAll executes all passed ShutdownFunc concurrently.

Types

type Config

type Config struct {
	// ServerStoragePath is the location of the database file to keep
	// zones and associated records.
	ServerStoragePath string `hcl:"server_storage_path,optional"`

	// ServerShutdownTimeout specifies a timeout for graceful shutdown
	// of a server. When timeout expires, the termination will be enforced.
	ServerShutdownTimeout string `hcl:"server_shutdown_timeout,optional"`

	// Servers is a list of servers to process user requests.
	Servers []ServerConfig `hcl:"server,block"`
}

Config is a structure that holds configurations for the whole DNS server.

func DecodeConfig

func DecodeConfig(filename string) (*Config, error)

DecodeConfig opens the given filename and loads the configuration.

Method returns an error, when file does not exist, configuration syntax is incorrect or the decoding failed.

type Error

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

Error represents a server error.

func NewError

func NewError(text string) Error

func (Error) Error

func (e Error) Error() string

Error returns string representation of the error.

type ForwardedHeader

type ForwardedHeader struct {
	Proto string
	Host  string
	By    net.TCPAddr
	For   []net.TCPAddr
}

func ParseForwarded

func ParseForwarded(header string) (fw ForwardedHeader, err error)

ParseForwarded parses a Forwarded header and returns all passed directives within a forwarded map.

type Handler

type Handler interface {
	Handle(context.Context, *Request) (*Response, error)
}

func MultiHandler

func MultiHandler(hh ...Handler) Handler

MultiHandler creates a handler that executes all passed handlers one by one until one of them successfully processes the request.

If a listed handler returns an error, the overall handle operation stops and returns the error; it does not continue down the list.

type HandlerFunc

type HandlerFunc func(context.Context, *Request) (*Response, error)

HandlerFunc is a function adapter to allow use of ordinary functions as request handlers. If f is a function with the appropriate signature, HandlerFunc(f) is a Handler that calls f.

func TimeoutHandler

func TimeoutHandler(h Handler, t time.Duration) HandlerFunc

TimeoutHandler is a handler that limits the handler execution by the specified timeout. Wrapped handler must implement context cancellation.

It adds a timeout to the passed context and then executes a wrapped handler instance.

func (HandlerFunc) Handle

func (fn HandlerFunc) Handle(ctx context.Context, req *Request) (*Response, error)

Handle implements Handler interface, calls f(ctx, req)

type ListenConfig

type ListenConfig struct {
	Addr           string
	MaxConns       int
	RequestTimeout time.Duration
}

type Listener

type Listener interface {
	ListenAndServe() error
	Shutdowner
}

Server describes an interface to start and terminate a server.

func Listen

func Listen(proto string, lc ListenConfig, h Handler) (Listener, error)

func ListenHTTP

func ListenHTTP(lc ListenConfig, h Handler) Listener

func ListenTCP

func ListenTCP(lc ListenConfig, h Handler) Listener

func ListenUDP

func ListenUDP(lc ListenConfig, h Handler) Listener

type Record

type Record struct {
	ID        uint64  `json:"id"`
	ZoneName  string  `json:"zoneName"`
	TTL       uint    `json:"ttl"`
	Name      string  `json:"name"`
	Class     *string `json:"class"`
	Type      string  `json:"type"`
	Data      string  `json:"data"`
	Priority  *string `json:"priority"`
	CreatedAt int64   `json:"createdAt"`
	UpdatedAt int64   `json:"updatedAt"`
}

func NewRecord

func NewRecord(id uint64, input RecordInput) *Record

type RecordInput

type RecordInput struct {
	ZoneName string  `json:"zoneName"`
	TTL      uint    `json:"ttl"`
	Name     string  `json:"name"`
	Class    *string `json:"class"`
	Type     string  `json:"type"`
	Data     string  `json:"data"`
	Priority *string `json:"priority"`
}

type Request

type Request struct {
	// ID is a unique identifier of the request. It's the same as DNS
	// request identifier.
	ID int64

	// RequestURI is a path where request was submitted.
	//
	// For some applications it is usefull to extract parameters from
	// the URL. This URL will be copied to each plugin.
	RequestURI string

	Header http.Header

	Body dns.Msg

	// At is a request submission timestamp.
	At time.Time
}

func NewRequest

func NewRequest(dnsreq dns.Msg) *Request

func ParseRequest

func ParseRequest(req *http.Request) (*Request, error)

func ReadRequest

func ReadRequest(r *bufio.Reader) (*Request, error)

ReadRequest reads and parses an incoming request from r.

ReadRequst is a low-level function and should only be used for specialized applications; most code should use Listener to read request and handle them via Handler interface.

func (*Request) Forward

func (r *Request) Forward(laddr, raddr net.Addr) *Request

Forward sets the "Forwarded" header defined in RFC 7239, section 4. This is used to pass local and remote address to the processing plugins.

func (*Request) Write

func (r *Request) Write(w io.Writer) error

type ResolverConfig

type ResolverConfig struct {
	// Name of the command used to execute the resolver.
	Name string `hcl:"resolver,label"`

	// Options is a list of additional options to execute the resolver.
	Options cty.Value `hcl:"options,optional"`

	Preload bool `hcl:"preload,optional"`

	// Processes is a number of processes to start for handling requests.
	// Default value is 1.
	Processes int `hcl:"processes,optional"`

	// MaxIdle is a maximum client requests waiting for processing.
	// Default value is 1024.
	MaxIdle int `hcl:"maxidle,optional"`
}

ResolverConfig is a configuration of a single resolver.

type Response

type Response struct {
	ID int64

	// StatusCode is numerical status of the HTTP response, e.g. 200.
	StatusCode int

	// Header maps HTTP header keys to values. Keys in the map are
	// canonicalized (see http.CanonicalHeaderKey).
	Header http.Header

	// Body respresents DNS response.
	Body dns.Msg
}

func NewResponse

func NewResponse(m dns.Msg) *Response

func ReadResponse

func ReadResponse(r *bufio.Reader) (*Response, error)

ReadResponse reads and returns HTTP response with encapsulated DNS response from r.

func (*Response) Redirect

func (r *Response) Redirect() *Response

func (*Response) Write

func (r *Response) Write(w io.Writer) error

type ServerConfig

type ServerConfig struct {
	// ResolverDirectory sets the root directory for resolvers, when
	// specified server searches the executable in the given path,
	// otherwise a current directory will be used.
	ResolverDirectory string `hcl:"resolver_directory,optional"`

	// Listen defines an IP address and port used to listen to
	//
	// Examples:
	//
	// 	listen = ":5353"
	// 	listen = "0.0.0.0:53"
	Listen string `hcl:"listen,optional"`

	// Proto specifies the protocol that will be used for communication
	// with remotes queriers.
	//
	// Examples:
	//
	// 	proto = "udp"
	//	proto = "tcp"
	Proto string `hcl:"proto,optional"`

	// Maximum number of concurrent connection, zero is no limit.
	//
	// Example:
	//
	//	max_conns = 512
	MaxConns int `hcl:"max_conns,optional"`

	// RequestTimeout is an optional maximum time for processing each request
	// by a single resolver.
	RequestTimeout string `hcl:"request_timeout,optional"`

	// Resolvers is a sequence of resolution plugins that are sequentially
	// polled in order to retrieve a response on the processing request.
	//
	// Each server starts resolvers isolated from other servers.
	Resolvers []ResolverConfig `hcl:"resolver,block"`
}

ServerConfig is a configuration for a single server instance.

type ShutdownFunc

type ShutdownFunc func(context.Context) error

ShutdownFunc tells a handler to terminate its work. ShutdownFunc waits for the work to stop. A ShutdownFunc may be called by multiple goroutines simultaneously.

func MultiShutdown

func MultiShutdown(ss ...Shutdowner) ShutdownFunc

func (ShutdownFunc) Shutdown

func (fn ShutdownFunc) Shutdown(ctx context.Context) error

type Shutdowner

type Shutdowner interface {
	Shutdown(context.Context) error
}

type Zone

type Zone struct {
	Name      string `json:"name"`
	CreatedAt int64  `json:"createdAt"`
	UpdatedAt int64  `json:"updatedAt"`
}

func NewZone

func NewZone(input ZoneInput) *Zone

type ZoneInput

type ZoneInput struct {
	Name string `json:"name"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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