Documentation
¶
Index ¶
- type DoQOption
- type DoQServer
- 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) CookiesEnforce() bool
- func (h *MainHandler) EnableCookies() error
- func (h *MainHandler) EnableCookiesWithSecret(secret []byte)
- func (h *MainHandler) Handle(query []byte, clientAddr net.Addr) (resp []byte, err error)
- func (h *MainHandler) Metrics() *metrics.Metrics
- func (h *MainHandler) RotateCookieSecret() error
- func (h *MainHandler) SetBlocklist(bl interface{ ... })
- func (h *MainHandler) SetCookiesEnforce(enforce bool)
- func (h *MainHandler) SetDDR(cfg dns.DDRConfig)
- 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) SetNSID(id string)
- func (h *MainHandler) SetNoCacheClients(cidrs []string)
- func (h *MainHandler) SetPrivateFilter(enabled bool)
- func (h *MainHandler) SetResolverInfo(info dns.ResolverInfo)
- type TCPOption
- type TCPServer
- type UDPServer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DoQOption ¶ added in v0.8.32
type DoQOption func(*DoQServer)
DoQOption configures optional DoQServer parameters.
func WithDoQIdleTimeout ¶ added in v0.8.32
WithDoQIdleTimeout sets the idle timeout for QUIC connections.
func WithDoQPipelineMax ¶ added in v0.8.32
WithDoQPipelineMax sets the maximum number of concurrent streams per connection.
type DoQServer ¶ added in v0.8.32
type DoQServer struct {
// contains filtered or unexported fields
}
DoQServer handles DNS queries over QUIC (RFC 9250).
func NewDoQServer ¶ added in v0.8.32
func NewDoQServer(addr string, handler Handler, certFile, keyFile string, timeout time.Duration, maxConns int, logger *slog.Logger, opts ...DoQOption) (*DoQServer, error)
NewDoQServer creates a new DNS-over-QUIC server. It loads TLS certificate/key and creates a QUIC listener.
func NewDoQServerWithTLSConfig ¶ added in v0.8.32
func NewDoQServerWithTLSConfig(addr string, handler Handler, tlsCfg *tls.Config, timeout time.Duration, maxConns int, logger *slog.Logger, opts ...DoQOption) (*DoQServer, error)
NewDoQServerWithTLSConfig creates a DoQ server using a pre-built tls.Config. The caller must set NextProtos to include "doq" and MinVersion to TLS 1.3. Used when auto-TLS provides the certificate dynamically.
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, maxConnsPerClient 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, maxConnsPerClient 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, maxConnsPerClient 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) CookiesEnforce ¶ added in v0.7.3
func (h *MainHandler) CookiesEnforce() bool
CookiesEnforce reports the current §5.4 strict-mode setting.
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) Metrics ¶ added in v0.8.32
func (h *MainHandler) Metrics() *metrics.Metrics
Metrics returns the handler's metrics registry (may be nil in tests).
func (*MainHandler) RotateCookieSecret ¶ added in v0.6.19
func (h *MainHandler) RotateCookieSecret() error
RotateCookieSecret generates a fresh random 16-byte server cookie secret. The previous secret is retained for one hour (the cookie validity window per RFC 9018 §4.3) so cookies the client minted moments before rotation are not invalidated — RFC 7873 §5.2.5 explicitly requires this grace ("Cookies created with old secrets remain valid until they expire"). Without grace every rotation would force every active client through a BADCOOKIE round-trip, turning a routine operational action into a service blip.
Returns the error from the OS RNG; on error the existing secrets are left intact (better to keep using a known-good secret than land on an all-zero replacement).
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) SetCookiesEnforce ¶ added in v0.7.3
func (h *MainHandler) SetCookiesEnforce(enforce bool)
SetCookiesEnforce toggles RFC 7873 §5.4 strict mode: cookie-less UDP queries are rejected with BADCOOKIE. No-op unless cookies themselves are also enabled (EnableCookies / EnableCookiesWithSecret).
func (*MainHandler) SetDDR ¶ added in v0.8.33
func (h *MainHandler) SetDDR(cfg dns.DDRConfig)
SetDDR configures the RFC 9462 designation this resolver publishes. An empty target name (the default) disables discovery: a designation naming a host whose certificate does not cover this resolver's address fails the client's RFC 9462 §4.2 verification, so publishing one would cost a round trip to hand out something guaranteed not to work.
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) SetNSID ¶ added in v0.8.33
func (h *MainHandler) SetNSID(id string)
SetNSID sets the RFC 5001 Name Server Identifier reported to clients that ask for it. An empty string disables NSID responses entirely, which is the default: RFC 5001 §3.1 warns that the identifier is visible to any client and advises operators to choose a value that does not disclose more topology than they intend.
Identifiers longer than dns.MaxNSIDLength are truncated at emit time.
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. Called from the /api/config/raw hot-reload callback. The atomic store publishes the new value to the DNS handler reader sites with the right happens-before edge (see field comment).
func (*MainHandler) SetResolverInfo ¶ added in v0.8.33
func (h *MainHandler) SetResolverInfo(info dns.ResolverInfo)
buildMinimalANYResponse returns a synthetic HINFO response per RFC 8482, preventing DNS amplification attacks via ANY queries. SetResolverInfo configures the RFC 9606 RESINFO record this resolver publishes at its own designated name.
type TCPOption ¶
type TCPOption func(*TCPServer)
TCPOption configures optional TCPServer parameters.
func WithIdleTimeout ¶
WithIdleTimeout sets the idle timeout between pipelined queries.
func WithMaxConnsPerClient ¶ added in v0.8.32
WithMaxConnsPerClient sets the per-source-IP connection cap for the TCP server.
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.
type UDPServer ¶
type UDPServer struct {
// contains filtered or unexported fields
}
UDPServer handles DNS queries over UDP.
func NewUDPServer ¶
func NewUDPServer(addr string, handler Handler, maxWorkers int, logger *slog.Logger) (*UDPServer, error)
NewUDPServer creates a new UDP DNS server.
func (*UDPServer) SetMetrics ¶ added in v0.8.32
SetMetrics wires optional metrics for UDP admission drops.