Skip to content

Commit 9b4da28

Browse files
committed
docs: sync docs with current code and trim crates.io package
1 parent c4e2490 commit 9b4da28

10 files changed

Lines changed: 156 additions & 100 deletions

Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ license = "GPL-3.0-or-later"
1212
readme = "README.md"
1313
keywords = ["dns", "smartdns", "doh", "dot", "doq"]
1414
categories = ["network-programming"]
15+
exclude = [
16+
".github/",
17+
".dockerignore",
18+
".gitignore",
19+
"Makefile",
20+
"benches/",
21+
"config.yaml",
22+
"docker/",
23+
"docs/",
24+
"etc/",
25+
"examples/",
26+
"scripts/",
27+
"tests/",
28+
"webui/",
29+
]
1530

1631
[dependencies]
1732
tokio = { version = "1.49", default-features = false, features = [

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
- **[Docs Home](docs/README.md)** - Main documentation index
1818
- **[Installation Guide](docs/en/03_INSTALLATION.md)** - Installation methods
1919
- **[Configuration Guide](docs/en/04_CONFIGURATION.md)** - Configuration file reference
20-
- **[Implementation](docs/IMPLEMENTATION.md)** - Phased implementation roadmap
2120

2221
## Current Status:
2322

build.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ fn main() {
88
if Path::new("webui/dist").exists() {
99
println!("cargo:rustc-cfg=webui_dist");
1010
} else {
11-
println!("cargo:warning=webui/dist not found; building without embedded webui assets");
11+
println!(
12+
"cargo:warning=webui/dist not found, web-embed feature will have no embedded assets. \
13+
Run `cd webui && npm run build` first."
14+
);
1215
}
1316
}

docs/IMPLEMENTATION.md

Lines changed: 109 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,148 @@
11
# Implementation status vs upstream mosdns
22

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`).
44

55
## Summary
66

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.
98

10-
## 1. Core DNS functionality
9+
## 1. Core DNS
1110

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/`:
1412

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
1619

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.
1821

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.
2423

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.
2643

2744
## 3. Plugin system
2845

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/`.
3186

32-
### Core plugin coverage (select)
87+
### Flow control
3388

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/`.
4090

41-
### Executable & control plugins
91+
### Linux integration
4292

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.
4894

49-
### ipset / nftset integration
95+
Status: IMPLEMENTED (CLI-based, not native netlink).
5096

51-
- `ipset`: Implemented (`src/plugins/executable/ipset.rs`). Behavior:
97+
## 5. Cache subsystem
5298

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
57104

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.
61106

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
63108

64-
## 4. Configuration system
109+
Audit is part of the `web` feature (no standalone plugin). When enabled:
65110

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
68115

69-
Status: PARTIAL: YAML loading and validation implemented; hot-reload present as a reloader component.
116+
Status: IMPLEMENTED (feature `web`).
70117

71-
## 5. Advanced features
118+
## 7. Metrics
72119

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`).
76121

77-
Status: PARTIAL: basic observability and TLS present; more integrations possible.
122+
Status: IMPLEMENTED.
78123

79-
## 6. Deployment & management
124+
## 8. Configuration
80125

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()`.
83127

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`.
85129

86-
## 7. Testing coverage
130+
Status: IMPLEMENTED.
87131

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
90133

91-
Status: IMPLEMENTED: good test coverage; integration tests added for key behaviors.
134+
Unit tests across all modules (950+ tests). Integration tests in `tests/`:
92135

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`
94140

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.
100142

101-
## File references (key files)
143+
## Gaps and next steps
102144

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).

docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Use the site sidebar (`en/SUMMARY.md`) or the quick links below to jump to commo
6060
- [Reject](en/05_09_04_PLUGIN_REJECT.md)
6161
- [Return](en/05_09_05_PLUGIN_RETURN.md)
6262
- [Prefer_IPv4](en/05_09_06_PLUGIN_PREFER_IPV4.md)
63-
- [Prefer_IPv6](05_09_07_PLUGIN_PREFER_IPV6.md)
63+
- [Prefer_IPv6](en/05_09_07_PLUGIN_PREFER_IPV6.md)
6464
* [Writing Plugins (Developer)](en/06_WRITING_PLUGINS.md)
6565
* [Datasets & Formats](en/07_DATASETS.md)
6666
* [Changelog](en/16_CHANGELOG.md)

docs/en/03_INSTALLATION.md

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,20 @@ Installs the latest published crate to your Cargo bin directory:
1010
cargo install lazydns
1111
```
1212

13-
### 2.1 Debian / Ubuntu (.deb via APT repo)
14-
Add the repository key and source, then install with `apt`:
15-
```bash
16-
sudo curl -fsSL https://raw.githubusercontent.com/lazywalker/apt/refs/heads/master/debian/key.asc -o /etc/apt/trusted.gpg.d/lazywalker.asc
17-
18-
echo "deb https://raw.githubusercontent.com/lazywalker/apt/refs/heads/master/debian/ stable main" | sudo tee /etc/apt/sources.list.d/lazywalker.list
13+
> **Note on the WebUI**: `cargo install` builds the server core only. For a binary with the WebUI bundled in, use the pre-built release binaries.
1914
20-
sudo apt update
21-
sudo apt install lazydns
15+
### 2.1 Debian / Ubuntu (amd64)
16+
Download the `.deb` from [GitHub Releases](https://github.com/lazywalker/lazydns/releases) and install with `dpkg`:
17+
```bash
18+
curl -LO https://github.com/lazywalker/lazydns/releases/latest/download/lazydns_<version>-1_amd64.deb
19+
sudo dpkg -i lazydns_<version>-1_amd64.deb
2220
```
2321

24-
### 2.2 Raspberry Pi OS (Trixie, arm64)
25-
Use the same repo but restrict to `arm64` architecture in the sources.list entry:
22+
### 2.2 Raspberry Pi OS / arm64
23+
Download the `arm64` `.deb` and install with `dpkg`:
2624
```bash
27-
sudo curl -fsSL https://raw.githubusercontent.com/lazywalker/apt/refs/heads/master/debian/key.asc -o /etc/apt/trusted.gpg.d/lazywalker.asc
28-
29-
echo "deb [arch=arm64] https://raw.githubusercontent.com/lazywalker/apt/refs/heads/master/debian/ stable main" | sudo tee /etc/apt/sources.list.d/lazywalker.list
30-
31-
sudo apt update
32-
sudo apt install lazydns
25+
curl -LO https://github.com/lazywalker/lazydns/releases/latest/download/lazydns_<version>-1_arm64.deb
26+
sudo dpkg -i lazydns_<version>-1_arm64.deb
3327
```
3428

3529
### 2.3 Install on Arch Linux
@@ -38,7 +32,7 @@ You can install lazydns from the Arch User Repository (AUR) using an AUR helper
3832
yay -S lazydns-bin
3933
```
4034

41-
### 3. Systemd Service Setup (via apt & systemd Linux)
35+
### 3. Systemd Service Setup (Debian / Ubuntu / Raspberry Pi OS)
4236
after installation, modify the config file at `/etc/lazydns/lazydns.yaml` as needed, then start the service:
4337
```bash
4438
sudo systemctl start lazydns
@@ -79,7 +73,7 @@ docker run -d \
7973

8074
## Upgrading
8175
- From `cargo install`: `cargo install --force lazydns`
82-
- From APT: `sudo apt update && sudo apt upgrade` (package upgrades coming from the repo)
76+
- From `.deb`: download the new `.deb` and run `sudo dpkg -i` again
8377
- From Docker: pull the new image and recreate the container:
8478
```bash
8579
docker pull lazywalker/lazydns:latest

docs/en/04_CONFIGURATION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Example:
9191
- `exec`: a plugin tag or quick-setup (such as `accept`, `drop_resp`)
9292
- `matches`: a condition (such as `qname $domain_list`, `has_resp`, `qtype 1`)
9393
- `jump`: jump to another sequence tag
94-
- `fallback` plugin accepts `primary`, `secondary`, `threshold`, `always_standby`.
94+
- `fallback` plugin accepts `primary` and `secondary`.
9595

9696
- Server plugins (udp_server, tcp_server, doh_server, dot_server, doq_server)
9797
- `entry`: the sequence tag to use as the processing entry point
File renamed without changes.

0 commit comments

Comments
 (0)