Thread (12 messages) flat view 12 messages, 5 authors, 2022-06-09
STALE1553d

[PATCH bpf-next 1/3] samples/bpf/xdpsock_user.c: Get rid of bpf_prog_load_xattr()

From: Hangbin Liu <hidden>
Date: 2022-06-07 08:40:41
Also in: bpf
Subsystem: bpf [general] (safe dynamic programs and tools), the rest, xdp (express data path) · Maintainers: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko, Eduard Zingerman, Kumar Kartikeya Dwivedi, Linus Torvalds, David S. Miller, Jakub Kicinski, Jesper Dangaard Brouer, John Fastabend

Commit 1e4edb6d8c4f ("samples/bpf: Get rid of bpf_prog_load_xattr()
use") tried to remove all the deprecated bpf_prog_load_xattr() API..
But xdpsock_user.c was left as it set GCC diagnostic ignored
"-Wdeprecated-declarations".

Signed-off-by: Hangbin Liu <redacted>
---
 samples/bpf/xdpsock_user.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/samples/bpf/xdpsock_user.c b/samples/bpf/xdpsock_user.c
index be7d2572e3e6..3ea46c300df2 100644
--- a/samples/bpf/xdpsock_user.c
+++ b/samples/bpf/xdpsock_user.c
@@ -1742,17 +1742,22 @@ static void l2fwd_all(void)
 
 static void load_xdp_program(char **argv, struct bpf_object **obj)
 {
-	struct bpf_prog_load_attr prog_load_attr = {
-		.prog_type      = BPF_PROG_TYPE_XDP,
-	};
+	struct bpf_program *prog;
 	char xdp_filename[256];
 	int prog_fd;
 
 	snprintf(xdp_filename, sizeof(xdp_filename), "%s_kern.o", argv[0]);
-	prog_load_attr.file = xdp_filename;
+	*obj = bpf_object__open_file(xdp_filename, NULL);
+	if (libbpf_get_error(*obj))
+		exit(EXIT_FAILURE);
 
-	if (bpf_prog_load_xattr(&prog_load_attr, obj, &prog_fd))
+	prog = bpf_object__next_program(*obj, NULL);
+	bpf_program__set_type(prog, BPF_PROG_TYPE_XDP);
+
+	if (bpf_object__load(*obj))
 		exit(EXIT_FAILURE);
+
+	prog_fd = bpf_program__fd(prog);
 	if (prog_fd < 0) {
 		fprintf(stderr, "ERROR: no program found: %s\n",
 			strerror(prog_fd));
@@ -1885,10 +1890,10 @@ int main(int argc, char **argv)
 {
 	struct __user_cap_header_struct hdr = { _LINUX_CAPABILITY_VERSION_3, 0 };
 	struct __user_cap_data_struct data[2] = { { 0 } };
+	struct bpf_object *obj = NULL;
 	bool rx = false, tx = false;
 	struct sched_param schparam;
 	struct xsk_umem_info *umem;
-	struct bpf_object *obj;
 	int xsks_map_fd = 0;
 	pthread_t pt;
 	int i, ret;
-- 
2.35.1
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help