dns

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package dns provides dns server implementation.

Index

Constants

This section is empty.

Variables

View Source
var ErrCreatingRunner = errors.New("error creating runner")

ErrCreatingRunner is an error that occurs when creating a runner.

Functions

func NewTCPListener

func NewTCPListener(network, addr string, control ControlFn) (net.Listener, error)

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

type AddressPair struct {
	Network string
	Addr    netip.AddrPort
}

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 NewCache

func NewCache(next plugin.Handler, l *zap.Logger) *Cache

NewCache creates a new Cache.

func (*Cache) ServeDNS

func (c *Cache) ServeDNS(wr dns.ResponseWriter, msg *dns.Msg)

ServeDNS implements dns.Handler.

type ControlFn added in v1.7.2

type ControlFn = func(string, string, syscall.RawConn) error

ControlFn is an alias to net.ListenConfig.Control function.

func MakeControl added in v1.7.2

func MakeControl(network string, forwardEnabled bool) (ControlFn, error)

MakeControl creates a control function for setting socket options.

type Handler

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

Handler is a dns proxy selector.

func NewHandler

func NewHandler(logger *zap.Logger) *Handler

NewHandler creates a new Handler.

func (*Handler) Name

func (h *Handler) Name() string

Name implements plugin.Handler.

func (*Handler) ServeDNS

func (h *Handler) ServeDNS(ctx context.Context, wrt dns.ResponseWriter, msg *dns.Msg) (int, error)

ServeDNS implements plugin.Handler.

func (*Handler) SetProxy

func (h *Handler) SetProxy(prxs iter.Seq[*proxy.Proxy]) bool

SetProxy sets destination dns proxy servers.

func (*Handler) Stop

func (h *Handler) Stop()

Stop stops and clears 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, hook suture.EventHook, logger *zap.Logger) *Manager

NewManager creates a new manager.

func (*Manager) AllowNodeResolving added in v1.9.0

func (m *Manager) AllowNodeResolving(enabled bool)

AllowNodeResolving enables or disables the node resolving feature.

func (*Manager) ClearAll added in v1.9.0

func (m *Manager) ClearAll(dry bool) error

ClearAll stops and removes all runners. It returns an iterator which yields the address pairs that were removed and/or errors that occurred during the removal process. It's mandatory to range over the iterator to ensure all runners are stopped.

func (*Manager) Done added in v1.9.0

func (m *Manager) Done() <-chan error

Done reports if superwisor finished execution.

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

func (m *Manager) ServeBackground(ctx context.Context)

ServeBackground starts the manager in the background. It panics if the manager is not initialized or if it's called more than once.

func (*Manager) SetUpstreams added in v1.9.0

func (m *Manager) SetUpstreams(prxs iter.Seq[*proxy.Proxy]) bool

SetUpstreams sets the upstreams for the DNS handler. It returns true if the upstreams were updated, false otherwise.

type MemberReader added in v1.9.0

type MemberReader interface {
	ReadMembers(ctx context.Context) (iter.Seq[*cluster.Member], error)
}

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

func (h *NodeHandler) Name() string

Name implements plugin.Handler.

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(opts RunnerOptions, l *zap.Logger) *Runner

NewRunner creates a new Runner.

func (*Runner) Serve added in v1.9.0

func (r *Runner) Serve(ctx context.Context) error

Serve starts the DNS server.

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 Status added in v1.9.0

type Status int

Status represents the status of a runner.

const (
	// StatusNew represents a new runner.
	StatusNew Status = iota
	// StatusRunning represents a already running runner.
	StatusRunning
	// StatusRemoved represents a removed runner.
	StatusRemoved
)

Jump to

Keyboard shortcuts

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