Skip to content

Commit

Permalink
util/xdp_samples: Add compatibility defines for libbpf
Browse files Browse the repository at this point in the history
The xdp_samples.h file was using some newer libbpf functions without the
required compatibility defines, leading to compilation errors on older
libbpf versions. Add the required defines to util/compat.h and include that
from xdp_sample.h. This includes a new configure check for
bpf_program__expected_attach_type(), which was renamed in libbpf 1.0.

Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
  • Loading branch information
tohojo committed May 31, 2023
1 parent 33326e1 commit 55f593d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ check_libbpf_functions()
check_libbpf_function "bpf_program__insn_cnt" "(NULL)" "" "$LIBBPF_CFLAGS" "$LIBBPF_LDLIBS"
check_libbpf_function "bpf_program__type" "(NULL)" "" "$LIBBPF_CFLAGS" "$LIBBPF_LDLIBS"
check_libbpf_function "bpf_program__flags" "(NULL)" "" "$LIBBPF_CFLAGS" "$LIBBPF_LDLIBS"
check_libbpf_function "bpf_program__expected_attach_type" "(NULL)" "" "$LIBBPF_CFLAGS" "$LIBBPF_LDLIBS"
check_libbpf_function "bpf_map_create" "(0, NULL, 0, 0, 0, NULL)" "" "$LIBBPF_CFLAGS" "$LIBBPF_LDLIBS"
check_libbpf_function "perf_buffer__new_raw" "(0, 0, NULL, NULL, NULL, NULL)" "" "$LIBBPF_CFLAGS" "$LIBBPF_LDLIBS"
check_libbpf_function "bpf_xdp_attach" "(0, 0, 0, NULL)" "" "$LIBBPF_CFLAGS" "$LIBBPF_LDLIBS"
Expand Down
22 changes: 22 additions & 0 deletions lib/util/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,26 @@ static __u32 btf__type_cnt(const struct btf *btf)
}
#endif

#ifndef HAVE_LIBBPF_BPF_PROGRAM__TYPE
static inline enum bpf_prog_type bpf_program__type(const struct bpf_program *prog)
{
return bpf_program__get_type((struct bpf_program *)prog);
}
#endif

#ifndef HAVE_LIBBPF_BPF_OBJECT__NEXT_PROGRAM
static inline struct bpf_program *bpf_object__next_program(const struct bpf_object *obj,
struct bpf_program *prog)
{
return bpf_program__next(prog, obj);
}
#endif

#ifndef HAVE_LIBBPF_BPF_PROGRAM__EXPECTED_ATTACH_TYPE
static inline enum bpf_attach_type bpf_program__expected_attach_type(const struct bpf_program *prog)
{
return bpf_program__get_expected_attach_type(prog);
}
#endif

#endif
1 change: 1 addition & 0 deletions lib/util/xdp_sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <getopt.h>

#include <xdp/xdp_sample_shared.h>
#include "compat.h"

enum stats_mask {
_SAMPLE_REDIRECT_MAP = 1U << 0,
Expand Down

0 comments on commit 55f593d

Please sign in to comment.