• Krzesimir Nowak's avatar
    tools: bpftool: Fix JSON output when lookup fails · 1884c066
    Krzesimir Nowak authored
    In commit 9a5ab8bf ("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: 9a5ab8bf ("tools: bpftool: turn err() and info() macros into functions")
    Cc: Quentin Monnet <quentin.monnet@netronome.com>
    Signed-off-by: default avatarKrzesimir Nowak <krzesimir@kinvolk.io>
    Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
    Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    1884c066
map.c 28.1 KB