Skip to content

Commit 695a073

Browse files
Yuyang HuangNipaLocal
authored andcommitted
selftest: add selftest for anycast notifications
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 <[email protected]> Cc: Lorenzo Colitti <[email protected]> Signed-off-by: Yuyang Huang <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 55781f9 commit 695a073

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

tools/testing/selftests/net/rtnetlink_notification.sh

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@
88

99
ALL_TESTS="
1010
kci_test_mcast_addr_notification
11+
kci_test_anycast_addr_notification
1112
"
1213

1314
source lib.sh
15+
test_dev="test-dummy1"
1416

1517
kci_test_mcast_addr_notification()
1618
{
1719
RET=0
1820
local tmpfile
1921
local monitor_pid
2022
local match_result
21-
local test_dev="test-dummy1"
2223

2324
tmpfile=$(mktemp)
2425
defer rm "$tmpfile"
@@ -56,6 +57,47 @@ kci_test_mcast_addr_notification()
5657
return $RET
5758
}
5859

60+
kci_test_anycast_addr_notification()
61+
{
62+
RET=0
63+
local tmpfile
64+
local monitor_pid
65+
local match_result
66+
67+
tmpfile=$(mktemp)
68+
defer rm "$tmpfile"
69+
70+
ip monitor acaddress > "$tmpfile" &
71+
monitor_pid=$!
72+
defer kill_process "$monitor_pid"
73+
sleep 1
74+
75+
if [ ! -e "/proc/$monitor_pid" ]; then
76+
RET=$ksft_skip
77+
log_test "anycast addr notification: iproute2 too old"
78+
return "$RET"
79+
fi
80+
81+
ip link add name "$test_dev" type dummy
82+
check_err $? "failed to add dummy interface"
83+
ip link set "$test_dev" up
84+
check_err $? "failed to set dummy interface up"
85+
sysctl -qw net.ipv6.conf."$test_dev".forwarding=1
86+
ip link del dev "$test_dev"
87+
check_err $? "Failed to delete dummy interface"
88+
sleep 1
89+
90+
# There should be 2 line matches as follows.
91+
# 9: dummy2 inet6 any fe80:: scope global
92+
# Deleted 9: dummy2 inet6 any fe80:: scope global
93+
match_result=$(grep -cE "$test_dev.*(fe80::)" "$tmpfile")
94+
if [ "$match_result" -ne 2 ]; then
95+
RET=$ksft_fail
96+
fi
97+
log_test "anycast addr notification: Expected 2 matches, got $match_result"
98+
return "$RET"
99+
}
100+
59101
#check for needed privileges
60102
if [ "$(id -u)" -ne 0 ];then
61103
RET=$ksft_skip

0 commit comments

Comments
 (0)