Documentation
¶
Overview ¶
Package filterlist implements the CoreDNS filterlist plugin. It intercepts DNS queries and checks them against allowlist and denylist matchers, blocking or allowing queries according to configuration.
Index ¶
- type ActionConfig
- type Config
- type Plugin
- func (rf *Plugin) GetAllowlist() *matcher.Matcher
- func (rf *Plugin) GetDenylist() *matcher.Matcher
- func (rf *Plugin) Name() string
- func (rf *Plugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)
- func (rf *Plugin) SetAllowlist(m *matcher.Matcher)
- func (rf *Plugin) SetDenylist(m *matcher.Matcher)
- func (rf *Plugin) StartWatcher() error
- func (rf *Plugin) Stop() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionConfig ¶
type ActionConfig struct {
Mode string // "nxdomain", "nullip", "refuse"
NullIPv4 net.IP
NullIPv6 net.IP
TTL uint32
}
ActionConfig describes how filterlist answers blocked DNS questions.
Mode selects the response policy and must be one of nxdomain, nullip, or refuse. NullIPv4 and NullIPv6 provide sinkhole answers for A and AAAA queries when Mode is nullip, while TTL controls the cache lifetime of those synthetic answers.
type Config ¶
type Config struct {
AllowlistDir string
DenylistDir string
Action ActionConfig
Debounce time.Duration
MaxStates int
CompileTimeout time.Duration
Debug bool
InvertAllowlist bool
DenyNonAllowlisted bool
DisableRFCChecks bool
MatcherMode matcher.Mode
}
Config holds the complete filterlist runtime configuration.
AllowlistDir and DenylistDir point at directories containing supported filter list files. Action configures the DNS response for blocked names, while Debounce, MaxStates, and CompileTimeout bound filesystem churn and matcher compilation cost. InvertAllowlist controls which rules from the allowlist directory are compiled: by default (false) only @@-prefixed exception rules are used; when true, non-@@ rules (||domain^) are used instead.
DenyNonAllowlisted, when true, blocks every query that was not accepted by the allowlist in the denylist phase — effectively a deny-all-except-listed policy. It runs before the denylist matcher but after allowlist evaluation. Default is false.
DisableRFCChecks, when true, skips the RFC 1035 + IDNA query-name validation step that normally runs after DenyNonAllowlisted in the denylist phase. When false (the default), queries whose names violate RFC 1035 LDH syntax or the IDNA Lookup profile are blocked before the denylist matcher is consulted.
MatcherMode selects how compiled rules are represented at runtime. "hybrid" (the default) keeps literal domains in a suffix map and compiles only wildcard patterns into a DFA. "dfa" compiles all rules into one DFA, which can reduce per-query lookup cost at the expense of much longer compile times during startup and reloads.
Setup callers typically obtain Config via parseConfig.
type Plugin ¶
Plugin is the CoreDNS plugin handler.
Each Plugin instance owns the active whitelist and blacklist matchers for one CoreDNS server block and swaps them atomically when reloads succeed. The handler is created during setup and then used on the DNS request path.
func (*Plugin) GetAllowlist ¶
GetAllowlist returns the current allowlist matcher.
The return value is nil when no allowlist has been compiled yet or when the last successful reload yielded no allow rules. ServeDNS uses this on every query before consulting the denylist.
func (*Plugin) GetDenylist ¶
GetDenylist returns the current denylist matcher.
The return value is nil when no denylist has been compiled yet or when the currently loaded deny set is empty. Callers use the returned matcher as a read-only structure and must not mutate it.
func (*Plugin) Name ¶
Name reports the CoreDNS plugin name used for error wrapping and chaining.
It returns the static identifier filterlist so CoreDNS can attribute handler failures and plugin ordering to this module.
func (*Plugin) ServeDNS ¶
ServeDNS evaluates r against the active matchers and writes the response to w.
The ctx, w, and r parameters are the standard CoreDNS request context, response writer, and DNS message for the current query. ServeDNS returns the DNS rcode written to the client together with any write error; whitelist matches are forwarded, blacklist matches are blocked according to Action, and unmatched queries are delegated to the next plugin.
func (*Plugin) SetAllowlist ¶
SetAllowlist atomically installs m as the active allowlist matcher.
The m parameter may be nil to clear the allowlist after a successful reload that produced no allow rules. Callers normally use this from watcher update callbacks rather than directly from the DNS hot path.
func (*Plugin) SetDenylist ¶
SetDenylist atomically installs m as the active denylist matcher.
The m parameter may be nil to clear the denylist after a successful reload that produced no deny rules. This keeps readers lock-free while reload logic swaps compiled matchers in the background.
func (*Plugin) StartWatcher ¶
StartWatcher starts filesystem monitoring and the initial matcher load.
It uses the directories and limits from rf.Config, publishes metrics for successful compiles and failed load or compile runs, and stores the stop callback for later shutdown. StartWatcher returns an error only when the watcher infrastructure itself cannot be started.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
filterlist-check
command
Command filterlist-check validates filter list directories offline.
|
Command filterlist-check validates filter list directories offline. |
|
pkg
|
|
|
automaton
Package automaton compiles domain filter patterns into a cache-optimized, array-based deterministic finite automaton (DFA) with rule attribution.
|
Package automaton compiles domain filter patterns into a cache-optimized, array-based deterministic finite automaton (DFA) with rule attribution. |
|
blockloader
Package blockloader reads all filter list files from a directory and aggregates them into a unified slice of listparser.Rule objects.
|
Package blockloader reads all filter list files from a directory and aggregates them into a unified slice of listparser.Rule objects. |
|
listparser
Package listparser parses AdGuard, EasyList, and hosts-style filter lists into canonical Rule objects that represent domain-focused blocking or allow rules.
|
Package listparser parses AdGuard, EasyList, and hosts-style filter lists into canonical Rule objects that represent domain-focused blocking or allow rules. |
|
matcher
Package matcher composes DNS rule matchers into a single match interface.
|
Package matcher composes DNS rule matchers into a single match interface. |
|
metrics
Package metrics provides Prometheus metrics helpers for the filterlist plugin.
|
Package metrics provides Prometheus metrics helpers for the filterlist plugin. |
|
suffixmap
Package suffixmap provides a domain-suffix lookup table that implements the ||domain^ anchor semantics from AdGuard and ABP filter lists.
|
Package suffixmap provides a domain-suffix lookup table that implements the ||domain^ anchor semantics from AdGuard and ABP filter lists. |
|
watcher
Package watcher provides fsnotify-based directory watching with debounced matcher recompilation.
|
Package watcher provides fsnotify-based directory watching with debounced matcher recompilation. |