From patchwork Thu Oct 27 13:33:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rong Tao X-Patchwork-Id: 13022163 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 94A66ECAAA1 for ; Thu, 27 Oct 2022 13:34:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236004AbiJ0NeI (ORCPT ); Thu, 27 Oct 2022 09:34:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234908AbiJ0NeH (ORCPT ); Thu, 27 Oct 2022 09:34:07 -0400 X-Greylist: delayed 7198 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 27 Oct 2022 06:34:04 PDT Received: from out162-62-57-64.mail.qq.com (out162-62-57-64.mail.qq.com [162.62.57.64]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90C0E119BE7; Thu, 27 Oct 2022 06:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1666877639; bh=GjdxY+5+AWezFVXzHMoHNfEQigyrPEi9AWt7c8Do1xI=; h=From:To:Cc:Subject:Date; b=dU1e0lJBoP77e+IOEtKjuNB0afhXZNc75K+MhlMQqaR4RpKLB8866iiw1xj8CHlWc xDOm/IV5UI2Yy8eIjL8LN6JXeD8YxDTFRtmTGYKpuPAO7b3mRSSkaaUU0/JbnIkSK7 1zDqCUCirOK3OstXLyFpKM3hIHeSzx14oB/MB41I= Received: from localhost.localdomain ([39.156.73.13]) by newxmesmtplogicsvrszb1-0.qq.com (New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3V4XVi1wdGnuCY9A+4qI33n8RF/xb2qpLd2f0rOy46ipyA== 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] samples/bpf: Fix sockex3: missing BPF prog type Date: Thu, 27 Oct 2022 21:33:54 +0800 X-OQ-MSGID: <20221027133354.82451-1-rtoax@foxmail.com> X-Mailer: git-send-email 2.31.1 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);