Re: [PATCH bpf-next v2 0/9] selftests/bpf: Test sockmap/sockhash redirection

From: Jiayuan Chen
Date: Fri Apr 11 2025 - 09:08:15 EST


On Fri, Apr 11, 2025 at 01:32:36PM +0200, Michal Luczaj wrote:
> The idea behind this series is to comprehensively test the BPF redirection:
>
> BPF_MAP_TYPE_SOCKMAP,
> BPF_MAP_TYPE_SOCKHASH
> x
> sk_msg-to-egress,
> sk_msg-to-ingress,
> sk_skb-to-egress,
> sk_skb-to-ingress
> x
> AF_INET, SOCK_STREAM,
> AF_INET6, SOCK_STREAM,
> AF_INET, SOCK_DGRAM,
> AF_INET6, SOCK_DGRAM,
> AF_UNIX, SOCK_STREAM,
> AF_UNIX, SOCK_DGRAM,
> AF_VSOCK, SOCK_STREAM,
> AF_VSOCK, SOCK_SEQPACKET
>
> New module is introduced, sockmap_redir: all supported and unsupported
> redirect combinations are tested for success and failure respectively. Code
> is pretty much stolen/adapted from Jakub Sitnicki's sockmap_redir_matrix.c
> [1].
>
> Usage:
> $ cd tools/testing/selftests/bpf
> $ make
> $ sudo ./test_progs -t sockmap_redir
> ...
> Summary: 1/576 PASSED, 0 SKIPPED, 0 FAILED
>
> [1]: https://github.com/jsitnicki/sockmap-redir-matrix/blob/main/sockmap_redir_matrix.c

This is exactly what we need, thanks.
>
> Changes in v2:
> - Verify that the unsupported redirect combos do fail [Jakub]
> - Dedup tests in sockmap_listen
> - Cosmetic changes and code reordering
> - Link to v1: https://lore.kernel.org/bpf/42939687-20f9-4a45-b7c2-342a0e11a014@xxxxxxx/
>
> Suggested-by: Jakub Sitnicki <jakub@xxxxxxxxxxxxxx>
> Signed-off-by: Michal Luczaj <mhal@xxxxxxx>
> ---
> Michal Luczaj (9):
> selftests/bpf: Support af_unix SOCK_DGRAM socket pair creation
> selftests/bpf: Add socket_kind_to_str() to socket_helpers
> selftests/bpf: Add u32()/u64() to sockmap_helpers
> selftests/bpf: Allow setting BPF_F_INGRESS in prog_msg_verdict()
> selftests/bpf: Add selftest for sockmap/hashmap redirection
> selftests/bpf: sockmap_listen cleanup: Drop af_vsock redir tests
> selftests/bpf: sockmap_listen cleanup: Drop af_unix redir tests
> selftests/bpf: sockmap_listen cleanup: Drop af_inet SOCK_DGRAM redir tests
> docs/bpf: sockmap: Add a missing comma
>
> Documentation/bpf/map_sockmap.rst | 2 +-
> .../selftests/bpf/prog_tests/socket_helpers.h | 84 +++-
> .../selftests/bpf/prog_tests/sockmap_helpers.h | 25 +-
> .../selftests/bpf/prog_tests/sockmap_listen.c | 459 +-------------------
> .../selftests/bpf/prog_tests/sockmap_redir.c | 461 +++++++++++++++++++++
> .../selftests/bpf/progs/test_sockmap_listen.c | 6 +-
> 6 files changed, 558 insertions(+), 479 deletions(-)
> ---
> base-commit: a27a97f713947b20ba91b23a3ef77fa92d74171b
> change-id: 20240922-selftests-sockmap-redir-5d839396c75e
>
> Best regards,
> --
> Michal Luczaj <mhal@xxxxxxx>
>