Skip to content

Commit a0fe3e5

Browse files
Alexei Starovoitovborkmann
authored andcommitted
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>
1 parent c4f6699 commit a0fe3e5

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎tools/include/uapi/linux/bpf.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ enum bpf_cmd {
9494
BPF_MAP_GET_FD_BY_ID,
9595
BPF_OBJ_GET_INFO_BY_FD,
9696
BPF_PROG_QUERY,
97+
BPF_RAW_TRACEPOINT_OPEN,
9798
};
9899

99100
enum bpf_map_type {
@@ -134,6 +135,7 @@ enum bpf_prog_type {
134135
BPF_PROG_TYPE_SK_SKB,
135136
BPF_PROG_TYPE_CGROUP_DEVICE,
136137
BPF_PROG_TYPE_SK_MSG,
138+
BPF_PROG_TYPE_RAW_TRACEPOINT,
137139
};
138140

139141
enum bpf_attach_type {
@@ -344,6 +346,11 @@ union bpf_attr {
344346
__aligned_u64 prog_ids;
345347
__u32 prog_cnt;
346348
} query;
349+
350+
struct {
351+
__u64 name;
352+
__u32 prog_fd;
353+
} raw_tracepoint;
347354
} __attribute__((aligned(8)));
348355

349356
/* BPF helper function descriptions:
@@ -1151,4 +1158,8 @@ struct bpf_cgroup_dev_ctx {
11511158
__u32 minor;
11521159
};
11531160

1161+
struct bpf_raw_tracepoint_args {
1162+
__u64 args[0];
1163+
};
1164+
11541165
#endif /* _UAPI__LINUX_BPF_H__ */

‎tools/lib/bpf/bpf.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,17 @@ int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len)
428428
return err;
429429
}
430430

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+
431442
int bpf_set_link_xdp_fd(int ifindex, int fd, __u32 flags)
432443
{
433444
struct sockaddr_nl sa;

‎tools/lib/bpf/bpf.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,5 @@ int bpf_map_get_fd_by_id(__u32 id);
7979
int bpf_obj_get_info_by_fd(int prog_fd, void *info, __u32 *info_len);
8080
int bpf_prog_query(int target_fd, enum bpf_attach_type type, __u32 query_flags,
8181
__u32 *attach_flags, __u32 *prog_ids, __u32 *prog_cnt);
82+
int bpf_raw_tracepoint_open(const char *name, int prog_fd);
8283
#endif

0 commit comments

Comments
 (0)