Files
RedBear-OS/netstack
Red Bear OS b27515d583 conntrack: full TCP state machine (RST, FIN, TimeWait, Close)
Complete TCP connection tracking state machine:

NEW TRANSITIONS (mirrors Linux nf_conntrack_proto_tcp.c):
- RST from either direction → Close (10s timeout, ConnState::New)
- Established + FIN (either dir) → FinWait (120s timeout)
- FinWait + FIN (other dir) → TimeWait (120s timeout)
- TimeWait extends timeout on any traffic (125s idle for safe
  delayed-ACK arrival)

PRESERVED TRANSITIONS (from original code):
- None → SynSent (on original SYN) — unchanged
- SynSent → SynRecv (on reply SYN-ACK) — unchanged
- SynRecv → Established (on reply ACK) — unchanged

NEW HELPERS:
- tcp_flags(): extract TCP flags byte from packet
- is_fin(): check FIN bit
- is_rst(): check RST bit

NEW TESTS:
- rst_forces_state_to_new: RST resets conn state to New
  (entry stays 10s for lingering cleanup)
- fin_transitions_established_to_timewait: double-FIN
  transition through FinWait → TimeWait

FIXED BUGS:
- advance_entry_state never processed FIN/RST/TimeWait, so
  connections stayed Established for 5 days after actual close.
  Now: FinWait after FIN, TimeWait after both FINs, Close on RST.

All 31 tests pass.
2026-07-09 01:15:52 +03:00
..