handler

package
v3.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: GPL-3.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DelInitFunc

func DelInitFunc(typ string)

DelInitFunc deletes the init func for this plugin type. It is a noop if pluginType is not registered.

func DelPlugin

func DelPlugin(tag string)

DelPlugin deletes this plugin tag. It is a noop if tag is not registered.

func ExecChainNode

func ExecChainNode(ctx context.Context, qCtx *Context, n ExecutableChainNode) error

func GetConfigurablePluginTypes

func GetConfigurablePluginTypes() []string

GetConfigurablePluginTypes returns all plugin types which are configurable.

func MustRegPlugin

func MustRegPlugin(p Plugin)

MustRegPlugin will panic the tag of p has already been registered.

func PurgePluginRegister

func PurgePluginRegister()

PurgePluginRegister should only be used in testing.

func RegInitFunc

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

RegInitFunc registers the type. If the type has been registered. RegInitFunc will panic.

func RegPlugin

func RegPlugin(p Plugin) bool

RegPlugin registers Plugin p. RegPlugin will not register p and returns false if the tag of p has already been registered.

func WeakDecode

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

WeakDecode decodes args from config to output.

Types

type BP

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

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

func NewBP

func NewBP(tag string, typ string) *BP

NewBP creates a new BP and initials its logger.

func NewBPWithLog added in v3.6.0

func NewBPWithLog(tag string, typ string, lc *mlog.LogConfig) (*BP, error)

NewBPWithLog creates a new BP and initials its logger with a static level.

func (*BP) L

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

func (*BP) S

func (p *BP) S() *zap.SugaredLogger

func (*BP) Shutdown

func (p *BP) Shutdown() error

func (*BP) Tag

func (p *BP) Tag() string

func (*BP) Type

func (p *BP) Type() string

type Config

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

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

	LogConfig mlog.LogConfig `yaml:"log"`

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

Config represents a plugin config

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

func NewContext(q *dns.Msg, meta *RequestMeta) *Context

NewContext creates a new query Context. q is the query dns msg. It cannot be nil, or NewContext will panic. meta can be nil.

func (*Context) Copy

func (ctx *Context) Copy() *Context

Copy deep copies this Context.

func (*Context) CopyTo

func (ctx *Context) CopyTo(d *Context) *Context

CopyTo deep copies this Context to d.

func (*Context) Id

func (ctx *Context) Id() uint32

Id returns the Context id. Note: This id is not the dns msg id. It's a unique uint32 growing with the number of query.

func (*Context) InfoField

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

InfoField returns a zap.Field. Just for convenience.

func (*Context) OriginalQuery

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

OriginalQuery returns the copied original query msg a that created the Context. It always returns a non-nil msg. The returned msg SHOULD NOT be modified.

func (*Context) Q

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

Q returns the query msg. It always returns a non-nil msg.

func (*Context) R

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

R returns the response. It might be nil.

func (*Context) ReqMeta

func (ctx *Context) ReqMeta() *RequestMeta

ReqMeta returns the request metadata. The returned *RequestMeta is a reference shared by all ReqMeta. Caller must not modify it.

func (*Context) SetResponse

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

SetResponse stores the response r to the context. Note: It just stores the pointer of r. So the caller shouldn't modify or read r after the call.

func (*Context) StartTime

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

StartTime returns the time when the Context was created.

func (*Context) Status

func (ctx *Context) Status() ContextStatus

Status returns the context status.

func (*Context) String

func (ctx *Context) String() string

String returns a short summery of its query.

type ContextStatus

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

func (ContextStatus) String

func (status ContextStatus) String() string

type DummyExecutablePlugin

type DummyExecutablePlugin struct {
	*BP
	WantSkip  bool
	WantSleep time.Duration
	WantR     *dns.Msg
	WantErr   error
}

func (*DummyExecutablePlugin) Exec

type DummyMatcherPlugin

type DummyMatcherPlugin struct {
	*BP
	Matched bool
	WantErr error
}

func (*DummyMatcherPlugin) Match

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

type DummyServicePlugin

type DummyServicePlugin struct {
	*BP
	WantShutdownErr error
}

