Commit c69f94a3 authored by Alexei Starovoitov's avatar Alexei Starovoitov Committed by Daniel Borkmann

libbpf: Open code raw_tp_open and link_create commands.

Open code raw_tracepoint_open and link_create used by light skeleton
to be able to avoid full libbpf eventually.
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarMartin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20220131220528.98088-4-alexei.starovoitov@gmail.com
parent e981f41f
...@@ -381,13 +381,13 @@ static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name) ...@@ -381,13 +381,13 @@ static void codegen_attach_detach(struct bpf_object *obj, const char *obj_name)
switch (bpf_program__type(prog)) { switch (bpf_program__type(prog)) {
case BPF_PROG_TYPE_RAW_TRACEPOINT: case BPF_PROG_TYPE_RAW_TRACEPOINT:
tp_name = strchr(bpf_program__section_name(prog), '/') + 1; tp_name = strchr(bpf_program__section_name(prog), '/') + 1;
printf("\tint fd = bpf_raw_tracepoint_open(\"%s\", prog_fd);\n", tp_name); printf("\tint fd = skel_raw_tracepoint_open(\"%s\", prog_fd);\n", tp_name);
break; break;
case BPF_PROG_TYPE_TRACING: case BPF_PROG_TYPE_TRACING:
if (bpf_program__expected_attach_type(prog) == BPF_TRACE_ITER) if (bpf_program__expected_attach_type(prog) == BPF_TRACE_ITER)
printf("\tint fd = bpf_link_create(prog_fd, 0, BPF_TRACE_ITER, NULL);\n"); printf("\tint fd = skel_link_create(prog_fd, 0, BPF_TRACE_ITER);\n");
else else
printf("\tint fd = bpf_raw_tracepoint_open(NULL, prog_fd);\n"); printf("\tint fd = skel_raw_tracepoint_open(NULL, prog_fd);\n");
break; break;
default: default:
printf("\tint fd = ((void)prog_fd, 0); /* auto-attach not supported */\n"); printf("\tint fd = ((void)prog_fd, 0); /* auto-attach not supported */\n");
......
...@@ -110,6 +110,32 @@ static inline int skel_map_update_elem(int fd, const void *key, ...@@ -110,6 +110,32 @@ static inline int skel_map_update_elem(int fd, const void *key,
return skel_sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, attr_sz); return skel_sys_bpf(BPF_MAP_UPDATE_ELEM, &attr, attr_sz);
} }
static inline int skel_raw_tracepoint_open(const char *name, int prog_fd)
{
const size_t attr_sz = offsetofend(union bpf_attr, raw_tracepoint.prog_fd);
union bpf_attr attr;
memset(&attr, 0, attr_sz);
attr.raw_tracepoint.name = (long) name;
attr.raw_tracepoint.prog_fd = prog_fd;
return skel_sys_bpf(BPF_RAW_TRACEPOINT_OPEN, &attr, attr_sz);
}
static inline int skel_link_create(int prog_fd, int target_fd,
enum bpf_attach_type attach_type)
{
const size_t attr_sz = offsetofend(union bpf_attr, link_create.iter_info_len);
union bpf_attr attr;
memset(&attr, 0, attr_sz);
attr.link_create.prog_fd = prog_fd;
attr.link_create.target_fd = target_fd;
attr.link_create.attach_type = attach_type;
return skel_sys_bpf(BPF_LINK_CREATE, &attr, attr_sz);
}
static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts) static inline int bpf_load_and_run(struct bpf_load_and_run_opts *opts)
{ {
int map_fd = -1, prog_fd = -1, key = 0, err; int map_fd = -1, prog_fd = -1, key = 0, err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment