Skip to content

ImanSeyed/tcp-tun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TCP Stack Implementation

A userspace TCP/IPv4 stack implementation using TUN interfaces for educational purposes.

Features

Implemented

  • 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.)

Planned

  • Retransmission and timeout handling
  • TCP window management and flow control
  • Out-of-order packet buffering
  • Congestion control algorithms

Architecture

 ┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
 │   Application   │<──>│   TCP Stack      │<──>│  TUN Interface  │
 │   (netcat, etc) │    │                  │    │                 │
 └─────────────────┘    └──────────────────┘    └─────────────────┘
                               │
                       ┌───────v───────┐
                       │ Connection    │
                       │ Hash Table    │
                       └───────────────┘

Quick Start

# 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

Limitations

WARNING: This is an educational implementation. Do not use in production or as your primary network stack.

Standards Compliance

Implementation follows these RFCs:

  • RFC 791 Internet Protocol (IPv4)
  • RFC 793 Transmission Control Protocol (TCP)
  • RFC 1071 Computing the Internet Checksum
  • RFC 7414 A Roadmap for TCP Implementation

About

A TCP implementation over a tun device

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages