English
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.
| Crate | ours-mod-dial, modules/system/dial |
| Binary feature | none, always in the build |
| Crate features | none |
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 inours check) it reads thenetwork_namespacessection, resolves tags into paths and putsArc<ours_net_sys::netns::Namespaces>into the services (ours_config::dial::namespaces(services)gets them), and publishes the dialers:Factory, the implementation ofours_config::dial::Dialers, throughours_config::dial::publish.Provide::Point("dial")andProvide::Block { block: "dial", key: "outbound" }— an outbound'sdialblock (block::decode).Provide::Section { key: "network_namespaces" }— the list of namespaces, entities bytag.
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; implementsours_api::dial::Dialerandours_api::udp::UdpDialer),Factory(ours_config::dial::Dialers:dialer,with_detour),network_namespaces, the constantsFALLBACK_DELAY(300 ms, the family race) andTCP_CONNECT_TIMEOUT(5 s).crates/config/src/dial.rs(ours_config::dial, outside the module) —DialOptions(from_abstract,from_options*: like sing-box'sNewDefault; netns is checked at build time, not at the first dial),namespaces(services),options(blocks)andRESOLVER, theDialerstrait withpublish/dialers, andDialerContext(dialer,dialer_of) for building a component's dialers from theContext.src/block.rs— thedialblock: parsing shared with DNS upstreams —ours_config::dial_members:interfaceandfwmarkare sing-box'sbind_interfaceandrouting_mark(the sing-box name is the error "bind_interfaceisinterfacehere"), the blocksinterfaces(INTERFACES),bind(DIAL_BIND), the sharedtcp(config::tcp, withkeep_alive: false | {idle, interval}) andudp(DIAL_UDP) — the sametcpandudpas in an inbound'slistener;domain_resolver,domain_strategyandprotect_pathare rejected, a non-block value is an error. The block the loader adds to an outbound fromdns.rulesisours_config::dial::RESOLVER(domain_resolver);ours_config::dial::options(blocks)gives the component's resultingDialerOptions.src/namespace.rs—NetworkNamespaceand its variants (default,unshare;unshareis not created by the runtime and is rejected).
Specifics
detourresolves throughours_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 withwith_detour.ours_api::host::HostCellholds route settings forauto_detect_interfaceand the network strategy. The kernel updates it for retained outbounds after a successful reload.- Addresses: those found by the
resolveaction 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.