]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bpf: Export bpf syscall wrapper
authorDavid Ahern <dsahern@kernel.org>
Mon, 7 Feb 2022 00:59:24 +0000 (17:59 -0700)
committerDavid Ahern <dsahern@kernel.org>
Mon, 7 Mar 2022 15:52:08 +0000 (08:52 -0700)
Move bpf syscall wrapper to bpf_glue to make it available to libbpf
based functions.

Signed-off-by: David Ahern <dsahern@kernel.org>
include/bpf_util.h
lib/bpf_glue.c
lib/bpf_legacy.c

index 53acc4106de8ba7704cfc52ce843b1202cf9580b..abb9627556ef098e7c19281e77d1896d6b73094f 100644 (file)
@@ -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,
index cc3015487c685cd3addf9381cd7f38d19e3e0cf4..c1cf351b7359ce1e7b48c743500c78ecf3f155cf 100644 (file)
@@ -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
index 3779ae90cc1ccfd610ab8b5ed2665f4686ae88a4..9bf7c1c493b49179b6a3ab72b23915b7b2f7bf74 100644 (file)
@@ -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)
 {