func (*DummyServicePlugin) Shutdown

func (d *DummyServicePlugin) Shutdown() error

type Executable

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

Executable represents something that is executable.

type ExecutableChainNode

type ExecutableChainNode interface {
	Executable
	LinkedListNode
}

ExecutableChainNode represents a node in a executable chain.

func FirstNode

FirstNode returns the first node of chain of n.

func LastNode

LastNode returns the Latest node of chain of n.

func WrapExecutable

func WrapExecutable(e Executable) ExecutableChainNode

WrapExecutable wraps a Executable to a ExecutableChainNode.

type ExecutableNodeWrapper

type ExecutableNodeWrapper struct {
	Executable
	NodeLinker
}

ExecutableNodeWrapper wraps a Executable to a ExecutableChainNode.

type ExecutablePlugin

type ExecutablePlugin interface {
	Plugin
	Executable
}

ExecutablePlugin represents a Plugin that is Executable.

type LinkedListNode

type LinkedListNode interface {
	Previous() ExecutableChainNode
	Next() ExecutableChainNode
	LinkPrevious(n ExecutableChainNode)
	LinkNext(n ExecutableChainNode)
}

type Matcher

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

Matcher represents a matcher that can match a certain patten in Context.

type MatcherPlugin

type MatcherPlugin interface {
	Plugin
	Matcher
}

MatcherPlugin represents a Plugin that is a Matcher.

type NewArgsFunc

type NewArgsFunc func() interface{}

NewArgsFunc represents a func that creates a new args object.

type NewPluginFunc

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

NewPluginFunc represents a func that can init a Plugin. args is the object created by NewArgsFunc.

type NodeLinker

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

NodeLinker implements LinkedListNode.

func (*NodeLinker) LinkNext

func (l *NodeLinker) LinkNext(n ExecutableChainNode)

func (*NodeLinker) LinkPrevious

func (l *NodeLinker) LinkPrevious(n ExecutableChainNode)

func (*NodeLinker) Next

func (l *NodeLinker) Next() ExecutableChainNode

func (*NodeLinker) Previous

func (l *NodeLinker) Previous() ExecutableChainNode

type Plugin

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

Plugin represents the basic plugin.

func GetPluginAll

func GetPluginAll() []Plugin

GetPluginAll returns all registered plugins.

func NewPlugin

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

NewPlugin initialize a Plugin from c.

type PluginError

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

func NewPluginError

func NewPluginError(tag string, err error) *PluginError

func (*PluginError) Error

func (e *PluginError) Error() string

func (*PluginError) Is

func (e *PluginError) Is(target error) bool

func (*PluginError) Unwrap

func (e *PluginError) Unwrap() error

type PluginInterfaceType

type PluginInterfaceType uint8
const (
	PITESExecutable PluginInterfaceType = iota
	PITMatcher
)

type PluginWrapper

type PluginWrapper struct {
	Plugin
	// contains filtered or unexported fields
}

PluginWrapper wraps the original plugin to avoid extremely frequently interface conversion.

func GetPlugin

func GetPlugin(tag string) (p *PluginWrapper)

GetPlugin gets a registered PluginWrapper. Also see PluginWrapper.

func NewPluginWrapper

func NewPluginWrapper(gp Plugin) *PluginWrapper

func (*PluginWrapper) Exec

func (w *PluginWrapper) Exec(ctx context.Context, qCtx *Context, next ExecutableChainNode) error

func (*PluginWrapper) Is

func (*PluginWrapper) Match

func (w *PluginWrapper) Match(ctx context.Context, qCtx *Context) (matched bool, err error)

type RequestMeta

type RequestMeta struct {
	// ClientIP contains the client ip address.
	ClientIP net.IP

	// FromUDP indicates the request is from an udp socket.
	FromUDP bool
}

RequestMeta represents some metadata about the request.

type TypeInfo

type TypeInfo struct {
	NewPlugin NewPluginFunc
	NewArgs   NewArgsFunc
}

func GetInitFunc

func GetInitFunc(typ string) (TypeInfo, bool)

GetInitFunc gets the registered type init func.

Jump to

Keyboard shortcuts

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