Skip to content

Commit

Permalink
ebpf: Update eBPF map to BTF defined map
Browse files Browse the repository at this point in the history
legacy map definition is removed from libbpf1.0+.
update the legacy map definition to BTF defined map.

Distros with < libbpf1.0 (0.5, 0.6, 0.7, 0.8) bpf_helpers.h
support BTF map definition, this change does not break
old libbpf and support new libpbf1.0+.

Bug: #6250

Signed-off-by: Vincent Li <[email protected]>
Co-authored-by: Victor Julien <[email protected]>
  • Loading branch information
vincentmli and victorjulien committed Dec 5, 2023
1 parent 13cc493 commit ef4c855
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 473 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,6 @@ jobs:
zlib1g \
zlib1g-dev \
clang \
libbpf-dev \
libelf-dev
- name: Install Rust
run: curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain $RUST_VERSION_KNOWN -y
Expand All @@ -2448,7 +2447,7 @@ jobs:
cp prep/cbindgen $HOME/.cargo/bin
chmod 755 $HOME/.cargo/bin/cbindgen
- run: ./autogen.sh
- run: CFLAGS="${DEFAULT_CFLAGS}" ./configure --enable-unittests --enable-fuzztargets --enable-ebpf --enable-ebpf-build
- run: CFLAGS="${DEFAULT_CFLAGS}" ./configure --enable-unittests --enable-fuzztargets
- run: make -j2
- run: make check
- run: tar xf prep/suricata-verify.tar.gz
Expand Down
17 changes: 17 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,23 @@
AC_SUBST(LLC)
],
[AC_MSG_ERROR([clang needed to build ebpf files])])
AC_MSG_CHECKING([libbpf has bpf/bpf_helpers.h])
AC_COMPILE_IFELSE(
[AC_LANG_PROGRAM(
[
#include <stddef.h>
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
],
[
])],
[HAVE_BPF="yes"],
[HAVE_BPF="no"])
if test "$HAVE_BPF" = "no"; then
AC_MSG_ERROR([libbpf include bpf/bpf_helpers.h not found])
else
AC_MSG_RESULT([ok])
fi
])

# enable debug output
Expand Down
4 changes: 2 additions & 2 deletions ebpf/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
EXTRA_DIST= include bypass_filter.c filter.c lb.c vlan_filter.c xdp_filter.c \
xdp_lb.c bpf_helpers.h hash_func01.h
xdp_lb.c hash_func01.h

if BUILD_EBPF

Expand All @@ -18,7 +18,7 @@ all: $(BPF_TARGETS)

$(BPF_TARGETS): %.bpf: %.c
# From C-code to LLVM-IR format suffix .ll (clang -S -emit-llvm)
${CLANG} -Wall $(BPF_CFLAGS) -O2 \
${CLANG} -Wall $(BPF_CFLAGS) -O2 -g \
-I/usr/include/$(build_cpu)-$(build_os)/ \
-D__KERNEL__ -D__ASM_SYSREG_H \
-target bpf -S -emit-llvm $< -o ${@:.bpf=.ll}
Expand Down
Loading

0 comments on commit ef4c855

Please sign in to comment.