| * The eBPF program loads a filter from file and attaches the |
| * program to a cgroup using BPF_PROG_ATTACH |
| static int usage(const char *argv0) |
| printf("Usage: %s cg-path filter-path [filter-id]\n", argv0); |
| int main(int argc, char **argv) |
| int cg_fd, ret, filter_id = 0; |
| cg_fd = open(argv[1], O_DIRECTORY | O_RDONLY); |
| printf("Failed to open cgroup path: '%s'\n", strerror(errno)); |
| if (load_bpf_file(argv[2])) |
| printf("Output from kernel verifier:\n%s\n-------\n", bpf_log_buf); |
| filter_id = atoi(argv[3]); |
| if (filter_id > prog_cnt) { |
| printf("Invalid program id; program not found in file\n"); |
| ret = bpf_prog_attach(prog_fd[filter_id], cg_fd, |
| BPF_CGROUP_INET_SOCK_CREATE); |
| printf("Failed to attach prog to cgroup: '%s'\n", |