handler

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: GPL-3.0 Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAllPluginTag added in v0.15.0

func GetAllPluginTag() []string

func GetConfigurablePluginTypes added in v0.15.0

func GetConfigurablePluginTypes() []string

GetConfigurablePluginTypes returns all plugin types which are configurable.

func InitAndRegPlugin added in v0.10.0

func InitAndRegPlugin(c *Config, errIfDup bool) (err error)

InitAndRegPlugin inits and registers this plugin globally.

func MustRegPlugin added in v0.14.0

func MustRegPlugin(p Plugin, errIfDup bool)

MustRegPlugin: see RegPlugin. MustRegPlugin will panic if any err occurred.

func ParseIfBlock added in v0.24.0

func ParseIfBlock(in map[string]interface{}) (*ifBlock, error)

func PluginFatalErr added in v0.16.0

func PluginFatalErr(tag string, msg string)

PluginFatalErr: If a plugin has a fatal err, call this.

func PurgePluginRegister added in v0.12.0

func PurgePluginRegister()

PurgePluginRegister should only be used in test.

func RegInitFunc

func RegInitFunc(pluginType string, initFunc NewPluginFunc, argsType NewArgsFunc)

RegInitFunc registers this plugin type. This should only be called in init() of the plugin package. Duplicate plugin types are not allowed.

func RegPlugin

func RegPlugin(p Plugin, errIfDup bool) error

RegPlugin registers this Plugin globally. Duplicate Plugin tag will overwrite the old one.

func WalkExecutableCmd added in v0.24.0

func WalkExecutableCmd(ctx context.Context, qCtx *Context, logger *zap.Logger, entry ExecutableCmd) (err error)

WalkExecutableCmd executes the sequence, include its `goto`.

func WeakDecode added in v0.13.0

func WeakDecode(in map[string]interface{}, output interface{}) error

WeakDecode decodes args from config to output.

Types

type BP added in v0.24.0

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

BP means basic plugin, which implements Plugin. It also has an internal logger, for convenience.

func NewBP added in v0.24.0

func NewBP(tag string, typ string) *BP

func (*BP) L added in v0.24.0

func (p *BP) L() *zap.Logger

func (*BP) Tag added in v0.24.0

func (p *BP) Tag() string

func (*BP) Type added in v0.24.0

func (p *BP) Type() string

type Config

type Config struct {
	// Tag, required
	Tag string `yaml:"tag"`

	// Type, required
	Type string `yaml:"type"`

	// Args, might be required by some plugins
	Args map[string]interface{} `yaml:"args"`
}

type Context

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

Context is a query context that pass through plugins A Context will always have a non-nil Q. Context MUST be created by NewContext.

func NewContext added in v0.17.1

func NewContext(q *dns.Msg, from net.Addr) *Context

NewContext q must not be nil.

func (*Context) Copy

func (ctx *Context) Copy() *Context

func (*Context) From

func (ctx *Context) From() net.Addr

func (*Context) Id added in v0.24.0

func (ctx *Context) Id() uint32

func (*Context) InfoField added in v0.24.0

func (ctx *Context) InfoField() zap.Field

InfoField returns a zap.Field. Just for convenience.

func (*Context) Q

func (ctx *Context) Q() *dns.Msg

func (*Context) R

func (ctx *Context) R() *dns.Msg

func (*Context) SetResponse added in v0.21.0

func (ctx *Context) SetResponse(r *dns.Msg, status ContextStatus)

func (*Context) StartTime added in v0.24.0

func (ctx *Context) StartTime() time.Time

func (*Context) Status added in v0.21.0

func (ctx *Context) Status() ContextStatus

type ContextPlugin added in v0.19.1

type ContextPlugin interface {
	Plugin

	// Connect connects this ContextPlugin to its predecessor.
	Connect(ctx context.Context, qCtx *Context, pipeCtx *PipeContext) (err error)
}

ContextPlugin

