bpftool: Formatting defined by user:fmt: decl tag
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest1 patch 6 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/1 | bpftool: Formatting defined by user:fmt: decl tagtools/ tools/ tools/ | +124 | 6 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/1] bpftool: Formatting defined by user:fmt: decl tag
bpftool map dump command is handy when developing and troubleshooting ebpf programs. It is nice to get data formatted in the most useful way, eliminating the need to postprocess bpftool output. There were multiple contributions in this vein over the years, e.g.:
30255d317579 bpftool: Print as a string for char array
Sometimes the type alone doesn't carry enough semantic information, such as __be32 storing an IPv4 address or __be16 encoding a port.
I propose using BTF decl tags to influence bpftool formatting. Specifically, if the type itself or any type in the typedef chain has "user:fmt:*" tag attached:
* "user:fmt:be" format the value as big-endian value (supports
2, 4, or 8 byte integers);
* "user:fmt:ip" format the value as IPv4 ot IPv6 address.
The typedef approach requires switching to a custom type (e.g. bpf_inaddr) in map keys, values, and types that are embedded in a key or value type.
The code remains nice and clean since the typedef and the underlying type are compatible; e.g. we can key.addr = iphdr->daddr;
Nick Zavaritsky (1):
bpftool: Formatting defined by user:fmt: decl tag
tools/bpf/bpftool/btf_dumper.c | 119 +++++++++++++++++++++++++++++---- tools/bpf/bpftool/main.h | 12 ++++ tools/bpf/bpftool/map.c | 7 +- 3 files changed, 124 insertions(+), 14 deletions(-)
Signature · 1 line
2.43.0