diff options
author | Alexei Starovoitov <ast@fb.com> | 2017-03-31 00:45:39 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-04-01 15:45:57 -0400 |
commit | 3084887378f5271daedd52cc3372cb8011ad39b6 (patch) | |
tree | 718b917960b188fc93def7948d09bf9d30ff71c3 /tools/lib/bpf/bpf.c | |
parent | 1cf1cae963c2e6032aebe1637e995bc2f5d330f4 (diff) |
tools/lib/bpf: add support for BPF_PROG_TEST_RUN command
add support for BPF_PROG_TEST_RUN command to libbpf.a
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Acked-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/lib/bpf/bpf.c')
-rw-r--r-- | tools/lib/bpf/bpf.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 9b58d20e8c93..f84c398c11f4 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -209,3 +209,27 @@ int bpf_prog_detach(int target_fd, enum bpf_attach_type type) | |||
209 | 209 | ||
210 | return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); | 210 | return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); |
211 | } | 211 | } |
212 | |||
213 | int bpf_prog_test_run(int prog_fd, int repeat, void *data, __u32 size, | ||
214 | void *data_out, __u32 *size_out, __u32 *retval, | ||
215 | __u32 *duration) | ||
216 | { | ||
217 | union bpf_attr attr; | ||
218 | int ret; | ||
219 | |||
220 | bzero(&attr, sizeof(attr)); | ||
221 | attr.test.prog_fd = prog_fd; | ||
222 | attr.test.data_in = ptr_to_u64(data); | ||
223 | attr.test.data_out = ptr_to_u64(data_out); | ||
224 | attr.test.data_size_in = size; | ||
225 | attr.test.repeat = repeat; | ||
226 | |||
227 | ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr)); | ||
228 | if (size_out) | ||
229 | *size_out = attr.test.data_size_out; | ||
230 | if (retval) | ||
231 | *retval = attr.test.retval; | ||
232 | if (duration) | ||
233 | *duration = attr.test.duration; | ||
234 | return ret; | ||
235 | } | ||