Commit Graph
669 Commits
Author SHA1 Message Date
Nils Andreas Svee ca2c3dcbd8 fix(server): reject unusable timestamp sessions 2026-08-12 17:21:23 +07:00
Nils Andreas Svee 68ed5c6e2e fix(proto): floor negative echo lengths 2026-08-12 17:16:03 +07:00
Nils Andreas Svee 2e2db4d3e0 Merge pull request #76 from Lochnair/docs/server-deep-dive-airlock
docs(protocol): airlock server black-box findings
2026-08-12 16:40:57 +07:00
Nils Andreas Svee 58472dbf7b docs(protocol): airlock server black-box findings
Transfer independently black-box-verified server behavior from a source-assisted
research phase conducted outside this repository. Only a sanitizer-candidate
report of black-box findings and the packet captures it referenced were admitted;
no upstream source, tests, history, harnesses, build trees, result files or
source-assisted analysis crossed the boundary. Provenance and the boundary
discipline are recorded in docs/clean-room/CLEANROOM_NOTES.md.

New upstream robustness defect (Section 22.5). An open selecting timestamps while
omitting the Clock parameter is accepted with a valid token and no Clock echoed,
and the first echo on that session is fatal to the server process, taking
unrelated sessions on the same process with it. An explicit Clock=0 is instead
rejected at open, so parameter presence is externally meaningful. Recorded as an
observed defect with a must-not-crash recommendation; the clean server's
resolution is deliberately left to the implementation work.

Also established or strengthened:

- the idle grace and maximum-duration grace are fixed additive margins across the
  settings swept, and the maximum-duration clock starts at the first echo that is
  actually served;
- a rate-limited request is the only tested drop class that keeps a session
  alive, and in one documented configuration a conforming client can observe the
  difference;
- a post-deadline packet of several tested classes consumes an expired session's
  one remaining reply, including packets that are themselves dropped;
- the reply-length cap is the bind interface's MTU on the interfaces where it was
  reachable, and a length the host cannot transmit ends the process;
- DSCP marking follows the session, with unmarked open replies and no
  cross-session leakage across interleaved sessions;
- repeated tags are last-valid-wins, with invalid-duplicate handling scoped to
  the orders actually tested, and unknown tag values are consumed as varints.

Three captures were admitted, each rewritten to the container convention already
used here and verified byte-identical in packet data and timestamps:
server-clock-absent (3 packets), server-expiry-consumption (14) and
server-dscp-interleaved (32). Two further captures were reviewed and rejected as
redundant or unsupporting; their textual results were kept instead.

Host-specific figures are labelled as such throughout, upstream defects are not
promoted to protocol requirements, observations are separated from inferences and
from recommendations, and no implementation policy is chosen here. The client
specification gains matching refinements where the two compatibility baselines
would otherwise state a lifecycle or marking rule differently.

Documentation and evidence only; no production code changed.
2026-08-12 16:24:57 +07:00
Nils Andreas Svee 035fb5a385 Merge pull request #75 from Lochnair/feat/server-client-close
feat(server): handle client close
2026-08-12 10:55:07 +07:00
Nils Andreas Svee 6c34fd3d20 docs(server): record IPv6 zone identity as project policy
Endpoint identity documented the IPv6 scope identifier as an established
component alongside family, address and port. The server specification does
list the zone, but its remaining-unknowns section records that multi-zone
behavior could not be tested on a single-host platform, so no evidence settles
how a reference server compares scoped addresses. Presenting the choice as
verified compatibility overstated what is known, which the crate's own guidance
forbids.

Say what it is instead: a deliberate policy taken under a recorded unknown. Two
peers reachable at the same link-local address in different zones are genuinely
different peers, so treating the zone as identity is the conservative reading —
the failure it prevents is one peer closing another's session, and the failure
it risks is a scoped client having to reopen. The excluded flow label is
labelled the same way, and `irtt-server` guidance now carries the rule so the
echo slice reuses this comparison rather than inventing a second one.

Behavior is unchanged; this is documentation and a test comment.
2026-08-12 10:48:42 +07:00
Nils Andreas Svee e79ea94318 fix(server): exclude IPv6 flow information from endpoint identity
Session identity is the address family, the IP address, the UDP source port
and — for IPv6 — the scope identifier. `SocketAddrV6` equality additionally
covers the flow label, so comparing endpoints with `==` admitted a field that
identifies no endpoint: a client whose flow label changed mid-session could be
refused its own close and strand the session, which nothing reclaims while
expiry is unimplemented. It bought nothing in exchange, since the token,
address, port and scope are what an off-path attacker would have to guess.

Compare the specified components instead. Scope still counts, and the address
is still stored verbatim, so a later reply goes back to exactly the endpoint
the request came from.

Not reachable through a default socket today: a receiver reports the flow
label only when asked to, and there is no runtime slice yet. It is reachable
through the public core, which takes caller-supplied addresses.
2026-08-12 10:42:11 +07:00
Nils Andreas Svee d269f77c87 feat(server): handle client close
Release the session a client close names. A close is bound to a session only
when the token matches and the datagram arrived from that session's exact
endpoint, so holding a token is not by itself authority to tear the session
down: a close from a foreign source port, address, family or IPv6 scope leaves
the session live, and one close cannot take down a sibling session the same
peer opened separately. A token that is unknown, already closed or zero matches
nothing and leaves the table untouched; zero is reserved for no-test replies and
never issued.

Nothing is sent either way. Protocol version 1 defines no acknowledgement for a
client close, so a successful close returns the same `Ok(None)` as a rejected
one and a delivered close is indistinguishable to the client from a lost one.
A standalone `Reply|Close` datagram is tolerated by clients but has no
demonstrated use, so none is encoded.

Authentication still runs before the session is looked up. That keeps a bad MAC
on a live token indistinguishable from an unknown token, and means a close that
fails authentication — missing, wrongly keyed, corrupted, or unexpected on a
server with no key — cannot remove a session. Trailing bytes after the token
stay acceptable: the structural decoder already tolerates them and the server
does not re-parse the request.

The session table remains the only record of how full the server is, so a close
frees capacity immediately and a refused open can succeed once one is released.
Close draws no token and touches no other state; the endpoint lookup borrows
the table only until the comparison is made, so the removal needs no clone.

Echo remains ignored. The test that pinned close as a no-op is replaced by
`tests/close.rs`, which covers removal, silence, repeated close, echo after
close, endpoint binding, unknown/zero/stale tokens, authentication failure,
trailing bytes, sibling sessions and capacity reuse; `unsupported.rs` keeps
echo and structurally invalid traffic.
2026-08-12 10:30:50 +07:00
Nils Andreas Svee be66a6a61d Merge pull request #74 from Lochnair/feat/server-core-open
feat(server): add open session core
2026-08-12 01:12:41 +07:00
Nils Andreas Svee b7e206f939 refactor(server): keep session state crate-private
`Session` and the token lookup that returns it were public, which published
internal session state before there is a consumer for it. The next slices are
all but certain to add and restructure fields here — receive counts and
windows, sequence tracking, activity and expiry state — and nothing outside
the crate needs a session yet.

Make `Session` and `ServerCore::session` crate-private. `session_count`
stays public: how much session state the server holds against its bound is a
sensible stable observable, unlike the sessions themselves.

The endpoint accessors have no production reader until echo and close
processing arrive, since a session's endpoint has to be captured at open time
and is not recoverable later. They are marked accordingly rather than left to
warn.
2026-08-12 01:10:56 +07:00
Nils Andreas Svee 59f6e88005 feat(server): add open session core
Add `irtt-server` with the deterministic protocol and session engine the
upcoming Tokio runtime will call. `ServerCore::handle_datagram` takes a source
endpoint and the bytes of one datagram and returns the bytes to send back, or
nothing. It performs no I/O and keeps no clock, so every decision is a pure
function of its state and that input apart from drawing session tokens.

Rejection is silence. The protocol defines no error reply, no reset and no
NACK, so malformed, unauthenticated and policy-refused datagrams are discarded
without a response and without disturbing any live session; a client tells
"rejected" from "lost" only by timing out. `ServerError` is reserved for
internal failures on the server's own side, so an inbound `ProtoError` never
surfaces as a server failure.

Open handling authenticates before decoding parameters, so a packet that fails
authentication is discarded without parsing untrusted data and no reply
behavior reveals which stage rejected it. Duration and Interval are accepted
when absent and rejected when explicitly present and not positive, which is
what the presence-aware parameter decode is for. Negotiation currently rewrites
only the protocol version; the restriction knobs the specification describes
are deliberately left for their own slices, with one obvious place to add them.

