]> git.baikalelectronics.ru Git - kernel.git/commit
bpf: btf: print map dump and lookup with btf info
authorOkash Khawaja <osk@fb.com>
Sat, 14 Jul 2018 04:57:04 +0000 (21:57 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Sat, 14 Jul 2018 11:00:40 +0000 (13:00 +0200)
commitf2f9a84a533b8df0d83794595b316d2d88861b31
treef1c1babdff4bf4d249818c588cb86afac4fc67f4
parent0d765741477e3ac69ca5c44361fd4d2e6a1c70c3
bpf: btf: print map dump and lookup with btf info

This patch augments the output of bpftool's map dump and map lookup
commands to print data along side btf info, if the correspondin btf
info is available. The outputs for each of  map dump and map lookup
commands are augmented in two ways:

1. when neither of -j and -p are supplied, btf-ful map data is printed
whose aim is human readability. This means no commitments for json- or
backward- compatibility.

2. when either -j or -p are supplied, a new json object named
"formatted" is added for each key-value pair. This object contains the
same data as the key-value pair, but with btf info. "formatted" object
promises json- and backward- compatibility. Below is a sample output.

$ bpftool map dump -p id 8
[{
        "key": ["0x0f","0x00","0x00","0x00"
        ],
        "value": ["0x03", "0x00", "0x00", "0x00", ...
        ],
        "formatted": {
                "key": 15,
                "value": {
                        "int_field":  3,
                        ...
                }
        }
}
]

This patch calls btf_dumper introduced in previous patch to accomplish
the above. Indeed, btf-ful info is only displayed if btf data for the
given map is available. Otherwise existing output is displayed as-is.

Signed-off-by: Okash Khawaja <osk@fb.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/bpf/bpftool/map.c