mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
pping: TC-BPF use BTF map if iproute has libbpf
Copy setup from traffic-pacing-edt to use BTF-defined map if configure detects that iproute2 has libbpf support, otherwise fall back on bpf_elf_map. Also fix a minor bug with setting default value for SEC in bpf_egress_loader.sh. Signed-off-by: Simon Sundberg <simon.sundberg@kau.se>
This commit is contained in:
@ -1,10 +1,34 @@
|
|||||||
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
|
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
|
||||||
|
|
||||||
USER_TARGETS := pping
|
USER_TARGETS := pping
|
||||||
BPF_TARGETS := pping_kern_xdp pping_kern_tc
|
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
|
LIB_DIR = ../lib
|
||||||
|
|
||||||
include $(LIB_DIR)/common.mk
|
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
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
# Author: Jesper Dangaaard Brouer <netoptimizer@brouer.com>
|
# Author: Jesper Dangaaard Brouer <netoptimizer@brouer.com>
|
||||||
# License: GPLv2
|
# License: GPLv2
|
||||||
#
|
#
|
||||||
|
# Extended by Simon Sundberg <simon.sundberg@kau.se> to add support
|
||||||
|
# of optional section (--sec) option
|
||||||
|
#
|
||||||
basedir=`dirname $0`
|
basedir=`dirname $0`
|
||||||
source ${basedir}/functions.sh
|
source ${basedir}/functions.sh
|
||||||
|
|
||||||
@ -16,13 +19,13 @@ export TC=/sbin/tc
|
|||||||
# This can be changed via --file or --obj
|
# This can be changed via --file or --obj
|
||||||
if [[ -z ${BPF_OBJ} ]]; then
|
if [[ -z ${BPF_OBJ} ]]; then
|
||||||
# Fallback default
|
# Fallback default
|
||||||
BPF_OBJ=pping.bpf.o
|
BPF_OBJ=pping_kern_tc.o
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# This can be changed via --sec
|
# This can be changed via --sec
|
||||||
if [[ -z ${BPF_OBJ} ]]; then
|
if [[ -z ${SEC} ]]; then
|
||||||
# Fallback default
|
# Fallback default
|
||||||
SEC=egress
|
SEC=pping_egress
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Applying TC-BPF egress setup on device: $DEV with object file: $BPF_OBJ"
|
info "Applying TC-BPF egress setup on device: $DEV with object file: $BPF_OBJ"
|
||||||
@ -57,7 +60,6 @@ function tc_egress_bpf_attach()
|
|||||||
local section=${3:-$SEC}
|
local section=${3:-$SEC}
|
||||||
shift 3
|
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 \
|
call_tc filter add dev "$device" pref 2 handle 2 \
|
||||||
egress bpf da obj "$objfile" sec "$section"
|
egress bpf da obj "$objfile" sec "$section"
|
||||||
}
|
}
|
||||||
|
29
pping/configure
vendored
Normal file
29
pping/configure
vendored
Normal file
@ -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
|
@ -16,6 +16,16 @@
|
|||||||
|
|
||||||
char _license[] SEC("license") = "GPL";
|
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 = {
|
struct bpf_elf_map SEC("maps") ts_start = {
|
||||||
.type = BPF_MAP_TYPE_HASH,
|
.type = BPF_MAP_TYPE_HASH,
|
||||||
.size_key = sizeof(struct ts_key),
|
.size_key = sizeof(struct ts_key),
|
||||||
@ -23,6 +33,7 @@ struct bpf_elf_map SEC("maps") ts_start = {
|
|||||||
.max_elem = 16384,
|
.max_elem = 16384,
|
||||||
.pinning = PIN_GLOBAL_NS,
|
.pinning = PIN_GLOBAL_NS,
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
// TC-BFP for parsing TSVAL from egress traffic and add to map
|
// TC-BFP for parsing TSVAL from egress traffic and add to map
|
||||||
SEC("pping_egress")
|
SEC("pping_egress")
|
||||||
|
Reference in New Issue
Block a user