diff options
author | Kui-Feng Lee <thinker.li@gmail.com> | 2023-04-21 14:41:31 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2023-04-27 14:51:44 +0200 |
commit | 74fc8801edc279fb5f778eb91df48e4d3cd951a2 (patch) | |
tree | 0ae29c92bbaa4a7aa0b8a3d5c63a8a51e25126e6 /tools/bpf | |
parent | 1a986518b8a517637f70cd6d7d494bd0cbbf6145 (diff) | |
download | linux-74fc8801edc279fb5f778eb91df48e4d3cd951a2.tar.gz linux-74fc8801edc279fb5f778eb91df48e4d3cd951a2.tar.bz2 linux-74fc8801edc279fb5f778eb91df48e4d3cd951a2.zip |
bpftool: Show map IDs along with struct_ops links.
A new link type, BPF_LINK_TYPE_STRUCT_OPS, was added to attach
struct_ops to links. (226bc6ae6405) It would be helpful for users to
know which map is associated with the link.
The assumption was that every link is associated with a BPF program, but
this does not hold true for struct_ops. It would be better to display
map_id instead of prog_id for struct_ops links. However, some tools may
rely on the old assumption and need a prog_id. The discussion on the
mailing list suggests that tools should parse JSON format. We will maintain
the existing JSON format by adding a map_id without removing prog_id. As
for plain text format, we will remove prog_id from the header line and add
a map_id for struct_ops links.
Signed-off-by: Kui-Feng Lee <kuifeng@meta.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/20230421214131.352662-1-kuifeng@meta.com
Diffstat (limited to 'tools/bpf')
-rw-r--r-- | tools/bpf/bpftool/link.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/tools/bpf/bpftool/link.c b/tools/bpf/bpftool/link.c index d98dbc50cf4c..243b74e18e51 100644 --- a/tools/bpf/bpftool/link.c +++ b/tools/bpf/bpftool/link.c @@ -212,7 +212,10 @@ static int show_link_close_json(int fd, struct bpf_link_info *info) case BPF_LINK_TYPE_NETFILTER: netfilter_dump_json(info, json_wtr); break; - + case BPF_LINK_TYPE_STRUCT_OPS: + jsonw_uint_field(json_wtr, "map_id", + info->struct_ops.map_id); + break; default: break; } @@ -245,7 +248,10 @@ static void show_link_header_plain(struct bpf_link_info *info) else printf("type %u ", info->type); - printf("prog %u ", info->prog_id); + if (info->type == BPF_LINK_TYPE_STRUCT_OPS) + printf("map %u ", info->struct_ops.map_id); + else + printf("prog %u ", info->prog_id); } static void show_link_attach_type_plain(__u32 attach_type) |