Skip to content

Commit

Permalink
samples/bpf: Stop using bpf_object__find_program_by_title API.
Browse files Browse the repository at this point in the history
bpf_object__find_program_by_title is going to be deprecated.
Replace use cases of bpf_object__find_program_by_title in samples/bpf/
with bpf_object__for_each_program.

Signed-off-by: Kui-Feng Lee <kuifeng@fb.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20211214035931.1148209-3-kuifeng@fb.com
  • Loading branch information
Kui-Feng Lee authored and Andrii Nakryiko committed Dec 14, 2021
1 parent a393ea8 commit 7490d59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
11 changes: 10 additions & 1 deletion samples/bpf/hbm.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ static void do_error(char *msg, bool errno_flag)

static int prog_load(char *prog)
{
struct bpf_program *pos;
const char *sec_name;

obj = bpf_object__open_file(prog, NULL);
if (libbpf_get_error(obj)) {
printf("ERROR: opening BPF object file failed\n");
Expand All @@ -132,7 +135,13 @@ static int prog_load(char *prog)
goto err;
}

bpf_prog = bpf_object__find_program_by_title(obj, "cgroup_skb/egress");
bpf_object__for_each_program(pos, obj) {
sec_name = bpf_program__section_name(pos);
if (sec_name && !strcmp(sec_name, "cgroup_skb/egress")) {
bpf_prog = pos;
break;
}
}
if (!bpf_prog) {
printf("ERROR: finding a prog in obj file failed\n");
goto err;
Expand Down
12 changes: 10 additions & 2 deletions samples/bpf/xdp_fwd_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ int main(int argc, char **argv)
.prog_type = BPF_PROG_TYPE_XDP,
};
const char *prog_name = "xdp_fwd";
struct bpf_program *prog;
struct bpf_program *prog = NULL;
struct bpf_program *pos;
const char *sec_name;
int prog_fd, map_fd = -1;
char filename[PATH_MAX];
struct bpf_object *obj;
Expand Down Expand Up @@ -134,7 +136,13 @@ int main(int argc, char **argv)
return 1;
}

prog = bpf_object__find_program_by_title(obj, prog_name);
bpf_object__for_each_program(pos, obj) {
sec_name = bpf_program__section_name(pos);
if (sec_name && !strcmp(sec_name, prog_name)) {
prog = pos;
break;
}
}
prog_fd = bpf_program__fd(prog);
if (prog_fd < 0) {
printf("program not found: %s\n", strerror(prog_fd));
Expand Down

0 comments on commit 7490d59

Please sign in to comment.