Skip to content

Commit 5c041cf

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 Signed-off-by: Yuyang Huang <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 7c98623 commit 5c041cf

File tree

1 file changed

+47
-5
lines changed

1 file changed

+47
-5
lines changed

tools/testing/selftests/net/rtnetlink_notification.sh

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,23 @@
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"
2526

26-
ip monitor maddr > $tmpfile &
27+
ip monitor maddr > "$tmpfile" &
2728
monitor_pid=$!
2829
defer kill_process "$monitor_pid"
2930

@@ -32,7 +33,7 @@ kci_test_mcast_addr_notification()
3233
if [ ! -e "/proc/$monitor_pid" ]; then
3334
RET=$ksft_skip
3435
log_test "mcast addr notification: iproute2 too old"
35-
return $RET
36+
return "$RET"
3637
fi
3738

3839
ip link add name "$test_dev" type dummy
@@ -53,7 +54,48 @@ kci_test_mcast_addr_notification()
5354
RET=$ksft_fail
5455
fi
5556
log_test "mcast addr notification: Expected 4 matches, got $match_result"
56-
return $RET
57+
return "$RET"
58+
}
59+
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"
5799
}
58100

59101
#check for needed privileges
@@ -67,4 +109,4 @@ require_command ip
67109

68110
tests_run
69111

70-
exit $EXIT_STATUS
112+
exit "$EXIT_STATUS"

0 commit comments

Comments
 (0)