public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] samples/bpf: Fix sockex3: missing BPF prog type
@ 2022-10-27 13:33 Rong Tao
  2022-10-27 13:38 ` [PATCH bpf-next] " Rong Tao
  0 siblings, 1 reply; 12+ messages in thread
From: Rong Tao @ 2022-10-27 13:33 UTC (permalink / raw)
  Cc: Rong Tao, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
	open list:BPF [GENERAL] (Safe Dynamic Programs and Tools),
	open list

From: Rong Tao <rongtao@cestc.cn>

since commit 450b167fb9be("libbpf: clean up SEC() handling"),
sec_def_matches() does not recognize "socket/xxx" as "socket", therefore,
the BPF program type is not recognized, we should add a custom program
type handler for "socket/xxx".

 $ cd samples/bpf
 $ sudo ./sockex3
 libbpf: prog 'bpf_func_PARSE_IP': missing BPF prog type, check ELF section name 'socket/3'
 libbpf: prog 'bpf_func_PARSE_IP': failed to load: -22
 libbpf: failed to load object './sockex3_kern.o'
 ERROR: loading BPF object file failed

Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
 samples/bpf/sockex3_user.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/samples/bpf/sockex3_user.c b/samples/bpf/sockex3_user.c
index cd6fa79df900..d18d7a3600b0 100644
--- a/samples/bpf/sockex3_user.c
+++ b/samples/bpf/sockex3_user.c
@@ -22,6 +22,14 @@ struct pair {
 	__u64 bytes;
 };
 
+static int socket_prog_type_id;
+
+__attribute__((destructor))
+static void unregister_socket_sec_handlers(void)
+{
+	libbpf_unregister_prog_handler(socket_prog_type_id);
+}
+
 int main(int argc, char **argv)
 {
 	int i, sock, key, fd, main_prog_fd, jmp_table_fd, hash_map_fd;
@@ -31,6 +39,13 @@ int main(int argc, char **argv)
 	char filename[256];
 	FILE *f;
 
+	LIBBPF_OPTS(libbpf_prog_handler_opts, socket_opts,
+		.cookie = 1,
+	);
+
+	socket_prog_type_id = libbpf_register_prog_handler("socket/",
+			BPF_PROG_TYPE_SOCKET_FILTER, 0, &socket_opts);
+
 	snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
 
 	obj = bpf_object__open_file(filename, NULL);
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2022-11-08  1:20 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-27 13:33 [PATCH] samples/bpf: Fix sockex3: missing BPF prog type Rong Tao
2022-10-27 13:38 ` [PATCH bpf-next] " Rong Tao
2022-10-27 20:15   ` Andrii Nakryiko
2022-10-28  1:01     ` [PATCH] " Rong Tao
2022-10-28 17:09       ` Andrii Nakryiko
2022-10-29  7:53         ` [PATCH bpf-next] " Rong Tao
2022-11-03 18:38           ` Andrii Nakryiko
2022-11-04  3:17             ` Rong Tao
2022-11-04 22:53               ` Andrii Nakryiko
2022-11-05  6:48                 ` [PATCH bpf-next] samples/bpf: Fix sockex3 error: " Rong Tao
2022-11-08  1:14                   ` Andrii Nakryiko
2022-11-08  1:20                   ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox