Documentation ¶
Index ¶
- func DelInitFunc(typ string)
- func DelPlugin(tag string)
- func ExecChainNode(ctx context.Context, qCtx *Context, n ExecutableChainNode) error
- func GetConfigurablePluginTypes() []string
- func MustRegPlugin(p Plugin)
- func PurgePluginRegister()
- func RegInitFunc(typ string, initFunc NewPluginFunc, argsType NewArgsFunc)
- func RegPlugin(p Plugin) bool
- func WeakDecode(in map[string]interface{}, output interface{}) error
- type BP
- type Config
- type Context
- func (ctx *Context) AddMark(m uint)
- func (ctx *Context) Copy() *Context
- func (ctx *Context) CopyTo(d *Context) *Context
- func (ctx *Context) HasMark(m uint) bool
- func (ctx *Context) Id() uint32
- func (ctx *Context) InfoField() zap.Field
- func (ctx *Context) OriginalQuery() *dns.Msg
- func (ctx *Context) Q() *dns.Msg
- func (ctx *Context) R() *dns.Msg
- func (ctx *Context) ReqMeta() *RequestMeta
- func (ctx *Context) SetResponse(r *dns.Msg, status ContextStatus)
- func (ctx *Context) StartTime() time.Time
- func (ctx *Context) Status() ContextStatus
- func (ctx *Context) String() string
- type ContextStatus
- type DummyExecutablePlugin
- type DummyMatcherPlugin
- type DummyServicePlugin
- type Executable
- type ExecutableChainNode
- type ExecutableNodeWrapper
- type ExecutablePlugin
- type LinkedListNode
- type Matcher
- type MatcherPlugin
- type NewArgsFunc
- type NewPluginFunc
- type NodeLinker
- type Plugin
- type PluginError
- type PluginInterfaceType
- type PluginWrapper
- type RequestMeta
- type TypeInfo
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 ¶
RegPlugin registers Plugin p. RegPlugin will not register p and returns false if the tag of p has already been registered.
func WeakDecode ¶
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 NewBPWithLog ¶ added in v3.6.0
NewBPWithLog creates a new BP and initials its logger with a static level.
func (*BP) S ¶
func (p *BP) S() *zap.SugaredLogger
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) Id ¶
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) OriginalQuery ¶
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) 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) Status ¶
func (ctx *Context) Status() ContextStatus
Status returns the context status.
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 ¶
func (d *DummyExecutablePlugin) Exec(ctx context.Context, qCtx *Context, next ExecutableChainNode) error
type DummyMatcherPlugin ¶
type DummyServicePlugin ¶
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 ¶
func FirstNode(n ExecutableChainNode) ExecutableChainNode
FirstNode returns the first node of chain of n.
func LastNode ¶
func LastNode(n ExecutableChainNode) ExecutableChainNode
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 MatcherPlugin ¶
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 ¶
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 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 (w *PluginWrapper) Is(t PluginInterfaceType) bool
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 ¶
GetInitFunc gets the registered type init func.