diff --git a/pping/Makefile b/pping/Makefile index 6166548..f34c4b0 100644 --- a/pping/Makefile +++ b/pping/Makefile @@ -1,10 +1,34 @@ # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) -USER_TARGETS := pping -BPF_TARGETS := pping_kern_xdp pping_kern_tc +USER_TARGETS := pping +TC_BPF_TARGETS := pping_kern_tc +BPF_TARGETS := pping_kern_xdp +BPF_TARGETS += $(TC_BPF_TARGETS) -LDFLAGS = -pthread +LDFLAGS += -pthread +EXTRA_DEPS += config.mk LIB_DIR = ../lib include $(LIB_DIR)/common.mk +include config.mk + +all: config.mk + +config.mk: configure + @sh configure + +ifndef HAVE_TC_LIBBPF +# If the iproute2 'tc' tool doesn't understand BTF debug info +# use llvm-strip to remove this debug info from object file +# +# *BUT* cannot strip everything as it removes ELF elems needed for +# creating maps +# +.PHONY: strip_tc_obj +strip_tc_obj: ${TC_BPF_TARGETS:=.o} + $(Q) echo "TC don't support libbpf - strip BTF info" + $(Q) llvm-strip --no-strip-all --remove-section .BTF $? + +all: strip_tc_obj +endif diff --git a/pping/bpf_egress_loader.sh b/pping/bpf_egress_loader.sh index e14084e..da4e467 100755 --- a/pping/bpf_egress_loader.sh +++ b/pping/bpf_egress_loader.sh @@ -3,6 +3,9 @@ # Author: Jesper Dangaaard Brouer # License: GPLv2 # +# Extended by Simon Sundberg to add support +# of optional section (--sec) option +# basedir=`dirname $0` source ${basedir}/functions.sh @@ -16,13 +19,13 @@ export TC=/sbin/tc # This can be changed via --file or --obj if [[ -z ${BPF_OBJ} ]]; then # Fallback default - BPF_OBJ=pping.bpf.o + BPF_OBJ=pping_kern_tc.o fi # This can be changed via --sec -if [[ -z ${BPF_OBJ} ]]; then +if [[ -z ${SEC} ]]; then # Fallback default - SEC=egress + SEC=pping_egress fi info "Applying TC-BPF egress setup on device: $DEV with object file: $BPF_OBJ" @@ -57,9 +60,8 @@ function tc_egress_bpf_attach() local section=${3:-$SEC} shift 3 - # TODO: Handle selecting program 'sec' - Simon Sundberg added section option 2021-01-08 call_tc filter add dev "$device" pref 2 handle 2 \ - egress bpf da obj "$objfile" sec "$section" + egress bpf da obj "$objfile" sec "$section" } function tc_egress_list() diff --git a/pping/configure b/pping/configure new file mode 100644 index 0000000..2f4c54b --- /dev/null +++ b/pping/configure @@ -0,0 +1,29 @@ +#!/bin/bash +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +# This is not an autoconf generated configure +# + +# Output file which is input to Makefile +CONFIG=config.mk + +# Assume tc is in $PATH +TC=tc + +check_tc_libbpf() +{ + tc_version=$($TC -V) + if echo $tc_version | grep -q libbpf; then + libbpf_version=${tc_version##*libbpf } + echo "HAVE_TC_LIBBPF:=y" >> $CONFIG + echo "BPF_CFLAGS += -DHAVE_TC_LIBBPF" >> $CONFIG + echo "yes ($libbpf_version)" + else + echo "no" + fi +} + +echo "# Generated config" > $CONFIG +echo "Detecting available features on system" + +echo -n " - libbpf support in tc tool: " +check_tc_libbpf \ No newline at end of file diff --git a/pping/pping_kern_tc.c b/pping/pping_kern_tc.c index 3eb7086..d5bdda9 100644 --- a/pping/pping_kern_tc.c +++ b/pping/pping_kern_tc.c @@ -16,6 +16,16 @@ char _license[] SEC("license") = "GPL"; +#ifdef HAVE_TC_LIBBPF /* detected by configure script in config.mk */ +struct { + __uint(type, BPF_MAP_TYPE_HASH); + __uint(key_size, sizeof(struct ts_key)); + __uint(value_size, sizeof(struct ts_timestamp)); + __uint(max_entries, 16384); + __uint(pinning, LIBBPF_PIN_BY_NAME); +} ts_start SEC(".maps"); + +#else struct bpf_elf_map SEC("maps") ts_start = { .type = BPF_MAP_TYPE_HASH, .size_key = sizeof(struct ts_key), @@ -23,6 +33,7 @@ struct bpf_elf_map SEC("maps") ts_start = { .max_elem = 16384, .pinning = PIN_GLOBAL_NS, }; +#endif // TC-BFP for parsing TSVAL from egress traffic and add to map SEC("pping_egress")