1 /* eBPF example program:
5 * The eBPF program loads a filter from file and attaches the
6 * program to a cgroup using BPF_PROG_ATTACH
20 #include <linux/bpf.h>
25 static int usage(const char *argv0
)
27 printf("Usage: %s cg-path filter-path [filter-id]\n", argv0
);
31 int main(int argc
, char **argv
)
33 int cg_fd
, ret
, filter_id
= 0;
36 return usage(argv
[0]);
38 cg_fd
= open(argv
[1], O_DIRECTORY
| O_RDONLY
);
40 printf("Failed to open cgroup path: '%s'\n", strerror(errno
));
44 if (load_bpf_file(argv
[2]))
47 printf("Output from kernel verifier:\n%s\n-------\n", bpf_log_buf
);
50 filter_id
= atoi(argv
[3]);
52 if (filter_id
> prog_cnt
) {
53 printf("Invalid program id; program not found in file\n");
57 ret
= bpf_prog_attach(prog_fd
[filter_id
], cg_fd
,
58 BPF_CGROUP_INET_SOCK_CREATE
, 0);
60 printf("Failed to attach prog to cgroup: '%s'\n",