-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to using libbpf and BPF skeleton
- Loading branch information
1 parent
88ea485
commit 3aeb962
Showing
26 changed files
with
617,726 additions
and
262 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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
{ | ||
"files.associations": { | ||
"socket.h": "c", | ||
"parsing_helpers.h": "c" | ||
"parsing_helpers.h": "c", | ||
"tc-gtpu.h": "c", | ||
"tcgtpu.h": "c", | ||
"unistd.h": "c", | ||
"signal.h": "c", | ||
"gtpu.h": "c", | ||
"tc-gtpu.skel.h": "c" | ||
} | ||
} |
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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
FROM ubuntu:latest | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y clang llvm libbpf-dev iproute2 iputils-ping tcpdump && \ | ||
rm -rf /var/lib/apt/lists/* | ||
apt-get install -y clang llvm iproute2 iputils-ping tcpdump make git \ | ||
libelf1 libelf-dev zlib1g-dev gcc pkg-config | ||
# && \ | ||
# rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /home | ||
|
||
COPY gtpu.bpf.c ./ | ||
COPY . ./ | ||
|
||
RUN clang -O2 -emit-llvm -c gtpu.bpf.c -o - | llc -march=bpf -mcpu=probe -filetype=obj -o gtpu.bpf.o | ||
RUN make build | ||
|
||
# RUN tc qdisc add dev eth0 clsact | ||
# RUN tc filter add dev eth0 ingress bpf direct-action obj gtpu.bpf.o sec .text | ||
# RUN tc filter show dev eth0 | ||
# RUN tc filter show dev eth0 ingress | ||
# ENTRYPOINT ./entrypoint.sh |
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,5 @@ | ||
build: | ||
make -C src | ||
|
||
clean: | ||
make -C src clean |
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 |
---|---|---|
|
@@ -32,16 +32,13 @@ Either: | |
1. create container and the mount the debugfs inside the container. | ||
|
||
```bash | ||
# For dev: -v `pwd`/:/home \ | ||
docker run \ | ||
-it \ | ||
# --privileged \ | ||
--cap-add=NET_ADMIN \ | ||
--cap-add=SYS_ADMIN \ | ||
--device /dev/net/tun \ | ||
-v /sys/:/sys/ \ | ||
# -v /lib/modules/:/lib/modules/:ro \ | ||
# -v /usr/src:/usr/src:ro \ | ||
-v `pwd`/:/home \ | ||
--device /dev/net/tun \ | ||
tariromukute/tc-gtpu:latest | ||
|
||
mount -t debugfs debugfs /sys/kernel/debug | ||
|
@@ -102,7 +99,7 @@ tcpdump -i eth0 -w tmp.pcap | |
Or | ||
|
||
```bash | ||
./gtpu_loader -g eth0 -i uegtp -s 172.0.0.1 -d 172.0.0.2 -u 12.1.1.2 -t 1234 -q 9 -n 2 | ||
./tc-gtpu -g eth0 -i uegtp -s 172.0.0.1 -d 172.0.0.2 -u 12.1.1.2 -t 1234 -q 9 -n 2 | ||
``` | ||
|
||
```bash | ||
|
@@ -114,4 +111,5 @@ docker run -it --rm --privileged --pid=host ubuntu:latest nsenter -t 1 -m -u -n | |
- [Run eBPF Programs in Docker using docker-bpf](https://hemslo.io/run-ebpf-programs-in-docker-using-docker-bpf/) | ||
- https://github.com/edgecomllc/eupf/issues/509 | ||
- http://arthurchiao.art/blog/differentiate-bpf-redirects/ | ||
- https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/ | ||
|
Submodule bpftool
updated
15 files
+1 −1 | BPF-CHECKPOINT-COMMIT | |
+1 −1 | CHECKPOINT-COMMIT | |
+6 −52 | docs/bpftool-gen.rst | |
+7 −116 | include/uapi/linux/bpf.h | |
+0 −1 | include/uapi/linux/if_link.h | |
+0 −13 | include/uapi/linux/perf_event.h | |
+47 −0 | include/uapi/linux/pkt_cls.h | |
+109 −0 | include/uapi/linux/pkt_sched.h | |
+1 −1 | libbpf | |
+1 −1 | src/Makefile.feature | |
+4 −0 | src/feature.c | |
+4 −242 | src/gen.c | |
+0 −4 | src/kernel/bpf/disasm.c | |
+17 −180 | src/link.c | |
+6 −10 | src/prog.c |
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
Binary file not shown.
Submodule libbpf
updated
41 files
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,3 @@ | ||
/.output | ||
/bootstrap | ||
/tc-gtpu |
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,110 @@ | ||
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) | ||
OUTPUT := .output | ||
CLANG ?= clang | ||
LLVM_STRIP ?= llvm-strip | ||
LIBBPF_SRC := $(abspath ../libbpf/src) | ||
BPFTOOL_SRC := $(abspath ../bpftool/src) | ||
LIBBPF_OBJ := $(abspath $(OUTPUT)/libbpf.a) | ||
BPFTOOL_OUTPUT ?= $(abspath $(OUTPUT)/bpftool) | ||
BPFTOOL ?= $(BPFTOOL_OUTPUT)/bootstrap/bpftool | ||
ARCH ?= $(shell uname -m | sed 's/x86_64/x86/' \ | ||
| sed 's/aarch64/arm64/' \ | ||
| sed 's/ppc64le/powerpc/' \ | ||
| sed 's/mips.*/mips/' \ | ||
| sed 's/arm.*/arm/' \ | ||
| sed 's/riscv64/riscv/') | ||
VMLINUX := ../vmlinux/$(ARCH)/vmlinux.h | ||
# Use our own libbpf API headers and Linux UAPI headers distributed with | ||
# libbpf to avoid dependency on system-wide headers, which could be missing or | ||
# outdated | ||
INCLUDES := -I$(OUTPUT) -I../libbpf/include/uapi -I$(dir $(VMLINUX)) | ||
CFLAGS := -g -Wall | ||
ALL_LDFLAGS := $(LDFLAGS) $(EXTRA_LDFLAGS) | ||
|
||
APPS = tc-gtpu | ||
|
||
# Get Clang's default includes on this system. We'll explicitly add these dirs | ||
# to the includes list when compiling with `-target bpf` because otherwise some | ||
# architecture-specific dirs will be "missing" on some architectures/distros - | ||
# headers such as asm/types.h, asm/byteorder.h, asm/socket.h, asm/sockios.h, | ||
# sys/cdefs.h etc. might be missing. | ||
# | ||
# Use '-idirafter': Don't interfere with include mechanics except where the | ||
# build would have failed anyways. | ||
CLANG_BPF_SYS_INCLUDES = $(shell $(CLANG) -v -E - </dev/null 2>&1 \ | ||
| sed -n '/<...> search starts here:/,/End of search list./{ s| \(/.*\)|-idirafter \1|p }') | ||
|
||
ifeq ($(V),1) | ||
Q = | ||
msg = | ||
else | ||
Q = @ | ||
msg = @printf ' %-8s %s%s\n' \ | ||
"$(1)" \ | ||
"$(patsubst $(abspath $(OUTPUT))/%,%,$(2))" \ | ||
"$(if $(3), $(3))"; | ||
MAKEFLAGS += --no-print-directory | ||
endif | ||
|
||
define allow-override | ||
$(if $(or $(findstring environment,$(origin $(1))),\ | ||
$(findstring command line,$(origin $(1)))),,\ | ||
$(eval $(1) = $(2))) | ||
endef | ||
|
||
$(call allow-override,CC,$(CROSS_COMPILE)cc) | ||
$(call allow-override,LD,$(CROSS_COMPILE)ld) | ||
|
||
.PHONY: all | ||
all: $(APPS) | ||
|
||
.PHONY: clean | ||
clean: | ||
$(call msg,CLEAN) | ||
$(Q)rm -rf $(OUTPUT) $(APPS) | ||
|
||
$(OUTPUT) $(OUTPUT)/libbpf $(BPFTOOL_OUTPUT): | ||
$(call msg,MKDIR,$@) | ||
$(Q)mkdir -p $@ | ||
|
||
# Build libbpf | ||
$(LIBBPF_OBJ): $(wildcard $(LIBBPF_SRC)/*.[ch] $(LIBBPF_SRC)/Makefile) | $(OUTPUT)/libbpf | ||
$(call msg,LIB,$@) | ||
$(Q)$(MAKE) -C $(LIBBPF_SRC) BUILD_STATIC_ONLY=1 \ | ||
OBJDIR=$(dir $@)/libbpf DESTDIR=$(dir $@) \ | ||
INCLUDEDIR= LIBDIR= UAPIDIR= \ | ||
install | ||
|
||
# Build bpftool | ||
$(BPFTOOL): | $(BPFTOOL_OUTPUT) | ||
$(call msg,BPFTOOL,$@) | ||
$(Q)$(MAKE) ARCH= CROSS_COMPILE= OUTPUT=$(BPFTOOL_OUTPUT)/ -C $(BPFTOOL_SRC) bootstrap | ||
|
||
# Build BPF code | ||
$(OUTPUT)/%.bpf.o: %.bpf.c $(LIBBPF_OBJ) $(wildcard %.h) $(VMLINUX) | $(OUTPUT) | ||
$(call msg,BPF,$@) | ||
$(Q)$(CLANG) -g -fstack-protector -O2 -target bpf -D__TARGET_ARCH_$(ARCH) $(INCLUDES) $(CLANG_BPF_SYS_INCLUDES) -c $(filter %.c,$^) -o $@ | ||
$(Q)$(LLVM_STRIP) -g $@ # strip useless DWARF info | ||
|
||
# Generate BPF skeletons | ||
$(OUTPUT)/%.skel.h: $(OUTPUT)/%.bpf.o | $(OUTPUT) $(BPFTOOL) | ||
$(call msg,GEN-SKEL,$@) | ||
$(Q)$(BPFTOOL) gen skeleton $< > $@ | ||
|
||
# Build user-space code | ||
$(patsubst %,$(OUTPUT)/%.o,$(APPS)): %.o: %.skel.h | ||
|
||
$(OUTPUT)/%.o: %.c $(wildcard %.h) | $(OUTPUT) | ||
$(call msg,CC,$@) | ||
$(Q)$(CC) $(CFLAGS) $(INCLUDES) -c $(filter %.c,$^) -o $@ | ||
|
||
# Build application binary | ||
$(APPS): %: $(OUTPUT)/%.o $(LIBBPF_OBJ) | $(OUTPUT) | ||
$(call msg,BINARY,$@) | ||
$(Q)$(CC) $(CFLAGS) $^ $(ALL_LDFLAGS) -lelf -lz -o $@ | ||
|
||
# delete failed targets | ||
.DELETE_ON_ERROR: | ||
|
||
# keep intermediate (.skel.h, .bpf.o, etc) targets | ||
.SECONDARY: |
File renamed without changes.
File renamed without changes.
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
Oops, something went wrong.