mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-18 04:34:36 +00:00
tools: bpftool: add "bpftool map freeze" subcommand
Add a new subcommand to freeze maps from user space. Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com> Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
c354ff2ef2
commit
0bb52b0dfc
3 changed files with 44 additions and 3 deletions
|
@ -36,6 +36,7 @@ MAP COMMANDS
|
||||||
| **bpftool** **map pop** *MAP*
|
| **bpftool** **map pop** *MAP*
|
||||||
| **bpftool** **map enqueue** *MAP* **value** *VALUE*
|
| **bpftool** **map enqueue** *MAP* **value** *VALUE*
|
||||||
| **bpftool** **map dequeue** *MAP*
|
| **bpftool** **map dequeue** *MAP*
|
||||||
|
| **bpftool** **map freeze** *MAP*
|
||||||
| **bpftool** **map help**
|
| **bpftool** **map help**
|
||||||
|
|
|
|
||||||
| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
|
| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
|
||||||
|
@ -127,6 +128,14 @@ DESCRIPTION
|
||||||
**bpftool map dequeue** *MAP*
|
**bpftool map dequeue** *MAP*
|
||||||
Dequeue and print **value** from the queue.
|
Dequeue and print **value** from the queue.
|
||||||
|
|
||||||
|
**bpftool map freeze** *MAP*
|
||||||
|
Freeze the map as read-only from user space. Entries from a
|
||||||
|
frozen map can not longer be updated or deleted with the
|
||||||
|
**bpf\ ()** system call. This operation is not reversible,
|
||||||
|
and the map remains immutable from user space until its
|
||||||
|
destruction. However, read and write permissions for BPF
|
||||||
|
programs to the map remain unchanged.
|
||||||
|
|
||||||
**bpftool map help**
|
**bpftool map help**
|
||||||
Print short help message.
|
Print short help message.
|
||||||
|
|
||||||
|
|
|
@ -449,7 +449,7 @@ _bpftool()
|
||||||
map)
|
map)
|
||||||
local MAP_TYPE='id pinned'
|
local MAP_TYPE='id pinned'
|
||||||
case $command in
|
case $command in
|
||||||
show|list|dump|peek|pop|dequeue)
|
show|list|dump|peek|pop|dequeue|freeze)
|
||||||
case $prev in
|
case $prev in
|
||||||
$command)
|
$command)
|
||||||
COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
|
COMPREPLY=( $( compgen -W "$MAP_TYPE" -- "$cur" ) )
|
||||||
|
@ -638,7 +638,7 @@ _bpftool()
|
||||||
[[ $prev == $object ]] && \
|
[[ $prev == $object ]] && \
|
||||||
COMPREPLY=( $( compgen -W 'delete dump getnext help \
|
COMPREPLY=( $( compgen -W 'delete dump getnext help \
|
||||||
lookup pin event_pipe show list update create \
|
lookup pin event_pipe show list update create \
|
||||||
peek push enqueue pop dequeue' -- \
|
peek push enqueue pop dequeue freeze' -- \
|
||||||
"$cur" ) )
|
"$cur" ) )
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -1262,6 +1262,35 @@ exit_free:
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_freeze(int argc, char **argv)
|
||||||
|
{
|
||||||
|
int err, fd;
|
||||||
|
|
||||||
|
if (!REQ_ARGS(2))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
fd = map_parse_fd(&argc, &argv);
|
||||||
|
if (fd < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (argc) {
|
||||||
|
close(fd);
|
||||||
|
return BAD_ARG();
|
||||||
|
}
|
||||||
|
|
||||||
|
err = bpf_map_freeze(fd);
|
||||||
|
close(fd);
|
||||||
|
if (err) {
|
||||||
|
p_err("failed to freeze map: %s", strerror(errno));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (json_output)
|
||||||
|
jsonw_null(json_wtr);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int do_help(int argc, char **argv)
|
static int do_help(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (json_output) {
|
if (json_output) {
|
||||||
|
@ -1286,6 +1315,7 @@ static int do_help(int argc, char **argv)
|
||||||
" %s %s pop MAP\n"
|
" %s %s pop MAP\n"
|
||||||
" %s %s enqueue MAP value VALUE\n"
|
" %s %s enqueue MAP value VALUE\n"
|
||||||
" %s %s dequeue MAP\n"
|
" %s %s dequeue MAP\n"
|
||||||
|
" %s %s freeze MAP\n"
|
||||||
" %s %s help\n"
|
" %s %s help\n"
|
||||||
"\n"
|
"\n"
|
||||||
" " HELP_SPEC_MAP "\n"
|
" " HELP_SPEC_MAP "\n"
|
||||||
|
@ -1304,7 +1334,8 @@ static int do_help(int argc, char **argv)
|
||||||
bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
|
bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
|
||||||
bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
|
bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
|
||||||
bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
|
bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
|
||||||
bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2]);
|
bin_name, argv[-2], bin_name, argv[-2], bin_name, argv[-2],
|
||||||
|
bin_name, argv[-2]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1326,6 +1357,7 @@ static const struct cmd cmds[] = {
|
||||||
{ "enqueue", do_update },
|
{ "enqueue", do_update },
|
||||||
{ "pop", do_pop_dequeue },
|
{ "pop", do_pop_dequeue },
|
||||||
{ "dequeue", do_pop_dequeue },
|
{ "dequeue", do_pop_dequeue },
|
||||||
|
{ "freeze", do_freeze },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue