netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexei Starovoitov <ast@fb.com>
To: "David S . Miller" <davem@davemloft.net>
Cc: Daniel Borkmann <daniel@iogearbox.net>, Tejun Heo <tj@kernel.org>,
	David Ahern <dsa@cumulusnetworks.com>, <netdev@vger.kernel.org>,
	<kernel-team@fb.com>
Subject: [PATCH v2 net-next 7/8] libbpf: add support for BPF_PROG_QUERY
Date: Mon, 2 Oct 2017 22:50:27 -0700	[thread overview]
Message-ID: <20171003055028.1294791-8-ast@fb.com> (raw)
In-Reply-To: <20171003055028.1294791-1-ast@fb.com>

add support for BPF_PROG_QUERY command to libbpf

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
---
 tools/lib/bpf/bpf.c | 20 ++++++++++++++++++++
 tools/lib/bpf/bpf.h |  3 ++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c
index d4b6ba8292ee..5128677e4117 100644
--- a/tools/lib/bpf/bpf.c
+++ b/tools/lib/bpf/bpf.c
@@ -303,6 +303,26 @@ int bpf_prog_detach2(int prog_fd, int target_fd, enum bpf_attach_type type)
 	return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr));
 }
 
+int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags,
+		   __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt)
+{
+	union bpf_attr attr;
+	int ret;
+
+	bzero(&attr, sizeof(attr));
+	attr.query.target_fd	= target_fd;
+	attr.query.attach_type	= type;
+	attr.query.query_flags	= query_flags;
+	attr.query.prog_cnt	= *prog_cnt;
+	attr.query.prog_ids	= ptr_to_u64(prog_ids);
+
+	ret = sys_bpf(BPF_PROG_QUERY, &attr, sizeof(attr));
+	if (attach_flags)
+		*attach_flags = attr.query.attach_flags;
+	*prog_cnt = attr.query.prog_cnt;
+	return ret;
+}
+
 int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size,
 		      void *data_out, __u32 *size_out, __u32 *retval,
 		      __u32 *duration)
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h
index afd64727c9cf..6534889e2b2f 100644
--- a/tools/lib/bpf/bpf.h
+++ b/tools/lib/bpf/bpf.h
@@ -75,5 +75,6 @@ int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
 int bpf_prog_get_fd_by_id(__u32 id);
 int bpf_map_get_fd_by_id(__u32 id);
 int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len);
-
+int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags,
+		   __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt);
 #endif
-- 
2.9.5

  parent reply	other threads:[~2017-10-03  5:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-03  5:50 [PATCH v2 net-next 0/8] bpf: muli prog support for cgroup-bpf Alexei Starovoitov
2017-10-03  5:50 ` [PATCH v2 net-next 1/8] bpf: multi program support for cgroup+bpf Alexei Starovoitov
2017-10-03  5:50 ` [PATCH v2 net-next 2/8] bpf: introduce BPF_PROG_QUERY command Alexei Starovoitov
2017-10-03  5:50 ` [PATCH v2 net-next 3/8] bpf: enforce return code for cgroup-bpf programs Alexei Starovoitov
2017-10-03  5:50 ` [PATCH v2 net-next 4/8] libbpf: introduce bpf_prog_detach2() Alexei Starovoitov
2017-10-03  5:50 ` [PATCH v2 net-next 5/8] samples/bpf: add multi-prog cgroup test case Alexei Starovoitov
2017-10-03  5:50 ` [PATCH v2 net-next 6/8] libbpf: sync bpf.h Alexei Starovoitov
2017-10-03  5:50 ` Alexei Starovoitov [this message]
2017-10-03  5:50 ` [PATCH v2 net-next 8/8] samples/bpf: use bpf_prog_query() interface Alexei Starovoitov
2017-10-04 23:05 ` [PATCH v2 net-next 0/8] bpf: muli prog support for cgroup-bpf David Miller

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=20171003055028.1294791-8-ast@fb.com \
    --to=ast@fb.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsa@cumulusnetworks.com \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=tj@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;
as well as URLs for NNTP newsgroup(s).