Skip to content

Commit e948947

Browse files
jsitnickiAlexei Starovoitov
authored andcommitted
bpftool: Support link show for netns-attached links
Make `bpf link show` aware of new link type, that is links attached to netns. When listing netns-attached links, display netns inode number as its identifier and link attach type. Sample session: # readlink /proc/self/ns/net net:[4026532251] # bpftool prog show 357: flow_dissector tag a04f5eef06a7f555 gpl loaded_at 2020-05-30T16:53:51+0200 uid 0 xlated 16B jited 37B memlock 4096B 358: flow_dissector tag a04f5eef06a7f555 gpl loaded_at 2020-05-30T16:53:51+0200 uid 0 xlated 16B jited 37B memlock 4096B # bpftool link show 108: netns prog 357 netns_ino 4026532251 attach_type flow_dissector # bpftool link -jp show [{ "id": 108, "type": "netns", "prog_id": 357, "netns_ino": 4026532251, "attach_type": "flow_dissector" } ] (... after netns is gone ...) # bpftool link show 108: netns prog 357 netns_ino 0 attach_type flow_dissector # bpftool link -jp show [{ "id": 108, "type": "netns", "prog_id": 357, "netns_ino": 0, "attach_type": "flow_dissector" } ] Signed-off-by: Jakub Sitnicki <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent be6e198 commit e948947

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

tools/bpf/bpftool/link.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ static const char * const link_type_name[] = {
1717
[BPF_LINK_TYPE_TRACING] = "tracing",
1818
[BPF_LINK_TYPE_CGROUP] = "cgroup",
1919
[BPF_LINK_TYPE_ITER] = "iter",
20+
[BPF_LINK_TYPE_NETNS] = "netns",
2021
};
2122

2223
static int link_parse_fd(int *argc, char ***argv)
@@ -122,6 +123,11 @@ static int show_link_close_json(int fd, struct bpf_link_info *info)
122123
info->cgroup.cgroup_id);
123124
show_link_attach_type_json(info->cgroup.attach_type, json_wtr);
124125
break;
126+
case BPF_LINK_TYPE_NETNS:
127+
jsonw_uint_field(json_wtr, "netns_ino",
128+
info->netns.netns_ino);
129+
show_link_attach_type_json(info->netns.attach_type, json_wtr);
130+
break;
125131
default:
126132
break;
127133
}
@@ -190,6 +196,10 @@ static int show_link_close_plain(int fd, struct bpf_link_info *info)
190196
printf("\n\tcgroup_id %zu ", (size_t)info->cgroup.cgroup_id);
191197
show_link_attach_type_plain(info->cgroup.attach_type);
192198
break;
199+
case BPF_LINK_TYPE_NETNS:
200+
printf("\n\tnetns_ino %u ", info->netns.netns_ino);
201+
show_link_attach_type_plain(info->netns.attach_type);
202+
break;
193203
default:
194204
break;
195205
}

0 commit comments

Comments
 (0)