Skip to content

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 ​

  1. build(config, previous = self) — everything new is built next to the running one, opening nothing. An error — exit.
  2. The new rule-sets start and become up to date; a new DNS (!Arc::ptr_eq) — start.
  3. 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_identity and the same udp_listener_fragmentation (replaced_by; an inbound without an address reports no identity, and there is nothing to hand over);
    • closed — the rest.
  4. closed are closed right away and release their Handover — their addresses are free before the successors start.
  5. 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.
  6. replaced are closed.
  7. The units' Stage::commit — after the inbounds: the service being replaced works until its successor has started.
  8. attach_services, DnsCell::set, dispatcher.reload(routing) → (closed, kept).
  9. 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.
  10. start only of the new outbounds (the kept ones are already running), close of the old ones that are not in the new configuration.
  11. hot_changed of the reused inbounds with changed blocks; closing the old rule-sets; replacing the state of the Instance.

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

  1. reload from the route-options of the rules the connection passed through;
  2. the outbound's reload block — first the chosen leaf, then the enclosing groups from the inside out;
  3. the inbound's reload block;
  4. the reload.connections section.

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_changed and a different outbound — a packet stream with a live Redirect is moved to the new outbound (Moved in ours-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 — build and DispatchControl::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/DependencyChanged with 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.

GPL-3.0-or-later