Commit 1e4edb6d authored by Andrii Nakryiko's avatar Andrii Nakryiko Committed by Daniel Borkmann

samples/bpf: Get rid of bpf_prog_load_xattr() use

Remove all the remaining uses of deprecated bpf_prog_load_xattr() API.
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Reviewed-by: default avatarQuentin Monnet <quentin@isovalent.com>
Link: https://lore.kernel.org/bpf/20220202225916.3313522-7-andrii@kernel.org
parent e4e284a8
...@@ -79,13 +79,11 @@ static void usage(const char *prog) ...@@ -79,13 +79,11 @@ static void usage(const char *prog)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
const char *optstr = "FSN"; const char *optstr = "FSN";
int prog_fd, map_fd, opt; int prog_fd, map_fd, opt;
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
struct bpf_map *map; struct bpf_map *map;
char filename[256]; char filename[256];
...@@ -123,11 +121,19 @@ int main(int argc, char **argv) ...@@ -123,11 +121,19 @@ int main(int argc, char **argv)
} }
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename; obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) err = bpf_object__load(obj);
if (err)
return 1; return 1;
prog_fd = bpf_program__fd(prog);
map = bpf_object__next_map(obj, NULL); map = bpf_object__next_map(obj, NULL);
if (!map) { if (!map) {
printf("finding a map in obj file failed\n"); printf("finding a map in obj file failed\n");
......
...@@ -82,15 +82,13 @@ static void usage(const char *cmd) ...@@ -82,15 +82,13 @@ static void usage(const char *cmd)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
unsigned char opt_flags[256] = {}; unsigned char opt_flags[256] = {};
const char *optstr = "i:T:P:SNFh"; const char *optstr = "i:T:P:SNFh";
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
unsigned int kill_after_s = 0; unsigned int kill_after_s = 0;
int i, prog_fd, map_fd, opt; int i, prog_fd, map_fd, opt;
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
__u32 max_pckt_size = 0; __u32 max_pckt_size = 0;
__u32 key = 0; __u32 key = 0;
...@@ -148,11 +146,20 @@ int main(int argc, char **argv) ...@@ -148,11 +146,20 @@ int main(int argc, char **argv)
} }
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1; return 1;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
err = bpf_object__load(obj);
if (err)
return 1;
prog_fd = bpf_program__fd(prog);
/* static global var 'max_pcktsz' is accessible from .data section */ /* static global var 'max_pcktsz' is accessible from .data section */
if (max_pckt_size) { if (max_pckt_size) {
map_fd = bpf_object__find_map_fd_by_name(obj, "xdp_adju.data"); map_fd = bpf_object__find_map_fd_by_name(obj, "xdp_adju.data");
......
...@@ -75,14 +75,11 @@ static void usage(const char *prog) ...@@ -75,14 +75,11 @@ static void usage(const char *prog)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
const char *prog_name = "xdp_fwd"; const char *prog_name = "xdp_fwd";
struct bpf_program *prog = NULL; struct bpf_program *prog = NULL;
struct bpf_program *pos; struct bpf_program *pos;
const char *sec_name; const char *sec_name;
int prog_fd, map_fd = -1; int prog_fd = -1, map_fd = -1;
char filename[PATH_MAX]; char filename[PATH_MAX];
struct bpf_object *obj; struct bpf_object *obj;
int opt, i, idx, err; int opt, i, idx, err;
...@@ -119,7 +116,6 @@ int main(int argc, char **argv) ...@@ -119,7 +116,6 @@ int main(int argc, char **argv)
if (attach) { if (attach) {
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
if (access(filename, O_RDONLY) < 0) { if (access(filename, O_RDONLY) < 0) {
printf("error accessing file %s: %s\n", printf("error accessing file %s: %s\n",
...@@ -127,7 +123,14 @@ int main(int argc, char **argv) ...@@ -127,7 +123,14 @@ int main(int argc, char **argv)
return 1; return 1;
} }
err = bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd); obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
err = bpf_object__load(obj);
if (err) { if (err) {
printf("Does kernel support devmap lookup?\n"); printf("Does kernel support devmap lookup?\n");
/* If not, the error message will be: /* If not, the error message will be:
......
...@@ -640,12 +640,10 @@ static void usage(const char *prog) ...@@ -640,12 +640,10 @@ static void usage(const char *prog)
int main(int ac, char **argv) int main(int ac, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
const char *optstr = "SF"; const char *optstr = "SF";
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
char filename[256]; char filename[256];
char **ifname_list; char **ifname_list;
...@@ -653,7 +651,6 @@ int main(int ac, char **argv) ...@@ -653,7 +651,6 @@ int main(int ac, char **argv)
int err, i = 1; int err, i = 1;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
total_ifindex = ac - 1; total_ifindex = ac - 1;
ifname_list = (argv + 1); ifname_list = (argv + 1);
...@@ -684,14 +681,20 @@ int main(int ac, char **argv) ...@@ -684,14 +681,20 @@ int main(int ac, char **argv)
return 1; return 1;
} }
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1; return 1;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
printf("\n******************loading bpf file*********************\n"); printf("\n******************loading bpf file*********************\n");
if (!prog_fd) { err = bpf_object__load(obj);
printf("bpf_prog_load_xattr: %s\n", strerror(errno)); if (err) {
printf("bpf_object__load(): %s\n", strerror(errno));
return 1; return 1;
} }
prog_fd = bpf_program__fd(prog);
lpm_map_fd = bpf_object__find_map_fd_by_name(obj, "lpm_map"); lpm_map_fd = bpf_object__find_map_fd_by_name(obj, "lpm_map");
rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt"); rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt");
......
...@@ -450,14 +450,12 @@ static void stats_poll(int interval, int action, __u32 cfg_opt) ...@@ -450,14 +450,12 @@ static void stats_poll(int interval, int action, __u32 cfg_opt)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
__u32 cfg_options= NO_TOUCH ; /* Default: Don't touch packet memory */ __u32 cfg_options= NO_TOUCH ; /* Default: Don't touch packet memory */
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
int prog_fd, map_fd, opt, err; int prog_fd, map_fd, opt, err;
bool use_separators = true; bool use_separators = true;
struct config cfg = { 0 }; struct config cfg = { 0 };
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
struct bpf_map *map; struct bpf_map *map;
char filename[256]; char filename[256];
...@@ -471,11 +469,19 @@ int main(int argc, char **argv) ...@@ -471,11 +469,19 @@ int main(int argc, char **argv)
char *action_str = NULL; char *action_str = NULL;
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return EXIT_FAIL; return EXIT_FAIL;
prog = bpf_object__next_program(obj, NULL);
bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
err = bpf_object__load(obj);
if (err)
return EXIT_FAIL;
prog_fd = bpf_program__fd(prog);
map = bpf_object__find_map_by_name(obj, "config_map"); map = bpf_object__find_map_by_name(obj, "config_map");
stats_global_map = bpf_object__find_map_by_name(obj, "stats_global_map"); stats_global_map = bpf_object__find_map_by_name(obj, "stats_global_map");
rx_queue_index_map = bpf_object__find_map_by_name(obj, "rx_queue_index_map"); rx_queue_index_map = bpf_object__find_map_by_name(obj, "rx_queue_index_map");
......
...@@ -152,9 +152,6 @@ static int parse_ports(const char *port_str, int *min_port, int *max_port) ...@@ -152,9 +152,6 @@ static int parse_ports(const char *port_str, int *min_port, int *max_port)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
int min_port = 0, max_port = 0, vip2tnl_map_fd; int min_port = 0, max_port = 0, vip2tnl_map_fd;
const char *optstr = "i:a:p:s:d:m:T:P:FSNh"; const char *optstr = "i:a:p:s:d:m:T:P:FSNh";
unsigned char opt_flags[256] = {}; unsigned char opt_flags[256] = {};
...@@ -162,6 +159,7 @@ int main(int argc, char **argv) ...@@ -162,6 +159,7 @@ int main(int argc, char **argv)
__u32 info_len = sizeof(info); __u32 info_len = sizeof(info);
unsigned int kill_after_s = 0; unsigned int kill_after_s = 0;
struct iptnl_info tnl = {}; struct iptnl_info tnl = {};
struct bpf_program *prog;
struct bpf_object *obj; struct bpf_object *obj;
struct vip vip = {}; struct vip vip = {};
char filename[256]; char filename[256];
...@@ -259,15 +257,20 @@ int main(int argc, char **argv) ...@@ -259,15 +257,20 @@ int main(int argc, char **argv)
} }
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]); snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
prog_load_attr.file = filename;
if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd)) obj = bpf_object__open_file(filename, NULL);
if (libbpf_get_error(obj))
return 1; return 1;
if (!prog_fd) { prog = bpf_object__next_program(obj, NULL);
printf("bpf_prog_load_xattr: %s\n", strerror(errno)); bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
err = bpf_object__load(obj);
if (err) {
printf("bpf_object__load(): %s\n", strerror(errno));
return 1; return 1;
} }
prog_fd = bpf_program__fd(prog);
rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt"); rxcnt_map_fd = bpf_object__find_map_fd_by_name(obj, "rxcnt");
vip2tnl_map_fd = bpf_object__find_map_fd_by_name(obj, "vip2tnl"); vip2tnl_map_fd = bpf_object__find_map_fd_by_name(obj, "vip2tnl");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment