mirror of
https://github.com/xdp-project/bpf-examples.git
synced 2024-05-06 15:54:53 +00:00
iproute2 tc util have recently gotten libbpf support
Implement configure script that detect support, and Makefile defines that propagate to BPF-C file, making it possible to use and compile with BTF type maps. Signed-off-by: Jesper D. Brouer <netoptimizer@brouer.com>
This commit is contained in:
@@ -4,11 +4,20 @@ USER_TARGETS :=
|
||||
BPF_TARGETS := edt_pacer01
|
||||
BPF_TARGETS += edt_pacer02
|
||||
|
||||
EXTRA_DEPS += config.mk
|
||||
|
||||
LIB_DIR = ../lib
|
||||
|
||||
include $(LIB_DIR)/common.mk
|
||||
include config.mk
|
||||
|
||||
# The iproute2 'tc' tool doesn't understand BTF debug info
|
||||
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
|
||||
@@ -16,6 +25,8 @@ include $(LIB_DIR)/common.mk
|
||||
#
|
||||
.PHONY: strip_tc_obj
|
||||
strip_tc_obj: ${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
|
||||
|
29
traffic-pacing-edt/configure
vendored
Executable file
29
traffic-pacing-edt/configure
vendored
Executable 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 "CFLAGS += -DHAVE_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
|
@@ -2,7 +2,6 @@
|
||||
#include <linux/bpf.h>
|
||||
#include <bpf/bpf_helpers.h>
|
||||
#include <bpf/compiler.h>
|
||||
#include "iproute2_compat.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -59,16 +58,31 @@ struct edt_val {
|
||||
struct codel_state codel;
|
||||
} __aligned(64); /* Align struct to cache-size to avoid false-sharing */
|
||||
|
||||
/* The tc tool (iproute2) use another ELF map layout than libbpf (struct
|
||||
* bpf_map_def), see struct bpf_elf_map from iproute2.
|
||||
#ifdef HAVE_TC_LIBBPF /* detected by configure script in config.mk */
|
||||
/* Use BTF format to create map */
|
||||
struct {
|
||||
__uint(type, BPF_MAP_TYPE_ARRAY);
|
||||
__uint(max_entries, 4096); /* Max possible VLANs */
|
||||
__type(key, __u32);
|
||||
__type(value, struct edt_val);
|
||||
// __uint(pinning, LIBBPF_PIN_BY_NAME);
|
||||
} time_delay_map SEC(".maps");
|
||||
|
||||
#else
|
||||
/* The (iproute2) tc tool (without libbpf support) use another ELF map
|
||||
* layout than libbpf (struct bpf_map_def), see struct bpf_elf_map
|
||||
* from iproute2.
|
||||
*/
|
||||
#include "iproute2_compat.h"
|
||||
struct bpf_elf_map SEC("maps") time_delay_map = {
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.size_key = sizeof(__u32),
|
||||
.size_value = sizeof(struct edt_val),
|
||||
.max_elem = 4096, /* Max possible VLANs */
|
||||
//.pinning = PIN_GLOBAL_NS,
|
||||
// .pinning = PIN_GLOBAL_NS,
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
/* Role of EDT (Earliest Departure Time) is to schedule departure of packets to
|
||||
* be send in the future.
|
||||
|
@@ -1,4 +1,5 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/* Taken from from #include <iproute2/bpf_elf.h> */
|
||||
|
||||
#ifndef __IPROUTE2_COMPAT_H
|
||||
#define __IPROUTE2_COMPAT_H
|
||||
@@ -8,6 +9,11 @@
|
||||
* binary layout until "flags". Thus, BPF-progs can use both if careful.
|
||||
*/
|
||||
|
||||
/* Object pinning settings */
|
||||
#define PIN_NONE 0
|
||||
#define PIN_OBJECT_NS 1
|
||||
#define PIN_GLOBAL_NS 2
|
||||
|
||||
/* ELF map definition (copied from iproute2 source code) */
|
||||
struct bpf_elf_map {
|
||||
__u32 type;
|
||||
|
Reference in New Issue
Block a user