English
Sections, sources, checks
Provide::Section, Provide::Source, Provide::Check, Provide::RuleSet — crates/api/src/module.rs; the function types — crates/api/src/config.rs. How the loader applies them — Sections, Entities, Subscriptions; here — what a module undertakes to provide.
Section — its own top-level section
rust
Provide::Section { key: &'static str, kind: Option<ComponentKind>, decode: SectionDecoder }
type SectionDecoder = fn(node: &Node, scope: &dyn Scope) -> Result<Decoded>;The module decodes the section into its own type itself; the result lies in Config::sections under the same key, and the module's unit or factory takes it back (Build::section::<T>(key), Blocks::get::<T>(key)). kind is the component the whole section is, if it is one: Decoders::decode_section adds it to the decoded value as whole(kind). A section of several components (http_clients, dns) gives None and names them in its parts.
Scope gives the decoder knowledge of the rest of the configuration: entity kinds and names, references, selection by pattern, rule-sets, point extensions, warnings.
A key may be a "path" inside a kernel section: router owns route.rules and route.default_http_client, while the rest of route is decoded by the kernel.
Besides the value, a section's Decoded carries: parts — components for the reload graph (Graph); defaults — which components become the "defaults"; gives — blocks the section gives to entities; written — where each list element is written; cold — the part that changes the fingerprint.
| Key | Module |
|---|---|
log, reload, runtime, route | the kernel (own() in crates/kernel/src/modules.rs) |
admin | the Admin API (ui::MODULE in app/ui/src/lib.rs) |
certificate | tls |
cache | cache |
network_namespaces | dial |
ntp | ntp |
http_clients, route.rules, route.default_http_client | router |
dns | dns |
adblock | adblock |
subscriptions | subscriptions |
A section that nobody in the build reads is the error "key is not built in (feature m)" or "unknown key" (Decoders::decode_section).
Source — entities that are not in the text
rust
Provide::Source { section: &'static str, expand: Expand }
type Expand = fn(node: &Node, scope: &dyn Scope, held: Option<&(dyn Any + Send + Sync)>) -> Result<Expanded>;A section "stands behind" inbounds, outbounds or leading route rules that the module adds next to the written ones (Entity { section, name, node, namespace }). The entity is given in native YAML form and is read the same way as a written one. Currently:
dns— inbounds fordns.listen;subscriptions— outbounds of subscription servers, in their own namespace (namespace): such names come and go, and only groups may refer to them.
held — where to read from instead of the module's internal state (a dashboard draft, a test): Decoders::with_held(section, value). Scope::accepts(entity) lets a source drop what will not load.
Check — requirements on the rest of the configuration
rust
Provide::Check(fn(view: &dyn View) -> Result<(), Located>)Runs after everything has been decoded. View shows the inbounds and outbounds of other modules only through their decoded Blocks (Seen) and places in the text (written). Located is a message and spans (first — the earlier of two incompatible places). The first finding stops the check. Currently there are two: tproxy (auto_nft on only one inbound, DNS listens where the redirection leads, no outbound marks sockets with the auto_nft bits) and tun (auto_redirect on only one inbound, not together with auto_nft, no outbound marks its sockets).
RuleSet — a rule-set source
rust
Provide::RuleSet { key: "remote" | "file" | "inline", decode: SectionDecoder }Decodes the definition of a rule-set with the given source; the rule-set is built by the RuleSets factory of the same module (Rules and rule-sets). All three are provided by router; a missing source — "rule-set source x is not built in" or "unknown rule-set source".