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: 11801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp237075wru; Thu, 27 Oct 2022 06:40:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4wTzFmtCn/Rdm2c2EMP9dKnPyMS/0mKvX+tj5tSWFBNUKbdkxO4Ym0BD7oerzS/GME9Is8 X-Received: by 2002:a63:88c8:0:b0:46f:1e8d:ece9 with SMTP id l191-20020a6388c8000000b0046f1e8dece9mr6106553pgd.249.1666878013284; Thu, 27 Oct 2022 06:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666878013; cv=none; d=google.com; s=arc-20160816; b=gkmLzvh4qk01G2Gu66QofhZ5mHmNsTyCf7Qt6T729dWSWtAD7t2L4xaAHo2G1JkqX9 lcf75m2jY+ScLVzzNXGlP6abuDepiDinlIOpWNGF36iWBRoHfigH8tKRmNMQ5fF+TV7Z 7MhneLUTcj2jBGJ7r6SY5sVZIJrfPRnBaiuyUk7fmUNGcIRO2N453yLpZXOv664bkGrY UiBiv6NjReIejm3ocrGn/lKE+4PGe9zcWprSmiqMeyfYV/b2kER93gMONmGvOen+5q6g aeFBZakMr8nGhWVIfppvKwCJA0mMYuWoKng4peHhL+2vdlt2AxMaosvjsbMDLLg5nC3X Y2RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:date:subject:cc:from:message-id :dkim-signature; bh=GjdxY+5+AWezFVXzHMoHNfEQigyrPEi9AWt7c8Do1xI=; b=PKFzK/UYP9wlh9+2WrbeD1Vn5ZDAg7FiZsEmEq6IVAif8RGstDJtJLMc/+xQxb26yc P/+rtJBq2uruAKm17NNix2IX9KavHwUYEXpxN7UM3Tr+KdEOrJU9AAoA8eUctw1zmly9 TFezT3+6l/3lzpfXXC3V6G2cWxZ5Z/cFYOPi4xzy8QdlM/98dO5Z9N2ApLqeNnPFGr/H om3gFTSh2KYGR7eY2szXxyDqExItxJ+3TPbtcSRftbRrPDezMoRlGIfQtsGBZrgw5dqN 05d2CTe2nCmJ6TatA5TGHHS7xO0262BSICtzrT09OUKNgEbukhEtIHDoEX27lkQbFcJJ bJIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@foxmail.com header.s=s201512 header.b="SNo/maKr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y10-20020a655b0a000000b0043a345c81edsi1516141pgq.836.2022.10.27.06.40.00; Thu, 27 Oct 2022 06:40:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=fail header.i=@foxmail.com header.s=s201512 header.b="SNo/maKr"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=foxmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236240AbiJ0Nii (ORCPT + 99 others); Thu, 27 Oct 2022 09:38:38 -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: xmsmtpt1666877902ta2m04jj8 Message-ID: X-QQ-XMAILINFO: Mm/8i8/T4yneTH87S8NiHWlXuaRzKgvN5M8NHOgZB5GzvA3VGBGMgX+8haIDr1 BNsIp8NI/v/wgxjzXeqxJJ6ip+m71oC18O1UPWrmtyFonQ/pbM7oxfdCnMcabTfq02QOqWiZUKdY 7zMWzAshYIcGimYlaWK8JlkU/kNt74M+c/ijVrWKf3of3UWeCm4LikrSZw5dBJvwCu9U5iHsIGj5 AnVK4yMV4RmnoVSxL8NIvtuVEGY3dgs4biT2TxN4HwS/5orLp8M7Bpn4YJHrtyIqJ2TUDbIfLAFQ 5EDmsqwWB5pA8lA5nvnPdQQrztZPXy1WSV8jZ/4qArWvThUI8QS18pY95QaTWUzWpHJIf9b0Evvx 1Jc2eNnt2YoEzMWKL7S6PuzagwjK37N70uCoDbAfbuu2sc5cTnLCUkOVeXunb9PGZ2ROVInIM2NH k4647QzjOYW1wXtXisCo3nqj30FIbsx5KqH2D42Q2zajUO6cGc//0go9qGMBgIZKbitkO45zGwsQ ymVHJrrU3NmKN/pvRyh3aCGdYJcveVE4Nq/0RWiLsGM0O9BcPkQv4sGs/aNALLGUCiUnPJpc+HVO oJZOtzyM2tQRPEqJGgGznWTbxreouJepVrEehW/Kx9vW0n7Eu34x6DpxWBRthDmpFlgOI5OZJEFF QdITi4Q62RToNOIuCvwtd1zHeUVplAvoBqAYJvb3sWekF3xjPtLG19zuEas3dmNmt/NyGa+jb4me hIptZhwu/hvLwPdH6IySJ/AqjxGlWz1pApmDuwhnXR+epXNPaykEwgsg7jOn/a8jdLukD4/pp6Zb Iior9A+HxWYWB555B8MczkHG96/gKe+kRrtocobyiWLVw98MniVUrP23lmcXYp/pnimuIVZjn0J4 xHeSrMq6qh8g3HPI7U9gU4NHvnMPxMJRM+s5UwNCEDhBscG3m8VmwgoVuy7ygnozU02W9nSRfT61 fXSzC1ZbMhqGvHIO5H21FTzl0nPuAY6piroi2rGPbJLqFPVTjxN9e3Z9/IWYqddNt5BkOiQnwYSL 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 X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, HELO_DYNAMIC_IPADDR,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,RDNS_DYNAMIC, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747848015234667972?= X-GMAIL-MSGID: =?utf-8?q?1747848279461331715?= 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);