English
Reload
Instance::reload (crates/kernel/src/instance.rs) and the dispatcher's DispatchControl::reload (modules/system/dispatch/src/lib.rs). It is triggered by: SIGHUP, file changes with --watch, subscription updates and the Admin API (app/ours/src/main.rs). An error at any step leaves the running configuration in place.
What is rebuilt
The plan between the graphs of the old and the new configuration. Components from plan.unchanged (outbounds, rule-sets, route rules, inbounds) are reused as objects; everything else is built anew. The DNS factory and the units decide by the plan themselves.
A change only to the "hot" parts of blocks (what the module's decoder left out of cold, for example the inbound's users; the whole reload block) does not change the fingerprint: the inbound stays, the kernel calls validate_hot(blocks) during the build and hot_changed(blocks) after routing is switched. This affects only new connections.
The DNS factory returns the previous DNS as is if the plan has no changes to any dns-server or dns (modules/dns/dns/src/module.rs, unchanged): the servers, the cache, the reverse-mapping table and the rule mode stay the same object. attach_services is called for it too — this is how it gets new services, for example the adblock filter.
Sections can declare their own component kinds for the plan. For example, an adblock edit appears as an update to the adblock component, and the unit applies it on commit by replacing the filter through ArcSwap. Sections that declare no components are applied by their units on commit.
Sequence
build(config, previous = self)— everything new is built next to the running one, opening nothing. An error — exit.- The new rule-sets start and become up to date; a new DNS (
!Arc::ptr_eq) —start. - The inbounds that are not among the reused ones ("retired") are split into:
- replaced — the new inbound has the same id and type, reports the same
socket_identityand the sameudp_listener_fragmentation(replaced_by; an inbound without an address reports no identity, and there is nothing to hand over); - closed — the rest.
- replaced — the new inbound has the same id and type, reports the same
- closed are closed right away and release their
Handover— their addresses are free before the successors start. - The new inbounds start on every shard; the replacing ones — with
owned = false, and they take the sockets of replaced (Runtime). On an error: what was opened is closed, closed are opened again, the new rule-sets are closed, routing does not change. - replaced are closed.
- The units'
Stage::commit— after the inbounds: the service being replaced works until its successor has started. attach_services,DnsCell::set,dispatcher.reload(routing)→(closed, kept).DialTable::set— the detour table switches together with routing, not earlier: a detour must not resolve to an outbound that is not routed yet or has not been started.startonly of the new outbounds (the kept ones are already running),closeof the old ones that are not in the new configuration.hot_changedof the reused inbounds with changed blocks; closing the old rule-sets; replacing the state of theInstance.
Reloaded { plan, closed, kept } is returned.
Live connections: policies
ReloadPolicy (crates/api/src/options.rs; the reload section is in crates/config/src/options/reload.rs): reroute_changed (the default), keep, close. The sources by priority (Policies::resolve, crates/api/src/dispatch.rs):
reloadfrom theroute-optionsof the rules the connection passed through;- the outbound's
reloadblock — first the chosen leaf, then the enclosing groups from the inside out; - the inbound's
reloadblock; - the
reload.connectionssection.
Dispatcher::reconsider, for every routed connection, walks the rules of the new Routing again on the saved metadata (ours_route_api::walk::walk — without sniffing, with what was sniffed the first time) and compares the new leaf with the current one by Arc::ptr_eq (a reused outbound is the same object):
keep— stays, even if the outbound is no longer in the configuration;close— is closed;reroute_changedand a different outbound — a packet stream with a liveRedirectis moved to the new outbound (Movedinours-relay), a TCP stream is closed.
Updating a rule-set in place (rule_set_updated) is a small reload: only the connections whose rules before the deciding one look at this rule-set are reconsidered; the dispatcher increments generation and wakes rule_sets_changed (on which the binary resynchronizes auto_nft).
Without applying
Instance::preview_reload—buildandDispatchControl::preview: how many connections will be closed, kept, moved, with examples. New rule-sets, DNS and probes are not started — the estimate is preliminary. Used by the Admin API.ours check -c running.yaml --diff next.yaml(app/ours/src/diff.rs) — builds both graphs, prints the plan (Added/Removed/Updated/DependencyChangedwith reasons, or "no components change") and changes to the configured group selection. The running process is not queried: the manual selection from the cache and probe results are not taken into account.