From patchwork Thu Oct 27 13:38:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 13022179 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 046F5FA3749 for ; Thu, 27 Oct 2022 13:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236204AbiJ0Nid (ORCPT ); Thu, 27 Oct 2022 09:38:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236208AbiJ0Nib (ORCPT ); Thu, 27 Oct 2022 09:38:31 -0400 Received: from out162-62-57-137.mail.qq.com (out162-62-57-137.mail.qq.com [162.62.57.137]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E45861814BB; Thu, 27 Oct 2022 06:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1666877906; bh=GjdxY+5+AWezFVXzHMoHNfEQigyrPEi9AWt7c8Do1xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=SNo/maKr//31FlJr19a9qQzO5O7G992c5+enWbmr4J+EP81rWOqflMSDBl8BJ1dPZ 8QkhrF3DUW66yqKIVqd6YmhbYvDOmYNnOe4We38mat6zUTs3xwCj7lYa9FhBt8tHfq Yr+L1/xwg7FdbxFEY5AH0xCaJqRbr2XPEruKfTVE= Received: from localhost.localdomain ([39.156.73.13]) by newxmesmtplogicsvrszc5-0.qq.com (NewEsmtp) with SMTP id 99635C94; Thu, 27 Oct 2022 21:38:22 +0800 X-QQ-mid: xmsmtpt1666877902ta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SL WYssK2WFuTsJzujmof From: Rong Tao 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 , bpf@vger.kernel.org (open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH bpf-next] samples/bpf: Fix sockex3: missing BPF prog type Date: Thu, 27 Oct 2022 21:38:20 +0800 X-OQ-MSGID: <20221027133820.82970-1-rtoax@foxmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Rong Tao 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 --- 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);