-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Makefile for eBPF program compilation and management
Signed-off-by: Dengfeng Liu <[email protected]>
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
LLC ?= llc | ||
CLANG ?= clang | ||
CC ?= gcc | ||
|
||
BPF_CFLAGS = -I$(PWD) | ||
|
||
all: aw-bpf.o update-ipv4_map | ||
|
||
# eBPF program compilation | ||
aw-bpf.o: aw-bpf.c | ||
$(CLANG) -O2 -target bpf -c $< $(BPF_CFLAGS) -o $@ | ||
|
||
# User space program compilation | ||
update-ipv4_map: update-ipv4_map.c | ||
$(CC) -O2 -o $@ $< -lbpf | ||
|
||
clean: | ||
rm -f aw-bpf.o update-ipv4_map | ||
|
||
# load ebpf program to the kernel by tc in both egress and ingress | ||
load: aw-bpf.o | ||
sudo tc qdisc add dev eth0 clsact | ||
sudo tc filter add dev eth0 egress bpf da obj aw-bpf.o sec egress | ||
sudo tc filter add dev eth0 ingress bpf da obj aw-bpf.o sec ingress | ||
|
||
unload: | ||
sudo tc filter del dev eth0 egress | ||
sudo tc filter del dev eth0 ingress | ||
sudo tc qdisc del dev eth0 clsact | ||
|
||
status: | ||
sudo tc filter show dev eth0 | ||
sudo tc qdisc show dev eth0 |