From: David Ahern Date: Mon, 7 Feb 2022 00:59:24 +0000 (-0700) Subject: bpf: Export bpf syscall wrapper X-Git-Tag: v5.18.0~35^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac4e0913beb117f9b1416ed18fef4283056cd659;p=thirdparty%2Fiproute2.git bpf: Export bpf syscall wrapper Move bpf syscall wrapper to bpf_glue to make it available to libbpf based functions. Signed-off-by: David Ahern --- diff --git a/include/bpf_util.h b/include/bpf_util.h index 53acc4106..abb962755 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -287,6 +287,8 @@ int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type); int bpf_dump_prog_info(FILE *f, uint32_t id); +int bpf(int cmd, union bpf_attr *attr, unsigned int size); + #ifdef HAVE_ELF int bpf_send_map_fds(const char *path, const char *obj); int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux, diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c index cc3015487..c1cf351b7 100644 --- a/lib/bpf_glue.c +++ b/lib/bpf_glue.c @@ -4,13 +4,26 @@ * Authors: Hangbin Liu * */ +#include #include +#include #include "bpf_util.h" #ifdef HAVE_LIBBPF #include #endif +int bpf(int cmd, union bpf_attr *attr, unsigned int size) +{ +#ifdef __NR_bpf + return syscall(__NR_bpf, cmd, attr, size); +#else + fprintf(stderr, "No bpf syscall, kernel headers too old?\n"); + errno = ENOSYS; + return -1; +#endif +} + int bpf_program_attach(int prog_fd, int target_fd, enum bpf_attach_type type) { #ifdef HAVE_LIBBPF diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c index 3779ae90c..9bf7c1c49 100644 --- a/lib/bpf_legacy.c +++ b/lib/bpf_legacy.c @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -134,17 +133,6 @@ static inline __u64 bpf_ptr_to_u64(const void *ptr) return (__u64)(unsigned long)ptr; } -static int bpf(int cmd, union bpf_attr *attr, unsigned int size) -{ -#ifdef __NR_bpf - return syscall(__NR_bpf, cmd, attr, size); -#else - fprintf(stderr, "No bpf syscall, kernel headers too old?\n"); - errno = ENOSYS; - return -1; -#endif -} - static int bpf_map_update(int fd, const void *key, const void *value, uint64_t flags) {