1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
//! Programmable Rust DNS control plane for the Lattice networking stack:
//! split DNS, Fake IP, address pools, and dynamic routing hooks.
//!
//! # Quick start
//!
//! The usual inbound path is `Server` → `Resolver` → static split-DNS
//! policy → `UpstreamBackend`. This `no_run` example uses the baseline UDP
//! transport; it needs a Tokio runtime, an available local listen address,
//! and a reachable upstream to run.
//!
//! ```no_run
//! use std::{net::SocketAddr, sync::Arc, time::Duration};
//!
//! use dns_lattice::{
//! core::Result,
//! engine::Resolver,
//! model::{SplitDnsPolicy, UpstreamGroupId},
//! server::ServerBuilder,
//! upstream::{UdpBackend, UdpBackendConfig},
//! };
//!
//! # async fn run() -> Result<()> {
//! let group = UpstreamGroupId::new("default");
//! let policy = SplitDnsPolicy::builder().default_group(group.clone()).build();
//! let resolver = Arc::new(
//! Resolver::builder(policy)
//! .backend(
//! group,
//! UdpBackend::new(UdpBackendConfig {
//! server: "1.1.1.1:53".parse::<SocketAddr>().unwrap(),
//! timeout: Duration::from_secs(5),
//! bind_addr: None,
//! }),
//! )
//! .build(),
//! );
//! let server = ServerBuilder::new(resolver)
//! .udp_addr("127.0.0.1:5353".parse().unwrap())
//! .bind()
//! .await?;
//! server.serve().await?;
//! # Ok(())
//! # }
//! ```
//!
//! # Fake IP
//!
//! [`fakeip::FakeIpPool`] and [`fakeip::FakeIpPolicy`] are opt-in through
//! [`engine::ResolverBuilder::fake_ip`]. Matching IN A/AAAA and canonical,
//! in-range IN PTR questions receive local synthetic answers that bypass the
//! ordinary cache and upstreams. The emitted DNS TTL never exceeds the
//! mapping's remaining lifetime; pools remain caller-owned and have no
//! durable persistence built in.
//!
//! # Dynamic routing hooks
//!
//! [`hooks::RouteHook`] is an opt-in, selection-only extension point for an
//! ordinary query. The resolver first obtains the static split-DNS candidate,
//! then invokes one configured hook, validates the resulting group, looks in
//! that group's cache scope, and finally tries that group's upstreams in
//! order. A local Fake IP answer is terminal before this sequence.
//!
//! This in-process example installs a hook and an in-process backend; it
//! opens no socket. Add `async-trait` to an application's dependencies when
//! implementing [`hooks::RouteHook`].
//!
//! ```no_run
//! use async_trait::async_trait;
//! use dns_lattice::{
//! core::Result,
//! engine::Resolver,
//! hooks::{RouteDecision, RouteHook, RouteHookError, RouteRequest},
//! model::{Message, SplitDnsPolicy, UpstreamGroupId},
//! upstream::UpstreamBackend,
//! };
//!
//! struct PreferFiltered;
//!
//! #[async_trait]
//! impl RouteHook for PreferFiltered {
//! async fn select(
//! &self,
//! request: RouteRequest<'_>,
//! ) -> std::result::Result<RouteDecision, RouteHookError> {
//! let _question = request.question();
//! let _static_candidate = request.static_group();
//! Ok(RouteDecision::Use(UpstreamGroupId::new("filtered")))
//! }
//! }
//!
//! struct InProcessBackend;
//!
//! #[async_trait]
//! impl UpstreamBackend for InProcessBackend {
//! async fn resolve(&self, query: &Message) -> Result<Message> {
//! Ok(query.clone())
//! }
//! }
//!
//! let resolver = Resolver::builder(SplitDnsPolicy::builder().build())
//! .backend(UpstreamGroupId::new("filtered"), InProcessBackend)
//! .route_hook(PreferFiltered)
//! .build();
//! # let _ = resolver;
//! ```
//!
//! A hook error, an unknown selected group, or an empty selected group is a
//! resolver error: it never falls back to static routing, touches the cache,
//! or calls an upstream. Cache entries are scoped by the validated effective
//! group, so equal DNS questions selected to different groups cannot share an
//! answer. The hook implementation owns timeout, retry, and cancellation
//! cleanup; dropping [`engine::Resolver::resolve`] drops its in-flight hook
//! future. A hook must not re-enter the same resolver directly or indirectly.
//! Hooks receive neither resolver/backend handles nor client metadata, and
//! DNS Lattice gives them no OS or networking side-effect capability; a host
//! application composes such work outside this crate.
//!
//! # Transport features
//!
//! UDP and TCP are available without Cargo features. The default-off `dot`,
//! `doh`, and `doq` features respectively add DNS-over-TLS,
//! DNS-over-HTTPS (including HTTP/3 over QUIC), and DNS-over-QUIC. `doh`
//! therefore includes HTTP/3/QUIC dependencies; `doq` remains an independent
//! feature for DNS-over-QUIC without the HTTP stack.
//!
//! # Canonical module imports
//!
//! ```
//! use dns_lattice::model::{DomainPattern, Name, SplitDnsPolicy, UpstreamGroupId};
//!
//! let policy = SplitDnsPolicy::builder()
//! .rule(
//! DomainPattern::suffix(Name::from_ascii("corp.internal").unwrap()),
//! UpstreamGroupId::new("corp"),
//! )
//! .build();
//!
//! let name = Name::from_ascii("host.corp.internal").unwrap();
//! assert_eq!(policy.resolve_group(&name), Some(&UpstreamGroupId::new("corp")));
//! ```
//!
//! # Facade design
//!
//! The canonical imports are domain-scoped: [`model`] for message, matcher,
//! and policy types; [`engine`] for query orchestration; [`upstream`] for
//! outbound transports; [`server`] for inbound listeners; and [`fakeip`] for
//! synthetic-address pools, policies, and snapshots. `Error` and `Result` are
//! shared across those domains. [`engine::ResolverBuilder::fake_ip`] explicitly
//! connects a pool and policy to local Fake IP DNS synthesis.
//!
//! There are no flat root aliases. Use the domain-scoped module paths above,
//! which make ownership and responsibility explicit.
//!
//! Each legacy root import is intentionally rejected. These compile-fail
//! examples are checked in every supported feature documentation build; the
//! encrypted transport checks therefore also run with all transport features.
//!
//! ```compile_fail
//! use dns_lattice::Error;
//! ```
//! ```compile_fail
//! use dns_lattice::Result;
//! ```
//! ```compile_fail
//! use dns_lattice::Name;
//! ```
//! ```compile_fail
//! use dns_lattice::Class;
//! ```
//! ```compile_fail
//! use dns_lattice::Message;
//! ```
//! ```compile_fail
//! use dns_lattice::Header;
//! ```
//! ```compile_fail
//! use dns_lattice::Question;
//! ```
//! ```compile_fail
//! use dns_lattice::RData;
//! ```
//! ```compile_fail
//! use dns_lattice::ResourceRecord;
//! ```
//! ```compile_fail
//! use dns_lattice::RecordType;
//! ```
//! ```compile_fail
//! use dns_lattice::Rcode;
//! ```
//! ```compile_fail
//! use dns_lattice::Opcode;
//! ```
//! ```compile_fail
//! use dns_lattice::DomainMatcher;
//! ```
//! ```compile_fail
//! use dns_lattice::DomainPattern;
//! ```
//! ```compile_fail
//! use dns_lattice::SplitDnsPolicy;
//! ```
//! ```compile_fail
//! use dns_lattice::SplitDnsPolicyBuilder;
//! ```
//! ```compile_fail
//! use dns_lattice::UpstreamGroupId;
//! ```
//! ```compile_fail
//! use dns_lattice::Resolver;
//! ```
//! ```compile_fail
//! use dns_lattice::ResolverBuilder;
//! ```
//! ```compile_fail
//! use dns_lattice::FakeIpPool;
//! ```
//! ```compile_fail
//! use dns_lattice::FakeIpPoolBuilder;
//! ```
//! ```compile_fail
//! use dns_lattice::FakeIpPoolSnapshot;
//! ```
//! ```compile_fail
//! use dns_lattice::FakeIpPolicy;
//! ```
//! ```compile_fail
//! use dns_lattice::FakeIpPolicyBuilder;
//! ```
//! ```compile_fail
//! use dns_lattice::FakeIpMappingSnapshot;
//! ```
//! ```compile_fail
//! use dns_lattice::Server;
//! ```
//! ```compile_fail
//! use dns_lattice::ServerBuilder;
//! ```
//! ```compile_fail
//! use dns_lattice::UpstreamBackend;
//! ```
//! ```compile_fail
//! use dns_lattice::UdpBackend;
//! ```
//! ```compile_fail
//! use dns_lattice::UdpBackendConfig;
//! ```
//! ```compile_fail
//! use dns_lattice::TcpBackend;
//! ```
//! ```compile_fail
//! use dns_lattice::TcpBackendConfig;
//! ```
//! ```compile_fail
//! use dns_lattice::DotBackend;
//! ```
//! ```compile_fail
//! use dns_lattice::DotBackendConfig;
//! ```
//! ```compile_fail
//! use dns_lattice::DohBackend;
//! ```
//! ```compile_fail
//! use dns_lattice::DohBackendConfig;
//! ```
//! ```compile_fail
//! use dns_lattice::DohMethod;
//! ```
//! ```compile_fail
//! use dns_lattice::Doh3Backend;
//! ```
//! ```compile_fail
//! use dns_lattice::Doh3BackendConfig;
//! ```
//! ```compile_fail
//! use dns_lattice::DohListenerConfig;
//! ```
//! ```compile_fail
//! use dns_lattice::DoqBackend;
//! ```
//! ```compile_fail
//! use dns_lattice::DoqBackendConfig;
//! ```
/// Shared error and result types.
///
/// This is the canonical facade path for [`dns_lattice_core::Error`] and
/// [`dns_lattice_core::Result`], supplied by `dns-lattice-core`.
/// Caller-supplied dynamic upstream-group selection types.
///
/// This is the canonical facade path for [`hooks::RouteHook`] and its
/// request, decision, and error types. Route hooks are intentionally not
/// re-exported from the crate root.
/// Optional, non-authoritative resolver event sink.
/// DNS message, domain-matching, and split-DNS policy types.
///
/// This is the canonical facade path for types supplied by
/// `dns-lattice-model`; for example, import [`dns_lattice_model::Name`] as
/// `dns_lattice::model::Name`.