Sessions are bounded to a finite default. A single unauthenticated datagram
creates one and opens are never deduplicated, so an unbounded table is a
liability rather than a compatibility feature; upstream's absence of session
bounds is explicitly not a target. A full table drops new opens silently and
evicts nothing. No-test opens keep working at capacity because they create no
state.

Session tokens come from the operating system's random source, since a token is
the only thing standing between an off-path attacker and a usable session on an
unauthenticated server. A drawn value that is zero or collides with a live
session is redrawn within a finite budget; there is no predictable fallback,
and a colliding token never overwrites the session that holds it. The reply is
encoded before the session is inserted, so an internal failure cannot leave a
half-created session behind.

Echo and close requests pass admission and are then deliberately ignored: this
slice creates sessions, and lifecycle and receive semantics belong to the
slices that implement them. Tests pin that so a half-implemented lifecycle
cannot appear by accident.
2026-08-12 00:47:46 +07:00
Nils Andreas Svee 93491e7762 refactor(proto): preserve open parameter presence
`Params::decode` seeded `Params::default()` and overwrote only the tags it
saw, so an omitted tag and one explicitly encoded as zero were
indistinguishable afterwards. The protocol gives those the same value but not
the same meaning, and a server cannot apply its open admission rules without
telling them apart: an absent Duration or Interval is accepted as the wire
default zero, while one explicitly encoded as zero is invalid.

Add `Params::decode_with_presence`, returning the decoded values alongside a
`ParamPresence` recording which known tags appeared. `Params::decode` now
delegates to it, so there is still exactly one parser and the two cannot
diverge. Unknown tags stay ignored and untracked, and repeated known tags keep
last-value-wins.

Add `Clock::Unspecified = 0` as the default, which is the wire default for an
absent Clock tag and what an empty parameter payload decodes to. An explicit
Clock tag encoding zero remains an invalid enum value, so `Unspecified` is
only ever reached by omission; `encode` omits the tag for it rather than
emitting an explicit zero. It selects no clock, so `has_wall`/`has_mono` are
false and no timestamp field is laid out.

`ClientConfig::clock` is public and therefore now constructible as
`Unspecified`, which is a wire default rather than a client mode. Reject it
during config validation. The client default stays `Clock::Both`, so normal
client-generated params and wire vectors are unchanged.
2026-08-12 00:23:14 +07:00
Nils Andreas Svee 78e503ffcc Merge pull request #73 from Lochnair/refactor/proto-request-codecs
refactor(proto): unify request codecs
2026-08-11 23:22:41 +07:00
Nils Andreas Svee 5a4272e7fd refactor(proto): unify request codecs
Replace the three per-kind request encoders and decoders with one
directional pair, ahead of introducing irtt-server.

Sender side: encode_request(RequestToEncode, hmac_key) constructs OPEN,
CLOSE and ECHO requests from borrowed values. Params and the ECHO payload
are borrowed rather than owned, removing a Params clone and a payload Vec
from the client's hot paths. Wire output is byte-identical; all captured
vectors still pass unchanged.

Receiver side: decode_request(packet) structurally classifies an inbound
request with no HMAC key, no negotiated Params, no session state and no
allocation. A server must extract a token before it knows which key
applies, so authentication is a separate step. Classification follows the
verified server spec: reserved bits and FLAG_REPLY are rejected, OPEN
takes precedence over CLOSE and over an echo-shaped body, and only the
structural minimums (4/12/16, plus 16 with FLAG_HMAC) are enforced.
Trailing bytes are tolerated, no negotiated length ceiling is applied, and
a zero token is structurally valid. OPEN parameters stay encoded bytes so
an authenticating receiver can verify before decoding untrusted data, and
everything after an ECHO sequence number is exposed as an opaque tail.

Add verify_packet_hmac(key, packet), which locates the standard field
itself and rejects a packet lacking FLAG_HMAC. hmac_present reports packet
layout, never authentication. The offset-based verify_hmac stays public as
the low-level primitive for hand-built and captured wire vectors, matching
the existing compute_hmac pair.

Refactor the private envelope into structural header decoding, codec flag
rules, HMAC presence policy and verification as separate steps. The reply
codecs compose the same steps in the same order, so decode_open_reply and
decode_echo_reply keep their exact error ordering and the client's
fatal-versus-ignore classification is unchanged. Reply decoding stays
state-specific: the client already knows which reply to expect, and the
two need different semantic context.

Migrate the production client and every fake peer to the new API; the
fake peers now admit requests the way a server does, instead of parsing
packets by hand.
2026-08-11 23:22:20 +07:00
Nils Andreas Svee c91e7917f7 Merge remote-tracking branch 'origin/renovate/lock-file-maintenance' 2026-08-11 23:22:03 +07:00
Nils Andreas Svee e380924414 Merge remote-tracking branch 'origin/renovate/tokio-1.x' 2026-08-11 23:22:03 +07:00
Nils Andreas Svee 7ea71f0811 Merge remote-tracking branch 'origin/renovate/nix-0.x' 2026-08-11 23:22:03 +07:00
Nils Andreas Svee db0bc282f3 Merge pull request #72 from Lochnair/audit/recv-window-downstream-loss
docs(stats): clarify server receive-window semantics
2026-08-11 23:22:03 +07:00
Nils Andreas Svee 0977db1fe2 docs(stats): clarify server receive-window semantics
An audit of the server-reported receive window found no defect in the
statistics pipeline: the bitmap is decoded raw, stored raw, never
interpreted, and never feeds the directional loss estimates, which use
the cumulative server receive count.

The public rustdoc was silent on all of that, leaving consumers of
PacketCounts free to read a window of 0x1 as a 63-packet loss burst.
Document the field's contract, name the count as the only server input
to LossStats, and cover the window-only case with a regression test.
2026-08-11 23:21:58 +07:00
renovate[bot] e0332b4360 chore(deps): maintain cargo lockfile 2026-08-11 14:25:00 +00:00
renovate[bot] 86c6422f14 fix(deps): update rust crate tokio to 1.53.1 2026-08-11 14:24:43 +00:00
renovate[bot] 554d197f14 fix(deps): update rust crate nix to 0.31.3 2026-08-11 14:24:34 +00:00
Nils Andreas Svee d5c3e21a05 Merge pull request #68 from Lochnair/fix/dscp-wire-semantics
fix(client): align DSCP wire semantics
2026-08-11 21:09:26 +07:00
Nils Andreas Svee 3d5a8fae14 fix(client): align DSCP wire semantics 2026-08-11 20:29:57 +07:00
Nils Andreas Svee 347af39d74 Merge pull request #67 from Lochnair/docs/server-protocol-airlock
docs(protocol): add sanitized server compatibility research
2026-08-11 18:34:51 +07:00
Nils Andreas Svee e0e8d3870b docs(agents): add server protocol guidance 2026-08-11 18:34:22 +07:00
Nils Andreas Svee 454bbc2378 docs(protocol): add sanitized server compatibility research 2026-08-11 18:25:31 +07:00
Nils Andreas Svee 8a94bc7ca6 Merge pull request #66 from Lochnair/fix/upstream-midpoint-echo-compat
fix(client): accept upstream midpoint echo replies
2026-08-11 17:43:05 +07:00
Nils Andreas Svee 88dd4f2a62 fix(proto): accept upstream midpoint echo replies
Upstream irtt 0.9.1 always emits both midpoint timestamp fields (wall,
then monotonic) in an ECHO reply for single-clock StampAt::Midpoint
negotiations, even though only one clock was negotiated, so its header is
one timestamp longer than the negotiated header.

The resulting datagram length is not simply negotiated_len + 8. Both
forms are max(negotiated_length, header), so the extra field lengthens
the datagram only while the larger header still exceeds the negotiated
length, and displaces payload beyond that; the difference is 8, then
7..1, then 0.

decode_echo_reply now accepts the compatibility length wherever it is
strictly longer than the negotiated length, parsing both wire fields and
exposing only the negotiated clock's value. Where the two lengths
coincide the forms are indistinguishable from the packet alone, so the
reply is accepted with normal negotiated parsing rather than a heuristic
- a monotonic-only midpoint negotiation therefore cannot always be
corrected, which is documented and tested. Every other length stays
strictly rejected.

Echo request decoding and encode_echo_reply are unchanged: the encoder
must keep emitting the sane negotiated layout.
2026-08-11 16:26:29 +07:00
Nils Andreas Svee 3d197c2353 ci: expand test matrix to include musl and aarch64 targets
Consolidate check and test jobs into a matrix strategy to verify compatibility across x86_64 and aarch64 architectures for both glibc and musl toolchains.
2026-08-11 14:23:06 +07:00
Nils Andreas Svee 8472745b42 Merge pull request #65 from Lochnair/fix/ancillary-safe
refactor(client): replace unsafe libc calls with nix for Linux ancillary data
2026-08-11 13:58:22 +07:00
Nils Andreas Svee 373bf32d0f refactor(client): replace unsafe libc calls with nix for Linux ancillary data
Eliminate unsafe code blocks and manual pointer arithmetic in Linux-specific receive paths by utilizing nix for socket options and control message parsing. This improves safety and maintainability while preserving the existing kernel RX timestamp and traffic class functionality.
2026-08-11 13:38:56 +07:00
Nils Andreas Svee 3c6c0e396f Merge pull request #64 from Lochnair/fix/tui-bound-input-drain
fix(tui): bound input event draining
2026-08-11 00:25:03 +07:00
Nils Andreas Svee 8651e93351 fix(tui): bound input event draining
handle_input() previously drained terminal events in an unbounded
while-poll loop, so a continuously-ready input stream could keep the
frontend inside handle_input() indefinitely, starving managed-event
processing, completion checks, peer-close stop policy, and rendering
in the outer run_tui() loop.

Bound each call to at most INPUT_EVENT_WORK_BUDGET (128) polled
terminal events, mirroring the MANAGED_EVENT_WORK_BUDGET pattern
already used for managed event draining. All polled events count
against the budget, including ignored/unknown/release events, so a
stream of non-actionable input can't bypass the bound. Remaining
events are left queued for the next outer-loop iteration rather than
dropped. Quit/Ctrl-C now also breaks out of the drain immediately
after being handled, since there is no benefit to consuming further
buffered input before the outer loop can request managed shutdown.
2026-08-11 00:12:37 +07:00
Nils Andreas Svee 17bbf72c6c Merge pull request #63 from Lochnair/fix/tui-lazy-graph-history
fix(tui): allocate graph history lazily
2026-08-10 23:59:11 +07:00
Nils Andreas Svee 17aeaf0b9b fix(tui): allocate graph history lazily 2026-08-10 23:57:27 +07:00
Nils Andreas Svee 3df71e0b69 fix(cli): account for targets in stats memory warning 2026-08-10 23:35:16 +07:00
Nils Andreas Svee b555451448 test(cli): make integration synchronization deterministic (#61) 2026-08-10 23:21:00 +07:00
Nils Andreas Svee 8924cc531c test(client): use protocol encoders in fake peers 2026-08-10 22:53:36 +07:00
Nils Andreas Svee e5c08997ed test(cli): use protocol encoders in fake peers 2026-08-10 21:55:54 +07:00
Nils Andreas Svee f0f9277469 test: trim redundant coverage 2026-08-10 21:06:49 +07:00
Nils Andreas Svee 186c6eba97 docs: add clean-room docs/specs and agent guidance 2026-08-10 18:54:22 +07:00
renovate[bot] 49826a5b3d fix(deps): update rust crate thiserror to 2.0.20 2026-08-10 11:15:42 +07:00
renovate[bot] d4cef6c2e7 fix(deps): update rust crate clap to 4.6.6 2026-08-10 11:15:26 +07:00
Nils Andreas Svee 8c31f14419 Merge pull request #55 from Lochnair/fix/managed-timeout-budget
fix(managed): bound timeout work per poll
2026-08-10 11:14:52 +07:00
Nils Andreas Svee 301542186a test(cli): bound peer-close synchronization waits 2026-08-10 11:09:00 +07:00
Nils Andreas Svee 04ea4af079 test(cli): synchronize multi-target peer close 2026-08-10 11:00:12 +07:00
Nils Andreas Svee 1f69c04274 test(managed): verify sparse timeout backlog progress 2026-08-10 10:30:36 +07:00
Nils Andreas Svee edb634146c fix(managed): retain timeout backlog fairness 2026-08-10 10:25:10 +07:00
Nils Andreas Svee ab9912b3d5 test(managed): cover timeout backlog scheduling 2026-08-10 02:06:41 +07:00