Skip to content

Commit ad3338d

Browse files
yonghong-songAlexei Starovoitov
authored andcommitted
tools/bpf: bpftool: support prog array map and map of maps
Currently, prog array map and map of maps are not supported in bpftool. This patch added the support. Different from other map types, for prog array map and map of maps, the key returned bpf_get_next_key() may not point to a valid value. So for these two map types, no error will be printed out when such a scenario happens. The following is the plain and json dump if btf is not available: $ ./bpftool map dump id 10 key: 08 00 00 00 value: 5c 01 00 00 Found 1 element $ ./bpftool -jp map dump id 10 [{ "key": ["0x08","0x00","0x00","0x00" ], "value": ["0x5c","0x01","0x00","0x00" ] }] If the BTF is available, the dump looks below: $ ./bpftool map dump id 2 [{ "key": 0, "value": 7 } ] $ ./bpftool -jp map dump id 2 [{ "key": ["0x00","0x00","0x00","0x00" ], "value": ["0x07","0x00","0x00","0x00" ], "formatted": { "key": 0, "value": 7 } }] Signed-off-by: Yonghong Song <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent a7c19db commit ad3338d

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

tools/bpf/bpftool/map.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -673,12 +673,6 @@ static int do_dump(int argc, char **argv)
673673
if (fd < 0)
674674
return -1;
675675

676-
if (map_is_map_of_maps(info.type) || map_is_map_of_progs(info.type)) {
677-
p_err("Dumping maps of maps and program maps not supported");
678-
close(fd);
679-
return -1;
680-
}
681-
682676
key = malloc(info.key_size);
683677
value = alloc_value(&info);
684678
if (!key || !value) {
@@ -732,7 +726,9 @@ static int do_dump(int argc, char **argv)
732726
} else {
733727
print_entry_plain(&info, key, value);
734728
}
735-
} else {
729+
num_elems++;
730+
} else if (!map_is_map_of_maps(info.type) &&
731+
!map_is_map_of_progs(info.type)) {
736732
if (json_output) {
737733
jsonw_name(json_wtr, "key");
738734
print_hex_data_json(key, info.key_size);
@@ -749,7 +745,6 @@ static int do_dump(int argc, char **argv)
749745
}
750746

751747
prev_key = key;
752-
num_elems++;
753748
}
754749

755750
if (json_output)

0 commit comments

Comments
 (0)