public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: sdf@google.com
To: Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Quentin Monnet <quentin@isovalent.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>,
	bpf@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/2] bpftool: Use strcmp() instead of is_prefix() to check parameters
Date: Mon, 14 Nov 2022 09:25:21 -0800	[thread overview]
Message-ID: <Y3J6AXOFcoGg7p8/@google.com> (raw)
In-Reply-To: <1668396484-4596-2-git-send-email-yangtiezhu@loongson.cn>

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


  reply	other threads:[~2022-11-14 17:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-14  3:28 [PATCH bpf-next 0/2] Some small changes about bpftool Tiezhu Yang
2022-11-14  3:28 ` [PATCH bpf-next 1/2] bpftool: Use strcmp() instead of is_prefix() to check parameters Tiezhu Yang
2022-11-14 17:25   ` sdf [this message]
2022-11-14 20:45     ` Quentin Monnet
2022-11-14  3:28 ` [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch() Tiezhu Yang
2022-11-14 17:30   ` sdf
2022-11-14 20:53     ` Quentin Monnet

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y3J6AXOFcoGg7p8/@google.com \
    --to=sdf@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=quentin@isovalent.com \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox