diff options
author | Alexei Starovoitov <ast@kernel.org> | 2018-03-28 15:05:38 -0400 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2018-03-28 16:55:19 -0400 |
commit | a0fe3e574b50461c4811ce81811f0eaefda62871 (patch) | |
tree | 5bb54d6a41ea191ac880d30d96b26542210a2deb | |
parent | c4f6699dfcb8558d138fe838f741b2c10f416cf9 (diff) |
libbpf: add bpf_raw_tracepoint_open helper
add bpf_raw_tracepoint_open(const char *name, int prog_fd) api to libbpf
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
-rw-r--r-- | tools/include/uapi/linux/bpf.h | 11 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.c | 11 | ||||
-rw-r--r-- | tools/lib/bpf/bpf.h | 1 |
3 files changed, 23 insertions, 0 deletions
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index d245c41213ac..58060bec999d 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h | |||
@@ -94,6 +94,7 @@ enum bpf_cmd { | |||
94 | BPF_MAP_GET_FD_BY_ID, | 94 | BPF_MAP_GET_FD_BY_ID, |
95 | BPF_OBJ_GET_INFO_BY_FD, | 95 | BPF_OBJ_GET_INFO_BY_FD, |
96 | BPF_PROG_QUERY, | 96 | BPF_PROG_QUERY, |
97 | BPF_RAW_TRACEPOINT_OPEN, | ||
97 | }; | 98 | }; |
98 | 99 | ||
99 | enum bpf_map_type { | 100 | enum bpf_map_type { |
@@ -134,6 +135,7 @@ enum bpf_prog_type { | |||
134 | BPF_PROG_TYPE_SK_SKB, | 135 | BPF_PROG_TYPE_SK_SKB, |
135 | BPF_PROG_TYPE_CGROUP_DEVICE, | 136 | BPF_PROG_TYPE_CGROUP_DEVICE, |
136 | BPF_PROG_TYPE_SK_MSG, | 137 | BPF_PROG_TYPE_SK_MSG, |
138 | BPF_PROG_TYPE_RAW_TRACEPOINT, | ||
137 | }; | 139 | }; |
138 | 140 | ||
139 | enum bpf_attach_type { | 141 | enum bpf_attach_type { |
@@ -344,6 +346,11 @@ union bpf_attr { | |||
344 | __aligned_u64 prog_ids; | 346 | __aligned_u64 prog_ids; |
345 | __u32 prog_cnt; | 347 | __u32 prog_cnt; |
346 | } query; | 348 | } query; |
349 | |||
350 | struct { | ||
351 | __u64 name; | ||
352 | __u32 prog_fd; | ||
353 | } raw_tracepoint; | ||
347 | } __attribute__((aligned(8))); | 354 | } __attribute__((aligned(8))); |
348 | 355 | ||
349 | /* BPF helper function descriptions: | 356 | /* BPF helper function descriptions: |
@@ -1151,4 +1158,8 @@ struct bpf_cgroup_dev_ctx { | |||
1151 | __u32 minor; | 1158 | __u32 minor; |
1152 | }; | 1159 | }; |
1153 | 1160 | ||
1161 | struct bpf_raw_tracepoint_args { | ||
1162 | __u64 args[0]; | ||
1163 | }; | ||
1164 | |||
1154 | #endif /* _UAPI__LINUX_BPF_H__ */ | 1165 | #endif /* _UAPI__LINUX_BPF_H__ */ |
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 592a58a2b681..e0500055f1a6 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -428,6 +428,17 @@ int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len) | |||
428 | return err; | 428 | return err; |
429 | } | 429 | } |
430 | 430 | ||
431 | int bpf_raw_tracepoint_open(const char *name, int prog_fd) | ||
432 | { | ||
433 | union bpf_attr attr; | ||
434 | |||
435 | bzero(&attr, sizeof(attr)); | ||
436 | attr.raw_tracepoint.name = ptr_to_u64(name); | ||
437 | attr.raw_tracepoint.prog_fd = prog_fd; | ||
438 | |||
439 | return sys_bpf(BPF_RAW_TRACEPOINT_OPEN, &attr, sizeof(attr)); | ||
440 | } | ||
441 | |||
431 | int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) | 442 | int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags) |
432 | { | 443 | { |
433 | struct sockaddr_nl sa; | 444 | struct sockaddr_nl sa; |
diff --git a/tools/lib/bpf/bpf.h b/tools/lib/bpf/bpf.h index 8d18fb73d7fb..ee59342c6f42 100644 --- a/tools/lib/bpf/bpf.h +++ b/tools/lib/bpf/bpf.h | |||
@@ -79,4 +79,5 @@ int bpf_map_get_fd_by_id(__u32 id); | |||
79 | int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len); | 79 | int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len); |
80 | int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags, | 80 | int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags, |
81 | __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt); | 81 | __u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt); |
82 | int bpf_raw_tracepoint_open(const char *name, int prog_fd); | ||
82 | #endif | 83 | #endif |