handler

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: GPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ETInvalidArgs    = "invalid args: %w"
	ETTypeNotDefined = "plugin type %s not defined"
	ETTagNotDefined  = "plugin tag %s not defined"
)

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) (err error)

InitAndRegPlugin inits and registers this plugin globally. Duplicate plugin tags are not allowed.

func MustRegPlugin added in v0.14.0

func MustRegPlugin(p Plugin)

MustRegPlugin: see RegPlugin. MustRegPlugin will panic if err.

func NewErrFromTemplate added in v0.12.0

func NewErrFromTemplate(t ErrTemplate, args ...interface{}) 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)

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) error

RegPlugin registers this Plugin globally. Duplicate Plugin tag will cause an error.

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 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 {
	Q    *dns.Msg
	From net.Addr

	Status ContextStatus
	R      *dns.Msg
	// 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) *Context

func (*Context) Copy

func (ctx *Context) Copy() *Context

func (*Context) SetResponse added in v0.21.0

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

func (*Context) String

func (ctx *Context) String() string

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 *logrus.Entry
	// 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 DummyExecutable added in v0.19.1

type DummyExecutable struct {
	WantErr error
}

func (*DummyExecutable) Exec added in v0.19.1

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

type DummyMatcher added in v0.10.0

type DummyMatcher struct {
	Matched bool
	WantErr error
}

func (*DummyMatcher) Match added in v0.10.0

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

type DummyServerHandler added in v0.16.0

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

func (*DummyServerHandler) ServeDNS added in v0.16.0

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

type ErrTemplate added in v0.12.0

type ErrTemplate string

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 *logrus.Entry) (goTwo string, err error)
}

type ExecutableCmdSequence added in v0.20.0

type ExecutableCmdSequence []ExecutableCmd

func NewExecutableCmdSequence added in v0.20.0

func NewExecutableCmdSequence() *ExecutableCmdSequence

func (*ExecutableCmdSequence) Exec added in v0.20.0

func (es *ExecutableCmdSequence) Exec(ctx context.Context, qCtx *Context, logger *logrus.Entry) (err error)

Exec executes the sequence, include its `goto`.

func (*ExecutableCmdSequence) ExecCmd added in v0.20.0

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

ExecCmd executes the sequence.

func (*ExecutableCmdSequence) Parse added in v0.20.0

func (es *ExecutableCmdSequence) Parse(in []interface{}) error

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 ExecutablePluginWrapper added in v0.19.1

type ExecutablePluginWrapper struct {
	Executable
	// contains filtered or unexported fields
}

func WrapExecutablePlugin added in v0.19.1

func WrapExecutablePlugin(tag, typ string, executable Executable) *ExecutablePluginWrapper

WrapExecutablePlugin returns a *ExecutablePluginWrapper which implements Plugin and ExecutablePlugin.

func (*ExecutablePluginWrapper) Tag added in v0.19.1

func (*ExecutablePluginWrapper) Type added in v0.19.1

func (p *ExecutablePluginWrapper) Type() string

type IfBlockConfig added in v0.20.0

type IfBlockConfig struct {
	If   []string      `yaml:"if"`
	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 MatcherPluginWrapper added in v0.10.0

type MatcherPluginWrapper struct {
	Matcher
	// contains filtered or unexported fields
}

func WrapMatcherPlugin added in v0.10.0

func WrapMatcherPlugin(tag, typ string, matcher Matcher) *MatcherPluginWrapper

WrapMatcherPlugin returns a *MatcherPluginWrapper which implements Plugin and MatcherPlugin.

func (*MatcherPluginWrapper) Tag added in v0.10.0

func (c *MatcherPluginWrapper) Tag() string

func (*MatcherPluginWrapper) Type added in v0.10.0

func (c *MatcherPluginWrapper) Type() string

type NewPluginFunc

type NewPluginFunc func(tag string, args map[string]interface{}) (p Plugin, err error)

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 *logrus.Entry) *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)
}

Jump to

Keyboard shortcuts

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