summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorKrzesimir Nowak <krzesimir@kinvolk.io>2019-06-05 21:17:06 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-07-14 08:09:38 +0200
commit0493503b1e28a8d096d241903f338303b5c908c2 (patch)
tree3d494e133f28b4ec457892ff05dafdbea1471b4b /tools
parent53374b5aa7392edcdc67c33a75fce30d4d109916 (diff)
downloadlinux-stable-0493503b1e28a8d096d241903f338303b5c908c2.tar.gz
linux-stable-0493503b1e28a8d096d241903f338303b5c908c2.tar.bz2
linux-stable-0493503b1e28a8d096d241903f338303b5c908c2.zip
tools: bpftool: Fix JSON output when lookup fails
[ Upstream commit 1884c066579a7a274dd981a4d9639ca63db66a23 ] In commit 9a5ab8bf1d6d ("tools: bpftool: turn err() and info() macros into functions") one case of error reporting was special cased, so it could report a lookup error for a specific key when dumping the map element. What the code forgot to do is to wrap the key and value keys into a JSON object, so an example output of pretty JSON dump of a sockhash map (which does not support looking up its values) is: [ "key": ["0x0a","0x41","0x00","0x02","0x1f","0x78","0x00","0x00" ], "value": { "error": "Operation not supported" }, "key": ["0x0a","0x41","0x00","0x02","0x1f","0x78","0x00","0x01" ], "value": { "error": "Operation not supported" } ] Note the key-value pairs inside the toplevel array. They should be wrapped inside a JSON object, otherwise it is an invalid JSON. This commit fixes this, so the output now is: [{ "key": ["0x0a","0x41","0x00","0x02","0x1f","0x78","0x00","0x00" ], "value": { "error": "Operation not supported" } },{ "key": ["0x0a","0x41","0x00","0x02","0x1f","0x78","0x00","0x01" ], "value": { "error": "Operation not supported" } } ] Fixes: 9a5ab8bf1d6d ("tools: bpftool: turn err() and info() macros into functions") Cc: Quentin Monnet <quentin.monnet@netronome.com> Signed-off-by: Krzesimir Nowak <krzesimir@kinvolk.io> Acked-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/bpf/bpftool/map.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/tools/bpf/bpftool/map.c b/tools/bpf/bpftool/map.c
index 994a7e0d16fb..14f581b562bd 100644
--- a/tools/bpf/bpftool/map.c
+++ b/tools/bpf/bpftool/map.c
@@ -713,12 +713,14 @@ static int dump_map_elem(int fd, void *key, void *value,
return 0;
if (json_output) {
+ jsonw_start_object(json_wtr);
jsonw_name(json_wtr, "key");
print_hex_data_json(key, map_info->key_size);
jsonw_name(json_wtr, "value");
jsonw_start_object(json_wtr);
jsonw_string_field(json_wtr, "error", strerror(lookup_errno));
jsonw_end_object(json_wtr);
+ jsonw_end_object(json_wtr);
} else {
if (errno == ENOENT)
print_entry_plain(map_info, key, NULL);