Skip to content

Commit a339ed6

Browse files
committed
Update libbpf to latest upstream version
Since libbpf now includes bpf_helpers.h, add the libbpf dir to the include path and remove our own version of the helper. This requires rewriting all the includes to use <bpf/bpf_helpers.h>, and some fiddling with include paths. Also, we need to import the bpf_legacy.h header from the kernel, since we're using BPF_ANNOTATE_KV_PAIR in tracing02. Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
1 parent 03cda89 commit a339ed6

21 files changed

Lines changed: 79 additions & 450 deletions

File tree

basic01-xdp-pass/xdp_pass_kern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#include <linux/bpf.h>
3-
#include "bpf_helpers.h"
3+
#include <bpf/bpf_helpers.h>
44

55
SEC("xdp")
66
int xdp_prog_simple(struct xdp_md *ctx)

basic02-prog-by-name/xdp_prog_kern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#include <linux/bpf.h>
3-
#include "bpf_helpers.h"
3+
#include <bpf/bpf_helpers.h>
44

55
/* Notice how this XDP/BPF-program contains several programs in the same source
66
* file. These will each get their own section in the ELF file, and via libbpf

basic03-map-counter/xdp_prog_kern.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#include <linux/bpf.h>
3-
#include "bpf_helpers.h"
3+
#include <bpf/bpf_helpers.h>
44

55
#include "common_kern_user.h" /* defines: struct datarec; */
66

basic04-pinning-maps/xdp_prog_kern.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/* SPDX-License-Identifier: GPL-2.0 */
22
#include <linux/bpf.h>
3-
#include "bpf_helpers.h"
3+
#include <bpf/bpf_helpers.h>
44

55
#include "common_kern_user.h" /* defines: struct datarec; */
66

77
/* Lesson: See how a map is defined.
88
* - Here an array with XDP_ACTION_MAX (max_)entries are created.
99
* - The idea is to keep stats per (enum) xdp_action
1010
*/
11-
struct bpf_map_def SEC("maps") xdp_stats_map = {
12-
.type = BPF_MAP_TYPE_PERCPU_ARRAY,
13-
.key_size = sizeof(__u32),
14-
.value_size = sizeof(struct datarec),
15-
.max_entries = XDP_ACTION_MAX,
16-
};
11+
struct {
12+
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
13+
__uint(max_entries, XDP_ACTION_MAX);
14+
__type(key, __u32);
15+
__type(value, struct datarec);
16+
__uint(pinning, 1);
17+
} xdp_stats_map SEC(".maps");
1718

1819
/* LLVM maps __sync_fetch_and_add() as a built-in function to the BPF atomic add
1920
* instruction (that is BPF_STX | BPF_XADD | BPF_W for word sizes)

common/common.mk

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ CFLAGS += -I/usr/include/x86_64-linux-gnu
4545
CFLAGS += -I../headers/
4646
LDFLAGS ?= -L$(LIBBPF_DIR)
4747

48+
BPF_CFLAGS ?= -I$(LIBBPF_DIR)/build/usr/include/ -I../headers/
49+
4850
LIBS = -l:libbpf.a -lelf $(USER_LIBS)
4951

5052
all: llvm-check $(USER_TARGETS) $(XDP_OBJ) $(COPY_LOADER) $(COPY_STATS)
@@ -111,7 +113,7 @@ $(XDP_OBJ): %.o: %.c Makefile $(COMMON_MK) $(KERN_USER_H) $(EXTRA_DEPS)
111113
$(CLANG) -S \
112114
-target bpf \
113115
-D __BPF_TRACING__ \
114-
$(CFLAGS) \
116+
$(BPF_CFLAGS) \
115117
-Wall \
116118
-Wno-unused-value \
117119
-Wno-pointer-sign \

common/rewrite_helpers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <linux/ipv6.h>
1414
#include <linux/if_ether.h>
1515

16-
#include "bpf_helpers.h"
17-
#include "bpf_endian.h"
16+
#include <bpf/bpf_helpers.h>
17+
#include <bpf/bpf_endian.h>
1818

1919
/* Pops the outermost VLAN tag off the packet. Returns the popped VLAN ID on
2020
* success or negative errno on failure.

0 commit comments

Comments
 (0)