func GetContextPlugin added in v0.19.1

func GetContextPlugin(tag string) (p ContextPlugin, err error)

type ContextStatus added in v0.21.0

type ContextStatus uint8
const (
	ContextStatusWaitingResponse ContextStatus = iota
	ContextStatusResponded
	ContextStatusServerFailed
	ContextStatusDropped
	ContextStatusRejected
)

func (ContextStatus) String added in v0.21.0

func (status ContextStatus) String() string

type DefaultServerHandler added in v0.15.0

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

func NewDefaultServerHandler added in v0.21.0

func NewDefaultServerHandler(config *DefaultServerHandlerConfig) *DefaultServerHandler

NewDefaultServerHandler: concurrentLimit <= 0 means no concurrent limit. Also see DefaultServerHandler.ServeDNS.

func (*DefaultServerHandler) ServeDNS added in v0.15.0

func (h *DefaultServerHandler) ServeDNS(ctx context.Context, qCtx *Context, w ResponseWriter)

ServeDNS: If entry returns an err, a SERVFAIL response will be sent back to client. If concurrentLimit is reached, the query will block and wait available token until ctx is done.

type DefaultServerHandlerConfig added in v0.21.0

type DefaultServerHandlerConfig struct {
	// Logger is used for logging, it cannot be nil.
	Logger *zap.Logger
	// Entry is the entry ExecutablePlugin's tag. This shouldn't be empty.
	Entry string
	// ConcurrentLimit controls the max concurrent queries.
	// If ConcurrentLimit <= 0, means no limit.
	ConcurrentLimit int
}

type DummyExecutablePlugin added in v0.24.0

type DummyExecutablePlugin struct {
	*BP
	WantR   *dns.Msg
	WantErr error
}

func (*DummyExecutablePlugin) Exec added in v0.24.0

func (d *DummyExecutablePlugin) Exec(_ context.Context, qCtx *Context) (err error)

type DummyMatcherPlugin added in v0.24.0

type DummyMatcherPlugin struct {
	*BP
	Matched bool
	WantErr error
}

func (*DummyMatcherPlugin) Match added in v0.24.0

func (d *DummyMatcherPlugin) Match(_ context.Context, _ *Context) (matched bool, err error)

type DummyServerHandler added in v0.16.0

type DummyServerHandler struct {
	T       *testing.T
	WantMsg *dns.Msg
	WantErr error
}

func (*DummyServerHandler) ServeDNS added in v0.16.0

func (d *DummyServerHandler) ServeDNS(_ context.Context, qCtx *Context, w ResponseWriter)

type DummyServicePlugin added in v0.24.0

type DummyServicePlugin struct {
	*BP
	WantShutdownErr error
}

func (*DummyServicePlugin) Shutdown added in v0.24.0

func (d *DummyServicePlugin) Shutdown() error

type ErrGroup added in v0.24.0

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

type Error added in v0.12.0

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

func NewPluginError added in v0.19.1

func NewPluginError(tag string, err error) *Error

func (*Error) Error added in v0.12.0

func (e *Error) Error() string

func (*Error) Unwrap added in v0.17.1

func (e *Error) Unwrap() error

type Executable added in v0.19.1

type Executable interface {
	Exec(ctx context.Context, qCtx *Context) (err error)
}

type ExecutableCmd added in v0.20.0

type ExecutableCmd interface {
	ExecCmd(ctx context.Context, qCtx *Context, logger *zap.Logger) (goTwo string, err error)
}

type ExecutableCmdSequence added in v0.20.0

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

func ParseExecutableCmdSequence added in v0.24.0

func ParseExecutableCmdSequence(in []interface{}) (*ExecutableCmdSequence, error)

func (*ExecutableCmdSequence) ExecCmd added in v0.20.0

func (es *ExecutableCmdSequence) ExecCmd(ctx context.Context, qCtx *Context, logger *zap.Logger) (goTwo string, err error)

