diff options
Diffstat (limited to 'tools/lib/bpf/bpf.c')
| -rw-r--r-- | tools/lib/bpf/bpf.c | 70 | 
1 files changed, 63 insertions, 7 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 0750681057c2..d27e34133973 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -32,9 +32,6 @@  #include "libbpf.h"  #include "libbpf_internal.h" -/* make sure libbpf doesn't use kernel-only integer typedefs */ -#pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64 -  /*   * When building perf, unistd.h is overridden. __NR_bpf is   * required to be defined explicitly. @@ -589,19 +586,31 @@ int bpf_link_create(int prog_fd, int target_fd,  		    enum bpf_attach_type attach_type,  		    const struct bpf_link_create_opts *opts)  { +	__u32 target_btf_id, iter_info_len;  	union bpf_attr attr;  	if (!OPTS_VALID(opts, bpf_link_create_opts))  		return -EINVAL; +	iter_info_len = OPTS_GET(opts, iter_info_len, 0); +	target_btf_id = OPTS_GET(opts, target_btf_id, 0); + +	if (iter_info_len && target_btf_id) +		return -EINVAL; +  	memset(&attr, 0, sizeof(attr));  	attr.link_create.prog_fd = prog_fd;  	attr.link_create.target_fd = target_fd;  	attr.link_create.attach_type = attach_type;  	attr.link_create.flags = OPTS_GET(opts, flags, 0); -	attr.link_create.iter_info = -		ptr_to_u64(OPTS_GET(opts, iter_info, (void *)0)); -	attr.link_create.iter_info_len = OPTS_GET(opts, iter_info_len, 0); + +	if (iter_info_len) { +		attr.link_create.iter_info = +			ptr_to_u64(OPTS_GET(opts, iter_info, (void *)0)); +		attr.link_create.iter_info_len = iter_info_len; +	} else if (target_btf_id) { +		attr.link_create.target_btf_id = target_btf_id; +	}  	return sys_bpf(BPF_LINK_CREATE, &attr, sizeof(attr));  } @@ -715,6 +724,37 @@ int bpf_prog_test_run_xattr(struct bpf_prog_test_run_attr *test_attr)  	return ret;  } +int bpf_prog_test_run_opts(int prog_fd, struct bpf_test_run_opts *opts) +{ +	union bpf_attr attr; +	int ret; + +	if (!OPTS_VALID(opts, bpf_test_run_opts)) +		return -EINVAL; + +	memset(&attr, 0, sizeof(attr)); +	attr.test.prog_fd = prog_fd; +	attr.test.cpu = OPTS_GET(opts, cpu, 0); +	attr.test.flags = OPTS_GET(opts, flags, 0); +	attr.test.repeat = OPTS_GET(opts, repeat, 0); +	attr.test.duration = OPTS_GET(opts, duration, 0); +	attr.test.ctx_size_in = OPTS_GET(opts, ctx_size_in, 0); +	attr.test.ctx_size_out = OPTS_GET(opts, ctx_size_out, 0); +	attr.test.data_size_in = OPTS_GET(opts, data_size_in, 0); +	attr.test.data_size_out = OPTS_GET(opts, data_size_out, 0); +	attr.test.ctx_in = ptr_to_u64(OPTS_GET(opts, ctx_in, NULL)); +	attr.test.ctx_out = ptr_to_u64(OPTS_GET(opts, ctx_out, NULL)); +	attr.test.data_in = ptr_to_u64(OPTS_GET(opts, data_in, NULL)); +	attr.test.data_out = ptr_to_u64(OPTS_GET(opts, data_out, NULL)); + +	ret = sys_bpf(BPF_PROG_TEST_RUN, &attr, sizeof(attr)); +	OPTS_SET(opts, data_size_out, attr.test.data_size_out); +	OPTS_SET(opts, ctx_size_out, attr.test.ctx_size_out); +	OPTS_SET(opts, duration, attr.test.duration); +	OPTS_SET(opts, retval, attr.test.retval); +	return ret; +} +  static int bpf_obj_get_next_id(__u32 start_id, __u32 *next_id, int cmd)  {  	union bpf_attr attr; @@ -818,7 +858,7 @@ int bpf_raw_tracepoint_open(const char *name, int prog_fd)  	return sys_bpf(BPF_RAW_TRACEPOINT_OPEN, &attr, sizeof(attr));  } -int bpf_load_btf(void *btf, __u32 btf_size, char *log_buf, __u32 log_buf_size, +int bpf_load_btf(const void *btf, __u32 btf_size, char *log_buf, __u32 log_buf_size,  		 bool do_log)  {  	union bpf_attr attr = {}; @@ -875,3 +915,19 @@ int bpf_enable_stats(enum bpf_stats_type type)  	return sys_bpf(BPF_ENABLE_STATS, &attr, sizeof(attr));  } + +int bpf_prog_bind_map(int prog_fd, int map_fd, +		      const struct bpf_prog_bind_opts *opts) +{ +	union bpf_attr attr; + +	if (!OPTS_VALID(opts, bpf_prog_bind_opts)) +		return -EINVAL; + +	memset(&attr, 0, sizeof(attr)); +	attr.prog_bind_map.prog_fd = prog_fd; +	attr.prog_bind_map.map_fd = map_fd; +	attr.prog_bind_map.flags = OPTS_GET(opts, flags, 0); + +	return sys_bpf(BPF_PROG_BIND_MAP, &attr, sizeof(attr)); +}  | 
