[PATCH net-next v2 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses

Oscar Maes posted 2 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH net-next v2 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses
Posted by Oscar Maes 1 month, 3 weeks ago
Add a test for ensuring that the dst hint mechanism is used for
directed broadcast addresses.

This test relies on mausezahn for sending directed broadcast packets.
Additionally, a high GRO flush timeout is set to ensure that packets
will be received as lists.

The test determines if the hint mechanism was used by checking
the in_brd statistic using lnstat.

Signed-off-by: Oscar Maes <oscmaes92@gmail.com>
---
 tools/testing/selftests/net/route_hint.sh | 58 +++++++++++++++++++++++
 1 file changed, 58 insertions(+)
 create mode 100755 tools/testing/selftests/net/route_hint.sh

diff --git a/tools/testing/selftests/net/route_hint.sh b/tools/testing/selftests/net/route_hint.sh
new file mode 100755
index 000000000000..fab08d8b742d
--- /dev/null
+++ b/tools/testing/selftests/net/route_hint.sh
@@ -0,0 +1,58 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# This test ensures directed broadcast routes use dst hint mechanism
+
+CLIENT_NS=$(mktemp -u client-XXXXXXXX)
+CLIENT_IP4="192.168.0.1"
+
+SERVER_NS=$(mktemp -u server-XXXXXXXX)
+SERVER_IP4="192.168.0.2"
+
+BROADCAST_ADDRESS="192.168.0.255"
+
+setup() {
+	ip netns add "${CLIENT_NS}"
+	ip netns add "${SERVER_NS}"
+
+	ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}"
+
+	ip -net "${CLIENT_NS}" link set link0 up
+	ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0
+
+	ip -net "${SERVER_NS}" link set link1 up
+	ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1
+
+	ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off
+	ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout"
+	ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs"
+	ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on
+}
+
+cleanup() {
+	ip -net "${SERVER_NS}" link del link1
+	ip netns del "${CLIENT_NS}"
+	ip netns del "${SERVER_NS}"
+}
+
+directed_bcast_hint_test()
+{
+	echo "Testing for directed broadcast route hint"
+
+	orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')
+	ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \
+		-B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q
+	sleep 1
+	new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')
+
+	res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc)
+
+	[ "${res}" -lt 100 ]
+}
+
+trap cleanup EXIT
+
+setup
+
+directed_bcast_hint_test
+exit $?
-- 
2.39.5
Re: [PATCH net-next v2 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses
Posted by Paolo Abeni 1 month, 2 weeks ago
On 8/14/25 4:03 PM, Oscar Maes wrote:
>  tools/testing/selftests/net/route_hint.sh | 58 +++++++++++++++++++++++
>  1 file changed, 58 insertions(+)
>  create mode 100755 tools/testing/selftests/net/route_hint.sh

You must additionally update the net selftest Makefile to include the
new test.

> 
> diff --git a/tools/testing/selftests/net/route_hint.sh b/tools/testing/selftests/net/route_hint.sh
> new file mode 100755
> index 000000000000..fab08d8b742d
> --- /dev/null
> +++ b/tools/testing/selftests/net/route_hint.sh
> @@ -0,0 +1,58 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +
> +# This test ensures directed broadcast routes use dst hint mechanism
> +
> +CLIENT_NS=$(mktemp -u client-XXXXXXXX)
> +CLIENT_IP4="192.168.0.1"
> +
> +SERVER_NS=$(mktemp -u server-XXXXXXXX)
> +SERVER_IP4="192.168.0.2"

> +
> +BROADCAST_ADDRESS="192.168.0.255"
> +
> +setup() {
> +	ip netns add "${CLIENT_NS}"
> +	ip netns add "${SERVER_NS}"

You can/should use setup_ns() from lib.sh to avoid some duplicate code

> +
> +	ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}"
> +
> +	ip -net "${CLIENT_NS}" link set link0 up
> +	ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0
> +
> +	ip -net "${SERVER_NS}" link set link1 up
> +	ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1
> +
> +	ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off
> +	ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout"
> +	ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs"
> +	ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on
> +}
> +
> +cleanup() {
> +	ip -net "${SERVER_NS}" link del link1
> +	ip netns del "${CLIENT_NS}"
> +	ip netns del "${SERVER_NS}"
> +}
> +
> +directed_bcast_hint_test()
> +{
> +	echo "Testing for directed broadcast route hint"
> +
> +	orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')

Likely using the '--json' argument and 'jq' will make the parsing more
clear.

> +	ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \
> +		-B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q

You should check for mausezahn presence and ev. error out with error
code 4 (ksft_skip)

> +	sleep 1
> +	new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')
> +
> +	res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc)
> +
> +	[ "${res}" -lt 100 ]

