Message ID | 1668396484-4596-2-git-send-email-yangtiezhu@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> 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 <rfc822;winker.wchi@gmail.com> + 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <yangtiezhu@loongson.cn> To: Quentin Monnet <quentin@isovalent.com>, Alexei Starovoitov <ast@kernel.org>, Daniel Borkmann <daniel@iogearbox.net>, Andrii Nakryiko <andrii@kernel.org> 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: <linux-kernel.vger.kernel.org> 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?= |
Series |
Some small changes about bpftool
|
|
Commit Message
Tiezhu Yang
Nov. 14, 2022, 3:28 a.m. UTC
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 <yangtiezhu@loongson.cn>
---
tools/bpf/bpftool/main.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On 11/14, Tiezhu Yang wrote: > 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. That's by design and is similar to what iproute2 commands are doing. > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > --- > 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) { > -- > 2.1.0
On Mon, 14 Nov 2022 at 17:25, <sdf@google.com> wrote: > > On 11/14, Tiezhu Yang wrote: > > 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. > > That's by design and is similar to what iproute2 commands are doing. Agreed with Stanislav, all bpftool commands support argument prefixing and it's helpful, I see no reason to remove it for the batch command. But thanks anyway for reporting
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) {