netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] ss: pretty-printing BPF socket-local storage
@ 2023-12-08 14:57 Quentin Deslandes
  2023-12-08 14:57 ` [PATCH v2 1/2] ss: add support for " Quentin Deslandes
  2023-12-08 14:57 ` [PATCH v2 2/2] ss: pretty-print " Quentin Deslandes
  0 siblings, 2 replies; 6+ messages in thread
From: Quentin Deslandes @ 2023-12-08 14:57 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Martin KaFai Lau, Quentin Deslandes, kernel-team

BPF allows programs to store socket-specific data using
BPF_MAP_TYPE_SK_STORAGE maps. The data is attached to the socket itself,
and Martin added INET_DIAG_REQ_SK_BPF_STORAGES, so it can be fetched
using the INET_DIAG mechanism.

Currently, ss doesn't request the socket-local data, this patch aims to
fix this.

The first patch requests the socket-local data for the requested map ID
(--bpf-map-id=) or all the maps (--bpf-maps). It then prints the map_id
in a dedicated column.

Patch #2 uses libbpf and BTF to pretty print the map's content, like
`bpftool map dump` would do.

While I think it makes sense for ss to provide the socket-local storage
content for the sockets, it's difficult to conciliate the column-based
output of ss and having readable socket-local data. Hence, the
socket-local data is printed in a readable fashion over multiple lines
under its socket statistics, independently of the column-based approach.

Here is an example of ss' output with --bpf-maps:
[...]
ESTAB                  340116             0 [...]     
    map_id: 114 [
        (struct my_sk_storage){
            .field_hh = (char)3,
            (union){
                .a = (int)17,
                .b = (int)17,
            },
        }
    ]

Changes from v1:
* Remove the first patch from the series (fix) and submit it separately.
* Remove double allocation of struct rtattr.
* Close BPF map FDs on exit.
* If bpf_map_get_fd_by_id() fails with ENOENT, print an error message
  and continue to the next map ID.
* Fix typo in new command line option documentation.
* Only use bpf_map_info.btf_value_type_id and ignore
  bpf_map_info.btf_vmlinux_value_type_id (unused for socket-local storage).
* Use btf_dump__dump_type_data() instead of manually using BTF to
  pretty-print socket-local storage data. This change alone divides the size
  of the patch series by 2.

Quentin Deslandes (2):
  ss: add support for BPF socket-local storage
  ss: pretty-print BPF socket-local storage

 misc/ss.c | 433 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 425 insertions(+), 8 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-12-13 17:46 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-08 14:57 [PATCH v2 0/2] ss: pretty-printing BPF socket-local storage Quentin Deslandes
2023-12-08 14:57 ` [PATCH v2 1/2] ss: add support for " Quentin Deslandes
2023-12-12 22:49   ` Martin KaFai Lau
2023-12-08 14:57 ` [PATCH v2 2/2] ss: pretty-print " Quentin Deslandes
2023-12-12 22:58   ` Martin KaFai Lau
2023-12-13 17:46   ` Alan Maguire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).