Skip to contentSkip to conversation

selftests/net: use tc rule to filter the na packet

PATCH Applied Hangbin Liu 4 participants 5 messages May 17, 2024 – May 21, 2024

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 selftests/net: use tc rule to filter the na packet

Test arp_ndisc_untracked_subnets use tcpdump to filter the unsolicited and untracked na messages. It set -e before calling tcpdump. But if tcpdump filters 0 packet, it will return none zero, and cause the script to exit.

Instead of using slow tcpdump to capture packets, let's using tc rule to filter out the na message.

At the same time, fix function setup_v6 which only needs one parameter. Move all the related helpers from forwarding lib.sh to net lib.sh.

Fixes 0ea7b0a454ca ("selftests: net: arp_ndisc_untracked_subnets: test for arp_accept and accept_untracked_na")

---

v2: rebase to latest net main code. no update,
v1: https://lore.kernel.org/netdev/[email protected]

---
 .../net/arp_ndisc_untracked_subnets.sh        | 53 ++++++-----------
 tools/testing/selftests/net/forwarding/lib.sh | 58 -------------------
 tools/testing/selftests/net/lib.sh            | 58 +++++++++++++++++++
 3 files changed, 75 insertions(+), 94 deletions(-)
tools/testing/selftests/net/arp_ndisc_untracked_subnets.sh +17 -36
index a40c0e9bd023..eef5cbf6eecc 100755
@@ -73,25 +73,19 @@ setup_v6() {
 	# namespaces. veth0 is veth-router, veth1 is veth-host.
 	# first, set up the inteface's link to the namespace
 	# then, set the interface "up"
-	ip -6 -netns ${ROUTER_NS_V6} link add name ${ROUTER_INTF} \
-		type veth peer name ${HOST_INTF}
-
-	ip -6 -netns ${ROUTER_NS_V6} link set dev ${ROUTER_INTF} up
-	ip -6 -netns ${ROUTER_NS_V6} link set dev ${HOST_INTF} netns \
-		${HOST_NS_V6}
+	ip -n ${ROUTER_NS_V6} link add name ${ROUTER_INTF} \
+		type veth peer name ${HOST_INTF} netns ${HOST_NS_V6}
 
-	ip -6 -netns ${HOST_NS_V6} link set dev ${HOST_INTF} up
-	ip -6 -netns ${ROUTER_NS_V6} addr add \
-		${ROUTER_ADDR_V6}/${PREFIX_WIDTH_V6} dev ${ROUTER_INTF} nodad
+	# Add tc rule to filter out host na message
+	tc -n ${ROUTER_NS_V6} qdisc add dev ${ROUTER_INTF} clsact
+	tc -n ${ROUTER_NS_V6} filter add dev ${ROUTER_INTF} \
+		ingress protocol ipv6 pref 1 handle 101 \
+		flower src_ip ${HOST_ADDR_V6} ip_proto icmpv6 type 136 skip_hw action pass
 
 	HOST_CONF=net.ipv6.conf.${HOST_INTF}
 	ip netns exec ${HOST_NS_V6} sysctl -qw ${HOST_CONF}.ndisc_notify=1
 	ip netns exec ${HOST_NS_V6} sysctl -qw ${HOST_CONF}.disable_ipv6=0
-	ip -6 -netns ${HOST_NS_V6} addr add ${HOST_ADDR_V6}/${PREFIX_WIDTH_V6} \
-		dev ${HOST_INTF}
-
 	ROUTER_CONF=net.ipv6.conf.${ROUTER_INTF}
-
 	ip netns exec ${ROUTER_NS_V6} sysctl -w \
 		${ROUTER_CONF}.forwarding=1 >/dev/null 2>&1
 	ip netns exec ${ROUTER_NS_V6} sysctl -w \
@@ -99,6 +93,13 @@ setup_v6() {
 	ip netns exec ${ROUTER_NS_V6} sysctl -w \
 		${ROUTER_CONF}.accept_untracked_na=${accept_untracked_na} \
 		>/dev/null 2>&1
+
+	ip -n ${ROUTER_NS_V6} link set dev ${ROUTER_INTF} up
+	ip -n ${HOST_NS_V6} link set dev ${HOST_INTF} up
+	ip -n ${ROUTER_NS_V6} addr add ${ROUTER_ADDR_V6}/${PREFIX_WIDTH_V6} \
+		dev ${ROUTER_INTF} nodad
+	ip -n ${HOST_NS_V6} addr add ${HOST_ADDR_V6}/${PREFIX_WIDTH_V6} \
+		dev ${HOST_INTF}
 	set +e
 }
 
@@ -162,26 +163,6 @@ arp_test_gratuitous_combinations() {
 	arp_test_gratuitous 2 1
 }
 
-cleanup_tcpdump() {
-	set -e
-	[[ ! -z  ${tcpdump_stdout} ]] && rm -f ${tcpdump_stdout}
-	[[ ! -z  ${tcpdump_stderr} ]] && rm -f ${tcpdump_stderr}
-	tcpdump_stdout=
-	tcpdump_stderr=
-	set +e
-}
-
-start_tcpdump() {
-	set -e
-	tcpdump_stdout=`mktemp`
-	tcpdump_stderr=`mktemp`
-	ip netns exec ${ROUTER_NS_V6} timeout 15s \
-		tcpdump --immediate-mode -tpni ${ROUTER_INTF} -c 1 \
-		"icmp6 && icmp6[0] == 136 && src ${HOST_ADDR_V6}" \
-		> ${tcpdump_stdout} 2> /dev/null
-	set +e
-}
-
 verify_ndisc() {
 	local accept_untracked_na=$1
 	local same_subnet=$2
@@ -222,8 +203,9 @@ ndisc_test_untracked_advertisements() {
 			HOST_ADDR_V6=2001:db8:abcd:0012::3
 		fi
 	fi
-	setup_v6 $1 $2
-	start_tcpdump
+	setup_v6 $1
+	slowwait_for_counter 15 1 \
+		tc_rule_handle_stats_get "dev ${ROUTER_INTF} ingress" 101 ".packets" "-n ${ROUTER_NS_V6}"
 
 	if verify_ndisc $1 $2; then
 		printf "    TEST: %-60s  [ OK ]\n" "${test_msg[*]}"
@@ -231,7 +213,6 @@ ndisc_test_untracked_advertisements() {
 		printf "    TEST: %-60s  [FAIL]\n" "${test_msg[*]}"
 	fi
 
-	cleanup_tcpdump
 	cleanup_v6
 	set +e
 }
tools/testing/selftests/net/forwarding/lib.sh +0 -58

76 lines not on this page · raw message

tools/testing/selftests/net/lib.sh +58 -0

67 lines not on this page · raw message

Signature · 1 line
2.43.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 5 lines · Hangbin Liu

Test arp_ndisc_untracked_subnets use tcpdump to filter the unsolicited and untracked na messages. It set -e before calling tcpdump. But if tcpdump filters 0 packet, it will return none zero, and cause the script to exit.

Quoted 8 lines

Instead of using slow tcpdump to capture packets, let's using tc rule to filter out the na message.

At the same time, fix function setup_v6 which only needs one parameter. Move all the related helpers from forwarding lib.sh to net lib.sh.

Fixes 0ea7b0a454ca ("selftests: net: arp_ndisc_untracked_subnets: test for arp_accept and accept_untracked_na")

I see that, as of writing, the last two runs of this test have succeeded. Which doesn't seem to have occurred since 9th May. So this does seem positive, albeit perhaps a bit too soon to call.

Jakub, is there a way to tell how long a test took to execute? Perhaps it's obvious, but I couldn't see it.

Code changes look good to me.

maintainer
#2 lore raw
Quoted 2 lines · On Fri, 17 May 2024 10:14:02 +0100 Simon Horman wrote:

Jakub, is there a way to tell how long a test took to execute? Perhaps it's obvious, but I couldn't see it.

It's not obvious, and it was broken. There's an 'info' file with extra metadata in the directory with results:

https://netdev-3.bots.linux.dev/vmksft-net-dbg/results/599300/39-arp-ndisc-untracked-subnets-sh/info

but it's currently reporting fractional seconds rather than total seconds:

https://github.com/linux-netdev/nipa/commit/fb7c45fd3b68b379b7bceb8f79c8df06aaf53ee0

Once we have a proper DB (any day now), I'll add it to the JSON output so it appears in the web UI.

reviewer
#3 lore raw
Quoted 9 lines · Jakub Kicinski
Quoted 2 lines · On Fri, 17 May 2024 10:14:02 +0100 Simon Horman wrote:

Jakub, is there a way to tell how long a test took to execute? Perhaps it's obvious, but I couldn't see it.

It's not obvious, and it was broken. There's an 'info' file with extra metadata in the directory with results:

https://netdev-3.bots.linux.dev/vmksft-net-dbg/results/599300/39-arp-ndisc-untracked-subnets-sh/info

Quoted 7 lines

but it's currently reporting fractional seconds rather than total seconds:

https://github.com/linux-netdev/nipa/commit/fb7c45fd3b68b379b7bceb8f79c8df06aaf53ee0

Once we have a proper DB (any day now), I'll add it to the JSON output so it appears in the web UI.

Great, thanks.

#4 lore raw
In reply to Hangbin Liu
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:

Quoted 9 lines · On Fri, 17 May 2024 09:03:27 +0800 you wrote:

Test arp_ndisc_untracked_subnets use tcpdump to filter the unsolicited and untracked na messages. It set -e before calling tcpdump. But if tcpdump filters 0 packet, it will return none zero, and cause the script to exit.

Instead of using slow tcpdump to capture packets, let's using tc rule to filter out the na message.

[...]

Here is the summary with links:
- [PATCHv2,net] selftests/net: use tc rule to filter the na packet

    https://git.kernel.org/netdev/net/c/ea63ac142925

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html