bpftool: allow match by name prefixes
Subsystems (4)
PATCH 1/1 bpftool: allow match by name prefixes
This patch extends bpftool to support lookup of programs and maps by name prefixes (instead of full name only), as follows.
$ ./bpftool prog show name tcp_
19: kprobe name tcp_cleanup_rbu tag 639217cf5b184808 gpl
[...]
20: kprobe name tcp_sendmsg tag 6546b9784163ee69 gpl
[...]Signed-off-by Paul Chaignon <[email protected]>
--- tools/bpf/bpftool/Documentation/bpftool-map.rst | 4 ++-- tools/bpf/bpftool/Documentation/bpftool-prog.rst | 2 +- tools/bpf/bpftool/main.h | 4 ++-- tools/bpf/bpftool/map.c | 2 +- tools/bpf/bpftool/prog.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-map.rst +2 -2
@@ -39,9 +39,9 @@ MAP COMMANDS | **bpftool** **map freeze** *MAP* | **bpftool** **map help** | -| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* | **name** *MAP_NAME* } +| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* | **name** *NAME_PREFIX* } | *DATA* := { [**hex**] *BYTES* } -| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* } +| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *NAME_PREFIX* } | *VALUE* := { *DATA* | *MAP* | *PROG* } | *UPDATE_FLAGS* := { **any** | **exist** | **noexist** } | *TYPE* := { **hash** | **array** | **prog_array** | **perf_event_array** | **percpu_hash**
tools/bpf/bpftool/Documentation/bpftool-prog.rst +1 -1
@@ -33,7 +33,7 @@ PROG COMMANDS | **bpftool** **prog help** | | *MAP* := { **id** *MAP_ID* | **pinned** *FILE* } -| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* } +| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *NAME_PREFIX* } | *TYPE* := { | **socket** | **kprobe** | **kretprobe** | **classifier** | **action** | | **tracepoint** | **raw_tracepoint** | **xdp** | **perf_event** | **cgroup/skb** |
tools/bpf/bpftool/main.h +2 -2
@@ -42,12 +42,12 @@#define BPF_TAG_FMT "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"#define HELP_SPEC_PROGRAM \ - "PROG := { id PROG_ID | pinned FILE | tag PROG_TAG | name PROG_NAME }" + "PROG := { id PROG_ID | pinned FILE | tag PROG_TAG | name NAME_PREFIX }"#define HELP_SPEC_OPTIONS \ "OPTIONS := { {-j|--json} [{-p|--pretty}] | {-f|--bpffs} |\n" \ "\t {-m|--mapcompat} | {-n|--nomount} }"#define HELP_SPEC_MAP \ - "MAP := { id MAP_ID | pinned FILE | name MAP_NAME }" + "MAP := { id MAP_ID | pinned FILE | name NAME_PREFIX }"static const char *const prog_type_name[] = { [BPF_PROG_TYPE_UNSPEC ] ="unspec" ,
tools/bpf/bpftool/map.c +1 -1
@@ -125,7 +125,7 @@ static int map_fd_by_name(char *name, int **fds) goto err_close_fd; } -if (strncmp (name, info.name,BPF_OBJ_NAME_LEN )) { +if (!is_prefix (name, info.name)) {close (fd);continue ; }
tools/bpf/bpftool/prog.c +1 -1
@@ -117,7 +117,7 @@ static int prog_fd_by_nametag(void *nametag, int **fds, bool tag) }if ((tag &&memcmp (nametag, info.tag,BPF_TAG_SIZE )) || - (!tag &&strncmp (nametag, info.name,BPF_OBJ_NAME_LEN ))) { + (!tag && !is_prefix (nametag, info.name))) {close (fd);continue ; }
Signature · 1 line
2.17.1
Quoted 9 lines · Paul Chaignon
This patch extends bpftool to support lookup of programs and maps by name prefixes (instead of full name only), as follows.
$ ./bpftool prog show name tcp_ 19: kprobe name tcp_cleanup_rbu tag 639217cf5b184808 gpl [...] 20: kprobe name tcp_sendmsg tag 6546b9784163ee69 gpl [...]
This should be more generic in matches - not just the names beginning with. Full regex might not be warranted, but certainly more than just begins with. e.g., handling *tcp*.