Documentation
¶
Index ¶
- type DoTServer
- func NewDoTServer(addr string, handler Handler, certFile, keyFile string, timeout time.Duration, ...) (*DoTServer, error)
- func NewDoTServerWithListener(ln net.Listener, handler Handler, timeout time.Duration, maxConns int, ...) *DoTServer
- func NewDoTServerWithTLSConfig(addr string, handler Handler, tlsCfg *tls.Config, timeout time.Duration, ...) (*DoTServer, error)
- type Handler
- type MainHandler
- func (h *MainHandler) EnableCookies() error
- func (h *MainHandler) EnableCookiesWithSecret(secret []byte)
- func (h *MainHandler) Handle(query []byte, clientAddr net.Addr) ([]byte, error)
- func (h *MainHandler) SetBlocklist(bl interface{ ... })
- func (h *MainHandler) SetDownstreamUDPBufferSize(size int)
- func (h *MainHandler) SetECS(enabled bool, maxPrefix int)
- func (h *MainHandler) SetECSPrefixes(enabled bool, maxPrefixV4, maxPrefixV6 int)
- func (h *MainHandler) SetNoCacheClients(cidrs []string)
- func (h *MainHandler) SetPrivateFilter(enabled bool)
- type TCPOption
- type TCPServer
- type UDPServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DoTServer ¶
type DoTServer struct {
// contains filtered or unexported fields
}
DoTServer handles DNS queries over TLS (RFC 7858).
func NewDoTServer ¶
func NewDoTServer(addr string, handler Handler, certFile, keyFile string, timeout time.Duration, maxConns int, logger *slog.Logger) (*DoTServer, error)
NewDoTServer creates a new DNS-over-TLS server. It loads the TLS certificate/key pair and wraps a TCP listener with TLS.
func NewDoTServerWithListener ¶
func NewDoTServerWithListener(ln net.Listener, handler Handler, timeout time.Duration, maxConns int, logger *slog.Logger) *DoTServer
NewDoTServerWithListener creates a DoT server using an existing TLS listener. This is primarily useful for testing.
func NewDoTServerWithTLSConfig ¶ added in v0.5.5
func NewDoTServerWithTLSConfig(addr string, handler Handler, tlsCfg *tls.Config, timeout time.Duration, maxConns int, logger *slog.Logger) (*DoTServer, error)
NewDoTServerWithTLSConfig creates a DoT server using a pre-built tls.Config. This is used when auto-TLS provides the certificate dynamically.
type MainHandler ¶
type MainHandler struct {
// OnQuery is an optional callback invoked after each query is resolved.
// Parameters: client IP, qname, qtype, rcode (may be "BLOCKED"), whether served from cache, duration in ms.
OnQuery func(client, qname, qtype, rcode string, cached bool, durationMs float64)
// contains filtered or unexported fields
}
MainHandler ties together parsing, resolution, and response assembly.
func NewMainHandler ¶
func NewMainHandler( res *resolver.Resolver, c *cache.Cache, rl *security.RateLimiter, rrl *security.RRL, acl *security.ACL, m *metrics.Metrics, logger *slog.Logger, ) *MainHandler
NewMainHandler creates a new MainHandler.
func (*MainHandler) EnableCookies ¶
func (h *MainHandler) EnableCookies() error
EnableCookies enables DNS cookie support (RFC 7873). A random 16-byte server secret is generated at startup. M-6: if the OS RNG fails we refuse to enable cookies rather than fall back to a public literal (which would defeat the anti-spoofing property entirely).
func (*MainHandler) EnableCookiesWithSecret ¶
func (h *MainHandler) EnableCookiesWithSecret(secret []byte)
EnableCookiesWithSecret enables DNS cookies with a specific secret (for testing).
func (*MainHandler) SetBlocklist ¶
func (h *MainHandler) SetBlocklist(bl interface { IsBlocked(string) bool BlockingMode() string CustomIP() string })
SetBlocklist configures an optional blocklist for the handler.
func (*MainHandler) SetDownstreamUDPBufferSize ¶ added in v0.6.2
func (h *MainHandler) SetDownstreamUDPBufferSize(size int)
SetDownstreamUDPBufferSize configures the EDNS0 UDP payload size this server advertises to clients in outgoing OPT records. Per RFC 9018 / DNS Flag Day 2020, the safe default is 1232 (IPv6 minimum MTU 1280 minus 40-byte IPv6 header minus 8-byte UDP header). Values outside [512, 65535] are silently clamped to 1232 by advertisedUDPBufferSize.
func (*MainHandler) SetECS ¶
func (h *MainHandler) SetECS(enabled bool, maxPrefix int)
SetECS enables or disables ECS forwarding. maxPrefix and maxPrefixV6 cap the source-prefix length we forward upstream for IPv4 and IPv6 clients respectively. Pass 0 or out-of-range values to accept the RFC 7871 §11.1 recommended defaults (/24 IPv4, /56 IPv6).
func (*MainHandler) SetECSPrefixes ¶ added in v0.6.9
func (h *MainHandler) SetECSPrefixes(enabled bool, maxPrefixV4, maxPrefixV6 int)
SetECSPrefixes is the IPv6-aware extension of SetECS. The legacy SetECS is preserved as a convenience wrapper for callers that only care about IPv4 limits.
func (*MainHandler) SetNoCacheClients ¶
func (h *MainHandler) SetNoCacheClients(cidrs []string)
SetNoCacheClients configures the list of client IPs/CIDRs that should bypass the cache.
func (*MainHandler) SetPrivateFilter ¶
func (h *MainHandler) SetPrivateFilter(enabled bool)
SetPrivateFilter enables or disables private address filtering.
type TCPOption ¶
type TCPOption func(*TCPServer)
TCPOption configures optional TCPServer parameters.
func WithIdleTimeout ¶
WithIdleTimeout sets the idle timeout between pipelined queries.
func WithPipelineMax ¶
WithPipelineMax sets the maximum number of queries per TCP connection.
type TCPServer ¶
type TCPServer struct {
// contains filtered or unexported fields
}
TCPServer handles DNS queries over TCP.