Code Monkey home page Code Monkey logo

network-stack's Introduction

Network Stack

Implentation of TCP handshakes from ethernet frames.

The original idea for this project was to implement a simple toy web server as inspired by this, however, things got away from me and it became something much more than just a HTTP server.

The ultimate goal is still to have this stack ping google.com or example.com on port 80 (so no SSL). See To be implemented for a list of things that still need to be implemented for this to happen.

Features

  • Implementation of IEEE 802.3 ethernet frame parsing
  • ARP
  • IPv4
  • ICMP
  • TCP SYN-SYN/ACK handshake

Setup

Setup virtual network interface:

Setup a Linux TAP device to access L2 data. Bring up the TAP device like so:

# largely taken from this post: https://stackoverflow.com/questions/1003684/how-to-interface-with-the-linux-tun-driver

ip addr show # my eth0 inet address is 10.0.2.15/24 as Im running on a VirtualBox vm with Ubuntu 18.04 guest
sudo ip tuntap add mode tap dev tun0 # make sure the mode is tap and not tun!
sudo ip addr add 10.0.3.0/24 dev tun0  # give it an address (that does not conflict with existing IP)
sudo ip link set dev tun0 up  # bring the if up
ip route get 10.0.3.50  # check that packets to 10.0.3.x are going through tun0
# 10.0.3.50 dev tun0 src 10.0.3.0 uid 1000 
ping 10.0.3.50 # leave this running in another shell to be able to see the effect of the next example, nobody is responding to the ping

C include path:

${workspaceFolder}/**
/usr/include/x86_64-linux-gnu
${workspaceFolder}/include
/usr/include
/usr/lib/gcc/x86_64-linux-gnu/13/include

Compile:

make

The compiled binary is /bin/main

Execution:

Check src/main.c for segmented tests.

Configuring ARPing updates kernel ARP Table

Replace <tuntap IF name> with your IF name (tun0, tap0, etc)

sudo bash -c 'echo 1 > /proc/sys/net/ipv4/conf/<tuntap IF name>/arp_accept'

See: https://www.spinics.net/lists/netdev/msg314093.html & https://askubuntu.com/questions/783017/bash-proc-sys-net-ipv4-ip-forward-permission-denied

Debugging

tcpdump -i <tun/tap name> <specify protocol, leave empty for everything> -v

With the above running, go to another terminal and run your command.

To be implemented

  • Full TCP RFC
  • Sockets API
  • Some sort of HTTP client (ex: a simple curl like tool that can send GET requests) - currently not planning to implement POST and the other HTTP requests.

References

network-stack's People

Contributors

jimfangx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.