Documentation
¶
Overview ¶
Package middleware provides the DNS query middleware pipeline used by sdns. Middlewares are Constructors that produce Handlers; they register into a Registry, which Setup compiles into an immutable Pipeline. Each incoming DNS query runs through the pipeline via a Chain.
Index ¶
- Variables
- func List() []string
- func Ready() bool
- func Register(name string, c Constructor)
- func RegisterAt(name string, c Constructor, idx int)
- func RegisterBefore(name string, c Constructor, before string)
- func Reset()
- func Setup(cfg *config.Config)
- type Chain
- type Constructor
- type Handler
- type HandlerFunc
- type Pipeline
- type Registry
- type ResponseWriter
Constants ¶
This section is empty.
Variables ¶
var DefaultRegistry = NewRegistry()
DefaultRegistry is the package-level registry used by the top-level Register / RegisterAt / RegisterBefore wrappers. Middleware packages register into it from their init hooks.
Functions ¶
func List ¶
func List() []string
List returns every registered middleware name in insertion order, including disabled ones. Before Setup it returns names from the DefaultRegistry; after Setup it returns the snapshot captured at Build.
func Register ¶
func Register(name string, c Constructor)
Register is a package-level shortcut for DefaultRegistry.Register.
func RegisterAt ¶ added in v1.1.0
func RegisterAt(name string, c Constructor, idx int)
RegisterAt is a package-level shortcut for DefaultRegistry.RegisterAt.
func RegisterBefore ¶ added in v1.1.0
func RegisterBefore(name string, c Constructor, before string)
RegisterBefore is a package-level shortcut for DefaultRegistry.RegisterBefore.
Types ¶
type Chain ¶ added in v1.1.0
type Chain struct {
Writer ResponseWriter
Request *dns.Msg
// contains filtered or unexported fields
}
Chain carries per-request state through the middleware pipeline. Instances are reused via a sync.Pool: NewChain allocates the fixed pipeline reference, Reset rebinds the per-request writer + message.
func NewChain ¶ added in v1.1.0
NewChain returns a Chain bound to the given handler pipeline. The slice is captured by reference and must not be mutated by the caller after this call.
func (*Chain) Cancel ¶ added in v1.1.0
func (ch *Chain) Cancel()
Cancel stops the chain without writing a response. Subsequent Next calls become no-ops.
func (*Chain) CancelWithRcode ¶ added in v1.1.7
CancelWithRcode writes a reply with the given rcode and stops the chain. do controls the DO bit in the response's OPT record.
type Constructor ¶ added in v1.6.3
Constructor builds a Handler from config. A Constructor that returns a typed-nil pointer (e.g. `(*Reflex)(nil)`) signals that the middleware is disabled for this config and is skipped at Build time.
type Handler ¶ added in v1.1.0
type Handler interface {
// Name returns the middleware name. It must match the name used in
// Register so Pipeline.Get can resolve the handler back.
Name() string
// ServeDNS processes a DNS query. A handler is expected to call
// ch.Next to continue the chain, or ch.Cancel / ch.CancelWithRcode
// to stop it.
ServeDNS(ctx context.Context, ch *Chain)
}
Handler is the middleware interface. Implementations must be safe for concurrent use.
type HandlerFunc ¶ added in v1.5.0
HandlerFunc adapts a plain function into a Handler. Handy in tests that want to inject a one-off behaviour without declaring a new type.
func (HandlerFunc) Name ¶ added in v1.5.0
func (f HandlerFunc) Name() string
Name returns the fixed label "HandlerFunc".
type Pipeline ¶ added in v1.6.3
type Pipeline struct {
// contains filtered or unexported fields
}
Pipeline is the compiled, immutable middleware chain produced by Registry.Build. All fields are set at construction time and never mutated, so every read is safe without synchronization.
func (*Pipeline) Get ¶ added in v1.6.3
Get returns the enabled handler with the given name or nil if the middleware is not registered or is disabled for the current config.
type Registry ¶ added in v1.6.3
type Registry struct {
// contains filtered or unexported fields
}
Registry collects middleware registrations and builds an immutable Pipeline from them. A Registry is safe for concurrent Register calls, but Build is expected to be called once.
func NewRegistry ¶ added in v1.6.3
func NewRegistry() *Registry
NewRegistry returns an empty Registry.
func (*Registry) Build ¶ added in v1.6.3
Build runs every Constructor against cfg, skips disabled middlewares (typed-nil), and returns an immutable Pipeline. Constructors run outside the registry lock, so they may do heavy work (open files, spawn goroutines) without starving concurrent List calls.
func (*Registry) Register ¶ added in v1.6.3
func (r *Registry) Register(name string, c Constructor)
Register appends a middleware to the end of the registry.
func (*Registry) RegisterAt ¶ added in v1.6.3
func (r *Registry) RegisterAt(name string, c Constructor, idx int)
RegisterAt inserts a middleware at the given index. Out-of-range index panics.
func (*Registry) RegisterBefore ¶ added in v1.6.3
func (r *Registry) RegisterBefore(name string, c Constructor, before string)
RegisterBefore inserts a middleware immediately before the named one. Panics if `before` is not registered.
type ResponseWriter ¶ added in v1.1.0
type ResponseWriter interface {
dns.ResponseWriter
Msg() *dns.Msg
Rcode() int
Written() bool
Reset(dns.ResponseWriter)
Proto() string
RemoteIP() net.IP
Internal() bool
}
ResponseWriter implement of dns.ResponseWriter.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package hostsfile implements a high-performance hosts file resolver with advanced features like wildcard support and automatic reloading
|
Package hostsfile implements a high-performance hosts file resolver with advanced features like wildcard support and automatic reloading |
|
Package kubernetes - Simple DNS cache
|
Package kubernetes - Simple DNS cache |
|
Package reflex detects DNS amplification/reflection attacks.
|
Package reflex detects DNS amplification/reflection attacks. |