| .. | .. |
|---|
| 13 | 13 | #include <bpf/bpf.h> |
|---|
| 14 | 14 | |
|---|
| 15 | 15 | #include "cgroup_helpers.h" |
|---|
| 16 | | -#include "bpf_endian.h" |
|---|
| 16 | +#include <bpf/bpf_endian.h> |
|---|
| 17 | 17 | #include "bpf_rlimit.h" |
|---|
| 18 | 18 | #include "bpf_util.h" |
|---|
| 19 | 19 | |
|---|
| .. | .. |
|---|
| 21 | 21 | #define MAX_INSNS 512 |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | char bpf_log_buf[BPF_LOG_BUF_SIZE]; |
|---|
| 24 | +static bool verbose = false; |
|---|
| 24 | 25 | |
|---|
| 25 | 26 | struct sock_test { |
|---|
| 26 | 27 | const char *descr; |
|---|
| .. | .. |
|---|
| 328 | 329 | enum bpf_attach_type attach_type) |
|---|
| 329 | 330 | { |
|---|
| 330 | 331 | struct bpf_load_program_attr attr; |
|---|
| 332 | + int ret; |
|---|
| 331 | 333 | |
|---|
| 332 | 334 | memset(&attr, 0, sizeof(struct bpf_load_program_attr)); |
|---|
| 333 | 335 | attr.prog_type = BPF_PROG_TYPE_CGROUP_SOCK; |
|---|
| .. | .. |
|---|
| 335 | 337 | attr.insns = prog; |
|---|
| 336 | 338 | attr.insns_cnt = probe_prog_length(attr.insns); |
|---|
| 337 | 339 | attr.license = "GPL"; |
|---|
| 340 | + attr.log_level = 2; |
|---|
| 338 | 341 | |
|---|
| 339 | | - return bpf_load_program_xattr(&attr, bpf_log_buf, BPF_LOG_BUF_SIZE); |
|---|
| 342 | + ret = bpf_load_program_xattr(&attr, bpf_log_buf, BPF_LOG_BUF_SIZE); |
|---|
| 343 | + if (verbose && ret < 0) |
|---|
| 344 | + fprintf(stderr, "%s\n", bpf_log_buf); |
|---|
| 345 | + |
|---|
| 346 | + return ret; |
|---|
| 340 | 347 | } |
|---|
| 341 | 348 | |
|---|
| 342 | 349 | static int attach_sock_prog(int cgfd, int progfd, |
|---|
| .. | .. |
|---|
| 457 | 464 | int cgfd = -1; |
|---|
| 458 | 465 | int err = 0; |
|---|
| 459 | 466 | |
|---|
| 460 | | - if (setup_cgroup_environment()) |
|---|
| 461 | | - goto err; |
|---|
| 462 | | - |
|---|
| 463 | | - cgfd = create_and_get_cgroup(CG_PATH); |
|---|
| 464 | | - if (!cgfd) |
|---|
| 465 | | - goto err; |
|---|
| 466 | | - |
|---|
| 467 | | - if (join_cgroup(CG_PATH)) |
|---|
| 467 | + cgfd = cgroup_setup_and_join(CG_PATH); |
|---|
| 468 | + if (cgfd < 0) |
|---|
| 468 | 469 | goto err; |
|---|
| 469 | 470 | |
|---|
| 470 | 471 | if (run_tests(cgfd)) |
|---|