This document summarizes the feature set and implementation notes of the upstream mosdns project (source: IrineSistiana/mosdns). It highlights core capabilities, transport features, plugins, operational behaviors, and recommended improvements that are relevant when maintaining parity or planning feature work in lazydns.
- DNS message parsing and serialization (wire format).
- Support for common record types (A, AAAA, CNAME, MX, NS, PTR, SOA, TXT, SRV) and several less-common types (such as SVCB/HTTPS, CAA in type lists).
- Asynchronous, highly concurrent server model (uses goroutines in upstream;
lazydnsmaps totokio).
- UDP server (standard DNS over UDP).
- TCP server (DNS over TCP for large responses).
- DoH (DNS over HTTPS): HTTP POST
application/dns-message. - DoT (DNS over TLS): TLS-protected DNS (RFC 7858).
- DoQ (DNS over QUIC): planned/experimental in upstream.
- Multi-listen, concurrent handling, and tunable timeouts and limits.
The upstream project exposes a plugin architecture with numerous built-in plugins. Key executable and core plugins include:
- forward: Forward queries to upstream resolvers (supports DoH upstreams). Includes health checks, load-balancing strategies (round-robin, random, fastest), concurrent queries (race mode), failover, and per-upstream metrics.
- cache: Caching layer for query responses.
- hosts: Local hosts file parsing and matching (supports ip-first and hostname-first formats, multiple IP entries per line).
- ip_set / nftset: System integration plugins that export IPs to
ipsetornft(CLI) on Linux; they compute prefixes and optionally aggregate CIDRs. - ros_addrlist: RouterOS (MikroTik) integration for managing address-lists; supports dry-run and aggregation.
- reverse_lookup: Generates reverse PTR records and supports save hooks.
- rate_limiter: Per-client or global query limiting.
- ttl: TTL rewrite/clamping plugin (fixed TTL or min/max range).
- query_summary, metrics_collector: Observability and stats gathering components.
- control & flow: sequence/parallel/if/goto/return/drop_resp; plugins to build control-flow logic.
- executable helpers: arbitrary, sleep, debug_print, drop_resp.
Note: Many plugins have a QuickSetup parsing style and both mnemonic and tag-based config options used by the plugin builder.
domain_set,ip_set, andhostssupport a set of files or inline data.- Optional
auto_reloadconfiguration: when enabled andfiles: [...]are provided, aFileWatchermonitors the underlying files and triggers rebuilds on changes.
Key features and improvements in upstream:
- Centralized
FileWatcherimplementation that handles fsnotify events with debouncing and robust handling of REMOVE/RENAME/CREATE scenarios. - Debounce to avoid duplicate reloads (default ~500ms).
- Re-add and retry logic for REMOVE/RENAME situations (exponential backoff retries) to handle atomic editor saves and rediscovery.
- Scheduled reload after CREATE to avoid missing atomic replace patterns (configurable short delay, default ~250ms).
-
Uses
viperto load YAML configuration, withAutomaticEnv()enabled and a key replacer mapping.->_. This allows environment-based overrides like:PLUGINS_HOSTS_ARGS_AUTO_RELOADPLUGINS_ADD_GFWLIST_ARGS_PASSWD
-
There is an
applyPluginEnvOverrideshelper that mapsPLUGINS_<IDENT>_ARGS_<KEY>into pluginArgsmaps. It supports boolean / numeric parsing where appropriate.
- Metrics: Prometheus-style metrics and plugin-level counters (queries, successes, failures, response durations). Plugins optionally expose these metrics when health checks are enabled.
- Logging:
time_formatconfigurable inLogConfigwith values liketimestamp,iso8601,rfc3339,custom:<layout>. - Tests and docs encourage using readable timestamps and consistent encoding for production vs development.
- Recommendations and docs for secret management (
docs/SECURE_SECRETS.md): Docker secrets, Kubernetes secrets, Vault, and others. - Some plugins and helpers are designed to avoid leaking secrets to logs; the env override helper is conscious of secrets handling.
- Unit tests for
FileWatcher,ros_addrlistsynchronization logic, and time-format and logger behavior. - Integration tests should avoid modifying repository example files; use
outputDiror./tmp/for test outputs. - CI should run
go test ./...and ensure tests do not mutate tracked sample files.
- Official Docker images are published; prebuilt binaries are available.
- Configurable CLI and flags for working directories and log levels.
- Router/OS integration (ros_addrlist) supports dry-run and multiple sync strategies (replace, append, diff-sync).
- Add
outputDiranddry_runto various writing functions for safer tests and more predictable behavior. - Consider replacing CLI-based
ipset/nftinvocation with native netlink-based implementations for robustness. - Continue hardening FileWatcher behavior for edge-case filesystems/editors and add tests for the edge cases.
- Improve plugin args decoding after env overrides (map to typed struct conversion) for better ergonomics.
- Core:
coremain/,server/,pkg/,plugin/ - Docs & recommendations:
docs/UPSTREAM_CHANGES.md,docs/SECURE_SECRETS.md,README.md - Plugin implementations:
plugin/executable/,plugin/data_provider/
(from reading upstream repository source and docs; useful as a checklist when porting features to lazydns.)