From: Fernando Fernandez Mancera <fmancera@suse.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, dsahern@kernel.org, kuba@kernel.org,
pabeni@redhat.com, horms@kernel.org, shuah@kernel.org,
linux-kselftest@vger.kernel.org,
Fernando Fernandez Mancera <fmancera@suse.de>
Subject: [PATCH 2/2 net-next v2] selftests: ipv6_icmp: add tests for ICMPv6 handling
Date: Wed, 7 Jan 2026 16:38:41 +0100 [thread overview]
Message-ID: <20260107153841.5030-2-fmancera@suse.de> (raw)
In-Reply-To: <20260107153841.5030-1-fmancera@suse.de>
Test ICMPv6 to link local address and local address, also VRF based
tests. In addition, this test set could be extended to cover more
situations in the future.
ICMPv6 to local addresses
TEST: Ping to link local address [OK]
TEST: Ping to link local address from ::1 [OK]
TEST: Ping to local address [OK]
TEST: Ping to local address from ::1 [OK]
ICMPv6 to VRF based local address
TEST: Ping to link local address on VRF context [OK]
TEST: Ping to link local address from ::1 on VRF context [OK]
TEST: Ping to local address on VRF context [OK]
TEST: Ping to local address from ::1 on VRF context [OK]
Tests passed: 8
Tests failed: 0
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
---
v2: shellcheck fixes, added VRF based tests and simplified linklocal
address parsing
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/ipv6_icmp.sh | 244 +++++++++++++++++++++++
2 files changed, 245 insertions(+)
create mode 100755 tools/testing/selftests/net/ipv6_icmp.sh
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index b66ba04f19d9..4d29b47bb084 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -47,6 +47,7 @@ TEST_PROGS := \
ip_local_port_range.sh \
ipv6_flowlabel.sh \
ipv6_force_forwarding.sh \
+ ipv6_icmp.sh \
ipv6_route_update_soft_lockup.sh \
l2_tos_ttl_inherit.sh \
l2tp.sh \
diff --git a/tools/testing/selftests/net/ipv6_icmp.sh b/tools/testing/selftests/net/ipv6_icmp.sh
new file mode 100755
index 000000000000..4ac0954e2963
--- /dev/null
+++ b/tools/testing/selftests/net/ipv6_icmp.sh
@@ -0,0 +1,244 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+# This test is for checking IPv6 ICMP behavior in different situations.
+source lib.sh
+ret=0
+nfail=0
+
+# all tests in this script, can be overridden with -t option
+TESTS="icmpv6_to_local_address icmpv6_to_vrf_based_local_address"
+
+VERBOSE=0
+PAUSE_ON_FAIL=no
+PAUSE=no
+
+which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
+
+log_test()
+{
+ local rc=$1
+ local expected=$2
+ local msg="$3"
+
+ if [ "${rc}" -eq "${expected}" ]; then
+ printf " TEST: %-60s [OK]\n" "${msg}"
+ nsuccess=$((nsuccess+1))
+ else
+ ret=1
+ nfail=$((nfail+1))
+ printf " TEST: %-60s [FAIL]\n" "${msg}"
+ if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
+ echo
+ echo "hit enter to continue, 'q' to quit"
+ read -r a
+ [ "$a" = "q" ] && exit 1
+ fi
+ fi
+
+ if [ "${PAUSE}" = "yes" ]; then
+ echo
+ echo "hit enter to continue, 'q' to quit"
+ read -r a
+ [ "$a" = "q" ] && exit 1
+ fi
+}
+
+setup()
+{
+ set -e
+ setup_ns ns1
+ IP="$(which ip) -netns $ns1"
+ NS_EXEC="$(which ip) netns exec $ns1"
+
+ $IP link add dummy0 type dummy
+ $IP link set dev dummy0 up
+ $IP -6 address add 2001:db8:1::1/64 dev dummy0 nodad
+ set +e
+}
+
+cleanup()
+{
+ $IP link del dev dummy0 &> /dev/null
+ cleanup_ns "$ns1"
+}
+
+get_linklocal()
+{
+ local dev=$1
+ local addr
+
+ addr=$($IP -j -6 addr show dev "${dev}" scope link | jq -r '.[].addr_info[1].local')
+
+ [ -z "$addr" ] && return 1
+
+ echo "$addr"
+
+ return 0
+}
+
+run_cmd()
+{
+ local cmd="$1"
+ local out
+ local stderr="2>/dev/null"
+
+ if [ "$VERBOSE" = "1" ]; then
+ printf " COMMAND: %s\n" "$cmd"
+ stderr=
+ fi
+
+ out=$(eval "$cmd" $stderr)
+ rc=$?
+ if [ "$VERBOSE" = "1" ] && [ -n "$out" ]; then
+ echo " $out"
+ fi
+
+ [ "$VERBOSE" = "1" ] && echo
+
+ return $rc
+}
+
+icmpv6_to_local_address()
+{
+ local rc
+ local lldummy
+
+ echo
+ echo "ICMPv6 to local addresses"
+
+ setup
+
+ lldummy=$(get_linklocal dummy0)
+
+ if [ -z "$lldummy" ]; then
+ echo "Failed to get link local address for dummy0"
+ return 1
+ fi
+
+ # ping6 to link local address
+ run_cmd "$NS_EXEC ${ping6} -c 3 $lldummy%dummy0"
+ log_test $? 0 "Ping to link local address"
+
+ # ping6 to link local address from localhost (::1)
+ run_cmd "$NS_EXEC ${ping6} -c 3 -I ::1 $lldummy%dummy0"
+ log_test $? 0 "Ping to link local address from ::1"
+
+ # ping6 to local address
+ run_cmd "$NS_EXEC ${ping6} -c 3 2001:db8:1::1"
+ log_test $? 0 "Ping to local address"
+
+ # ping6 to local address from localhost (::1)
+ run_cmd "$NS_EXEC ${ping6} -c 3 -I ::1 2001:db8:1::1"
+ log_test $? 0 "Ping to local address from ::1"
+}
+
+icmpv6_to_vrf_based_local_address()
+{
+ local rc
+ local lldummy
+
+ echo
+ echo "ICMPv6 to VRF based local address"
+
+ setup
+
+ lldummy=$(get_linklocal dummy0)
+
+ if [ -z "$lldummy" ]; then
+ echo "Failed to get link local address for dummy0"
+ return 1
+ fi
+
+ run_cmd "$NS_EXEC sysctl -w net.ipv6.conf.all.keep_addr_on_down=1"
+
+ # create VRF and setup
+ run_cmd "$IP link add vrf0 type vrf table 10"
+ run_cmd "$IP link set vrf0 up"
+ run_cmd "$IP link set dummy0 master vrf0"
+
+ # route to reach 2001:db8::1/128 on VRF device and back to ::1
+ run_cmd "$IP -6 route add 2001:db8:1::1/64 dev vrf0"
+ run_cmd "$IP -6 route add ::1/128 dev vrf0 table 10"
+
+ # ping6 to link local address
+ run_cmd "$NS_EXEC ${ping6} -c 3 $lldummy%dummy0"
+ log_test $? 0 "Ping to link local address on VRF context"
+
+ # ping6 to link local address from localhost (::1)
+ run_cmd "$NS_EXEC ${ping6} -c 3 -I ::1 $lldummy%dummy0"
+ log_test $? 0 "Ping to link local address from ::1 on VRF context"
+
+ # ping6 to local address
+ run_cmd "$NS_EXEC ${ping6} -c 3 2001:db8:1::1"
+ log_test $? 0 "Ping to local address on VRF context"
+
+ # ping6 to local address from localhost (::1)
+ run_cmd "$NS_EXEC ${ping6} -c 3 -I ::1 2001:db8:1::1"
+ log_test $? 0 "Ping to local address from ::1 on VRF context"
+}
+
+################################################################################
+# usage
+
+usage()
+{
+ cat <<EOF
+usage: ${0##*/} OPTS
+
+ -t <test> Test(s) to run (default: all)
+ (options: $TESTS)
+ -p Pause on fail
+ -P Pause after each test before cleanup
+ -v Verbose mode (show commands and output)
+EOF
+}
+
+################################################################################
+# main
+
+trap cleanup EXIT
+
+while getopts :t:pPhv o
+do
+ case $o in
+ t) TESTS=$OPTARG;;
+ p) PAUSE_ON_FAIL=yes;;
+ P) PAUSE=yes;;
+ v) VERBOSE=$((VERBOSE + 1));;
+ h) usage; exit 0;;
+ *) usage; exit 1;;
+ esac
+done
+
+[ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
+
+if [ "$(id -u)" -ne 0 ];then
+ echo "SKIP: Need root privileges"
+ exit "$ksft_skip"
+fi
+
+if [ ! -x "$(command -v ip)" ]; then
+ echo "SKIP: Could not run test without ip tool"
+ exit "$ksft_skip"
+fi
+
+# start clean
+cleanup &> /dev/null
+
+for t in $TESTS
+do
+ case $t in
+ icmpv6_to_local_address) icmpv6_to_local_address;;
+ icmpv6_to_vrf_based_local_address) icmpv6_to_vrf_based_local_address;;
+
+ help) echo "Test names: $TESTS"; exit 0;;
+ esac
+done
+
+if [ "$TESTS" != "none" ]; then
+ printf "\nTests passed: %3d\n" "${nsuccess}"
+ printf "Tests failed: %3d\n" "${nfail}"
+fi
+
+exit $ret
--
2.52.0
next prev parent reply other threads:[~2026-01-07 15:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-07 15:38 [PATCH 1/2 net-next v2] ipv6: use the right ifindex when replying to icmpv6 from localhost Fernando Fernandez Mancera
2026-01-07 15:38 ` Fernando Fernandez Mancera [this message]
2026-01-07 16:41 ` [PATCH 2/2 net-next v2] selftests: ipv6_icmp: add tests for ICMPv6 handling David Ahern
2026-01-08 11:24 ` Fernando Fernandez Mancera
2026-01-08 15:20 ` David Ahern
2026-01-20 19:24 ` Fernando Fernandez Mancera
2026-01-20 19:44 ` Fernando Fernandez Mancera
2026-01-07 17:05 ` [PATCH 1/2 net-next v2] ipv6: use the right ifindex when replying to icmpv6 from localhost Brian Haley
2026-01-08 11:27 ` Fernando Fernandez Mancera
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=20260107153841.5030-2-fmancera@suse.de \
--to=fmancera@suse.de \
--cc=davem@davemloft.net \
--cc=dsahern@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox