Skip to content

dial ​

How outbounds and DNS transports open connections: a single Dialer in which detour, netns, bind addresses, the mark, the interface and the network strategy are handled in one place. Other modules do not name this crate: they lower DialOptions and take a dialer through ours_config::dial and the contract's ours_api::dial::Dialer.

Crateours-mod-dial, modules/system/dial
Binary featurenone, always in the build
Crate featuresnone

requires ​

Nothing — it is the base layer. Almost all outgoing modules require it (direct, socks, shadowsocks, the protocols over TLS/QUIC, dns, ntp, subscriptions): they call the factory it publishes, not its crate.

provides ​

  • Provide::Unit(Namespaces) — during the build (and in ours check) it reads the network_namespaces section, resolves tags into paths and puts Arc<ours_net_sys::netns::Namespaces> into the services (ours_config::dial::namespaces(services) gets them), and publishes the dialers: Factory, the implementation of ours_config::dial::Dialers, through ours_config::dial::publish.
  • Provide::Point("dial") and Provide::Block { block: "dial", key: "outbound" } — an outbound's dial block (block::decode).
  • Provide::Section { key: "network_namespaces" } — the list of namespaces, entities by tag.

User syntax: the dial block, network_namespaces.

Dependencies ​

ours-api, ours-config, ours-net-sys (sockets, netns), ours-bufpool, ours-codec, ours-json.

Design ​

  • src/lib.rs — Dialer (stream, packet, addresses, udp_socket; implements ours_api::dial::Dialer and ours_api::udp::UdpDialer), Factory (ours_config::dial::Dialers: dialer, with_detour), network_namespaces, the constants FALLBACK_DELAY (300 ms, the family race) and TCP_CONNECT_TIMEOUT (5 s).
  • crates/config/src/dial.rs (ours_config::dial, outside the module) — DialOptions (from_abstract, from_options*: like sing-box's NewDefault; netns is checked at build time, not at the first dial), namespaces(services), options(blocks) and RESOLVER, the Dialers trait with publish/dialers, and DialerContext (dialer, dialer_of) for building a component's dialers from the Context.
  • src/block.rs — the dial block: parsing shared with DNS upstreams — ours_config::dial_members: interface and fwmark are sing-box's bind_interface and routing_mark (the sing-box name is the error "bind_interface is interface here"), the blocks interfaces (INTERFACES), bind (DIAL_BIND), the shared tcp (config::tcp, with keep_alive: false | {idle, interval}) and udp (DIAL_UDP) — the same tcp and udp as in an inbound's listener; domain_resolver, domain_strategy and protect_path are rejected, a non-block value is an error. The block the loader adds to an outbound from dns.rules is ours_config::dial::RESOLVER (domain_resolver); ours_config::dial::options(blocks) gives the component's resulting DialerOptions.
  • src/namespace.rs — NetworkNamespace and its variants (default, unshare; unshare is not created by the runtime and is rejected).

Specifics ​

  • detour resolves through ours_api::DialTable (the instance's outbounds by tag). The dialer gets a weak reference during construction. A successful reload replaces the table snapshot. DNS transports can pin one detour with with_detour.
  • ours_api::host::HostCell holds route settings for auto_detect_interface and the network strategy. The kernel updates it for retained outbounds after a successful reload.
  • Addresses: those found by the resolve action or resolved right now through the instance's DNS; the family race — only for those resolved right now.

Tests ​

modules/system/dial/tests/: dial.rs (detour chains, an unknown tag, bind, override), udp_options.rs (peer filtering, connected/domain reply), dial_regressions.rs; unit tests in src/lib.rs, src/block.rs.

GPL-3.0-or-later