selftests/bpf: Test bpf_sock_destroy
authorAditi Ghag <aditi.ghag@isovalent.com>
Fri, 19 May 2023 22:51:57 +0000 (22:51 +0000)
committerMartin KaFai Lau <martin.lau@kernel.org>
Sat, 20 May 2023 05:44:28 +0000 (22:44 -0700)
commit1a8bc2299f4028e9bac36020ffaaec27a0dfb9c1
tree3ad42c66005ca05fd9774e0fb61e572754d4ca43
parent176ba657e6aaa61df637558a57acd8b7bf043cb4
selftests/bpf: Test bpf_sock_destroy

The test cases for destroying sockets mirror the intended usages of the
bpf_sock_destroy kfunc using iterators.

The destroy helpers set `ECONNABORTED` error code that we can validate
in the test code with client sockets. But UDP sockets have an overriding
error code from `disconnect()` called during abort, so the error code
validation is only done for TCP sockets.

The failure test cases validate that the `bpf_sock_destroy` kfunc is not
allowed from program attach types other than BPF trace iterator, and
such programs fail to load.

Signed-off-by: Aditi Ghag <aditi.ghag@isovalent.com>
Link: https://lore.kernel.org/r/20230519225157.760788-10-aditi.ghag@isovalent.com
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
tools/testing/selftests/bpf/prog_tests/sock_destroy.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/sock_destroy_prog.c [new file with mode: 0644]
tools/testing/selftests/bpf/progs/sock_destroy_prog_fail.c [new file with mode: 0644]