- Overview
- Project origin and attribution
- Assignment context
- Implemented features
- Repository structure
- Platform requirements
- Build
- Topology setup
- Run conntrack program
- Functional testing
- Policy switches
- Cleanup
- Known limitations and disclaimer
- Report
This repository contains a simplified connection tracker implemented with eBPF/XDP for the Network Computing (2024/2025) course at the Politecnico di Milano.
The tracker inspects packets at XDP hook, keeps per-flow state in BPF maps, and decides whether to forward or drop traffic based on protocol state and policy rules.
This project is based on the course template provided in the Network Computing labs repository:
- Template source (exact subdirectory/commit path):
@Polimi-NetClasses/058172-network-computing-labs/ebpf-labs/project_24-25
This repository contains custom modifications and extensions made for project submission.
The project requirements ask:
- Understand the TCP state machine logic.
- Identify bugs/inconsistencies in state transitions and flags.
- Improve the state machine.
- Extend support for missing scenarios (example: RST handling).
- Suggest potential enhancements (example: connection timeout).
- Optionally extend tracking to UDP flows.
- Stricter TCP control-flag validation (SYN-only / SYN+ACK / ACK checks).
- Handshake transition fixes using correct ACK expectations.
- Improved close-path handling with additional states:
CLOSE_WAITCLOSING
- Direction-aware close behavior using
finInitiatormetadata. - Better invalid-transition rejection.
- Explicit RST handling:
- in-flow RST tears down the flow entry,
- unsolicited RST is treated as invalid.
- Lazy timeout expiration: expired entries are evicted on lookup.
- UDP flow tracking (
NEW$\to$ ESTABLISHEDbased on bidirectional traffic). - ICMP policy support (IPv4 echo request/reply tracking).
- IPv6 policy support (pass/drop policy mode, currently pass-through by default).
- Correct L4 offset calculation with VLAN/IPv4 options.
- Host-order conversion for ports/seq/ack fields.
ebpf/conntrack.bpf.c: main XDP conntrack program.ebpf/conntrack_parser.h: packet parser.ebpf/conntrack_structs.h: shared state structs and enums.ebpf/conntrack_common.h: constants, timeouts, policy switches.conntrack.c: userspace loader for conntrack XDP program.xdp_loader.c: helper loader used by topology script.create-topo.sh: lab namespace/veth setup.docs/main.tex: project report (LaTeX).
- Linux only (XDP/eBPF requires Linux kernel support).
- Kernel with eBPF + XDP enabled.
- Root privileges (
sudo) to:- create namespaces/veth,
- attach XDP programs,
- configure interfaces.
Typical required packages (Debian/Ubuntu):
sudo apt install clang \
llvm \
libelf-dev \
libpcap-dev \
gcc-multilib \
build-essential \
linux-headers-$(uname -r) \
linux-tools-common \
linux-tools-generic \
tcpdumpThe build also uses lab libraries under ../libs/ (libbpf, bpftool, libargparse, etc.), expected by this repository layout.
They can be found in the Course Labs Repository: @Polimi-NetClasses/058172-network-computing-labs/ebpf-labs/libs.
From project root:
makeIf build fails with missing libelf/libnl, install the corresponding development packages listed above and rebuild.
Create the test topology (2 namespaces, veth pairs, ARP entries, helper XDP loaders):
./create-topo.shThis script creates:
ns1withveth1_and IP10.0.0.1/24ns2withveth2_and IP10.0.0.2/24- root-side peers
veth1andveth2
Attach conntrack XDP program on root-side interfaces:
sudo ./conntrack -1 veth1 -2 veth2 -l 5Where:
-1first interface in root namespace-2second interface in root namespace-llog verbosity (0..5)
Server:
sudo ip netns exec ns2 nc -lv 12345Client:
sudo ip netns exec ns1 nc 10.0.0.2 12345Type text from one side and verify reception on the other side.
ACK-first test:
sudo ip netns exec ns1 hping3 -A -p 12345 -c 1 10.0.0.2SYN+ACK-first test:
sudo ip netns exec ns1 hping3 -S -A -p 12345 -c 1 10.0.0.2Expected: no valid response / packets dropped.
- Open TCP session with
nc. - Interrupt client (
Ctrl+C). - Reconnect immediately.
Expected: reconnect succeeds without stale-state issues.
Receiver:
sudo ip netns exec ns2 socat -u UDP-RECVFROM:9999,fork -Sender:
sudo ip netns exec ns1 sh -c 'echo hello-udp | socat - UDP:10.0.0.2:9999'Expected: datagram delivered.
Configure addresses:
sudo ip -n ns1 -6 addr add fd00::1/64 dev veth1_
sudo ip -n ns2 -6 addr add fd00::2/64 dev veth2_Test:
sudo ip netns exec ns1 ping6 -c 2 fd00::2Expected: success when IPv6 pass policy is enabled.
Policy and timeout constants are in ebpf/conntrack_common.h.
Relevant switches:
POLICY_IPV6_PASS1: pass IPv6 traffic (untracked)0: drop IPv6 traffic
POLICY_ICMP_TRACK1: apply ICMP echo tracking policy0: treat ICMP as invalid in conntrack path
Timeouts can be tuned via:
TCP_*UDP_*ICMP_TIMEOUT
If needed, remove topology manually:
sudo ip link del veth1 2>/dev/null || true
sudo ip link del veth2 2>/dev/null || true
sudo ip netns del ns1 2>/dev/null || true
sudo ip netns del ns2 2>/dev/null || true- This is a student project delivery, not production software.
- It may contain logic bugs, edge-case gaps, and incomplete protocol coverage.
- IPv6 is currently policy-based pass/drop, not full IPv6 conntrack.
- ICMP handling focuses on echo request/reply policy behavior.
- Validation has been performed on the lab topology and common test cases, not exhaustive real-world workloads.
The accompanying report is in:
docs/main.tex- compiled output:
docs/main.pdf