Commit 2fd206d4 authored by Daniel Borkmann's avatar Daniel Borkmann

Merge branch 'bpf-bpftool-misc-fixes'

Jakub Kicinski says:

====================
This series addresses small issues that snuck through the review
of cgroup code.  "list" and "show" are now made aliases to satisfy
all users.  Small fix to errors printed is needed, errors can't
contain new line characters, otherwise JSON will break.
====================
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
parents 5620e1a8 b4fac96d
...@@ -15,12 +15,12 @@ SYNOPSIS ...@@ -15,12 +15,12 @@ SYNOPSIS
*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } } *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
*COMMANDS* := *COMMANDS* :=
{ **list** | **attach** | **detach** | **help** } { **show** | **list** | **attach** | **detach** | **help** }
MAP COMMANDS MAP COMMANDS
============= =============
| **bpftool** **cgroup list** *CGROUP* | **bpftool** **cgroup { show | list }** *CGROUP*
| **bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*] | **bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
| **bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG* | **bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
| **bpftool** **cgroup help** | **bpftool** **cgroup help**
...@@ -31,7 +31,7 @@ MAP COMMANDS ...@@ -31,7 +31,7 @@ MAP COMMANDS
DESCRIPTION DESCRIPTION
=========== ===========
**bpftool cgroup list** *CGROUP* **bpftool cgroup { show | list }** *CGROUP*
List all programs attached to the cgroup *CGROUP*. List all programs attached to the cgroup *CGROUP*.
Output will start with program ID followed by attach type, Output will start with program ID followed by attach type,
......
...@@ -15,13 +15,13 @@ SYNOPSIS ...@@ -15,13 +15,13 @@ SYNOPSIS
*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } } *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
*COMMANDS* := *COMMANDS* :=
{ **show** | **dump** | **update** | **lookup** | **getnext** | **delete** { **show** | **list** | **dump** | **update** | **lookup** | **getnext** | **delete**
| **pin** | **help** } | **pin** | **help** }
MAP COMMANDS MAP COMMANDS
============= =============
| **bpftool** **map show** [*MAP*] | **bpftool** **map { show | list }** [*MAP*]
| **bpftool** **map dump** *MAP* | **bpftool** **map dump** *MAP*
| **bpftool** **map update** *MAP* **key** *BYTES* **value** *VALUE* [*UPDATE_FLAGS*] | **bpftool** **map update** *MAP* **key** *BYTES* **value** *VALUE* [*UPDATE_FLAGS*]
| **bpftool** **map lookup** *MAP* **key** *BYTES* | **bpftool** **map lookup** *MAP* **key** *BYTES*
...@@ -36,7 +36,7 @@ MAP COMMANDS ...@@ -36,7 +36,7 @@ MAP COMMANDS
DESCRIPTION DESCRIPTION
=========== ===========
**bpftool map show** [*MAP*] **bpftool map { show | list }** [*MAP*]
Show information about loaded maps. If *MAP* is specified Show information about loaded maps. If *MAP* is specified
show information only about given map, otherwise list all show information only about given map, otherwise list all
maps currently loaded on the system. maps currently loaded on the system.
......
...@@ -15,12 +15,12 @@ SYNOPSIS ...@@ -15,12 +15,12 @@ SYNOPSIS
*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } } *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
*COMMANDS* := *COMMANDS* :=
{ **show** | **dump xlated** | **dump jited** | **pin** | **load** | **help** } { **show** | **list** | **dump xlated** | **dump jited** | **pin** | **load** | **help** }
MAP COMMANDS MAP COMMANDS
============= =============
| **bpftool** **prog show** [*PROG*] | **bpftool** **prog { show | list }** [*PROG*]
| **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes**}] | **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes**}]
| **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}] | **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}]
| **bpftool** **prog pin** *PROG* *FILE* | **bpftool** **prog pin** *PROG* *FILE*
...@@ -31,7 +31,7 @@ MAP COMMANDS ...@@ -31,7 +31,7 @@ MAP COMMANDS
DESCRIPTION DESCRIPTION
=========== ===========
**bpftool prog show** [*PROG*] **bpftool prog { show | list }** [*PROG*]
Show information about loaded programs. If *PROG* is Show information about loaded programs. If *PROG* is
specified show information only about given program, otherwise specified show information only about given program, otherwise
list all programs currently loaded on the system. list all programs currently loaded on the system.
......
...@@ -22,13 +22,13 @@ SYNOPSIS ...@@ -22,13 +22,13 @@ SYNOPSIS
| { **-j** | **--json** } [{ **-p** | **--pretty** }] } | { **-j** | **--json** } [{ **-p** | **--pretty** }] }
*MAP-COMMANDS* := *MAP-COMMANDS* :=
{ **show** | **dump** | **update** | **lookup** | **getnext** | **delete** { **show** | **list** | **dump** | **update** | **lookup** | **getnext** | **delete**
| **pin** | **help** } | **pin** | **help** }
*PROG-COMMANDS* := { **show** | **dump jited** | **dump xlated** | **pin** *PROG-COMMANDS* := { **show** | **list** | **dump jited** | **dump xlated** | **pin**
| **load** | **help** } | **load** | **help** }
*CGROUP-COMMANDS* := { **list** | **attach** | **detach** | **help** } *CGROUP-COMMANDS* := { **show** | **list** | **attach** | **detach** | **help** }
DESCRIPTION DESCRIPTION
=========== ===========
......
...@@ -197,7 +197,7 @@ _bpftool() ...@@ -197,7 +197,7 @@ _bpftool()
local PROG_TYPE='id pinned tag' local PROG_TYPE='id pinned tag'
case $command in case $command in
show) show|list)
[[ $prev != "$command" ]] && return 0 [[ $prev != "$command" ]] && return 0
COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$PROG_TYPE" -- "$cur" ) )
return 0 return 0
...@@ -232,7 +232,7 @@ _bpftool() ...@@ -232,7 +232,7 @@ _bpftool()
;; ;;
*) *)
[[ $prev == $object ]] && \ [[ $prev == $object ]] && \
COMPREPLY=( $( compgen -W 'dump help pin show' -- \ COMPREPLY=( $( compgen -W 'dump help pin show list' -- \
"$cur" ) ) "$cur" ) )
;; ;;
esac esac
...@@ -240,7 +240,7 @@ _bpftool() ...@@ -240,7 +240,7 @@ _bpftool()
map) map)
local MAP_TYPE='id pinned' local MAP_TYPE='id pinned'
case $command in case $command in
show|dump) show|list|dump)
case $prev in case $prev in
$command) $command)
COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) ) COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
...@@ -343,7 +343,7 @@ _bpftool() ...@@ -343,7 +343,7 @@ _bpftool()
*) *)
[[ $prev == $object ]] && \ [[ $prev == $object ]] && \
COMPREPLY=( $( compgen -W 'delete dump getnext help \ COMPREPLY=( $( compgen -W 'delete dump getnext help \
lookup pin show update' -- "$cur" ) ) lookup pin show list update' -- "$cur" ) )
;; ;;
esac esac
;; ;;
......
...@@ -41,7 +41,7 @@ static enum bpf_attach_type parse_attach_type(const char *str) ...@@ -41,7 +41,7 @@ static enum bpf_attach_type parse_attach_type(const char *str)
return __MAX_BPF_ATTACH_TYPE; return __MAX_BPF_ATTACH_TYPE;
} }
static int list_bpf_prog(int id, const char *attach_type_str, static int show_bpf_prog(int id, const char *attach_type_str,
const char *attach_flags_str) const char *attach_flags_str)
{ {
struct bpf_prog_info info = {}; struct bpf_prog_info info = {};
...@@ -77,7 +77,7 @@ static int list_bpf_prog(int id, const char *attach_type_str, ...@@ -77,7 +77,7 @@ static int list_bpf_prog(int id, const char *attach_type_str,
return 0; return 0;
} }
static int list_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type) static int show_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type)
{ {
__u32 prog_ids[1024] = {0}; __u32 prog_ids[1024] = {0};
char *attach_flags_str; char *attach_flags_str;
...@@ -111,29 +111,29 @@ static int list_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type) ...@@ -111,29 +111,29 @@ static int list_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type)
} }
for (iter = 0; iter < prog_cnt; iter++) for (iter = 0; iter < prog_cnt; iter++)
list_bpf_prog(prog_ids[iter], attach_type_strings[type], show_bpf_prog(prog_ids[iter], attach_type_strings[type],
attach_flags_str); attach_flags_str);
return 0; return 0;
} }
static int do_list(int argc, char **argv) static int do_show(int argc, char **argv)
{ {
enum bpf_attach_type type; enum bpf_attach_type type;
int cgroup_fd; int cgroup_fd;
int ret = -1; int ret = -1;
if (argc < 1) { if (argc < 1) {
p_err("too few parameters for cgroup list\n"); p_err("too few parameters for cgroup show");
goto exit; goto exit;
} else if (argc > 1) { } else if (argc > 1) {
p_err("too many parameters for cgroup list\n"); p_err("too many parameters for cgroup show");
goto exit; goto exit;
} }
cgroup_fd = open(argv[0], O_RDONLY); cgroup_fd = open(argv[0], O_RDONLY);
if (cgroup_fd < 0) { if (cgroup_fd < 0) {
p_err("can't open cgroup %s\n", argv[1]); p_err("can't open cgroup %s", argv[1]);
goto exit; goto exit;
} }
...@@ -147,10 +147,10 @@ static int do_list(int argc, char **argv) ...@@ -147,10 +147,10 @@ static int do_list(int argc, char **argv)
/* /*
* Not all attach types may be supported, so it's expected, * Not all attach types may be supported, so it's expected,
* that some requests will fail. * that some requests will fail.
* If we were able to get the list for at least one * If we were able to get the show for at least one
* attach type, let's return 0. * attach type, let's return 0.
*/ */
if (list_attached_bpf_progs(cgroup_fd, type) == 0) if (show_attached_bpf_progs(cgroup_fd, type) == 0)
ret = 0; ret = 0;
} }
...@@ -171,19 +171,19 @@ static int do_attach(int argc, char **argv) ...@@ -171,19 +171,19 @@ static int do_attach(int argc, char **argv)
int i; int i;
if (argc < 4) { if (argc < 4) {
p_err("too few parameters for cgroup attach\n"); p_err("too few parameters for cgroup attach");
goto exit; goto exit;
} }
cgroup_fd = open(argv[0], O_RDONLY); cgroup_fd = open(argv[0], O_RDONLY);
if (cgroup_fd < 0) { if (cgroup_fd < 0) {
p_err("can't open cgroup %s\n", argv[1]); p_err("can't open cgroup %s", argv[1]);
goto exit; goto exit;
} }
attach_type = parse_attach_type(argv[1]); attach_type = parse_attach_type(argv[1]);
if (attach_type == __MAX_BPF_ATTACH_TYPE) { if (attach_type == __MAX_BPF_ATTACH_TYPE) {
p_err("invalid attach type\n"); p_err("invalid attach type");
goto exit_cgroup; goto exit_cgroup;
} }
...@@ -199,7 +199,7 @@ static int do_attach(int argc, char **argv) ...@@ -199,7 +199,7 @@ static int do_attach(int argc, char **argv)
} else if (is_prefix(argv[i], "override")) { } else if (is_prefix(argv[i], "override")) {
attach_flags |= BPF_F_ALLOW_OVERRIDE; attach_flags |= BPF_F_ALLOW_OVERRIDE;
} else { } else {
p_err("unknown option: %s\n", argv[i]); p_err("unknown option: %s", argv[i]);
goto exit_cgroup; goto exit_cgroup;
} }
} }
...@@ -229,13 +229,13 @@ static int do_detach(int argc, char **argv) ...@@ -229,13 +229,13 @@ static int do_detach(int argc, char **argv)
int ret = -1; int ret = -1;
if (argc < 4) { if (argc < 4) {
p_err("too few parameters for cgroup detach\n"); p_err("too few parameters for cgroup detach");
goto exit; goto exit;
} }
cgroup_fd = open(argv[0], O_RDONLY); cgroup_fd = open(argv[0], O_RDONLY);
if (cgroup_fd < 0) { if (cgroup_fd < 0) {
p_err("can't open cgroup %s\n", argv[1]); p_err("can't open cgroup %s", argv[1]);
goto exit; goto exit;
} }
...@@ -277,7 +277,7 @@ static int do_help(int argc, char **argv) ...@@ -277,7 +277,7 @@ static int do_help(int argc, char **argv)
} }
fprintf(stderr, fprintf(stderr,
"Usage: %s %s list CGROUP\n" "Usage: %s %s { show | list } CGROUP\n"
" %s %s attach CGROUP ATTACH_TYPE PROG [ATTACH_FLAGS]\n" " %s %s attach CGROUP ATTACH_TYPE PROG [ATTACH_FLAGS]\n"
" %s %s detach CGROUP ATTACH_TYPE PROG\n" " %s %s detach CGROUP ATTACH_TYPE PROG\n"
" %s %s help\n" " %s %s help\n"
...@@ -294,7 +294,8 @@ static int do_help(int argc, char **argv) ...@@ -294,7 +294,8 @@ static int do_help(int argc, char **argv)
} }
static const struct cmd cmds[] = { static const struct cmd cmds[] = {
{ "list", do_list }, { "show", do_show },
{ "list", do_show },
{ "attach", do_attach }, { "attach", do_attach },
{ "detach", do_detach }, { "detach", do_detach },
{ "help", do_help }, { "help", do_help },
......
...@@ -861,7 +861,7 @@ static int do_help(int argc, char **argv) ...@@ -861,7 +861,7 @@ static int do_help(int argc, char **argv)
} }
fprintf(stderr, fprintf(stderr,
"Usage: %s %s show [MAP]\n" "Usage: %s %s { show | list } [MAP]\n"
" %s %s dump MAP\n" " %s %s dump MAP\n"
" %s %s update MAP key BYTES value VALUE [UPDATE_FLAGS]\n" " %s %s update MAP key BYTES value VALUE [UPDATE_FLAGS]\n"
" %s %s lookup MAP key BYTES\n" " %s %s lookup MAP key BYTES\n"
...@@ -885,6 +885,7 @@ static int do_help(int argc, char **argv) ...@@ -885,6 +885,7 @@ static int do_help(int argc, char **argv)
static const struct cmd cmds[] = { static const struct cmd cmds[] = {
{ "show", do_show }, { "show", do_show },
{ "list", do_show },
{ "help", do_help }, { "help", do_help },
{ "dump", do_dump }, { "dump", do_dump },
{ "update", do_update }, { "update", do_update },
......
...@@ -813,12 +813,12 @@ static int do_load(int argc, char **argv) ...@@ -813,12 +813,12 @@ static int do_load(int argc, char **argv)
usage(); usage();
if (bpf_prog_load(argv[0], BPF_PROG_TYPE_UNSPEC, &obj, &prog_fd)) { if (bpf_prog_load(argv[0], BPF_PROG_TYPE_UNSPEC, &obj, &prog_fd)) {
p_err("failed to load program\n"); p_err("failed to load program");
return -1; return -1;
} }
if (do_pin_fd(prog_fd, argv[1])) { if (do_pin_fd(prog_fd, argv[1])) {
p_err("failed to pin program\n"); p_err("failed to pin program");
return -1; return -1;
} }
...@@ -836,7 +836,7 @@ static int do_help(int argc, char **argv) ...@@ -836,7 +836,7 @@ static int do_help(int argc, char **argv)
} }
fprintf(stderr, fprintf(stderr,
"Usage: %s %s show [PROG]\n" "Usage: %s %s { show | list } [PROG]\n"
" %s %s dump xlated PROG [{ file FILE | opcodes }]\n" " %s %s dump xlated PROG [{ file FILE | opcodes }]\n"
" %s %s dump jited PROG [{ file FILE | opcodes }]\n" " %s %s dump jited PROG [{ file FILE | opcodes }]\n"
" %s %s pin PROG FILE\n" " %s %s pin PROG FILE\n"
...@@ -854,6 +854,7 @@ static int do_help(int argc, char **argv) ...@@ -854,6 +854,7 @@ static int do_help(int argc, char **argv)
static const struct cmd cmds[] = { static const struct cmd cmds[] = {
{ "show", do_show }, { "show", do_show },
{ "list", do_show },
{ "help", do_help }, { "help", do_help },
{ "dump", do_dump }, { "dump", do_dump },
{ "pin", do_pin }, { "pin", do_pin },
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment