Sorry, please ignore this patch. Accidentally send the old patch again.....
On Wed, Jun 18, 2025 at 7:32 PM Yuyang Huang yuyanghuang@google.com wrote:
This commit adds a new kernel selftest to verify RTNLGRP_IPV4_MCADDR and RTNLGRP_IPV6_MCADDR notifications. The test works by adding and removing a dummy interface and then confirming that the system correctly receives join and removal notifications for the 224.0.0.1 and ff02::1 multicast addresses.
The test relies on the iproute2 version to be 6.13+.
Tested by the following command: $ vng -v --user root --cpus 16 -- \ make -C tools/testing/selftests TARGETS=net TEST_PROGS=rtnetlink_notification.sh \ TEST_GEN_PROGS="" run_tests
Cc: Maciej Żenczykowski maze@google.com Cc: Lorenzo Colitti lorenzo@google.com Signed-off-by: Yuyang Huang yuyanghuang@google.com
Changelog since v2:
- Move the test cases to a separate file.
Changelog since v1:
- Skip the test if the iproute2 is too old.
tools/testing/selftests/net/Makefile | 1 + .../selftests/net/rtnetlink_notification.sh | 159 ++++++++++++++++++ 2 files changed, 160 insertions(+) create mode 100755 tools/testing/selftests/net/rtnetlink_notification.sh
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile index 70a38f485d4d..ad258b25bc9d 100644 --- a/tools/testing/selftests/net/Makefile +++ b/tools/testing/selftests/net/Makefile @@ -40,6 +40,7 @@ TEST_PROGS += netns-name.sh TEST_PROGS += link_netns.py TEST_PROGS += nl_netdev.py TEST_PROGS += rtnetlink.py +TEST_PROGS += rtnetlink_notification.sh TEST_PROGS += srv6_end_dt46_l3vpn_test.sh TEST_PROGS += srv6_end_dt4_l3vpn_test.sh TEST_PROGS += srv6_end_dt6_l3vpn_test.sh diff --git a/tools/testing/selftests/net/rtnetlink_notification.sh b/tools/testing/selftests/net/rtnetlink_notification.sh new file mode 100755 index 000000000000..a2c1afed5023 --- /dev/null +++ b/tools/testing/selftests/net/rtnetlink_notification.sh @@ -0,0 +1,159 @@ +#!/bin/bash +# +# This test is for checking rtnetlink notification callpaths, and get as much +# coverage as possible. +# +# set -e
+ALL_TESTS="
kci_test_mcast_addr_notification+"
+VERBOSE=0 +PAUSE=no +PAUSE_ON_FAIL=no
+source lib.sh
+# set global exit status, but never reset nonzero one. +check_err() +{
if [ $ret -eq 0 ]; thenret=$1fi[ -n "$2" ] && echo "$2"+}
+run_cmd_common() +{
local cmd="$*"local outif [ "$VERBOSE" = "1" ]; thenecho "COMMAND: ${cmd}"fiout=$($cmd 2>&1)rc=$?if [ "$VERBOSE" = "1" -a -n "$out" ]; thenecho " $out"fireturn $rc+}
+run_cmd() {
run_cmd_common "$@"rc=$?check_err $rcreturn $rc+}
+end_test() +{
echo "$*"[ "${VERBOSE}" = "1" ] && echoif [[ $ret -ne 0 ]] && [[ "${PAUSE_ON_FAIL}" = "yes" ]]; thenecho "Hit enter to continue"read afi;if [ "${PAUSE}" = "yes" ]; thenecho "Hit enter to continue"read afi+}
+kci_test_mcast_addr_notification() +{
local tmpfilelocal monitor_pidlocal match_resulttmpfile=$(mktemp)ip monitor maddr > $tmpfile &monitor_pid=$!sleep 1if [ ! -e "/proc/$monitor_pid" ]; thenend_test "SKIP: mcast addr notification: iproute2 too old"rm $tmpfilereturn $ksft_skipfirun_cmd ip link add name test-dummy1 type dummyrun_cmd ip link set test-dummy1 uprun_cmd ip link del dev test-dummy1sleep 1match_result=$(grep -cE "test-dummy1.*(224.0.0.1|ff02::1)" $tmpfile)kill $monitor_pidrm $tmpfile# There should be 4 line matches as follows.# 13: test-dummy1 inet6 mcast ff02::1 scope global# 13: test-dummy1 inet mcast 224.0.0.1 scope global# Deleted 13: test-dummy1 inet mcast 224.0.0.1 scope global# Deleted 13: test-dummy1 inet6 mcast ff02::1 scope globalif [ $match_result -ne 4 ];thenend_test "FAIL: mcast addr notification"return 1fiend_test "PASS: mcast addr notification"+}
+kci_test_rtnl() +{
local current_testlocal ret=0for current_test in ${TESTS:-$ALL_TESTS}; do$current_testcheck_err $?donereturn $ret+}
+usage() +{
cat <<EOF+usage: ${0##*/} OPTS
-t <test> Test(s) to run (default: all)(options: $(echo $ALL_TESTS))-v Verbose mode (show commands and output)-P Pause after every test-p Pause after every failing test before cleanup (for debugging)+EOF +}
+#check for needed privileges +if [ "$(id -u)" -ne 0 ];then
end_test "SKIP: Need root privileges"exit $ksft_skip+fi
+for x in ip;do
$x -Version 2>/dev/null >/dev/nullif [ $? -ne 0 ];thenend_test "SKIP: Could not run test without the $x tool"exit $ksft_skipfi+done
+while getopts t:hvpP o; do
case $o int) TESTS=$OPTARG;;v) VERBOSE=1;;p) PAUSE_ON_FAIL=yes;;P) PAUSE=yes;;h) usage; exit 0;;*) usage; exit 1;;esac+done
+[ $PAUSE = "yes" ] && PAUSE_ON_FAIL="no"
+kci_test_rtnl
+exit $?
2.50.0.rc1.591.g9c95f17f64-goog