English
Sections
Code: crates/api/src/config.rs (Decoders::decode_section, SectionDecoder), crates/native-config/src/entity.rs (section), crates/native-config/src/rules.rs.
A section is a top-level value (or a route subkey) that wholly belongs to one module. The module declares it like this:
rust
Provide::Section { key: "ntp", kind: Some(ComponentKind::Ntp), decode: section }
// SectionDecoder = fn(node: &Node, scope: &dyn Scope) -> Result<Decoded>The loader hands the decoder the section's node as written (with spans) and a Scope — access to the configuration's names. The result is put into Config::sections under the section's key; the module later takes its value back by the key: a unit — Build::section::<T>(key), a factory — sections.get::<T>(key).
Who owns which section
| Key | Module | Value |
|---|---|---|
log | the kernel (own) | LogOptions, kind Log |
reload, runtime, route | the kernel (own) | ReloadOptions, RuntimeOptions, RouteOptions |
admin | the Admin API (app/ui) | AdminOptions |
certificate | tls | CertificateOptions, kind Certificate |
ntp | ntp | NTPOptions, kind Ntp |
network_namespaces | dial | Vec<NetworkNamespace>, each(NetworkNamespace) |
http_clients | router | Vec<HTTPClient>, each(HttpClient) |
cache | cache | CacheFileOptions, kind Cache |
dns | dns | DNSOptions with parts, gives, written |
adblock | adblock | Options, hot(), kind Other("adblock") |
subscriptions | subscriptions | Subscriptions |
route.rules | router | Vec<Rule>, kind Route, written |
route.default_http_client | router | a name, defaults: [HttpClient] |
Maps by name (network_namespaces, http_clients) turn into lists with tag via the helper ours_config::tagged: the key becomes tag, an explicit tag is an error.
route subkeys
rules::route parses route like this:
rulestogether with the DNS hijacking rule and the rule fromfinalare collected into one list and handed to theroute.rulessection (rules);- rule-sets are decoded (entities);
- every remaining key
k: if some module of the workspace declares a sectionroute.k(Decoders::knows_section, including ones not built in), it is decoded as the sectionroute.k; otherwise it stays inroute; - the rest of
routetogether withfinalanddefault_domain_resolverfrom DNS is decoded by the kernel.
This way a module adds its own key to route without changing either the loader or RouteOptions. Example — the router's route.default_http_client.
"Section not built in"
Besides the build's decoders, Decoders holds the known table: (point, key, module) of all modules of the workspace. It is generated by app/ours/build.rs from the MODULE constants in the sources and passed to the kernel (Modules::with_known). When a key is not among the decoders:
- the key is in
known→"`dns` is not built in (feature `dns`)"; - the key is not there →
"unknown `x`".
The same rule applies to entity types, block variants, rule-set sources and rule conditions (Decoders::left_out, Scope::left_out). Points in detail — in the contract.
What a section can return besides the value
A section's Decoded carries more than an entity block:
parts— the components the section is split into for reload (whole,eachor by hand, like DNS: per server plus the DNS router);defaults— which components the section makes the default of their kind (route.default_http_client);gives— blocks the section gives to entities or to another section (only DNS);written— the spans of list elements, for rule positions.
In detail — types, how reload uses them — canonical form.
Order and visibility
Sections are decoded in the fixed loading order. A section does not see other sections, only the Scope: the names of outbounds and groups, rule-set names, point extensions. Links between sections go through Given (DNS → route) and through Part::reads (a DNS server reads route.dhcp_lease_files for its fingerprint).