* [PATCH bpf-next 0/2] Some small changes about bpftool
@ 2022-11-14 3:28 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 3:28 ` [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch() Tiezhu Yang
0 siblings, 2 replies; 7+ messages in thread
From: Tiezhu Yang @ 2022-11-14 3:28 UTC (permalink / raw)
To: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko
Cc: bpf, linux-kernel
Tiezhu Yang (2):
bpftool: Use strcmp() instead of is_prefix() to check parameters
bpftool: Check argc first before "file" in do_batch()
tools/bpf/bpftool/main.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
--
2.1.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH bpf-next 1/2] bpftool: Use strcmp() instead of is_prefix() to check parameters
2022-11-14 3:28 [PATCH bpf-next 0/2] Some small changes about bpftool Tiezhu Yang
@ 2022-11-14 3:28 ` Tiezhu Yang
2022-11-14 17:25 ` sdf
2022-11-14 3:28 ` [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch() Tiezhu Yang
1 sibling, 1 reply; 7+ messages in thread
From: Tiezhu Yang @ 2022-11-14 3:28 UTC (permalink / raw)
To: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko
Cc: bpf, linux-kernel
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(-)
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
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch()
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 3:28 ` Tiezhu Yang
2022-11-14 17:30 ` sdf
1 sibling, 1 reply; 7+ messages in thread
From: Tiezhu Yang @ 2022-11-14 3:28 UTC (permalink / raw)
To: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko
Cc: bpf, linux-kernel
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 <yangtiezhu@loongson.cn>
---
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();
--
2.1.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 1/2] bpftool: Use strcmp() instead of is_prefix() to check parameters
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
2022-11-14 20:45 ` Quentin Monnet
0 siblings, 1 reply; 7+ messages in thread
From: sdf @ 2022-11-14 17:25 UTC (permalink / raw)
To: Tiezhu Yang
Cc: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, bpf, linux-kernel
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch()
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
0 siblings, 1 reply; 7+ messages in thread
From: sdf @ 2022-11-14 17:30 UTC (permalink / raw)
To: Tiezhu Yang
Cc: Quentin Monnet, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, bpf, linux-kernel
On 11/14, Tiezhu Yang wrote:
> 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.
Seems fine if you respin with is_prefix instead of strcmp.
Has the potential of breaking some buggy users which pass
more than one file, but I don't think it's a good justification
no to do the fix? Quentin?
> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> ---
> 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();
> --
> 2.1.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 1/2] bpftool: Use strcmp() instead of is_prefix() to check parameters
2022-11-14 17:25 ` sdf
@ 2022-11-14 20:45 ` Quentin Monnet
0 siblings, 0 replies; 7+ messages in thread
From: Quentin Monnet @ 2022-11-14 20:45 UTC (permalink / raw)
To: sdf
Cc: Tiezhu Yang, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
bpf, linux-kernel
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 2/2] bpftool: Check argc first before "file" in do_batch()
2022-11-14 17:30 ` sdf
@ 2022-11-14 20:53 ` Quentin Monnet
0 siblings, 0 replies; 7+ messages in thread
From: Quentin Monnet @ 2022-11-14 20:53 UTC (permalink / raw)
To: sdf
Cc: Tiezhu Yang, Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
bpf, linux-kernel
On Mon, 14 Nov 2022 at 17:30, <sdf@google.com> wrote:
>
> On 11/14, Tiezhu Yang wrote:
> > 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.
Thanks for the patch
> Seems fine if you respin with is_prefix instead of strcmp.
> Has the potential of breaking some buggy users which pass
> more than one file, but I don't think it's a good justification
> no to do the fix? Quentin?
I don't think it could break, the argc check is already enforced
(currently after the check on "file") and no more than one batch file
can be passed. I'm not sure it's super useful to swap the checks
either, because you can similarly argue that there's no need to check
argc is <= 2 if the first arg for "bpftool batch" is different from
"file" (or a prefix). The argc check is faster than the is_prefix()
comparison, but that's a minor optimization for one specific error
case. I don't really see the point, but I'm not opposed to the patch
either if you repost with is_prefix() as suggested by Stanislav.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-11-14 20:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox