Commit 6748182c authored by Jakub Kicinski's avatar Jakub Kicinski Committed by Daniel Borkmann

samples: bpf: convert xdpsock_user.c to libbpf

Convert xdpsock_user.c to use libbpf instead of bpf_load.o.
Signed-off-by: default avatarJakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: default avatarQuentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parent e1a40ef4
...@@ -105,7 +105,7 @@ xdp_rxq_info-objs := xdp_rxq_info_user.o ...@@ -105,7 +105,7 @@ xdp_rxq_info-objs := xdp_rxq_info_user.o
syscall_tp-objs := bpf_load.o syscall_tp_user.o syscall_tp-objs := bpf_load.o syscall_tp_user.o
cpustat-objs := bpf_load.o cpustat_user.o cpustat-objs := bpf_load.o cpustat_user.o
xdp_adjust_tail-objs := xdp_adjust_tail_user.o xdp_adjust_tail-objs := xdp_adjust_tail_user.o
xdpsock-objs := bpf_load.o xdpsock_user.o xdpsock-objs := xdpsock_user.o
xdp_fwd-objs := xdp_fwd_user.o xdp_fwd-objs := xdp_fwd_user.o
task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS) task_fd_query-objs := bpf_load.o task_fd_query_user.o $(TRACE_HELPERS)
xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS) xdp_sample_pkts-objs := xdp_sample_pkts_user.o $(TRACE_HELPERS)
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <poll.h> #include <poll.h>
#include "bpf_load.h" #include "bpf/libbpf.h"
#include "bpf_util.h" #include "bpf_util.h"
#include <bpf/bpf.h> #include <bpf/bpf.h>
...@@ -891,7 +891,13 @@ static void l2fwd(struct xdpsock *xsk) ...@@ -891,7 +891,13 @@ static void l2fwd(struct xdpsock *xsk)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY}; struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
struct bpf_prog_load_attr prog_load_attr = {
.prog_type = BPF_PROG_TYPE_XDP,
};
int prog_fd, qidconf_map, xsks_map;
struct bpf_object *obj;
char xdp_filename[256]; char xdp_filename[256];
struct bpf_map *map;
int i, ret, key = 0; int i, ret, key = 0;
pthread_t pt; pthread_t pt;
...@@ -904,24 +910,38 @@ int main(int argc, char **argv) ...@@ -904,24 +910,38 @@ int main(int argc, char **argv)
} }
snprintf(xdp_filename, sizeof(xdp_filename), "%s_kern.o", argv[0]); snprintf(xdp_filename, sizeof(xdp_filename), "%s_kern.o", argv[0]);
prog_load_attr.file = xdp_filename;
if (load_bpf_file(xdp_filename)) { if (bpf_prog_load_xattr(&prog_load_attr, &obj, &prog_fd))
fprintf(stderr, "ERROR: load_bpf_file %s\n", bpf_log_buf); exit(EXIT_FAILURE);
if (prog_fd < 0) {
fprintf(stderr, "ERROR: no program found: %s\n",
strerror(prog_fd));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!prog_fd[0]) { map = bpf_object__find_map_by_name(obj, "qidconf_map");
fprintf(stderr, "ERROR: load_bpf_file: \"%s\"\n", qidconf_map = bpf_map__fd(map);
strerror(errno)); if (qidconf_map < 0) {
fprintf(stderr, "ERROR: no qidconf map found: %s\n",
strerror(qidconf_map));
exit(EXIT_FAILURE);
}
map = bpf_object__find_map_by_name(obj, "xsks_map");
xsks_map = bpf_map__fd(map);
if (xsks_map < 0) {
fprintf(stderr, "ERROR: no xsks map found: %s\n",
strerror(xsks_map));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (bpf_set_link_xdp_fd(opt_ifindex, prog_fd[0], opt_xdp_flags) < 0) { if (bpf_set_link_xdp_fd(opt_ifindex, prog_fd, opt_xdp_flags) < 0) {
fprintf(stderr, "ERROR: link set xdp fd failed\n"); fprintf(stderr, "ERROR: link set xdp fd failed\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ret = bpf_map_update_elem(map_fd[0], &key, &opt_queue, 0); ret = bpf_map_update_elem(qidconf_map, &key, &opt_queue, 0);
if (ret) { if (ret) {
fprintf(stderr, "ERROR: bpf_map_update_elem qidconf\n"); fprintf(stderr, "ERROR: bpf_map_update_elem qidconf\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -938,7 +958,7 @@ int main(int argc, char **argv) ...@@ -938,7 +958,7 @@ int main(int argc, char **argv)
/* ...and insert them into the map. */ /* ...and insert them into the map. */
for (i = 0; i < num_socks; i++) { for (i = 0; i < num_socks; i++) {
key = i; key = i;
ret = bpf_map_update_elem(map_fd[1], &key, &xsks[i]->sfd, 0); ret = bpf_map_update_elem(xsks_map, &key, &xsks[i]->sfd, 0);
if (ret) { if (ret) {
fprintf(stderr, "ERROR: bpf_map_update_elem %d\n", i); fprintf(stderr, "ERROR: bpf_map_update_elem %d\n", i);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
......
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