All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hangbin Liu <hangbin.liu@linux.dev>
To: Andrea Mayer <andrea.mayer@uniroma2.it>
Cc: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
	Ido Schimmel <idosch@nvidia.com>, Shuah Khan <shuah@kernel.org>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-kselftest@vger.kernel.org, bpf@vger.kernel.org,
	David Lebrun <david.lebrun@uclouvain.be>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Mathieu Xhonneux <m.xhonneux@gmail.com>,
	David Lebrun <dlebrun@google.com>,
	Justin Iurman <justin.iurman@gmail.com>,
	Stefano Salsano <stefano.salsano@uniroma2.it>,
	Andrea Mayer <andrea@common-net.org>
Subject: Re: [PATCH net v2 6/6] selftests: seg6: add test for skb checksum with CHECKSUM_COMPLETE
Date: Thu, 19 Nov 2026 17:20:58 +0800	[thread overview]
Message-ID: <av6_eqt8yH5qmLYL@fedora> (raw)
In-Reply-To: <20261118150251.65-7-andrea.mayer@uniroma2.it>

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@uniroma2.it>
> ---

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@kylinos.cn>
Reviewed-by: Hangbin Liu <liuhangbin@kylinos.cn>

      reply	other threads:[~2026-11-19  9:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 15:02 [PATCH net v2 0/6] seg6: fix skb checksum updates with CHECKSUM_COMPLETE Andrea Mayer
2026-11-18 15:02 ` [PATCH net v2 1/6] seg6: fix skb checksum update helpers Andrea Mayer
2026-11-18 15:02 ` [PATCH net v2 2/6] seg6: update skb checksum when ipv6_srh_rcv() decrements the Hop Limit Andrea Mayer
2026-11-18 15:02 ` [PATCH net v2 3/6] seg6: update skb checksum when SRv6 behaviors advance to the next SID Andrea Mayer
2026-11-18 15:02 ` [PATCH net v2 4/6] seg6: discard CHECKSUM_COMPLETE after the End.BPF program Andrea Mayer
2026-11-19  8:42   ` Hangbin Liu
2026-11-18 15:02 ` [PATCH net v2 5/6] seg6: account for the MAC header in skb checksum on L2 encapsulation Andrea Mayer
2026-11-19  8:47   ` Hangbin Liu
2026-11-18 15:02 ` [PATCH net v2 6/6] selftests: seg6: add test for skb checksum with CHECKSUM_COMPLETE Andrea Mayer
2026-11-19  9:20   ` Hangbin Liu [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=av6_eqt8yH5qmLYL@fedora \
    --to=hangbin.liu@linux.dev \
    --cc=andrea.mayer@uniroma2.it \
    --cc=andrea@common-net.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=david.lebrun@uclouvain.be \
    --cc=dlebrun@google.com \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=justin.iurman@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=m.xhonneux@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shuah@kernel.org \
    --cc=stefano.salsano@uniroma2.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.