This commit is contained in:
Mateusz Gruszczyński committed 2026-11-22 14:21:54 +01:00
commit fa432bebda
189 files changed
+26219

No files matched your search

+86
View File
@@ -0,0 +1,86 @@
# Architecture
```
crates/
dns-core protocol helpers on hickory-proto: client (UDP→TCP, AXFR/IXFR streams, NOTIFY),
TSIG (RFC 8945, multi-message), RFC 1982 serials, zone files (+DNSSEC/RFC 3597
pre-processor), DNSSEC primitives (sign/verify/DS/NSEC/NSEC3), DoT/DoH client
dns-config YAML/JSON schema, ENV/CLI precedence, offline validation with locations
dns-authoritative Zone (immutable snapshot + RFC 1034/4592 lookup), journal (IXFR), xfr,
store (Primary/Secondary entries, atomic swap), secondary (SOA timers),
update (RFC 2136), signing (online DNSSEC)
dns-cache bounded LRU answer/RRset cache, namespaces per route, RFC 2308
dns-recursive iterative resolver, root hints, validator (DNSSEC chain of trust)
dns-forwarder upstream pools, strategies, circuit breaker, health checks
dns-policy ACLs, views, rate limiter, block/allow lists, local-only names
dns-server listeners (UDP/TCP/DoT/DoH), dispatcher (handler), router (hybrid),
encoded-answer cache, query coalescing,
runtime snapshot + hot reload, audit log, offline checks
dns-api REST API (axum), auth/roles, metrics endpoint
dns-metrics low-cardinality counters/histograms, Prometheus text, logging setup
dns-cli `easydns`
dns-tools ed, eh, ens, etrace, ednssec, eptr, ezone, econf, ebench, ewhois, edoh, edot, ediff
```
## Data flow
Each listener reads a message and calls `handler::handle(shared, bytes, peer, transport)`,
which returns zero, one or many encoded messages (zone transfers). The handler takes an
`Arc<Runtime>` snapshot at the start of every query; a reload builds a complete new
`Runtime` and swaps the pointer, so in-flight queries finish on the configuration they
started with and a failed reload leaves the old one active (rollback).
Fast path: before parsing, `handler::handle_with` (and, for UDP, `udp_fast_path` inside
the receive loop) looks the raw query up in the **encoded-answer cache**
(`packet_cache.rs`), keyed by the query bytes and the client profile. A hit is the
stored response with the ID, question case and TTLs patched – no parsing, policy,
lookup or encoding. Misses take the full path; their responses are stored if cacheable.
Zone publication (`ZoneEntry::install`), expiry changes, reloads and cache flushes bump a
generation number that invalidates all stored answers. On Linux the UDP loop receives
and sends in batches (`recvmmsg`/`sendmmsg`).
## Zone data
A `Zone` is immutable and validated on construction (single SOA at the apex, apex NS,
no CNAME conflicts, all data in-zone, TTL normalisation per RRset). Changes always build a
new `Zone` and publish it with one pointer swap (`ZoneEntry::install`), therefore a query
can never observe a half-applied change. IXFR diffs are computed between snapshots and
appended to a JSON-lines journal (`<data_dir>/journal/<zone>.jnl`, wire-format records).
### Why files and not SQLite?
The spec asks for a durable backend for zones, transfer journals and admin data and to
justify the choice. EasyDNS uses plain files because:
* zones stay in BIND format, editable and diffable by operators (spec: "identycznie do bind");
* the only mutable data is append-only (journal, audit) or replaced atomically
(`write tmp → fsync → rename → fsync dir`), which needs no transactions;
* no extra native dependency, trivial backup (`tar` of `/etc/easydns` + `/etc/easydns/data`).
Schema "migrations" are version-tolerant readers: unknown journal lines truncate the
journal (IXFR then falls back to AXFR); snapshots are plain zone files.
| Path (`data_dir`) | Content |
|---|---|
| `zones/secondary/<zone>.zone` + `.meta.json` | last valid secondary copy + last successful refresh |
| `journal/<zone>.jnl` | IXFR differences |
| `signed/<zone>.zone` | last signed version of DNSSEC zones (keeps signatures stable across restarts) |
| `zones/` | zones created via the API |
| `api-overlay.yaml` | API changes (zones, upstreams, allowlist, block rules) merged on load |
| `blocklists/` | downloaded/API block lists |
| `audit.log` | JSON lines of administrative actions |
## Hybrid decision order
1. local authoritative zone (most specific, visible in the client's view) → AA answer;
2. client not allowed to recurse → REFUSED;
3. local-only names (RFC 6761/6303, configurable) → NXDOMAIN, never sent out;
4. allow/block policy;
5. conditional forwarding (longest suffix, optional client ACL);
6. default resolution: `recursive`, `forward`, `forwardthenrecursive` or `refuse`.
Each route has its own cache namespace; authoritative data is never cached.
## Extension points
* Transports: implement a listener that feeds `handler::handle` (DoQ/DoH3 planned).
* Zone backends: `ZoneEntry` owns loading/persisting; a database backend would replace
`load_primary_file`/`modify` while keeping snapshot publication unchanged.