Commit a06ae6ac authored by Alexei Starovoitov's avatar Alexei Starovoitov

Merge branch 'bpftool-match-by-name'

Paul Chaignon says:

====================
When working with frequently modified BPF programs, both the ID and the
tag may change.  bpftool currently doesn't provide a "stable" way to match
such programs.  This patchset allows bpftool to match programs and maps by
name.

When given a tag that matches several programs, bpftool currently only
considers the first match.  The first patch changes that behavior to
either process all matching programs (for the show and dump commands) or
error out.  The second patch implements program lookup by name, with the
same behavior as for tags in case of ambiguity.  The last patch implements
map lookup by name.

Changelogs:
  Changes in v2:
    - Fix buffer overflow after realloc.
    - Add example output to commit message.
    - Properly close JSON arrays on errors.
    - Fix style errors (line breaks, for loops, exit labels, type for
      tagname).
    - Move do_show code for argc == 2 to do_show_subset functions.
    - Rebase.
====================
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
parents a06bf42f 99f9863a
...@@ -39,9 +39,9 @@ MAP COMMANDS ...@@ -39,9 +39,9 @@ MAP COMMANDS
| **bpftool** **map freeze** *MAP* | **bpftool** **map freeze** *MAP*
| **bpftool** **map help** | **bpftool** **map help**
| |
| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* } | *MAP* := { **id** *MAP_ID* | **pinned** *FILE* | **name** *MAP_NAME* }
| *DATA* := { [**hex**] *BYTES* } | *DATA* := { [**hex**] *BYTES* }
| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* } | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* }
| *VALUE* := { *DATA* | *MAP* | *PROG* } | *VALUE* := { *DATA* | *MAP* | *PROG* }
| *UPDATE_FLAGS* := { **any** | **exist** | **noexist** } | *UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
| *TYPE* := { **hash** | **array** | **prog_array** | **perf_event_array** | **percpu_hash** | *TYPE* := { **hash** | **array** | **prog_array** | **perf_event_array** | **percpu_hash**
...@@ -55,8 +55,9 @@ DESCRIPTION ...@@ -55,8 +55,9 @@ DESCRIPTION
=========== ===========
**bpftool map { show | list }** [*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 maps, otherwise list all
maps currently loaded on the system. maps currently loaded on the system. In case of **name**,
*MAP* may match several maps which will all be shown.
Output will start with map ID followed by map type and Output will start with map ID followed by map type and
zero or more named attributes (depending on kernel version). zero or more named attributes (depending on kernel version).
...@@ -66,7 +67,8 @@ DESCRIPTION ...@@ -66,7 +67,8 @@ DESCRIPTION
as *FILE*. as *FILE*.
**bpftool map dump** *MAP* **bpftool map dump** *MAP*
Dump all entries in a given *MAP*. Dump all entries in a given *MAP*. In case of **name**,
*MAP* may match several maps which will all be dumped.
**bpftool map update** *MAP* [**key** *DATA*] [**value** *VALUE*] [*UPDATE_FLAGS*] **bpftool map update** *MAP* [**key** *DATA*] [**value** *VALUE*] [*UPDATE_FLAGS*]
Update map entry for a given *KEY*. Update map entry for a given *KEY*.
......
...@@ -33,7 +33,7 @@ PROG COMMANDS ...@@ -33,7 +33,7 @@ PROG COMMANDS
| **bpftool** **prog help** | **bpftool** **prog help**
| |
| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* } | *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* } | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* }
| *TYPE* := { | *TYPE* := {
| **socket** | **kprobe** | **kretprobe** | **classifier** | **action** | | **socket** | **kprobe** | **kretprobe** | **classifier** | **action** |
| **tracepoint** | **raw_tracepoint** | **xdp** | **perf_event** | **cgroup/skb** | | **tracepoint** | **raw_tracepoint** | **xdp** | **perf_event** | **cgroup/skb** |
...@@ -53,8 +53,10 @@ DESCRIPTION ...@@ -53,8 +53,10 @@ DESCRIPTION
=========== ===========
**bpftool prog { show | list }** [*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 programs,
list all programs currently loaded on the system. otherwise list all programs currently loaded on the system.
In case of **tag** or **name**, *PROG* may match several
programs which will all be shown.
Output will start with program ID followed by program type and Output will start with program ID followed by program type and
zero or more named attributes (depending on kernel version). zero or more named attributes (depending on kernel version).
...@@ -68,11 +70,15 @@ DESCRIPTION ...@@ -68,11 +70,15 @@ DESCRIPTION
performed via the **kernel.bpf_stats_enabled** sysctl knob. performed via the **kernel.bpf_stats_enabled** sysctl knob.
**bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** | **linum** }] **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** | **linum** }]
Dump eBPF instructions of the program from the kernel. By Dump eBPF instructions of the programs from the kernel. By
default, eBPF will be disassembled and printed to standard default, eBPF will be disassembled and printed to standard
output in human-readable format. In this case, **opcodes** output in human-readable format. In this case, **opcodes**
controls if raw opcodes should be printed as well. controls if raw opcodes should be printed as well.
In case of **tag** or **name**, *PROG* may match several
programs which will all be dumped. However, if **file** or
**visual** is specified, *PROG* must match a single program.
If **file** is specified, the binary image will instead be If **file** is specified, the binary image will instead be
written to *FILE*. written to *FILE*.
...@@ -80,15 +86,17 @@ DESCRIPTION ...@@ -80,15 +86,17 @@ DESCRIPTION
built instead, and eBPF instructions will be presented with built instead, and eBPF instructions will be presented with
CFG in DOT format, on standard output. CFG in DOT format, on standard output.
If the prog has line_info available, the source line will If the programs have line_info available, the source line will
be displayed by default. If **linum** is specified, be displayed by default. If **linum** is specified,
the filename, line number and line column will also be the filename, line number and line column will also be
displayed on top of the source line. displayed on top of the source line.
**bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** | **linum** }] **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** | **linum** }]
Dump jited image (host machine code) of the program. Dump jited image (host machine code) of the program.
If *FILE* is specified image will be written to a file, If *FILE* is specified image will be written to a file,
otherwise it will be disassembled and printed to stdout. otherwise it will be disassembled and printed to stdout.
*PROG* must match a single program when **file** is specified.
**opcodes** controls if raw opcodes will be printed. **opcodes** controls if raw opcodes will be printed.
......
This diff is collapsed.
...@@ -42,12 +42,12 @@ ...@@ -42,12 +42,12 @@
#define BPF_TAG_FMT "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx" #define BPF_TAG_FMT "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
#define HELP_SPEC_PROGRAM \ #define HELP_SPEC_PROGRAM \
"PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }" "PROG := { id PROG_ID | pinned FILE | tag PROG_TAG | name PROG_NAME }"
#define HELP_SPEC_OPTIONS \ #define HELP_SPEC_OPTIONS \
"OPTIONS := { {-j|--json} [{-p|--pretty}] | {-f|--bpffs} |\n" \ "OPTIONS := { {-j|--json} [{-p|--pretty}] | {-f|--bpffs} |\n" \
"\t {-m|--mapcompat} | {-n|--nomount} }" "\t {-m|--mapcompat} | {-n|--nomount} }"
#define HELP_SPEC_MAP \ #define HELP_SPEC_MAP \
"MAP := { id MAP_ID | pinned FILE }" "MAP := { id MAP_ID | pinned FILE | name MAP_NAME }"
static const char * const prog_type_name[] = { static const char * const prog_type_name[] = {
[BPF_PROG_TYPE_UNSPEC] = "unspec", [BPF_PROG_TYPE_UNSPEC] = "unspec",
......
This diff is collapsed.
This diff is collapsed.
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