Skip to content

Commit

Permalink
feat: add Makefile for eBPF program compilation and management
Browse files Browse the repository at this point in the history
Signed-off-by: Dengfeng Liu <[email protected]>
  • Loading branch information
liudf0716 committed Feb 3, 2025
1 parent 5dc2cdc commit 5e2379e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions ebpf/Makefile
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

0 comments on commit 5e2379e

Please sign in to comment.