]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftest: add selftest for anycast notifications
authorYuyang Huang <yuyanghuang@google.com>
Thu, 19 Jun 2025 03:51:16 +0000 (12:51 +0900)
committerDavid S. Miller <davem@davemloft.net>
Sun, 22 Jun 2025 16:32:04 +0000 (17:32 +0100)
This commit adds a new kernel selftest to verify RTNLGRP_IPV6_ACADDR
notifications. The test works by adding/removing a dummy interface,
enabling packet forwarding, and then confirming that user space can
correctly receive anycast notifications.

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>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/rtnetlink_notification.sh

index 39c1b815bbe4e20f1fc7e018f0af1fbcd0c80bff..3f9780232bd62c59ba310476401c791aeaffa15f 100755 (executable)
@@ -8,9 +8,11 @@
 
 ALL_TESTS="
        kci_test_mcast_addr_notification
+       kci_test_anycast_addr_notification
 "
 
 source lib.sh
+test_dev="test-dummy1"
 
 kci_test_mcast_addr_notification()
 {
@@ -18,7 +20,6 @@ kci_test_mcast_addr_notification()
        local tmpfile
        local monitor_pid
        local match_result
-       local test_dev="test-dummy1"
 
        tmpfile=$(mktemp)
        defer rm "$tmpfile"
@@ -56,6 +57,47 @@ kci_test_mcast_addr_notification()
        return $RET
 }
 
+kci_test_anycast_addr_notification()
+{
+       RET=0
+       local tmpfile
+       local monitor_pid
+       local match_result
+
+       tmpfile=$(mktemp)
+       defer rm "$tmpfile"
+
+       ip monitor acaddress > "$tmpfile" &
+       monitor_pid=$!
+       defer kill_process "$monitor_pid"
+       sleep 1
+
+       if [ ! -e "/proc/$monitor_pid" ]; then
+               RET=$ksft_skip
+               log_test "anycast addr notification: iproute2 too old"
+               return "$RET"
+       fi
+
+       ip link add name "$test_dev" type dummy
+       check_err $? "failed to add dummy interface"
+       ip link set "$test_dev" up
+       check_err $? "failed to set dummy interface up"
+       sysctl -qw net.ipv6.conf."$test_dev".forwarding=1
+       ip link del dev "$test_dev"
+       check_err $? "Failed to delete dummy interface"
+       sleep 1
+
+       # There should be 2 line matches as follows.
+       # 9: dummy2    inet6 any fe80:: scope global
+       # Deleted 9: dummy2    inet6 any fe80:: scope global
+       match_result=$(grep -cE "$test_dev.*(fe80::)" "$tmpfile")
+       if [ "$match_result" -ne 2 ]; then
+               RET=$ksft_fail
+       fi
+       log_test "anycast addr notification: Expected 2 matches, got $match_result"
+       return "$RET"
+}
+
 #check for needed privileges
 if [ "$(id -u)" -ne 0 ];then
        RET=$ksft_skip