Skip to content

tproxy ​

The tproxy inbound: connections and packets that nftables tproxy redirects to it. The original destination is taken from the socket; UDP replies leave from the address the client sent to.

Crateours-mod-tproxy, modules/protocols/tproxy
Binary featuretproxy; auto-nft (= ours-auto-nft + tproxy + router)
Crate featuresnone

requires ​

Nothing: the inbound only accepts, it has no outbound and no TLS.

provides ​

  • Provide::Inbound { key: "tproxy", decode: config::decode } — its own decoder: udp_nat and auto_nft are nested blocks, and auto_nft gets all default values explicitly.
  • Provide::Check(config::check) — a check of the whole configuration at load time: auto_nft — on no more than one inbound; with auto_nft.dns the dns.listen addresses (direct inbounds supplied by the dns module) must be reachable by the redirection; the mark's mask.
  • Provide::Schema { name: "inbounds.tproxy" } — the schema with the udp_nat and auto_nft blocks.

Syntax: tproxy.

Dependencies ​

ours-net-sys (transparent sockets, netns), ours-relay (UdpNat, tproxy), ours-api, ours-codec, ours-json.

Design ​

  • src/lib.rs — TProxyInbound: TCP and/or UDP (network); the UdpNat is shared by the shards (the client's packets may arrive at any socket). The sockets are served by ours_relay::tproxy::{accept, receive}, shared with wireguard: Replies — the reply sockets of one flow, one per remote address it has heard from. An accepted TCP connection is served by the least loaded shard (ours_runtime::balance::spawn_accepted, as for the other TCP inbounds): the reuseport hash often puts several connections opened at once on one shard.
  • src/config.rs — the notation in the native configuration (udp_nat.mapping/filtering/max_flows → udp_mapping/udp_filtering/udp_nat_max; auto_nft, including a mark of the form value/mask), check, schema.
  • src/options.rs — TProxyInboundOptions.

auto_nft ​

The nftables tables themselves, policy routing and the "real" DNS answers are not in the module but in the ours-auto-nft crate and the binary (app/ours/src/auto_nft.rs); what to capture is decided by the analysis of router's rules (modules/routing/router/src/bypass.rs). That is why auto-nft pulls in router.

Limitations ​

detour and listening in a netns are rejected at build time.

Tests ​

Unit tests in src/config.rs; behaviour on the bench — tests/e2e/.

GPL-3.0-or-later