It would be helpful additionally printing the test result:  '[ ok ]' /
'[fail] expected ... found ...'

/P
Re: [PATCH net-next v2 2/2] selftests: net: add test for dst hint mechanism with directed broadcast addresses
Posted by Oscar Maes 1 month, 2 weeks ago
On Tue, Aug 19, 2025 at 12:56:58PM +0200, Paolo Abeni wrote:
> On 8/14/25 4:03 PM, Oscar Maes wrote:
> >  tools/testing/selftests/net/route_hint.sh | 58 +++++++++++++++++++++++
> >  1 file changed, 58 insertions(+)
> >  create mode 100755 tools/testing/selftests/net/route_hint.sh
> 
> You must additionally update the net selftest Makefile to include the
> new test.
> 

My bad.

> > 
> > diff --git a/tools/testing/selftests/net/route_hint.sh b/tools/testing/selftests/net/route_hint.sh
> > new file mode 100755
> > index 000000000000..fab08d8b742d
> > --- /dev/null
> > +++ b/tools/testing/selftests/net/route_hint.sh
> > @@ -0,0 +1,58 @@
> > +#!/bin/bash
> > +# SPDX-License-Identifier: GPL-2.0
> > +
> > +# This test ensures directed broadcast routes use dst hint mechanism
> > +
> > +CLIENT_NS=$(mktemp -u client-XXXXXXXX)
> > +CLIENT_IP4="192.168.0.1"
> > +
> > +SERVER_NS=$(mktemp -u server-XXXXXXXX)
> > +SERVER_IP4="192.168.0.2"
> 
> > +
> > +BROADCAST_ADDRESS="192.168.0.255"
> > +
> > +setup() {
> > +	ip netns add "${CLIENT_NS}"
> > +	ip netns add "${SERVER_NS}"
> 
> You can/should use setup_ns() from lib.sh to avoid some duplicate code
> 
> > +
> > +	ip -net "${SERVER_NS}" link add link1 type veth peer name link0 netns "${CLIENT_NS}"
> > +
> > +	ip -net "${CLIENT_NS}" link set link0 up
> > +	ip -net "${CLIENT_NS}" addr add "${CLIENT_IP4}/24" dev link0
> > +
> > +	ip -net "${SERVER_NS}" link set link1 up
> > +	ip -net "${SERVER_NS}" addr add "${SERVER_IP4}/24" dev link1
> > +
> > +	ip netns exec "${CLIENT_NS}" ethtool -K link0 tcp-segmentation-offload off
> > +	ip netns exec "${SERVER_NS}" sh -c "echo 500000000 > /sys/class/net/link1/gro_flush_timeout"
> > +	ip netns exec "${SERVER_NS}" sh -c "echo 1 > /sys/class/net/link1/napi_defer_hard_irqs"
> > +	ip netns exec "${SERVER_NS}" ethtool -K link1 generic-receive-offload on
> > +}
> > +
> > +cleanup() {
> > +	ip -net "${SERVER_NS}" link del link1
> > +	ip netns del "${CLIENT_NS}"
> > +	ip netns del "${SERVER_NS}"
> > +}
> > +
> > +directed_bcast_hint_test()
> > +{
> > +	echo "Testing for directed broadcast route hint"
> > +
> > +	orig_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')
> 
> Likely using the '--json' argument and 'jq' will make the parsing more
> clear.
> 
> > +	ip netns exec "${CLIENT_NS}" mausezahn link0 -a own -b bcast -A "${CLIENT_IP4}" \
> > +		-B "${BROADCAST_ADDRESS}" -c1 -t tcp "sp=1-100,dp=1234,s=1,a=0" -p 5 -q
> 
> You should check for mausezahn presence and ev. error out with error
> code 4 (ksft_skip)
> 
> > +	sleep 1
> > +	new_in_brd=$(ip netns exec "${SERVER_NS}" lnstat -k in_brd -s0 -i1 -c1 | tr -d ' |')
> > +
> > +	res=$(echo "${new_in_brd} - ${orig_in_brd}" | bc)
> > +
> > +	[ "${res}" -lt 100 ]
> 
> It would be helpful additionally printing the test result:  '[ ok ]' /
> '[fail] expected ... found ...'
> 
> /P
> 

Will fix everything in v3 and resend shortly.