ExecCmd executes the sequence.

func (*ExecutableCmdSequence) Len added in v0.24.0

func (es *ExecutableCmdSequence) Len() int

type ExecutablePlugin added in v0.19.1

type ExecutablePlugin interface {
	Plugin
	Executable
}

func GetExecutablePlugin added in v0.19.1

func GetExecutablePlugin(tag string) (p ExecutablePlugin, err error)

type FallbackConfig added in v0.24.0

type FallbackConfig struct {
	// Primary exec sequence, must have at least one element.
	Primary []interface{} `yaml:"primary"`
	// Secondary exec sequence, must have at least one element.
	Secondary []interface{} `yaml:"secondary"`

	StatLength int `yaml:"stat_length"` // default is 10
	Threshold  int `yaml:"threshold"`   // default is 5
}

type FallbackECS added in v0.24.0

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

func ParseFallbackECS added in v0.24.0

func ParseFallbackECS(primary, secondary []interface{}, threshold, statLength int) (*FallbackECS, error)

func (*FallbackECS) ExecCmd added in v0.24.0

func (f *FallbackECS) ExecCmd(ctx context.Context, qCtx *Context, logger *zap.Logger) (goTwo string, err error)

type IfBlockConfig added in v0.20.0

type IfBlockConfig struct {
	If    []string      `yaml:"if"`
	IfAnd []string      `yaml:"if_and"`
	Exec  []interface{} `yaml:"exec"`
	Goto  string        `yaml:"goto"`
}

type Matcher added in v0.10.0

type Matcher interface {
	Match(ctx context.Context, qCtx *Context) (matched bool, err error)
}

type MatcherPlugin added in v0.10.0

type MatcherPlugin interface {
	Plugin
	Matcher
}

func GetMatcherPlugin added in v0.10.0

func GetMatcherPlugin(tag string) (p MatcherPlugin, err error)

type NewArgsFunc added in v0.24.0

type NewArgsFunc func() interface{}

type NewPluginFunc

type NewPluginFunc func(bp *BP, args interface{}) (p Plugin, err error)

type ParallelECS added in v0.24.0

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

func ParseParallelECS added in v0.24.0

func ParseParallelECS(in [][]interface{}) (*ParallelECS, error)

func (*ParallelECS) ExecCmd added in v0.24.0

func (p *ParallelECS) ExecCmd(ctx context.Context, qCtx *Context, logger *zap.Logger) (_ string, err error)

type ParallelECSConfig added in v0.24.0

type ParallelECSConfig struct {
	Parallel [][]interface{} `yaml:"parallel"`
}

type PipeContext added in v0.17.1

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

func NewPipeContext added in v0.17.1

func NewPipeContext(s []string, logger *zap.Logger) *PipeContext

func (*PipeContext) ExecNextPlugin added in v0.17.1

func (c *PipeContext) ExecNextPlugin(ctx context.Context, qCtx *Context) error

type Plugin

type Plugin interface {
	Tag() string
	Type() string
}

func GetPlugin

func GetPlugin(tag string) (p Plugin, err error)

func NewPlugin added in v0.10.0

func NewPlugin(c *Config) (p Plugin, err error)

type ResponseWriter added in v0.15.0

type ResponseWriter interface {
	Write(m *dns.Msg) (n int, err error)
}

ResponseWriter can write msg to the client.

type ServerHandler added in v0.15.0

type ServerHandler interface {
	// ServeDNS uses ctx to control deadline, exchanges qCtx, and writes response to w.
	ServeDNS(ctx context.Context, qCtx *Context, w ResponseWriter)
}

type Service added in v0.24.0

type Service interface {
	// Shutdown and release resources.
	Shutdown() error
}

type ServicePlugin added in v0.24.0

type ServicePlugin interface {
	Plugin
	Service
}

ServicePlugin is a plugin that has one or more background tasks that will keep running after Init().

Jump to

Keyboard shortcuts

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