bpf: Add BPF_(PROG|MAP)_GET_NEXT_ID command

This patch adds BPF_PROG_GET_NEXT_ID and BPF_MAP_GET_NEXT_ID
to allow userspace to iterate all bpf_prog IDs and bpf_map IDs.

The API is trying to be consistent with the existing
BPF_MAP_GET_NEXT_KEY.

It is currently limited to CAP_SYS_ADMIN which we can
consider to lift it in followup patches.

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Alexei Starovoitov <ast@fb.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Martin KaFai Lau
2017-06-05 12:15:48 -07:00
committed by David S. Miller
parent f3f1c054c2
commit 34ad5580f8
2 changed files with 45 additions and 0 deletions

View File

@@ -82,6 +82,8 @@ enum bpf_cmd {
BPF_PROG_ATTACH,
BPF_PROG_DETACH,
BPF_PROG_TEST_RUN,
BPF_PROG_GET_NEXT_ID,
BPF_MAP_GET_NEXT_ID,
};
enum bpf_map_type {
@@ -209,6 +211,11 @@ union bpf_attr {
__u32 repeat;
__u32 duration;
} test;
struct { /* anonymous struct used by BPF_*_GET_NEXT_ID */
__u32 start_id;
__u32 next_id;
};
} __attribute__((aligned(8)));
/* BPF helper function descriptions: