|
1 | 1 | # Implementation status vs upstream mosdns |
2 | 2 |
|
3 | | -This document summarizes the current implementation status of the Rust `lazydns` project against the upstream `mosdns` feature list (see `upstream-features.md`). It lists implemented features, partial implementations, and known gaps. Paths reference current source files where applicable. |
| 3 | +Compares lazydns (Rust) against the upstream mosdns feature list (see `UPSTREAM_FEATURES.md`). |
4 | 4 |
|
5 | 5 | ## Summary |
6 | 6 |
|
7 | | -- Overall status: large portion of core features and many plugins implemented in Rust with the goal of parity. |
8 | | -- Focus so far: plugin architecture, forward/cache/hosts, control-flow plugins, and executable plugins including `reverse_lookup`, `ipset`, and `nftset`. |
| 7 | +Core DNS functionality, plugin system, all five transports, cache with persistence and lazy refresh, and a WebUI dashboard are implemented. Gaps are in native netlink integration and some upstream plugin parity. |
9 | 8 |
|
10 | | -## 1. Core DNS functionality |
| 9 | +## 1. Core DNS |
11 | 10 |
|
12 | | -- DNS parsing & serialization: Implemented. See `src/dns/*` (message, wire, record, rdata, types). |
13 | | -- Supported record types: implemented for the common set (A, AAAA, CNAME, MX, NS, PTR, SOA, TXT, SRV). SVCB/HTTPS and CAA are present in `RecordType` definitions (`src/dns/types.rs`). |
| 11 | +Wire-format parse/serialize is built on `hickory-proto` 0.24. See `src/dns/`: |
14 | 12 |
|
15 | | -Status: IMPLEMENTED (core parsing and record support). |
| 13 | +- `message.rs` - DNS message (header + 4 sections); `records()` / `records_mut()` iterate all RRs; DNSSEC bits (AD, CD) |
| 14 | +- `question.rs` - Question struct (qname, qtype, qclass) |
| 15 | +- `record.rs` - ResourceRecord (name, type, class, ttl, rdata) |
| 16 | +- `rdata.rs` - RData enum (A, AAAA, CNAME, NS, PTR, MX, TXT, SOA, SRV, OPT, CAA, DS, RRSIG, NSEC, DNSKEY, etc.) |
| 17 | +- `types.rs` - RecordType, RecordClass, OpCode, ResponseCode |
| 18 | +- `wire.rs` - parse_message / serialize_message |
16 | 19 |
|
17 | | -## 2. Transport & server features |
| 20 | +Record types: A, AAAA, CNAME, MX, NS, PTR, SOA, TXT, SRV fully supported. OPT (EDNS0), DS, RRSIG, NSEC, DNSKEY, SVCB, HTTPS, CAA defined in the enum. |
18 | 21 |
|
19 | | -- UDP and TCP servers: Implemented (`src/server/udp.rs`, `src/server/tcp.rs`). |
20 | | -- DoT (DNS over TLS): Implemented (`src/server/dot.rs`, `src/server/tls.rs`). |
21 | | -- DoH (DNS over HTTPS): Implemented (`src/server/doh.rs`). |
22 | | -- DoQ (DNS over QUIC): implemented (`src/server/doq.rs`). |
23 | | -- Multi-listen, concurrency, connection handling: Implemented via `tokio`-based servers (`src/server/*`). |
| 22 | +Status: IMPLEMENTED. |
24 | 23 |
|
25 | | -Status: PARTIAL: UDP/TCP/DoH/DoT/DoQ present, not all features. |
| 24 | +## 2. Transports and servers |
| 25 | + |
| 26 | +All five transports via the `Server` trait (`src/server/mod.rs`): |
| 27 | + |
| 28 | +| Transport | File | Feature | |
| 29 | +|-----------|------|---------| |
| 30 | +| UDP | `udp.rs` | always | |
| 31 | +| TCP | `tcp.rs` | always | |
| 32 | +| DoT | `dot.rs` | `dot` | |
| 33 | +| DoH | `doh.rs` | `doh` | |
| 34 | +| DoQ | `doq.rs` | `doq` | |
| 35 | +| Admin API | `admin.rs` | `admin` | |
| 36 | +| Monitoring | `monitoring.rs` | `metrics` | |
| 37 | + |
| 38 | +`ServerLauncher` (`launcher.rs`) spawns servers from plugin config. A shared `spawn_server` helper handles the oneshot + spawn + error-log pattern for all transport types. |
| 39 | + |
| 40 | +`RequestHandler` trait and `DefaultHandler` (`handler.rs`) wire requests to the plugin entry point, with `RequestContext` carrying client IP and protocol. |
| 41 | + |
| 42 | +Status: IMPLEMENTED. |
26 | 43 |
|
27 | 44 | ## 3. Plugin system |
28 | 45 |
|
29 | | -- Plugin architecture: Implemented (`src/plugin/*`, `src/plugins/mod.rs`). |
30 | | -- Execution flow, context, and conditional execution: Implemented (`src/plugin/context.rs`, `src/plugins/advanced.rs`, `src/plugin/builder.rs`). |
| 46 | +Core traits in `src/plugin/`: |
| 47 | + |
| 48 | +- `traits.rs` - `Plugin` (execute, init, aliases, as_any, as_shutdown, spawn_background_task), `ExecPlugin` (quick_setup), `Shutdown`, `BackgroundTask`, `Matcher` |
| 49 | +- `context.rs` - `Context` holds request/response Messages and typed metadata; `set_refused()` builds a REFUSED response echoing the request |
| 50 | +- `builder.rs` - `PluginBuilder` resolves `$tag` references and builds plugin instances from `PluginConfig` |
| 51 | +- `factory.rs` - auto-registration via `#[derive(RegisterPlugin)]` + `linkme::distributed_slice` |
| 52 | +- `registry.rs` - runtime lookup by name/tag |
| 53 | +- `condition/` - condition builders (qname, qname_neg, qtype, qclass, rcode, has_cname, has_resp, resp_ip, resp_ip_neg) |
| 54 | + |
| 55 | +`PluginHandler` (`mod.rs`) runs the entry plugin, handles control-flow metadata (`goto_label`, `jump_target`, `RETURN_FLAG`), and does post-processing: cache store, reverse-lookup IP save, and audit query logging. |
| 56 | + |
| 57 | +Status: IMPLEMENTED. |
| 58 | + |
| 59 | +## 4. Plugins |
| 60 | + |
| 61 | +### Server-facing |
| 62 | + |
| 63 | +| Plugin | Path | Notes | |
| 64 | +|--------|------|-------| |
| 65 | +| `forward` | `forward/{mod,engine,builder,types}.rs` | UDP multiplexing (qid demux), DoH (reqwest), concurrent racing, health tracking, load balancing (round-robin/random/fastest) | |
| 66 | +| `cache` | `cache/{mod,entry,persistence,stats}.rs` | LRU + LazyCache (pre-expiry background refresh) + stale-serving + binary persistence (`dump_file`/`dump_interval`); cache key includes DNSSEC flags (DO/AD/CD) | |
| 67 | +| `hosts` | `dataset/hosts.rs` | HashMap O(1), multiple IPs/domain, file-watch auto-reload | |
| 68 | +| `acl` | `acl.rs` | IP-based allow/deny | |
| 69 | +| `geoip` | `geoip.rs` | Country-code matching | |
| 70 | +| `geosite` | `geosite.rs` | Category/domain matching | |
| 71 | +| `domain_validator` | `domain_validator.rs` | RFC 1035/1123 name validation, rejects malformed queries early | |
| 72 | +| `rate_limit` | `executable/ratelimit.rs` | Per-IP token-bucket / window limiting | |
| 73 | +| `redirect` | `executable/redirect.rs` | Query name rewriting (wildcard, multi-rule, first-match-wins) | |
| 74 | +| `ecs` | `executable/ecs.rs` | EDNS Client Subnet | |
| 75 | +| `cron` | `cron.rs` | Scheduled tasks (`cronexpr`); drives downloader | |
| 76 | + |
| 77 | +### Executable (inline `exec:` in sequences) |
| 78 | + |
| 79 | +`ttl`, `black_hole`, `arbitrary`, `query_summary`, `debug_print`, `drop_resp`, `sleep`, `dual_selector`, `edns0opt`, `mark`, `reverse_lookup`, `downloader`, `collector` (Prometheus variant under `metrics` feature). |
| 80 | + |
| 81 | +All in `src/plugins/executable/`. |
| 82 | + |
| 83 | +### Datasets |
| 84 | + |
| 85 | +`domain_set` (full/domain/regexp/keyword match types), `ip_set` (CIDR), `arbitrary`. All in `src/plugins/dataset/`. |
31 | 86 |
|
32 | | -### Core plugin coverage (select) |
| 87 | +### Flow control |
33 | 88 |
|
34 | | -- `forward`: Implemented (`src/plugins/forward.rs`); supports multiple upstreams and concurrent queries. Transport feature parity (DoH/DoT/DoQ upstream) is partial on transport side. |
35 | | -- `cache`: Implemented (`src/plugins/cache/mod.rs`). - TODO: `lazy_cache_ttl` |
36 | | -- `hosts`: Implemented (`src/plugins/hosts.rs`). Parser supports both ip-first and hostname-first lines, multiple IPs per line, and mixed ordering across files; unit tests verify A/AAAA behavior and hostname-first parsing. |
37 | | -- `domain_set` / `geosite`: Implemented (`src/plugins/domain_matcher.rs`, `src/plugins/geosite.rs`). |
38 | | -- `ip_set` / IP matching: Implemented (`src/plugins/ip_matcher.rs`, `src/plugins/data_provider.rs`). |
39 | | -- `geoip`: Implemented (`src/plugins/geoip.rs`); GeoIP integration present; check for data loader details. |
| 89 | +`sequence`, `goto`, `jump`, `accept`, `reject`, `return`, `prefer_ipv4`, `prefer_ipv6`. In `src/plugins/executable/sequence.rs` and `src/plugins/flow/`. |
40 | 90 |
|
41 | | -### Executable & control plugins |
| 91 | +### Linux integration |
42 | 92 |
|
43 | | -- `sequence`, `parallel`, `if`, `goto`, `return`, `drop_resp`: Implemented (`src/plugins/advanced.rs`, `src/plugins/control_flow.rs`). |
44 | | -- `ttl`: Implemented (`src/plugins/executable/ttl.rs`). |
45 | | -- `query_summary`: Implemented (`src/plugins/executable/query_summary.rs`). |
46 | | -- `reverse_lookup`: Implemented with in-memory cache and save hook (`src/plugins/executable/reverse_lookup.rs`). Integration: `PluginHandler` calls `save_ips_after` after response population. |
47 | | -- `arbitrary`, `black_hole`, `drop_resp`: Implemented in `src/plugins/executable/*.rs`. |
| 93 | +`ipset` (`executable/ipset.rs`) and `nftset` (`executable/nftset.rs`) compute CIDR prefixes from A/AAAA answers and invoke `ipset` / `nft` binaries on Linux; record metadata on other platforms. |
48 | 94 |
|
49 | | -### ipset / nftset integration |
| 95 | +Status: IMPLEMENTED (CLI-based, not native netlink). |
50 | 96 |
|
51 | | -- `ipset`: Implemented (`src/plugins/executable/ipset.rs`). Behavior: |
| 97 | +## 5. Cache subsystem |
52 | 98 |
|
53 | | - - Computes CIDR prefixes from A/AAAA answers. |
54 | | - - QuickSetup parser present. |
55 | | - - On Linux, invokes system `ipset` binary via `std::process::Command` (guarded with `cfg(target_os = "linux")`). |
56 | | - - On other platforms records metadata (`ipset_added`) for tests/visibility. |
| 99 | +- LRU eviction with periodic cleanup (60s interval, 0.8 pressure threshold) |
| 100 | +- LazyCache: proactively refreshes entries when remaining TTL drops below 5% |
| 101 | +- Stale-serving via `cache_ttl`: serves stale at TTL=0 while refreshing |
| 102 | +- Negative caching with configurable `negative_ttl` |
| 103 | +- Persistence: binary dump (`LZDNSCv1` format, atomic temp+rename) to `dump_file` every N changes; loaded on startup and on shutdown |
57 | 104 |
|
58 | | -- `nftset`: Implemented (`src/plugins/executable/nftset.rs`). Behavior mirrors `ipset`: |
59 | | - - Computes prefixes, QuickSetup parser. |
60 | | - - On Linux uses `nft` binary; otherwise records metadata (`nftset_added_v4`, `nftset_added_v6`). |
| 105 | +Status: IMPLEMENTED. |
61 | 106 |
|
62 | | -Status: IMPLEMENTED (CLI-based integration). Note: upstream native netlink integration is not used; a native implementation could be added later. |
| 107 | +## 6. Audit and WebUI |
63 | 108 |
|
64 | | -## 4. Configuration system |
| 109 | +Audit is part of the `web` feature (no standalone plugin). When enabled: |
65 | 110 |
|
66 | | -- YAML config loader and validation: Implemented (`src/config/*`) with `PluginBuilder` and `PluginConfig` parsing. Example configs included in `examples/etc/config.yaml`. |
67 | | -- Hot reload: partial; `ConfigReloader` exists, verify runtime hot-reload semantics for production. |
| 111 | +- `PluginHandler` auto-logs every query via `log_query_for_context` |
| 112 | +- Plugins emit security events (ACL deny, rate-limit, malformed query) via `AUDIT_LOGGER` |
| 113 | +- Event bus (`audit/event_bus.rs`) fans out to SSE stream and alert engine |
| 114 | +- WebUI (`src/web/`): real-time dashboard, audit SSE stream, config viewer, admin ops, WebSocket metrics |
68 | 115 |
|
69 | | -Status: PARTIAL: YAML loading and validation implemented; hot-reload present as a reloader component. |
| 116 | +Status: IMPLEMENTED (feature `web`). |
70 | 117 |
|
71 | | -## 5. Advanced features |
| 118 | +## 7. Metrics |
72 | 119 |
|
73 | | -- Performance: designed for async `tokio` concurrency; memory pools and advanced tuning are incremental work (some pool utilities exist in project). |
74 | | -- Observability: metrics and monitoring modules exist (`src/server/monitoring.rs`, `src/metrics` planned). Prometheus-style exposure may be partial. |
75 | | -- Security: TLS support for DoT/DoH implemented. Certificate handling present in `src/server/tls.rs`. |
| 120 | +Prometheus gauges/counters in `src/metrics/mod.rs` (cache hits/misses, DNS queries, upstream stats, domain validation). Process memory metrics (RSS/VMS/cgroup) in `src/metrics/memory/`. Exposed via monitoring server (feature `metrics`). |
76 | 121 |
|
77 | | -Status: PARTIAL: basic observability and TLS present; more integrations possible. |
| 122 | +Status: IMPLEMENTED. |
78 | 123 |
|
79 | | -## 6. Deployment & management |
| 124 | +## 8. Configuration |
80 | 125 |
|
81 | | -- Standalone binary and Docker artifacts: project includes `Dockerfile` and `docker-compose.yml` in workspace root. |
82 | | -- CLI flags and signal handling: implemented in `src/main.rs` (config path, working dir, log level, graceful shutdown via ctrl-c). |
| 126 | +YAML config with serde, env var substitution, `!include`, and hot-reload via file watcher (`config/reload.rs`). Validation in `config/validation.rs` checks ranges and required keys for known plugins. Plugin args are free-form YAML parsed by each plugin's `init()`. |
83 | 127 |
|
84 | | -Status: IMPLEMENTED (basic deployment support present). |
| 128 | +Feature flags (`Cargo.toml`): `cron`, `log`, `log-ansi`, `log-file`, `dot`, `doh`, `doq`, `admin`, `metrics`, `web`, `web-embed`. The `full` feature enables everything except `web-embed`. |
85 | 129 |
|
86 | | -## 7. Testing coverage |
| 130 | +Status: IMPLEMENTED. |
87 | 131 |
|
88 | | -- Unit tests: extensive unit tests across DNS, plugin, and executable modules (run via `cargo test`). |
89 | | -- Integration tests: added integration tests for the reverse-lookup save hook and ipset/nftset metadata behavior under `tests/`. |
| 132 | +## 9. Testing |
90 | 133 |
|
91 | | -Status: IMPLEMENTED: good test coverage; integration tests added for key behaviors. |
| 134 | +Unit tests across all modules (950+ tests). Integration tests in `tests/`: |
92 | 135 |
|
93 | | -## Gaps and recommended next steps |
| 136 | +- `integration_cache.rs`, `integration_ratelimit.rs`, `integration_doq.rs` |
| 137 | +- `integration_ipset_nftset.rs`, `integration_save_hook.rs` |
| 138 | +- `integration_tls_doh_dot.rs`, `integration_test.rs` (wire format) |
| 139 | +- `server_test.rs` (real UDP queries), `web_api_test.rs` |
94 | 140 |
|
95 | | -1. DoQ (DNS over QUIC): implement DoQ server and transport support to match upstream feature set. |
96 | | -2. Replace CLI-based ipset/nft manipulation with native netlink integration (via a Rust netlink crate) for more robust system integration and error handling. |
97 | | -3. Expand documentation per-plugin (config examples and QuickSetup documentation) and add README snippets linking `examples/etc/config.yaml` to plugin behaviors. |
98 | | -4. Add further integration tests for multi-plugin sequences (such as forward->ipset->ros_addrlist flow) and permissioned system behaviors. |
99 | | -5. Verify Prometheus metrics coverage and add exporter where missing. |
| 141 | +Status: IMPLEMENTED. |
100 | 142 |
|
101 | | -## File references (key files) |
| 143 | +## Gaps and next steps |
102 | 144 |
|
103 | | -- Core DNS: `src/dns/*` (types.rs, message.rs, record.rs, wire.rs) |
104 | | -- Server: `src/server/*` (`udp.rs`, `tcp.rs`, `doh.rs`, `dot.rs`) |
105 | | -- Plugin system: `src/plugin/*`, `src/plugins/*` |
106 | | -- Executable plugins: `src/plugins/executable/*` (includes `ipset.rs`, `nftset.rs`, `reverse_lookup.rs`, `ttl.rs`, `query_summary.rs`) |
107 | | -- Config and examples: `src/config/*`, `examples/etc/config.yaml` |
| 145 | +1. Replace CLI-based ipset/nftset with native netlink integration. |
| 146 | +2. Add more per-plugin validation coverage (only 5 plugin types validated today). |
| 147 | +3. Expand integration tests for multi-plugin sequences. |
| 148 | +4. DoH/DoT upstream transport in forward (currently UDP + DoH upstream only). |
0 commit comments