All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpftool: allow match by name prefixes
@ 2019-12-27 16:16 Paul Chaignon
  2019-12-31  4:28 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Paul Chaignon @ 2019-12-27 16:16 UTC (permalink / raw)
  To: bpf
  Cc: paul.chaignon, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	netdev

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 <paul.chaignon@orange.com>
---
 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(-)

diff --git a/tools/bpf/bpftool/Documentation/bpftool-map.rst b/tools/bpf/bpftool/Documentation/bpftool-map.rst
index cdeae8ae90ba..bcc38ff9da65 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-map.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-map.rst
@@ -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**
diff --git a/tools/bpf/bpftool/Documentation/bpftool-prog.rst b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
index 64ddf8a4c518..8e39ac362c16 100644
--- a/tools/bpf/bpftool/Documentation/bpftool-prog.rst
+++ b/tools/bpf/bpftool/Documentation/bpftool-prog.rst
@@ -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** |
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 4e75b58d3989..8e70617e55fb 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -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",
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index c01f76fa6876..79e0d72ffdd2 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -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;
 		}
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 2221bae037f1..295509548c8b 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -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;
 		}
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf-next] bpftool: allow match by name prefixes
  2019-12-27 16:16 [PATCH bpf-next] bpftool: allow match by name prefixes Paul Chaignon
@ 2019-12-31  4:28 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2019-12-31  4:28 UTC (permalink / raw)
  To: Paul Chaignon, bpf
  Cc: paul.chaignon, Alexei Starovoitov, Daniel Borkmann,
	Martin KaFai Lau, Song Liu, Yonghong Song, Andrii Nakryiko,
	netdev

On 12/27/19 9:16 AM, Paul Chaignon wrote:
> 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*.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-31  4:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-27 16:16 [PATCH bpf-next] bpftool: allow match by name prefixes Paul Chaignon
2019-12-31  4:28 ` David Ahern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.