A lightweight experimental Layer 4 / Layer 7 reverse proxy and DoS mitigation prototype exploring Linux in-kernel packet filtering via eBPF/XDP and asynchronous user-space I/O via io_uring.
PHALANX is an educational systems programming project designed to investigate modern Linux networking primitives and their performance characteristics.
The goal of this project is to explore how user-space packet processing can be minimized by combining:
- Early packet drops at the network driver level using eBPF/XDP.
- An asynchronous, multi-threaded reverse proxy utilizing a shared-nothing model with
io_uringandSO_REUSEPORT.
Incoming Packets
│
▼
[ XDP Hook (Driver / Generic) ] ─── (Blacklisted IP) ───> XDP_DROP (~10ns)
│
(Clean IP)
│
▼
[ Kernel TCP Stack / SO_REUSEPORT ]
│
┌────┴───────────────────────────┐
▼ ▼
[ Worker Thread 0 ] [ Worker Thread N ] (Thread-per-Core, CPU pinned)
io_uring loop io_uring loop
(accept/recv/send) (accept/recv/send)
┌────────────────────────────────┘
▼
[ Upstream Pool ] ───> Target Backend (P2C Selection)
- Packet headers are parsed in the XDP hook before the kernel allocates an
sk_buff. - Source IPv4 addresses are checked against a
BPF_MAP_TYPE_HASHblacklist. - Matching packets are discarded immediately via
XDP_DROP. - Filter statistics are maintained in a
BPF_MAP_TYPE_ARRAYfor user-space telemetry.
- Shared-Nothing Concurrency: Worker threads are pinned to dedicated CPU cores via
pthread_setaffinity_npto improve cache locality. - Independent Rings: Each thread initializes its own
io_uringinstance and listens on the proxy port viaSO_REUSEPORT, eliminating cross-thread lock contention on accepts. - Load Balancing: Upstream selection implements the Power of Two Random Choices (P2C) algorithm based on active connection counts.
- Telemetry: Injected headers (
X-Phalanx-Worker,X-Phalanx-Upstream,X-Phalanx-Latency-Us) provide per-request latency tracking in microseconds.
This project is an experimental prototype intended for learning and benchmarking, not a production-grade reverse proxy. Current architectural limitations include:
- Simplified HTTP Handling: The proxy operates on simple HTTP/1.1 request boundaries and does not implement a complete streaming HTTP parser.
- Transport Security: No TLS/SSL termination support.
- Connection Model: Upstream connections are created per request without connection pooling (keep-alive pipeline).
- Generic XDP Mode: Tested primarily under
XDP_FLAGS_SKB_MODEfor cross-platform compatibility across virtual and loopback interfaces.
- Linux kernel >= 5.15 with eBPF and io_uring support
clang&llvm(for BPF bytecode compilation)libbpfliburingcmake(>= 3.20) andninja- C++20 compliant compiler (GCC >= 11 or Clang >= 13)
cmake -B build -G Ninja
cmake --build build- Start the mock backend cluster:
python3 scripts/spawn_backends.py- Launch the proxy core (root privileges required for attaching XDP programs):
sudo ./build/phalanx loThe process provides a basic stdin interface for runtime map interaction:
block <ip>: Insert an IPv4 address into the BPF blacklist map.unblock <ip>: Remove an IPv4 address from the map.stats: Query packet counters from the kernel telemetry map.exit: Detach eBPF filter and initiate graceful worker shutdown.
GPL-2.0-only