dnsserver

package
v0.0.0-...-0c57748 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2016 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultZone is the default zone.
	DefaultZone = "."
	// DefaultPort is the default port.
	DefaultPort = "2053"
	// DefaultRoot is the default root folder.
	DefaultRoot = "."
)

Variables

View Source
var (
	// Root is the site root
	Root = DefaultRoot

	// Host is the site host
	Zone = DefaultZone

	// Port is the site port
	Port = DefaultPort

	// GracefulTimeout is the maximum duration of a graceful shutdown.
	GracefulTimeout time.Duration
)

These "soft defaults" are configurable by command line flags, etc.

Functions

func DefaultErrorFunc

func DefaultErrorFunc(w dns.ResponseWriter, r *dns.Msg, rcode int)

DefaultErrorFunc responds to an DNS request with an error.

func RegisterDevDirective

func RegisterDevDirective(name, before string)

RegisterDevDirective splices name into the list of directives immediately before another directive. This function is ONLY for plugin development purposes! NEVER use it for a plugin that you are not currently building. If before is empty, the directive will be appended to the end of the list.

It is imperative that directives execute in the proper order, and hard-coding the list of directives guarantees a correct, absolute order every time. This function is convenient when developing a plugin, but it does not guarantee absolute ordering. Multiple plugins registering directives with this function will lead to non- deterministic builds and buggy software.

Directive names must be lower-cased and unique. Any errors here are fatal, and even successful calls print a message to stdout as a reminder to use it only in development.

Types

type Config

type Config struct {
	// The zone of the site.
	Zone string

	// The hostname to bind listener to, defaults to the wildcard address
	ListenHost string

	// The port to listen on.
	Port string

	// The directory from which to parse db files, and store keys.
	Root string

	// Middleware stack.
	Middleware []Middleware
	// contains filtered or unexported fields
}

Config configuration for a single server.

func GetConfig

func GetConfig(c *caddy.Controller) *Config

GetConfig gets the Config that corresponds to c. If none exist nil is returned.

func (*Config) AddMiddleware

func (c *Config) AddMiddleware(m Middleware)

AddMiddleware adds a middleware to a site's middleware stack.

type Handler

type Handler interface {
	ServeDNS(context.Context, dns.ResponseWriter, *dns.Msg) (int, error)
}

Handler is like dns.Handler except ServeDNS may return an rcode and/or error.

If ServeDNS writes to the response body, it should return a status code. If the status code is not one of the following: * SERVFAIL (dns.RcodeServerFailure) * REFUSED (dns.RecodeRefused) * FORMERR (dns.RcodeFormatError) * NOTIMP (dns.RcodeNotImplemented)

CoreDNS assumes *no* reply has yet been written. All other response codes signal other handlers above it that the response message is already written, and that they should not write to it also.

If ServeDNS encounters an error, it should return the error value so it can be logged by designated error-handling middleware.

If writing a response after calling another ServeDNS method, the returned rcode SHOULD be used when writing the response.

If handling errors after calling another ServeDNS method, the returned error value SHOULD be logged or handled accordingly.

Otherwise, return values should be propagated down the middleware chain by returning them unchanged.

type HandlerFunc

type HandlerFunc func(context.Context, dns.ResponseWriter, *dns.Msg) (int, error)

HandlerFunc is a convenience type like dns.HandlerFunc, except ServeDNS returns an rcode and an error. See Handler documentation for more information.

func (HandlerFunc) ServeDNS

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

ServeDNS implements the Handler interface.

type Middleware

type Middleware func(Handler) Handler

Middleware is the middle layer which represents the traditional idea of middleware: it chains one Handler to the next by being passed the next Handler in the chain.

type Server

type Server struct {
	Addr string // Address we listen on
	// contains filtered or unexported fields
}

Server represents an instance of a server, which serves DNS requests at a particular address (host and port). A server is capable of serving numerous zones on the same address and the listener may be stopped for graceful termination (POSIX only).

func NewServer

func NewServer(addr string, group []*Config) (*Server, error)

NewServer returns a new CoreDNS server and compiles all middleware in to it.

func (*Server) Listen

func (s *Server) Listen() (net.Listener, error)

Listen implements caddy.TCPServer interface.

func (*Server) ListenPacket

func (s *Server) ListenPacket() (net.PacketConn, error)

ListenPacket implements caddy.UDPServer interface.

func (*Server) Serve

func (s *Server) Serve(l net.Listener) error

Serve starts the server with an existing listener. It blocks until the server stops.

func (*Server) ServeDNS

func (s *Server) ServeDNS(w dns.ResponseWriter, r *dns.Msg)

ServeDNS is the entry point for every request to the address that s is bound to. It acts as a multiplexer for the requests zonename as defined in the request so that the correct zone (configuration and middleware stack) will handle the request.

func (*Server) ServePacket

func (s *Server) ServePacket(p net.PacketConn) error

ServePacket starts the server with an existing packetconn. It blocks until the server stops.

func (*Server) Stop

func (s *Server) Stop() (err error)

Stop stops the server. It blocks until the server is totally stopped. On POSIX systems, it will wait for connections to close (up to a max timeout of a few seconds); on Windows it will close the listener immediately.

Jump to

Keyboard shortcuts

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