Skip to content

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 ​

KeyModuleValue
logthe kernel (own)LogOptions, kind Log
reload, runtime, routethe kernel (own)ReloadOptions, RuntimeOptions, RouteOptions
adminthe Admin API (app/ui)AdminOptions
certificatetlsCertificateOptions, kind Certificate
ntpntpNTPOptions, kind Ntp
network_namespacesdialVec<NetworkNamespace>, each(NetworkNamespace)
http_clientsrouterVec<HTTPClient>, each(HttpClient)
cachecacheCacheFileOptions, kind Cache
dnsdnsDNSOptions with parts, gives, written
adblockadblockOptions, hot(), kind Other("adblock")
subscriptionssubscriptionsSubscriptions
route.rulesrouterVec<Rule>, kind Route, written
route.default_http_clientroutera 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:

  1. rules together with the DNS hijacking rule and the rule from final are collected into one list and handed to the route.rules section (rules);
  2. rule-sets are decoded (entities);
  3. every remaining key k: if some module of the workspace declares a section route.k (Decoders::knows_section, including ones not built in), it is decoded as the section route.k; otherwise it stays in route;
  4. the rest of route together with final and default_domain_resolver from 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, each or 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).

GPL-3.0-or-later