A userspace TCP/IPv4 stack implementation using TUN interfaces for educational purposes.
- IPv4 header processing with checksum validation
- TCP header parsing and generation
- TCP 3-way handshake (SYN, SYN-ACK, ACK)
- Connection establishment and termination
- Dynamic connection hash table with
list_head
collision chains - Proper sequence number arithmetic with wrap-around support
- TUN interface integration for packet I/O
- Basic TCP state machine (LISTEN, SYN-RCVD, ESTABLISHED, FIN-WAIT-1, etc.)
- Retransmission and timeout handling
- TCP window management and flow control
- Out-of-order packet buffering
- Congestion control algorithms
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Application │<──>│ TCP Stack │<──>│ TUN Interface │
│ (netcat, etc) │ │ │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│
┌───────v───────┐
│ Connection │
│ Hash Table │
└───────────────┘
# Build and run with proper network setup
bash secure_run.sh
Currently the server IP address is hard-coded (192.168.20.1
), but client range can be any IP in 192.168.20.2-254
.
# In another terminal, connect using netcat
nc 192.168.20.42 42
WARNING: This is an educational implementation. Do not use in production or as your primary network stack.
Implementation follows these RFCs: