BPF List
 help / color / mirror / Atom feed
From: Roberto Sassu <roberto.sassu@huawei.com>
To: <quentin@isovalent.com>, <ast@kernel.org>, <daniel@iogearbox.net>,
	<andrii@kernel.org>, <martin.lau@linux.dev>, <song@kernel.org>,
	<john.fastabend@gmail.com>, <kpsingh@kernel.org>,
	<sdf@google.com>, <jevburton.kernel@gmail.com>
Cc: <bpf@vger.kernel.org>, Roberto Sassu <roberto.sassu@huawei.com>
Subject: [RFC][PATCH v3 08/15] bpftool: Add opts parameter to open_obj_pinned_any() and open_obj_pinned()
Date: Fri, 22 Jul 2022 19:18:29 +0200	[thread overview]
Message-ID: <20220722171836.2852247-9-roberto.sassu@huawei.com> (raw)
In-Reply-To: <20220722171836.2852247-1-roberto.sassu@huawei.com>

Start to propagate the opts parameter from libbpf up to the bpftool
subcommand implementation, so that the appropriate permissions can be
requested depending on the operation type.

Add the bpf_get_fd_opts structure as parameter to open_obj_pinned_any() and
open_obj_pinned(), so that it can be sent to the new libbpf function
bpf_obj_get_opts().

Pass NULL as argument value, so that there is no change in the current
behavior.

Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 tools/bpf/bpftool/common.c | 16 +++++++++-------
 tools/bpf/bpftool/link.c   |  2 +-
 tools/bpf/bpftool/main.c   |  1 -
 tools/bpf/bpftool/main.h   |  7 +++++--
 4 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c
index 067e9ea59e3b..d3e3c779b027 100644
--- a/tools/bpf/bpftool/common.c
+++ b/tools/bpf/bpftool/common.c
@@ -191,7 +191,8 @@ int mount_tracefs(const char *target)
 	return err;
 }
 
-int open_obj_pinned(const char *path, bool quiet)
+int open_obj_pinned(const char *path, bool quiet,
+		    const struct bpf_get_fd_opts *opts)
 {
 	char *pname;
 	int fd = -1;
@@ -203,7 +204,7 @@ int open_obj_pinned(const char *path, bool quiet)
 		goto out_ret;
 	}
 
