diff options
author | David Ahern <dsahern@kernel.org> | 2022-02-06 17:59:24 -0700 |
---|---|---|
committer | David Ahern <dsahern@kernel.org> | 2022-03-07 08:52:08 -0700 |
commit | ac4e0913beb117f9b1416ed18fef4283056cd659 (patch) | |
tree | 7cb0148dec478e91e63eb71cace015e3c9c72dcf /lib | |
parent | 873bb9751f84252542040ad68632651144fbf1d3 (diff) | |
download | iproute2-ac4e0913beb117f9b1416ed18fef4283056cd659.tar.gz |
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 <dsahern@kernel.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bpf_glue.c | 13 | ||||
-rw-r--r-- | lib/bpf_legacy.c | 12 |
2 files changed, 13 insertions, 12 deletions
diff --git a/lib/bpf_glue.c b/lib/bpf_glue.c index cc301548..c1cf351b 100644 --- a/lib/bpf_glue.c +++ b/lib/bpf_glue.c @@ -4,13 +4,26 @@ * Authors: Hangbin Liu <haliu@redhat.com> * */ +#include <sys/syscall.h> #include <limits.h> +#include <unistd.h> #include "bpf_util.h" #ifdef HAVE_LIBBPF #include <bpf/bpf.h> #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 3779ae90..9bf7c1c4 100644 --- a/lib/bpf_legacy.c +++ b/lib/bpf_legacy.c @@ -33,7 +33,6 @@ #include <sys/un.h> #include <sys/vfs.h> #include <sys/mount.h> -#include <sys/syscall.h> #include <sys/sendfile.h> #include <sys/resource.h> @@ -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) { |