qqt

The four doors

One server, four doors

Forward, SOCKS, interface and WireGuard: what a client mode changes locally, what it needs from the box, and the shapes the interface can take on either end.

|hadron|: QQT-009 every client mode is a local door onto one invariant far side: a QUIC connection, mutually authenticated, carrying one bidirectional stream per flow, whose header names the dial target. A mode changes what the local box presents to its own OS and nothing else. The server learns a new door only when the door needs the server to do something it does not already do.

This document is the design home for the multi-door release. Protocol specifics stay in architecture_qqt-protocol.md; the honest gaps stay in architecture_qqt-limitations.md. Where this document and the code disagree, the code wins and this document is the bug.

Why the doors exist

The tunnel’s real constraint is a box that cannot own a network interface: a container on a GPU rental with no CAP_NET_ADMIN, no /dev/net/tun, and seccomp blocking unshare -U. That box can only dial and be dialed. Every design decision below follows from serving it without asking its operator for privileges it cannot get.

The second constraint is that the operator’s existing habits are ssh-shaped. A host list already written for ssh should name the boxes qqt dials.

The mode table

A mode is named for what the local box is given.

Mode Local door Needs Far side
forward TCP ports: -l, -R nothing a qqt server
socks a SOCKS5 proxy nothing a qqt server
interface a TUN or TAP device: a prefix routed in CAP_NET_ADMIN a qqt server
wireguard a WireGuard peer identity nothing stock WireGuard, or a qqt server

Forwarding is the shipped default and stays a contract: qqt client -l … -r … parses and behaves identically with every other mode present, and no new flag is ever required to reach it.

The server is universal: one qqt server process serves all four doors at once, from one cert set, on one UDP port (plus the WireGuard port). A client picks its door.

The four shapes

The mode table says what a client can be. The shapes say where the interface lives. They matter because they decide whether a capability is needed on one end or both.

Shape Interface on Far side Why it exists
A — asymmetric our side only plain forwarder the constrained box; the product
B — symmetric both sides qqt both ends, both privileged becomes a real routed link
C — reversed far side only the far side holds the caps the mirror of A

Shape A is the one that fixes the constraint. B falls out of A once the address plan is real on both ends. C is -R mirrored.

The netstack is the whole cost, and it is paid once

Every interface-and-WireGuard cell terminates IP locally. That means one userspace TCP/IP stack, driven by whichever packet source is in play and carried out by whichever transport is in play:

Packet source Carrier out Caps needed
TUN device qqt streams yes
WireGuard UDP qqt streams no
TUN device WireGuard UDP yes
WireGuard UDP WireGuard UDP no

So the work splits as netstack and adapters — never as “two features”. A netstack that can dial a host:port works against the existing forwarder unchanged; one that can emit IP works against a stock WireGuard peer. The far end is a plug.

Stream contract (unchanged by every door)

A flow is one bidirectional QUIC stream. Its first byte is a frame type:

  • data frame — carries host and port; the RECEIVING side dials them. This is why the interface door’s far side needs no idea that a network exists: it receives “dial this target” exactly as a forward does.
  • control frame (client-opened only) — a -R registration the server answers with bind status.

write_dial_header is the single place a stream is opened with a target header; both today’s forwarding paths call it. Every new door must go through it, or the far side grows a second dialect.

Addressing plan (interface mode)

Three roles, three addresses, never collapsed:

--tun-local  100.64.0.1/32    the interface's own address
--tun-door   100.64.0.2/32    a synthetic address routed into the tun; ICMP
                              echo is reflected over the tunnel, which is the
                              tunnel's honest liveness proof
--tun-route  100.64.0.0/24    destinations passed through verbatim

The default prefix is CGNAT 100.64.0.0/10 (or a ULA for IPv6), never 10.x, which collides with real infrastructure often enough to be a support ticket. A prefix that already has a route on a non-tun interface is refused unless --tun-force says otherwise.

The door is a separate address rather than “.2 is the box” because in shape A the box has no address in the prefix; pretending it does breaks the moment a far-side host really owns that address.

Sequence

The order is forced by the netstack’s testability, not by marketing.

  1. Netstack, driven by a TUN, against today’s forwarder. Shape A. It is the only shape that fixes the real constraint, and every other cell reuses it. Until it exists, WireGuard mode has no harness.
  2. -R into the interface. Cheap once the stack exists, and the only inbound path in shape A.
  3. SOCKS5. Independent of the netstack — it is a local door onto the existing dial header — so it can land in parallel with anything else.
  4. WireGuard peer mode (qqt as a WG peer, no caps). Reuses the netstack, which by now has a test harness.
  5. The universal server’s WireGuard door — admitting a stock WG client.
  6. Shape B — verify, do not design.

Invariants a new door must not break

  • One read, two renderings. Every stat the tunnel reports comes from one Metrics::snapshot; a new counter source is a contract break with no test to catch it. Interface counters are another renderer, never a second source.
  • The role string is load-bearing. The stats line and the Prometheus renderer branch on the role. A new role name that nobody taught the renderer prints the wrong family of counters, silently.
  • The -R allow-list is the client’s authority boundary. A server-written reverse target is dialled only if the operator named it. Interface shape B widens this to “any address in the prefix” — a real widening that belongs in the limitations list in the same change.
  • Teardown is a Drop guard, not a code path. A route added over the platform’s route table must be removed on every exit, or the box keeps a route into a dead interface — the one orphaned state a user cannot diagnose.
  • The stream budget is a flow-table ceiling. Exhausting it parks the opener rather than failing it. A door that opens a stream per flow must choose an explicit overflow policy and count it.
  • Privileges are dropped after setup. Open the device, configure it, then drop what can be dropped.

The ssh-shaped host list

qqt reads an ssh_config-shaped file for the boxes it dials out to. Host, HostName, Port, Match, and Include are honoured with ssh’s own semantics — first obtained value wins, file order decides, an Include inside a block is conditional on that block. The default is ~/.ssh/config, overridable with --ssh-config. This is a resolver in front of -r, not a config format of the tunnel’s own: a name that resolves nowhere in the file is still a host name the ordinary way.

The dial path walks the resolution chain on every connect, so a name that changes between two attempts changes the dial with it. The chain’s order, its single-dump invariant, and the module boundaries are rationale_qqt-name-resolution.md’s; the musts are functional_requirements_qqt-ssh-bridge.md §2.

IPv6

Every door carries IPv6. One listener on the wildcard IPv6 address answers both families; a prefix may be IPv4, IPv6, or both; -4/-6 narrow a lookup, a bind, or a dial, never widen one. Two consequences with teeth:

  • Inner IPv6 packets are the stack’s fragmentation problem, and the chosen stack has no IPv6 egress fragmentation. The interface door therefore pre-splits on the v6 path or documents the MTU it requires.
  • A -4-only client and a -6-only client can both reach a dual-stack door. Nothing in the protocol prefers one.

← All documentation