English
Document envelope
Code: crates/native-config/src/entity.rs, crates/native-config/src/rules.rs, crates/native-config/src/dns.rs, crates/kernel/src/modules.rs (own).
The envelope is what the loader parses itself without handing it to a module: the shape of the top level, the shape of entities, the names and references all modules rely on. Everything inside blocks is the modules' business.
The top level
The list of keys is fixed in the loader (TOP_LEVEL in entity.rs):
| Key | Who reads it |
|---|---|
version | the loader: taken out before anything else (version::migrate) |
log, reload, runtime | the kernel (own) |
ntp, certificate, network_namespaces, http_clients, cache, dns, adblock, subscriptions | the section's module (Provide::Section) |
admin | the Admin API (app/ui) |
inbounds, outbounds, endpoints, groups | the loader: per entity, blocks — to modules |
rule_sets | the loader: name and source, the body — to a module (Provide::RuleSet) |
route | the loader + modules: route.rules and route.<key> — to modules, the rest — to the kernel |
A module cannot add a new top-level key: it is rejected by root.known as "unknown field". Only the route subkeys are open (see sections). The sing-box experimental is read before that check and only for its old cache_file name (migration).
What the loader knows itself
- The shape of an entity: the name is the key, the type is the only key not in
ENTITY_BLOCKS— entities. - The namespace of outbounds and groups (
Names) — names and references. outbounds.defaults: merged into every outbound before decoding — entities.route.final: mandatory — rules.route: forbidden keys with a hint —rule_set,default_domain_resolver,geoip/geosite.- Rule-set names: known before decoding — entities.
- The
dns→route/outboundslink: the blocks ofDecoded::gives— dns. - Object positions (
Origin) for the dashboard.
What the kernel decodes
ours_kernel::modules::own adds to Decoders the decoders of what belongs to the kernel rather than to a module:
| Key | Type | Specifics |
|---|---|---|
the log section | LogOptions | |
the reload section | ReloadOptions | the default reload policy |
the route section | RouteOptions | final, default_domain_resolver from DNS and everything else that is not rules; default_http_client here is the error "not built in (feature router)" |
the reload block (inbound/outbound) | ReloadPolicy | Decoded::hot(): a change does not rebuild the entity |
The kernel decodes route because the component graph needs final with any set of modules (the default router is "the first outbound"). If there are rules but no router module, the route.rules section gets the "not built in" error.
What is not there
- Merging several files,
include, environment variables. - YAML anchors, aliases, merge keys and tags —
outbounds.defaultsreplaces them (YAML). - Reading sing-box JSON as a configuration:
libs/jsonis the format of the tree and of the canonical form, andours_codec::section/entitiesare test helpers.