From: David Ahern <dsahern@kernel.org>
To: netdev@vger.kernel.org
Cc: stephen@networkplumber.org, David Ahern <dsahern@kernel.org>
Subject: [PATCH iproute2-next 2/3] bpf: Export bpf syscall wrapper
Date: Sun, 27 Feb 2022 18:58:39 -0700 [thread overview]
Message-ID: <20220228015840.1413-3-dsahern@kernel.org> (raw)
In-Reply-To: <20220228015840.1413-1-dsahern@kernel.org>
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 | 2 ++
lib/bpf_glue.c | 13 +++++++++++++
lib/bpf_legacy.c | 12 ------------
3 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/include/bpf_util.h b/include/bpf_util.h
index 53acc4106de8..abb9627556ef 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 cc3015487c68..c1cf351b7359 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 3779ae90cc1c..9bf7c1c493b4 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)
{
--
2.24.3 (Apple Git-128)
next prev parent reply other threads:[~2022-02-28 1:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-28 1:58 [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations David Ahern
2022-02-28 1:58 ` [PATCH iproute2-next 1/3] bpf_glue: Remove use of bpf_load_program from libbpf David Ahern
2022-02-28 1:58 ` David Ahern [this message]
2022-02-28 1:58 ` [PATCH iproute2-next 3/3] bpf: Remove use of bpf_create_map_xattr David Ahern
2022-03-07 16:10 ` [PATCH iproute2-next 0/3] bpf: Work around libbpf deprecations patchwork-bot+netdevbpf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220228015840.1413-3-dsahern@kernel.org \
--to=dsahern@kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.