From patchwork Mon Nov 14 03:28:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 19533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1941803wru; Sun, 13 Nov 2022 19:31:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf7nceGxTWyjrYKNZy9w6eNjoi40YOQfeGzbsKJ+//i4LxbF+eqIu2mt83u6btwApWBlg0m0 X-Received: by 2002:a17:906:51a:b0:78d:b3ef:656c with SMTP id j26-20020a170906051a00b0078db3ef656cmr8404405eja.627.1668396692461; Sun, 13 Nov 2022 19:31:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668396692; cv=none; d=google.com; s=arc-20160816; b=BQrm3+/P32E3ZQLTI7E+kifeFEGrX74FwZLhr7ThDbUXlNfseKvieu7LHkdVLhwU5a Q0pTVuaEATVV5N4XK9qCtTe1a5snOYFLDiExAJ5IkuWzTSm0ef2Lm0nTov72lNM0TuGv 24m3B7VEcBKZfLanzDk41/fHKutoibAAbIdOJz+MFQD/etSJRxq9VtF+DnbxaEZvxb3v glylhJMw3w+q5haKOPhdgR99oCiPVqBSmBVhO81vaMOb1hRa8KyljbWuS9ybItUl2+dN EG6QWYfz7YjQatBBj0d5XM+HJ4mfKwyPGinPwV5w5UWFdFzRwWN2aw7ou28D1iSoCehp S0vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=+fWPG777ZMQQxb9afbiDX0t80vVCPSsk95PAgFZDPK4=; b=EnqABoyVUFE2VuxRe8rWkeQkvKGY4lziEZBF9Irw1murEYRZqnJfrGphVSZNUB43Ea Y30BVFf2PhJtsh2I0/IX5Wxb9nC3bqHF86+8VTeH4ZoYMxeLI1eFLPY8XYCeme2PBYA5 SMFSfMZTShnwv6oez1ZKX1xg/8tcCkDt1zEb5lphQKR6Yfgk+rpgYQyPRabNjPQKMY9D OLsKvyK/ownSJJWbD9YZfpN/JAl5mWkDzjPx50kzEG6Q2em3RDklbW4BoGrchlDgeSJP lvmm99a1Dm0Av4t2AR0XYvZavzp4qLBAK4c5NhffGczr8pP+XFnIADdTHqnTjlTzy4Z3 Yy7g== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs12-20020a170906dc8c00b007af041e40b4si1099380ejc.129.2022.11.13.19.31.09; Sun, 13 Nov 2022 19:31:32 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235615AbiKND2K (ORCPT + 99 others); Sun, 13 Nov 2022 22:28:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235338AbiKND2J (ORCPT ); Sun, 13 Nov 2022 22:28:09 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9E812DECF; Sun, 13 Nov 2022 19:28:07 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Dxu9jGtXFj0skGAA--.20398S3; Mon, 14 Nov 2022 11:28:06 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxn+DFtXFj3j0SAA--.49444S3; Mon, 14 Nov 2022 11:28:05 +0800 (CST) From: Tiezhu Yang To: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 1/2] bpftool: Use strcmp() instead of is_prefix() to check parameters Date: Mon, 14 Nov 2022 11:28:03 +0800 Message-Id: <1668396484-4596-2-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1668396484-4596-1-git-send-email-yangtiezhu@loongson.cn> References: <1668396484-4596-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf8Cxn+DFtXFj3j0SAA--.49444S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvdXoWrZrW3AF1DuFWUWr1xZrWUurg_yoWktwc_WF ZxXrnavrZ5Jry7CFW09398uFy8Ka15X3Z7Cw4avr15AFW8Xay7Ar48Ca95Z3y5ZFyqv3Wa yF9xZr1fGF47CjkaLaAFLSUrUUUU1b8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUY g7kC6x804xWl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3w AFIxvE14AKwVWUXVWUAwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK 6xIIjxv20xvE14v26r4j6ryUM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7 xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJwAa w2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JF0_Jw1lYx0Ex4A2 jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20x vY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s02 6c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF 0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvE c7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14 v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvfC2KfnxnUUI43ZEXa7I U8q2NtUUUUU== X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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?1749440730060453593?= X-GMAIL-MSGID: =?utf-8?q?1749440730060453593?= In the current code, the parameters check of bpftool seems not correct, for example, "bpftool batch file FILE" is the expected command format, but "bpftool b f FILE" is recognized as valid, so use strcmp() instead of is_prefix() to check parameters. Signed-off-by: Tiezhu Yang --- tools/bpf/bpftool/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c index 741e50e..4ef87c2 100644 --- a/tools/bpf/bpftool/main.c +++ b/tools/bpf/bpftool/main.c @@ -200,7 +200,7 @@ int cmd_select(const struct cmd *cmds, int argc, char **argv, return cmds[0].func(argc, argv); for (i = 0; cmds[i].cmd; i++) { - if (is_prefix(*argv, cmds[i].cmd)) { + if (!strcmp(*argv, cmds[i].cmd)) { if (!cmds[i].func) { p_err("command '%s' is not supported in bootstrap mode", cmds[i].cmd); @@ -337,7 +337,7 @@ static int do_batch(int argc, char **argv) if (argc < 2) { p_err("too few parameters for batch"); return -1; - } else if (!is_prefix(*argv, "file")) { + } else if (strcmp(*argv, "file")) { p_err("expected 'file', got: %s", *argv); return -1; } else if (argc > 2) { From patchwork Mon Nov 14 03:28:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tiezhu Yang X-Patchwork-Id: 19534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1942190wru; Sun, 13 Nov 2022 19:32:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf44j0QbCuWP/ehsd/vVKBy8ehLICctgjbykYOl2LTdw36SIfsoEFLrkUE3+6EbTfQVvtJS4 X-Received: by 2002:aa7:d4d3:0:b0:45f:b80f:1fe8 with SMTP id t19-20020aa7d4d3000000b0045fb80f1fe8mr9359479edr.118.1668396779340; Sun, 13 Nov 2022 19:32:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668396779; cv=none; d=google.com; s=arc-20160816; b=amrloIzVaAwYL7J4qyUW2fIuqNpMK41nsNob56yiHkOc8dQ/2U4b95XKdBzjuA6UZO TBf/8Um2S+NXN2ZPEPT0b29ibF6cevcAdsW+mHbafGmlntIVOfxsillRZg8h731tT5uJ 0PI9r5Ytg4FYGNp+HrmkZExx0PsiamCCN6iz5e1FSCes9XeIYhLIhUPdhUHrJAT92WSu TDGnLPcMuAqw6x/6lMqkyjqVixBV3/uLJwGDAlUNxDmdN/EPqT+1uU3cyYJAz2otUMd/ v5qIzlrYFvAZKHDukGKS1J3HO93uvD/uHX4wXlvA7D4DgiC/L7W5gxAc0/gcGrmDzfq6 ms2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=UMfVfqISYes1ncxJZwZDAPgvvqwpLd9XY/sYs6t9MSc=; b=YDnGSu0bTDLH6JhVBaFwVE7wSGCsSUvU4NDnisEwe0MK7/B7d8v5GzbIKlUGrzUgfx h1jelNXF6x+uMgN+zDRKIn/yObUcPkeD2Ja2W3biqUgokeEaI+E713bYMjEjAeLrCdRp GFkC37tgHtKt8JnZzvJnefuaZjwtEsVUh5w48bugVGIwbMFOnibmg/2f1m8ooKyOHVop vijfMHayDIgq/j+UcLI5sQF6SFZJE9EcJlOztzRHqny+UWk1ET826orYIbRfZKb3QNuG WJvV2ZHrIY6jld3Ap1fodxwE4LfhBPEC1yK1yzue8Qw/VgiKBdK+64pwO+5jAUFLZwLj jIlA== ARC-Authentication-Results: i=1; mx.google.com; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cs14-20020a170906dc8e00b007adf388f2dasi9093642ejc.497.2022.11.13.19.32.36; Sun, 13 Nov 2022 19:32:59 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235669AbiKND2Q (ORCPT + 99 others); Sun, 13 Nov 2022 22:28:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235376AbiKND2J (ORCPT ); Sun, 13 Nov 2022 22:28:09 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D4751DF5A; Sun, 13 Nov 2022 19:28:07 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Dx_7fGtXFj1skGAA--.18954S3; Mon, 14 Nov 2022 11:28:06 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8Cxn+DFtXFj3j0SAA--.49444S4; Mon, 14 Nov 2022 11:28:06 +0800 (CST) From: Tiezhu Yang To: Quentin Monnet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch() Date: Mon, 14 Nov 2022 11:28:04 +0800 Message-Id: <1668396484-4596-3-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1668396484-4596-1-git-send-email-yangtiezhu@loongson.cn> References: <1668396484-4596-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf8Cxn+DFtXFj3j0SAA--.49444S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvdXoW7Xr4xAF4xur1Utr4rKw4DJwb_yoWDGrg_Wa y3ZF1avFn5JryakF4UG398uryxKa18ZwsYqr4akr18JrW8Xw17AF48C395Xw45uFWqkw12 yFZ3uryfGF129jkaLaAFLSUrUUUU1b8apTn2vfkv8UJUUUU8wcxFpf9Il3svdxBIdaVrn0 xqx4xG64xvF2IEw4CE5I8CrVC2j2Jv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UUUY y7kC6x804xWl14x267AKxVWUJVW8JwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0rVWrJVCq3w AFIxvE14AKwVWUXVWUAwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK021l84ACjcxK 6xIIjxv20xvE14v26ryj6F1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4j6F4UM28EF7 xvwVC2z280aVAFwI0_Gr1j6F4UJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr1j6F4UJwAa w2AFwI0_Jrv_JF1le2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44 I27wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2 jsIE14v26r4j6F4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20x vY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwCFI7km07C267AKxVWUXVWUAwC20s02 6c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_JF 0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvE c7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14 v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x 07jz2NtUUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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?1749440821367812437?= X-GMAIL-MSGID: =?utf-8?q?1749440821367812437?= If the parameters for batch are more than 2, check argc first can return immediately, no need to use strcmp() to check "file" with a little overhead and then check argc, it is better to check "file" only when the parameters for batch are 2. Signed-off-by: Tiezhu Yang --- tools/bpf/bpftool/main.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/bpf/bpftool/main.c b/tools/bpf/bpftool/main.c index 4ef87c2..27d6dbf 100644 --- a/tools/bpf/bpftool/main.c +++ b/tools/bpf/bpftool/main.c @@ -337,12 +337,12 @@ static int do_batch(int argc, char **argv) if (argc < 2) { p_err("too few parameters for batch"); return -1; - } else if (strcmp(*argv, "file")) { - p_err("expected 'file', got: %s", *argv); - return -1; } else if (argc > 2) { p_err("too many parameters for batch"); return -1; + } else if (strcmp(*argv, "file")) { + p_err("expected 'file', got: %s", *argv); + return -1; } NEXT_ARG();