Re: [PATCH net v2 6/6] selftests: seg6: add test for skb checksum with CHECKSUM_COMPLETE
From: Hangbin Liu
Date: Thu Nov 19 2026 - 04:21:31 EST
Hi Andrea,
On Wed, Nov 18, 2026 at 04:02:51PM +0100, Andrea Mayer wrote:
> Add a selftest for received packets with CHECKSUM_COMPLETE that the SRv6
> code processes before they are delivered on the same node. The test checks
> that, after the node changes the packet, UDP does not read a wrong
> skb->csum.
>
> The test uses a host and a router connected through a veth pair. Since veth
> does not provide CHECKSUM_COMPLETE, a tc ct action on the router computes
> skb->csum in software.
>
> The host sends a UDP datagram to the router along five paths: no SRH (the
> reference), an SRH with local segments, End.B6.Encaps with End.DT6, End
> with the next-csid flavor, and End.BPF. Each datagram is expected to be
> delivered, not dropped as a checksum error. Without the previous patches,
> every path except the reference fails. With them, every path passes.
>
> The host also sends a control datagram. It checks that the test detects a
> wrong skb->csum after a change to the packet. After the ct action, a BPF
> program on the router changes the Flow Label of the control datagram
> without updating skb->csum, and UDP must drop it. If UDP accepts it, the
> paths above may report a false pass, and the test fails.
>
> Signed-off-by: Andrea Mayer <andrea.mayer@xxxxxxxxxxx>
> ---
Here are some code style comments. You can decide whether to change them or not.
>
> +print_log_test_results()
> +{
> + printf "\nTests passed: %3d\n" "${nsuccess}"
> + printf "Tests failed: %3d\n" "${nfail}"
> +
> + # when a test fails, the value of 'ret' is set to 1 (error code).
> + # Conversely, when all tests are passed successfully, the 'ret' value
> + # is set to 0 (success code).
> + if [ "${ret}" -ne 1 ]; then
> + ret=0
> + fi
Do we need to reset the "ret"? It's $ksft_skip by default. If any test failed,
it is set to $ksft_fail. We can just exit with $ret at cleanup().
> +
> +cleanup()
> +{
> + cleanup_all_ns
> +
> + # check whether the setup phase was completed successfully or not. In
> + # case of an error during the setup phase of the testing environment,
> + # the selftest is considered as "skipped".
> + if [ "${SETUP_ERR}" -ne 0 ]; then
> + echo "SKIP: Setting up the testing environment failed"
> + exit "${ksft_skip}"
if [ "${SETUP_ERR}" -ne 0 ], the ret should be ${ksft_skip}, right? Cause
we haven't run any test.
Then we can goto the following exit directly.
> + fi
> +
> + exit "${ret}"
> +}
> +
[...]
> +test_end_bpf_or_ksft_skip()
> +{
> + local test_netns
> +
> + setup_ns test_netns
> +
> + ip -netns "${test_netns}" link add "${DUMMY_DEVNAME}" type dummy
> + ip -netns "${test_netns}" link set "${DUMMY_DEVNAME}" up
> +
> + if ! ip -netns "${test_netns}" -6 route \
> + add "${SID_LOCATOR}::${BPF_FUNC}/128" encap seg6local \
> + action End.BPF endpoint obj "${BPF_FILE}" \
> + sec "${BPF_END_SEC}" dev "${DUMMY_DEVNAME}" \
> + 2>/dev/null; then
> + cleanup_ns "${test_netns}"
> + echo "SKIP: SRv6 End.BPF not supported"
> + exit "${ksft_skip}"
> + fi
> +
> + cleanup_ns "${test_netns}"
> +}
Maybe move the `trap cleanup EXIT` here.
Then we can just `exit` instead of `exit "${ksft_skip}"` for all the
test_* functions. The cleanup_all_ns() will just do nothing when the
NS_LIST is NULL.
If a command missing, or test_* function failed. The report shows
SKIP: xxx not supported
SKIP: Setting up the testing environment failed
# echo $?
4
> +
> +if [ "$(id -u)" -ne 0 ]; then
> + echo "SKIP: Need root privileges"
> + exit "${ksft_skip}"
> +fi
> +
> +# required programs to carry out this selftest
> +require_command ip
> +require_command tc
> +require_command ethtool
> +require_command ping
> +require_command sysctl
> +require_command awk
> +require_command grep
> +
> +test_dummy_dev_or_ksft_skip
> +test_iproute2_supp_or_ksft_skip
> +test_kernel_supp_or_ksft_skip
> +test_veth_tx_csum_off_or_ksft_skip
> +test_bpf_file_or_ksft_skip
> +test_tc_or_ksft_skip
> +test_end_bpf_or_ksft_skip
> +
> +set -e
> +trap cleanup EXIT
> +
> +setup
> +set +e
> +
> +connectivity_tests
> +udp_delivery_tests
> +
> +print_log_test_results
> --
Apart from the comments, the test looks good to me.
Tested-by: Hangbin Liu <liuhangbin@xxxxxxxxxx>
Reviewed-by: Hangbin Liu <liuhangbin@xxxxxxxxxx>