This repository contains eBPF learning exercises and projects written in C, with a focus on packet filtering.
eBPF (extended Berkeley Packet Filter) is a powerful technology in the Linux kernel that allows running sandboxed programs in kernel space without changing kernel code or loading kernel modules.
sudo apt update
sudo apt install -y \
clang \
llvm \
libelf-dev \
libbpf-dev \
linux-headers-$(uname -r) \
build-essential \
gcc-multilibsudo dnf install -y \
clang \
llvm \
elfutils-libelf-devel \
libbpf-devel \
kernel-devel \
make \
gccsudo pacman -S \
clang \
llvm \
libelf \
libbpf \
linux-headers \
base-develTo ensure the tools are correctly installed:
clang --version
llc --versionEach project has its own Makefile. To run any program:
cd <directory-name>
makeThis command compiles both the eBPF and user-space files.
sudo ./program-nameNote: Running eBPF programs requires root access.
make clean.
├── example1/
│ ├── Makefile
│ ├── program.c # User-space code
│ └── program_kern.c # eBPF kernel code
├── example2/
│ ├── Makefile
│ ├── ...
└── README.md
These projects demonstrate how to filter network packets:
- Basic Packet Filter: Simple filtering based on protocol
- IP Filter: Filtering based on IP address
- Port Filter: Filtering based on port numbers
- Programs must be run with
sudo - Linux kernel must support eBPF (version 4.4 or higher)
To view eBPF logs:
sudo cat /sys/kernel/debug/tracing/trace_pipesudo bpftool prog list
sudo bpftool map listThis is a personal learning project, but suggestions and improvements are welcome!
These programs are for educational purposes only. Make sure to run thorough tests before using in production environments.
This project is released under the MIT License.
Note: If you encounter any issues with installation or execution, make sure your kernel supports eBPF:
uname -r # Should be 4.4 or higher