bpftool: Add bpf_token show
Subsystems (4)
PATCH v3 1/3 bpftool: Add bpf_token show
Add bpftool token show command to get token info from bpffs in /proc/mounts.
Example plain output for token show:token_info /sys/fs/bpf/token
allowed_cmds:
map_create prog_load
allowed_maps:
allowed_progs:
kprobe
allowed_attachs:
xdptoken_info /sys/fs/bpf/token2
allowed_cmds:
map_create prog_load
allowed_maps:
allowed_progs:
kprobe
allowed_attachs:
xdp
Example json output for token show:
[{
"token_info": "/sys/fs/bpf/token",
"allowed_cmds": ["map_create", "prog_load"],
"allowed_maps": [],
"allowed_progs": ["kprobe"],
"allowed_attachs": ["xdp"]
}, {
"token_info": "/sys/fs/bpf/token2",
"allowed_cmds": ["map_create", "prog_load"],
"allowed_maps": [],
"allowed_progs": ["kprobe"],
"allowed_attachs": ["xdp"]
}]--- tools/bpf/bpftool/main.c | 3 +- tools/bpf/bpftool/main.h | 1 + tools/bpf/bpftool/token.c | 226 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 229 insertions(+), 1 deletion(-) create mode 100644 tools/bpf/bpftool/token.c
Change list:
v2 -> v3:
Quentin suggested:
- patch1
- remove print when token not found.
- patch2
- refactor description message.
- patch3
- update commit message.
v2: https://lore.kernel.org/bpf/[email protected]
https://lore.kernel.org/bpf/[email protected]
v1 -> v2:
Quentin suggested:
- patch1
- remove zclose macro.
- rename __json_array_str to split_json_array_str
- print empty array when value is null for json format.
- show all tokens info and format plain output for readable.
- add info when token not found.
- add copyright in token.c
- patch2
- update 'eBPF progs' to 'eBPF tokens'.
- update description.
- patch3
- add bash-completion.
v1: https://lore.kernel.org/bpf/[email protected]
tools/bpf/bpftool/main.c +2 -1
@@ -61,7 +61,7 @@ static int do_help(int argc, char **argv)" %s batch file FILE\n" " %s version\n" "\n" -" OBJECT := { prog | map | link | cgroup | perf | net | feature | btf | gen | struct_ops | iter }\n" +" OBJECT := { prog | map | link | cgroup | perf | net | feature | btf | gen | struct_ops | iter | token }\n" " " HELP_SPEC_OPTIONS " |\n" " {-V|--version} }\n" "",
@@ -87,6 +87,7 @@ static const struct cmd commands[] = { { "gen", do_gen }, { "struct_ops", do_struct_ops }, { "iter", do_iter }, + { "token", do_token }, { "version", do_version }, { 0 } };
tools/bpf/bpftool/main.h +1 -0
@@ -166,6 +166,7 @@ int do_tracelog(int argc, char **arg) __weak;int do_feature (int argc,char **argv)__weak ;int do_struct_ops (int argc,char **argv)__weak ;int do_iter (int argc,char **argv)__weak ; +int do_token (int argc,char **argv)__weak ;int parse_u32_arg (int *argc,char ***argv,__u32 *val,const char *what);int prog_parse_fd (int *argc,char ***argv);
tools/bpf/bpftool/token.c new file +226 -0
226 lines not on this page · raw message
Signature · 1 line
2.48.1
PATCH v3 2/3 bpftool: Add bpftool-token manpage
Add bpftool-token manpage with information and examples of token-related commands.
--- .../bpftool/Documentation/bpftool-token.rst | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tools/bpf/bpftool/Documentation/bpftool-token.rst
tools/bpf/bpftool/Documentation/bpftool-token.rst new file +64 -0
@@ -0,0 +1,64 @@ +.. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) + +================ +bpftool-token +================ +------------------------------------------------------------------------------- +tool for inspection and simple manipulation of eBPF tokens +------------------------------------------------------------------------------- + +:Manual section: 8 + +.. include:: substitutions.rst + +SYNOPSIS +======== + +**bpftool** [*OPTIONS*] **token** *COMMAND* + +*OPTIONS* := { |COMMON_OPTIONS| } + +*COMMANDS* := { **show** | **list** | **help** } + +TOKEN COMMANDS +=============== + +| **bpftool** **token** { **show** | **list** } +| **bpftool** **token help** +| + +DESCRIPTION +=========== +bpftool token { show | list } + List BPF token information for each *bpffs* mount point containing token + information on the system. Information include mount point path, allowed + **bpf**\ () system call commands, maps, programs, and attach types for the + token. + +bpftool prog help + Print short help message. + +OPTIONS +======== +.. include:: common_options.rst + +EXAMPLES +======== +| +| **# mkdir -p /sys/fs/bpf/token** +| **# mount -t bpf bpffs /sys/fs/bpf/token** \ +| **-o delegate_cmds=prog_load:map_create** \ +| **-o delegate_progs=kprobe** \ +| **-o delegate_attachs=xdp** +| **# bpftool token list** + +:: + + token_info /sys/fs/bpf/token + allowed_cmds: + map_create prog_load + allowed_maps: + allowed_progs: + kprobe + allowed_attachs: + xdp
Signature · 1 line
2.48.1
PATCH v3 3/3 bpftool: Add bash completion for token argument
In reply to Tao ChenThis commit updates the bash completion script with the new token argument.
$ bpftool token help list show
--- tools/bpf/bpftool/bash-completion/bpftool | 11 +++++++++++ 1 file changed, 11 insertions(+)
tools/bpf/bpftool/bash-completion/bpftool +11 -0
@@ -1215,6 +1215,17 @@ _bpftool() ;; esac ;; + token) + case $command in + show|list) + return 0 + ;; + *) + [[ $prev == $object ]] && \ + COMPREPLY=( $( compgen -W 'help show list' -- "$cur" ) ) + ;; + esac + ;; esac } && complete -F _bpftool bpftool
Signature · 1 line
2.48.1
Re: [PATCH bpf-next v3 2/3] bpftool: Add bpftool-token manpage
In reply to Tao Chen2025-07-23 11:31 UTC+0800 ~ Tao Chen <[email protected]>
Quoted 5 lines
Add bpftool-token manpage with information and examples of token-related commands.
Suggested-by Quentin Monnet <[email protected]>Signed-off-by Tao Chen <[email protected]>
Thanks!
2025-07-23 11:31 UTC+0800 ~ Tao Chen <[email protected]>
Quoted 38 lines
Add
bpftool token showcommand to get token info from bpffs in/proc/mounts.Example plain output for
token show:token_info/sys/fs/bpf/token
allowed_cmds:
map_createprog_load
allowed_maps:
allowed_progs:
kprobe
allowed_attachs:
xdptoken_info/sys/fs/bpf/token2
allowed_cmds:
map_createprog_load
allowed_maps:
allowed_progs:
kprobe
allowed_attachs:
xdpExample json output for
token show:[{ "token_info": "/sys/fs/bpf/token", "allowed_cmds": ["map_create", "prog_load"], "allowed_maps": [], "allowed_progs": ["kprobe"], "allowed_attachs": ["xdp"] }, { "token_info": "/sys/fs/bpf/token2", "allowed_cmds": ["map_create", "prog_load"], "allowed_maps": [], "allowed_progs": ["kprobe"], "allowed_attachs": ["xdp"] }]Signed-off-by Tao Chen <[email protected]>---
[...]
Quoted 5 lines
tools/bpf/bpftool/token.c new file +0
-0
[...]
tools/bpf/bpftool/token.c line 209
Quoted 10 lines
tools/bpf/bpftool/token.c new file +10
-0+static int do_help (int argc,char **argv) +{ +if (json_output) { +jsonw_null (json_wtr); +return 0 ; + } + +fprintf (stderr, +"Usage: %1$s %2$s { show | list }\n" + " %1$s %2$s help\n"
One more nit: applying and testing the help message locally, I noticed that the alignement is not correct:
$ ./bpftool token help
Usage: bpftool token { show | list }
bpftool token helpThe two "bpftool" should be aligned. This is because you use a tab for indent on the "help" line. Can you please replace it with spaces to fix indentation, and remain consistent with what other files do?
After that change, you can add:
Quentin Monnet
maintainer2025-07-23 11:40 UTC+0100 ~ Quentin Monnet <[email protected]>
Quoted 69 lines
2025-07-23 11:31 UTC+0800 ~ Tao Chen <[email protected]>
Quoted 38 lines
Add
bpftool token showcommand to get token info from bpffs in/proc/mounts.Example plain output for
token show:token_info/sys/fs/bpf/token
allowed_cmds:
map_createprog_load
allowed_maps:
allowed_progs:
kprobe
allowed_attachs:
xdptoken_info/sys/fs/bpf/token2
allowed_cmds:
map_createprog_load
allowed_maps:
allowed_progs:
kprobe
allowed_attachs:
xdpExample json output for
token show:[{ "token_info": "/sys/fs/bpf/token", "allowed_cmds": ["map_create", "prog_load"], "allowed_maps": [], "allowed_progs": ["kprobe"], "allowed_attachs": ["xdp"] }, { "token_info": "/sys/fs/bpf/token2", "allowed_cmds": ["map_create", "prog_load"], "allowed_maps": [], "allowed_progs": ["kprobe"], "allowed_attachs": ["xdp"] }]Signed-off-by Tao Chen <[email protected]>---
[...]
Quoted 5 lines
tools/bpf/bpftool/token.c new file +0
-0[...]
tools/bpf/bpftool/token.c line 209
Quoted 10 lines
tools/bpf/bpftool/token.c new file +10
-0+static int do_help (int argc,char **argv) +{ +if (json_output) { +jsonw_null (json_wtr); +return 0 ; + } + +fprintf (stderr, +"Usage: %1$s %2$s { show | list }\n" + " %1$s %2$s help\n"One more nit: applying and testing the help message locally, I noticed that the alignement is not correct:
$ ./bpftool token help Usage: bpftool token { show | list } bpftool token help
Quoted 8 lines
The two "bpftool" should be aligned. This is because you use a tab for indent on the "help" line. Can you please replace it with spaces to fix indentation, and remain consistent with what other files do?
After that change, you can add:
Reviewed-by Quentin Monnet <[email protected]>
Please also take a look at the "CHECK" reports from checkpatch, some of them are worth addressing:
https://netdev.bots.linux.dev/static/nipa/984952/14165722/checkpatch/stdout
(accessed via
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/)
Thanks,
Quentin
Quoted 65 lines · Quentin Monnet
2025-07-23 11:31 UTC+0800 ~ Tao Chen <[email protected]>
Quoted 38 lines
Add
bpftool token showcommand to get token info from bpffs in/proc/mounts.Example plain output for
token show:token_info/sys/fs/bpf/token
allowed_cmds:
map_createprog_load
allowed_maps:
allowed_progs:
kprobe
allowed_attachs:
xdptoken_info/sys/fs/bpf/token2
allowed_cmds:
map_createprog_load
allowed_maps:
allowed_progs:
kprobe
allowed_attachs:
xdpExample json output for
token show:[{ "token_info": "/sys/fs/bpf/token", "allowed_cmds": ["map_create", "prog_load"], "allowed_maps": [], "allowed_progs": ["kprobe"], "allowed_attachs": ["xdp"] }, { "token_info": "/sys/fs/bpf/token2", "allowed_cmds": ["map_create", "prog_load"], "allowed_maps": [], "allowed_progs": ["kprobe"], "allowed_attachs": ["xdp"] }]Signed-off-by Tao Chen <[email protected]>---
[...]
Quoted 5 lines
tools/bpf/bpftool/token.c new file +0
-0[...]
tools/bpf/bpftool/token.c line 209
Quoted 10 lines
tools/bpf/bpftool/token.c new file +10
-0+static int do_help (int argc,char **argv) +{ +if (json_output) { +jsonw_null (json_wtr); +return 0 ; + } + +fprintf (stderr, +"Usage: %1$s %2$s { show | list }\n" + " %1$s %2$s help\n"One more nit: applying and testing the help message locally, I noticed that the alignement is not correct:
Quoted 8 lines
$ ./bpftool token help Usage: bpftool token { show | list } bpftool token helpThe two "bpftool" should be aligned. This is because you use a tab for indent on the "help" line. Can you please replace it with spaces to fix indentation, and remain consistent with what other files do?
Thanks for your testing, i will fix it, thanks again.
Quoted 3 lines
After that change, you can add:
Reviewed-by Quentin Monnet <[email protected]>
Signature · 2 lines
Best Regards Tao Chen