diff options
author | Jakub Kicinski <jakub.kicinski@netronome.com> | 2017-12-27 21:39:10 -0500 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2017-12-31 10:12:23 -0500 |
commit | 522622104ebabbc3372d2fad706b4d30cee13319 (patch) | |
tree | 3be32b64c434196ddab3ab47693552aa1eaf7834 /tools/bpf | |
parent | 675fc275a3a2d905535207237402c6d8dcb5fa4b (diff) |
tools: bpftool: report device information for offloaded programs
Print the just-exposed device information about device to which
program is bound.
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/bpf')
-rw-r--r-- | tools/bpf/bpftool/common.c | 52 | ||||
-rw-r--r-- | tools/bpf/bpftool/main.h | 2 | ||||
-rw-r--r-- | tools/bpf/bpftool/prog.c | 3 |
3 files changed, 57 insertions, 0 deletions
diff --git a/tools/bpf/bpftool/common.c b/tools/bpf/bpftool/common.c index b62c94e3997a..6601c95a9258 100644 --- a/tools/bpf/bpftool/common.c +++ b/tools/bpf/bpftool/common.c | |||
@@ -44,7 +44,9 @@ | |||
44 | #include <unistd.h> | 44 | #include <unistd.h> |
45 | #include <linux/limits.h> | 45 | #include <linux/limits.h> |
46 | #include <linux/magic.h> | 46 | #include <linux/magic.h> |
47 | #include <net/if.h> | ||
47 | #include <sys/mount.h> | 48 | #include <sys/mount.h> |
49 | #include <sys/stat.h> | ||
48 | #include <sys/types.h> | 50 | #include <sys/types.h> |
49 | #include <sys/vfs.h> | 51 | #include <sys/vfs.h> |
50 | 52 | ||
@@ -412,3 +414,53 @@ void delete_pinned_obj_table(struct pinned_obj_table *tab) | |||
412 | free(obj); | 414 | free(obj); |
413 | } | 415 | } |
414 | } | 416 | } |
417 | |||
418 | static char * | ||
419 | ifindex_to_name_ns(__u32 ifindex, __u32 ns_dev, __u32 ns_ino, char *buf) | ||
420 | { | ||
421 | struct stat st; | ||
422 | int err; | ||
423 | |||
424 | err = stat("/proc/self/ns/net", &st); | ||
425 | if (err) { | ||
426 | p_err("Can't stat /proc/self: %s", strerror(errno)); | ||
427 | return NULL; | ||
428 | } | ||
429 | |||
430 | if (st.st_dev != ns_dev || st.st_ino != ns_ino) | ||
431 | return NULL; | ||
432 | |||
433 | return if_indextoname(ifindex, buf); | ||
434 | } | ||
435 | |||
436 | void print_dev_plain(__u32 ifindex, __u64 ns_dev, __u64 ns_inode) | ||
437 | { | ||
438 | char name[IF_NAMESIZE]; | ||
439 | |||
440 | if (!ifindex) | ||
441 | return; | ||
442 | |||
443 | printf(" dev "); | ||
444 | if (ifindex_to_name_ns(ifindex, ns_dev, ns_inode, name)) | ||
445 | printf("%s", name); | ||
446 | else | ||
447 | printf("ifindex %u ns_dev %llu ns_ino %llu", | ||
448 | ifindex, ns_dev, ns_inode); | ||
449 | } | ||
450 | |||
451 | void print_dev_json(__u32 ifindex, __u64 ns_dev, __u64 ns_inode) | ||
452 | { | ||
453 | char name[IF_NAMESIZE]; | ||
454 | |||
455 | if (!ifindex) | ||
456 | return; | ||
457 | |||
458 | jsonw_name(json_wtr, "dev"); | ||
459 | jsonw_start_object(json_wtr); | ||
460 | jsonw_uint_field(json_wtr, "ifindex", ifindex); | ||
461 | jsonw_uint_field(json_wtr, "ns_dev", ns_dev); | ||
462 | jsonw_uint_field(json_wtr, "ns_inode", ns_inode); | ||
463 | if (ifindex_to_name_ns(ifindex, ns_dev, ns_inode, name)) | ||
464 | jsonw_string_field(json_wtr, "ifname", name); | ||
465 | jsonw_end_object(json_wtr); | ||
466 | } | ||
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h index 8f6d3cac0347..65b526fe6e7e 100644 --- a/tools/bpf/bpftool/main.h +++ b/tools/bpf/bpftool/main.h | |||
@@ -96,6 +96,8 @@ struct pinned_obj { | |||
96 | int build_pinned_obj_table(struct pinned_obj_table *table, | 96 | int build_pinned_obj_table(struct pinned_obj_table *table, |
97 | enum bpf_obj_type type); | 97 | enum bpf_obj_type type); |
98 | void delete_pinned_obj_table(struct pinned_obj_table *tab); | 98 | void delete_pinned_obj_table(struct pinned_obj_table *tab); |
99 | void print_dev_plain(__u32 ifindex, __u64 ns_dev, __u64 ns_inode); | ||
100 | void print_dev_json(__u32 ifindex, __u64 ns_dev, __u64 ns_inode); | ||
99 | 101 | ||
100 | struct cmd { | 102 | struct cmd { |
101 | const char *cmd; | 103 | const char *cmd; |
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index fd0873178503..98f871ed53d6 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c | |||
@@ -230,6 +230,8 @@ static void print_prog_json(struct bpf_prog_info *info, int fd) | |||
230 | info->tag[0], info->tag[1], info->tag[2], info->tag[3], | 230 | info->tag[0], info->tag[1], info->tag[2], info->tag[3], |
231 | info->tag[4], info->tag[5], info->tag[6], info->tag[7]); | 231 | info->tag[4], info->tag[5], info->tag[6], info->tag[7]); |
232 | 232 | ||
233 | print_dev_json(info->ifindex, info->netns_dev, info->netns_ino); | ||
234 | |||
233 | if (info->load_time) { | 235 | if (info->load_time) { |
234 | char buf[32]; | 236 | char buf[32]; |
235 | 237 | ||
@@ -287,6 +289,7 @@ static void print_prog_plain(struct bpf_prog_info *info, int fd) | |||
287 | 289 | ||
288 | printf("tag "); | 290 | printf("tag "); |
289 | fprint_hex(stdout, info->tag, BPF_TAG_SIZE, ""); | 291 | fprint_hex(stdout, info->tag, BPF_TAG_SIZE, ""); |
292 | print_dev_plain(info->ifindex, info->netns_dev, info->netns_ino); | ||
290 | printf("\n"); | 293 | printf("\n"); |
291 | 294 | ||
292 | if (info->load_time) { | 295 | if (info->load_time) { |