Skip to content

Commit

Permalink
fixup! samples/bpf: Switch over to libbpf
Browse files Browse the repository at this point in the history
  • Loading branch information
joestringer committed Dec 15, 2016
1 parent e480135 commit 6ff7726
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
3 changes: 2 additions & 1 deletion samples/bpf/bpf_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
bool is_perf_event = strncmp(event, "perf_event", 10) == 0;
bool is_cgroup_skb = strncmp(event, "cgroup/skb", 10) == 0;
bool is_cgroup_sk = strncmp(event, "cgroup/sock", 11) == 0;
size_t insns_cnt = size / sizeof(struct bpf_insn);
enum bpf_prog_type prog_type;
char buf[256];
int fd, efd, err, id;
Expand Down Expand Up @@ -95,7 +96,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
return -1;
}

fd = bpf_load_program(prog_type, prog, size, license, kern_version,
fd = bpf_load_program(prog_type, prog, insns_cnt, license, kern_version,
bpf_log_buf, BPF_LOG_BUF_SIZE);
if (fd < 0) {
printf("bpf_load_program() err=%d\n%s", errno, bpf_log_buf);
Expand Down
3 changes: 2 additions & 1 deletion samples/bpf/fds_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@ static int bpf_prog_create(const char *object)
BPF_MOV64_IMM(BPF_REG_0, 1),
BPF_EXIT_INSN(),
};
size_t insns_cnt = sizeof(insns) / sizeof(struct bpf_insn);

if (object) {
assert(!load_bpf_file((char *)object));
return prog_fd[0];
} else {
return bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER,
insns, sizeof(insns), "GPL", 0,
insns, insns_cnt, "GPL", 0,
bpf_log_buf, BPF_LOG_BUF_SIZE);
}
}
Expand Down
3 changes: 2 additions & 1 deletion samples/bpf/sock_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ static int test_sock(void)
BPF_MOV64_IMM(BPF_REG_0, 0), /* r0 = 0 */
BPF_EXIT_INSN(),
};
size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);

prog_fd = bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog, sizeof(prog),
prog_fd = bpf_load_program(BPF_PROG_TYPE_SOCKET_FILTER, prog, insns_cnt,
"GPL", 0, bpf_log_buf, BPF_LOG_BUF_SIZE);
if (prog_fd < 0) {
printf("failed to load prog '%s'\n", strerror(errno));
Expand Down
3 changes: 2 additions & 1 deletion samples/bpf/test_cgrp2_attach.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ static int prog_load(int map_fd, int verdict)
BPF_MOV64_IMM(BPF_REG_0, verdict), /* r0 = verdict */
BPF_EXIT_INSN(),
};
size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);

return bpf_load_program(BPF_PROG_TYPE_CGROUP_SKB,
prog, sizeof(prog), "GPL", 0,
prog, insns_cnt, "GPL", 0,
bpf_log_buf, BPF_LOG_BUF_SIZE);
}

Expand Down
3 changes: 2 additions & 1 deletion samples/bpf/test_cgrp2_attach2.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ static int prog_load(int verdict)
BPF_MOV64_IMM(BPF_REG_0, verdict), /* r0 = verdict */
BPF_EXIT_INSN(),
};
size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);

ret = bpf_load_program(BPF_PROG_TYPE_CGROUP_SKB,
prog, sizeof(prog), "GPL", 0,
prog, insns_cnt, "GPL", 0,
bpf_log_buf, BPF_LOG_BUF_SIZE);

if (ret < 0) {
Expand Down
3 changes: 2 additions & 1 deletion samples/bpf/test_cgrp2_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ static int prog_load(int idx)
BPF_MOV64_IMM(BPF_REG_0, 1), /* r0 = verdict */
BPF_EXIT_INSN(),
};
size_t insns_cnt = sizeof(prog) / sizeof(struct bpf_insn);

return bpf_load_program(BPF_PROG_TYPE_CGROUP_SOCK, prog, sizeof(prog),
return bpf_load_program(BPF_PROG_TYPE_CGROUP_SOCK, prog, insns_cnt,
"GPL", 0, bpf_log_buf, BPF_LOG_BUF_SIZE);
}

Expand Down

0 comments on commit 6ff7726

Please sign in to comment.