Skip to content

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):

KeyWho reads it
versionthe loader: taken out before anything else (version::migrate)
log, reload, runtimethe kernel (own)
ntp, certificate, network_namespaces, http_clients, cache, dns, adblock, subscriptionsthe section's module (Provide::Section)
adminthe Admin API (app/ui)
inbounds, outbounds, endpoints, groupsthe loader: per entity, blocks — to modules
rule_setsthe loader: name and source, the body — to a module (Provide::RuleSet)
routethe 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/outbounds link: the blocks of Decoded::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:

KeyTypeSpecifics
the log sectionLogOptions
the reload sectionReloadOptionsthe default reload policy
the route sectionRouteOptionsfinal, 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)ReloadPolicyDecoded::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.defaults replaces them (YAML).
  • Reading sing-box JSON as a configuration: libs/json is the format of the tree and of the canonical form, and ours_codec::section/entities are test helpers.

GPL-3.0-or-later