Documentation
¶
Overview ¶
Package dns provides dns server implementation.
Index ¶
- Variables
- func NewTCPListener(network, addr string, control ControlFn) (net.Listener, error)
- func NewUDPPacketConn(network, addr string, control ControlFn) (net.PacketConn, error)
- type AddressPair
- type Cache
- type ControlFn
- type Handler
- type HostMapper
- type Manager
- func (m *Manager) AllowNodeResolving(enabled bool)
- func (m *Manager) ClearAll(dry bool) error
- func (m *Manager) Done() <-chan error
- func (m *Manager) RunAll(pairs iter.Seq[AddressPair], forwardEnabled bool) iter.Seq2[RunResult, error]
- func (m *Manager) ServeBackground(ctx context.Context)
- func (m *Manager) SetUpstreams(prxs iter.Seq[Upstream]) bool
- type MemberReader
- type NodeHandler
- type RunResult
- type Runner
- type RunnerOptions
- type StaticHostHandler
- type StaticHostReader
- type Status
- type Upstream
Constants ¶
This section is empty.
Variables ¶
var ErrCreatingRunner = errors.New("error creating runner")
ErrCreatingRunner is an error that occurs when creating a runner.
Functions ¶
func NewTCPListener ¶
NewTCPListener creates a new TCP listener.
func NewUDPPacketConn ¶
func NewUDPPacketConn(network, addr string, control ControlFn) (net.PacketConn, error)
NewUDPPacketConn creates a new UDP packet connection.
Types ¶
type AddressPair ¶ added in v1.9.0
AddressPair represents a network and address with port.
func (AddressPair) String ¶ added in v1.9.0
func (a AddressPair) String() string
String returns a string representation of the address pair.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a dns.Handler to plugin.Handler adapter.
func (*Cache) ServeDNS ¶
func (c *Cache) ServeDNS(wr dns.ResponseWriter, msg *dns.Msg)
ServeDNS implements dns.Handler.
type ControlFn ¶ added in v1.7.2
ControlFn is an alias to net.ListenConfig.Control function.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a dns proxy selector.
type HostMapper ¶
type HostMapper interface {
ResolveAddr(ctx context.Context, qType uint16, name string) (iter.Seq[netip.Addr], bool)
}
HostMapper is a name to node mapper.
type Manager ¶ added in v1.9.0
type Manager struct {
// contains filtered or unexported fields
}
Manager manages DNS runners.
func NewManager ¶ added in v1.9.0
func NewManager(mr MemberReader, shr StaticHostReader, hook suture.EventHook, logger *zap.Logger) *Manager
NewManager creates a new manager.
func (*Manager) AllowNodeResolving ¶ added in v1.9.0
AllowNodeResolving enables or disables the node resolving feature.
func (*Manager) ClearAll ¶ added in v1.9.0
ClearAll stops and removes all runners. Returns all errors if any runner failed to properly stop.
func (*Manager) RunAll ¶ added in v1.9.0
func (m *Manager) RunAll(pairs iter.Seq[AddressPair], forwardEnabled bool) iter.Seq2[RunResult, error]
RunAll updates and run the runners managed by the manager. It returns an iterator which yields the address pairs for all running and attempted ro run configurations. It's mandatory to range over the iterator to ensure all runners are updated.
func (*Manager) ServeBackground ¶ added in v1.9.0
ServeBackground starts the manager in the background. It panics if the manager is not initialized or if it's called more than once.
type MemberReader ¶ added in v1.9.0
MemberReader is an interface to read members.
type NodeHandler ¶
type NodeHandler struct {
// contains filtered or unexported fields
}
NodeHandler try to resolve dns request to a node. If required node is not found, it will move to the next handler.
func NewNodeHandler ¶
func NewNodeHandler(next plugin.Handler, hostMapper HostMapper, logger *zap.Logger) *NodeHandler
NewNodeHandler creates a new NodeHandler.
func (*NodeHandler) ServeDNS ¶
func (h *NodeHandler) ServeDNS(ctx context.Context, wrt dns.ResponseWriter, msg *dns.Msg) (int, error)
ServeDNS implements plugin.Handler.
func (*NodeHandler) SetEnabled ¶
func (h *NodeHandler) SetEnabled(enabled bool)
SetEnabled sets the handler enabled state.
type RunResult ¶ added in v1.9.0
type RunResult struct {
AddressPair
Status Status
}
RunResult represents the result of a RunAll iteration.
type Runner ¶ added in v1.9.0
type Runner struct {
// contains filtered or unexported fields
}
Runner is a DNS server runner.
func NewRunner ¶ added in v1.9.0
func NewRunner(newOpts func() (RunnerOptions, error), l *zap.Logger) *Runner
NewRunner creates a new Runner.
newOpts is invoked on every (re)start to build a fresh dns.Server with fresh listeners. Both are single-use: once dns.Server.ActivateAndServe returns it leaves the server marked as started and miekg/dns closes the underlying listener/packet conn. Reusing the same instances across a supervisor restart therefore fails permanently with "dns: server already started", so the runner must reconstruct them.
type RunnerOptions ¶ added in v1.9.0
type RunnerOptions struct {
Listener net.Listener
PacketConn net.PacketConn
Handler dns.Handler
ReadTimeout time.Duration
WriteTimeout time.Duration
IdleTimeout func() time.Duration
MaxTCPQueries int
}
RunnerOptions is a Runner options.
type StaticHostHandler ¶ added in v1.14.0
type StaticHostHandler struct {
// contains filtered or unexported fields
}
StaticHostHandler resolves a configured set of host names to fixed addresses.
It sits in the handler chain ahead of NodeHandler/Handler so that statically configured entries always win against upstream resolution. On miss, the request is forwarded to the next handler.
func NewStaticHostHandler ¶ added in v1.14.0
func NewStaticHostHandler(next plugin.Handler, mapper HostMapper, logger *zap.Logger) *StaticHostHandler
NewStaticHostHandler creates a new StaticHostHandler with an empty table.
func (*StaticHostHandler) Name ¶ added in v1.14.0
func (h *StaticHostHandler) Name() string
Name implements plugin.Handler.
type StaticHostReader ¶ added in v1.14.0
type StaticHostReader interface {
ReadStaticHosts(ctx context.Context, name string) (iter.Seq[netip.Addr], error)
}
StaticHostReader is an interface to read static hosts.
type Upstream ¶ added in v1.14.0
type Upstream interface {
// Connect sends a DNS query to the upstream and returns the response.
Connect(ctx context.Context, state request.Request, opts proxy.Options) (*dns.Msg, error)
// Addr returns the upstream address (used for logging).
Addr() string
}
Upstream is the abstraction used by Handler to forward DNS queries to a concrete upstream resolver.
It is implemented by the CoreDNS plugin proxy (used for plain DNS and DoT) and by the DoH proxy in this package, so the handler can iterate uniformly across all configured upstream protocols.