-	fd = bpf_obj_get(pname);
+	fd = bpf_obj_get_opts(pname, opts);
 	if (fd < 0) {
 		if (!quiet)
 			p_err("bpf obj get (%s): %s", pname,
@@ -219,12 +220,13 @@ int open_obj_pinned(const char *path, bool quiet)
 	return fd;
 }
 
-int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type)
+int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type,
+			const struct bpf_get_fd_opts *opts)
 {
 	enum bpf_obj_type type;
 	int fd;
 
-	fd = open_obj_pinned(path, false);
+	fd = open_obj_pinned(path, false, opts);
 	if (fd < 0)
 		return -1;
 
@@ -474,7 +476,7 @@ static int do_build_table_cb(const char *fpath, const struct stat *sb,
 	if (typeflag != FTW_F)
 		goto out_ret;
 
-	fd = open_obj_pinned(fpath, true);
+	fd = open_obj_pinned(fpath, true, NULL);
 	if (fd < 0)
 		goto out_ret;
 
@@ -835,7 +837,7 @@ int prog_parse_fds(int *argc, char ***argv, int **fds)
 		path = **argv;
 		NEXT_ARGP();
 
-		(*fds)[0] = open_obj_pinned_any(path, BPF_OBJ_PROG);
+		(*fds)[0] = open_obj_pinned_any(path, BPF_OBJ_PROG, NULL);
 		if ((*fds)[0] < 0)
 			return -1;
 		return 1;
@@ -972,7 +974,7 @@ int map_parse_fds(int *argc, char ***argv, int **fds)
 		path = **argv;
 		NEXT_ARGP();
 
-		(*fds)[0] = open_obj_pinned_any(path, BPF_OBJ_MAP);
+		(*fds)[0] = open_obj_pinned_any(path, BPF_OBJ_MAP, NULL);
 		if ((*fds)[0] < 0)
 			return -1;
 		return 1;
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c
index 7a20931c3250..62902d5ea1ae 100644
--- a/tools/bpf/bpftool/link.c
+++ b/tools/bpf/bpftool/link.c
@@ -44,7 +44,7 @@ static int link_parse_fd(int *argc, char ***argv)
 		path = **argv;
 		NEXT_ARGP();
 
-		return open_obj_pinned_any(path, BPF_OBJ_LINK);
+		return open_obj_pinned_any(path, BPF_OBJ_LINK, NULL);
 	}
 
 	p_err("expected 'id' or 'pinned', got: '%s'?", **argv);
diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c
index 451cefc2d0da..c0f783f0f3b7 100644
--- a/tools/bpf/bpftool/main.c
+++ b/tools/bpf/bpftool/main.c
@@ -9,7 +9,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <bpf/bpf.h>
 #include <bpf/btf.h>
 #include <bpf/hashmap.h>
 #include <bpf/libbpf.h>
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 5e5060c2ac04..53dfcb91ecac 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -9,6 +9,7 @@
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <bpf/bpf.h>
 #include <linux/bpf.h>
 #include <linux/compiler.h>
 #include <linux/kernel.h>
@@ -141,8 +142,10 @@ void get_prog_full_name(const struct bpf_prog_info *prog_info, int prog_fd,
 int get_fd_type(int fd);
 const char *get_fd_type_name(enum bpf_obj_type type);
 char *get_fdinfo(int fd, const char *key);
-int open_obj_pinned(const char *path, bool quiet);
-int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type);
+int open_obj_pinned(const char *path, bool quiet,
+		    const struct bpf_get_fd_opts *opts);
+int open_obj_pinned_any(const char *path, enum bpf_obj_type exp_type,
+			const struct bpf_get_fd_opts *opts);
 int mount_bpffs_for_pin(const char *name);
 int do_pin_any(int argc, char **argv, int (*get_fd_by_id)(int *, char ***));
 int do_pin_fd(int fd, const char *name);
-- 
2.25.1


  parent reply	other threads:[~2022-07-22 17:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-22 17:18 [RFC][PATCH v3 00/15] bpf: Per-operation map permissions Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 01/15] bpftool: Attempt to link static libraries Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 02/15] bpf: Set open_flags as last bpf_attr field for bpf_*_get_fd_by_id() funcs Roberto Sassu
2022-07-22 17:55   ` Alexei Starovoitov
2022-07-25  7:10     ` Roberto Sassu
2022-07-29 18:49       ` Andrii Nakryiko
2022-08-01 10:33         ` Roberto Sassu
2022-08-25 12:21           ` Roberto Sassu
2022-08-25 22:06             ` Andrii Nakryiko
2022-07-22 17:18 ` [RFC][PATCH v3 03/15] libbpf: Introduce bpf_prog_get_fd_by_id_opts() Roberto Sassu
2022-07-29 18:51   ` Andrii Nakryiko
2022-07-22 17:18 ` [RFC][PATCH v3 04/15] libbpf: Introduce bpf_map_get_fd_by_id_opts() Roberto Sassu
2022-07-29 18:52   ` Andrii Nakryiko
2022-07-22 17:18 ` [RFC][PATCH v3 05/15] libbpf: Introduce bpf_btf_get_fd_by_id_opts() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 06/15] libbpf: Introduce bpf_link_get_fd_by_id_opts() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 07/15] libbpf: Introduce bpf_obj_get_opts() Roberto Sassu
2022-07-22 17:58   ` Stanislav Fomichev
2022-07-22 18:01     ` Alexei Starovoitov
2022-07-25  7:18       ` Roberto Sassu
2022-07-22 17:18 ` Roberto Sassu [this message]
2022-07-22 17:18 ` [RFC][PATCH v3 09/15] bpftool: Add opts parameter to *_parse_fd() functions Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 10/15] bpftool: Add opts parameter to *_parse_fds() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 11/15] bpftool: Add opts parameter to map_parse_fd_and_info() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 12/15] bpftool: Add opts parameter in struct_ops functions Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 13/15] bpftool: Complete switch to bpf_*_get_fd_by_id_opts() Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 14/15] bpftool: Adjust map permissions Roberto Sassu
2022-07-22 17:18 ` [RFC][PATCH v3 15/15] selftests/bpf: Add map access tests Roberto Sassu

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=20220722171836.2852247-9-roberto.sassu@huawei.com \
    --to=roberto.sassu@huawei.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=jevburton.kernel@gmail.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=quentin@isovalent.com \
    --cc=sdf@google.com \
    --cc=song@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox