A Rust toy/demo project leveraging eBPF XDP for high-performance packet routing at the Linux kernel level, specifically at the earliest possible point in the network stack.
The project comprises three main components:
- router_xdp: The core program implementing UDP packet routing with eBPF XDP
- router: A server application that loads the eBPF XDP program into the kernel, manages XDP routing maps, and listens for TCP commands
- routerctl: A client for remotely managing the server over TCP (no TLS currently)
Server (192.168.171.10):
sudo router --iface eth1 --bind 0.0.0.0:6707Client (192.168.171.1):
routerctl 192.168.171.10:6707 set policy drop
routerctl 192.168.171.10:6707 add mirror 12345
nc -u 192.168.171.10 12345Server (192.168.171.10):
sudo router --iface eth1 --bind 0.0.0.0:6707Client-1 (192.168.171.1:1111):
routerctl 192.168.171.10:6707 set policy drop
routerctl 192.168.171.10:6707 add route 192.168.171.1 1111 12345 192.168.171.1 2222 12345
nc -u -p 1111 192.168.171.10 12345Client-2 (192.168.171.1:2222):
nc -u -p 2222 192.168.171.10 12345-
Install:
- nix:
nix-shell - nix+direnv:
direnv allow . - Debian / Ubuntu:
- install rustup:
./asset/install_rustup.sh - prepare rustup:
./asset/prepare_rustup.sh
- install rustup:
- other:
- install rustup: https://www.rust-lang.org/tools/install
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh - prepare rustup:
./asset/prepare_rustup.sh
- install rustup: https://www.rust-lang.org/tools/install
- nix:
-
Build:
./build_debug.sh
-
Run server, load XDP:
./run_router_local.sh
-
Run client:
./run_routerctl_local_demo.sh
-
Start Debian 12 "Bookworm" VMs:
vagrant up
-
Build, run server, load XDP (on VM):
vagrant ssh server --command "/vagrant/build_debug.sh" vagrant ssh server --command "/vagrant/run_router_vagrant.sh"
-
Run client (optionaly on VM):
vagrant ssh client --command "/vagrant/run_routerctl_vagrant_demo.sh" # or just: ./run_routerctl_vagrant_demo.sh
Check if XDP was loaded:
vagrant ssh server
sudo xdp-loader status | grep router_xdp
sudo bpftool prog show | grep router_xdpTest mirroring/pong with debug port:
# XDP loaded locally
nc -u 127.0.0.1 65500
# XDP loaded on vagrant
nc -u 192.168.171.10 65500
