How mannava-daasaradhi/tcp-stack works
tcp-stack is a userspace IPv4/TCP stack over Linux TUN, with ICMP and UDP echo plus TCP echo and HTTP server applications. The principal workflow is peer packets entering TUN, main dispatching by IP protocol, TCP maintaining per-connection state and delivering ordered data to an application, then transmitting replies through TUN. TCP’s internal mechanisms include reassembly, sequence arithmetic, RTT estimation, and selectable congestion control. README documents additional TCP lifecycle, recovery, options, and socket capabilities; the excerpts do not expose every internal call, so only documented or sampled wiring is shown.
Main entry points: main.rs Event Loop · tcp.rs TCP Connection · ip.rs IPv4 · icmp.rs ICMP Echo
Components 15
Packet Runtime
- Event Loop
src/main.rs
IP Protocols
- IPv4
src/ip.rs - ICMP Echo
src/icmp.rs - UDP Echo
src/udp.rs - Internet Checksum
src/utils.rs
TCP Core
- TCP Connection
src/tcp.rs - Sequence Arithmetic
src/seq.rs
Reliability Control
- Receive Reassembly
src/reassembly.rs - RTT Estimator
src/rtt.rs - CUBIC Control
src/congestion.rs - BBR Control
src/bbr.rs
Applications
- HTTP Responder
src/http.rs - Socket API
src/socket.rs
Other components
- Network Peers
- Linux TUN
Connections 20
- Network Peers → Linux TUN: send packets
- Linux TUN → Event Loop: receive packets
- Event Loop → Linux TUN: send packets
- Linux TUN → Network Peers: deliver packets
- Event Loop → IPv4: parse IPv4
- Event Loop → ICMP Echo: dispatch ICMP
- Event Loop → UDP Echo: dispatch UDP
- Event Loop → TCP Connection: dispatch TCP
- ICMP Echo → IPv4: update header
- ICMP Echo → Internet Checksum: compute checksum
- UDP Echo → IPv4: update header
- UDP Echo → Internet Checksum: compute checksum
- IPv4 → Internet Checksum: compute checksum
- TCP Connection → Sequence Arithmetic: compare sequences
- TCP Connection → Receive Reassembly: reassemble data
- TCP Connection → RTT Estimator: sample RTT
- TCP Connection → CUBIC Control: update control
- TCP Connection → BBR Control: update control
- Event Loop → HTTP Responder: parse and respond
- Socket API → TCP Connection: drive connections