2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for the accept_untracked_na feature to
5 # enable RFC9131 behaviour. The following is the test-matrix.
6 # drop accept fwding behaviour
7 # ---- ------ ------ ----------------------------------------------
8 # 1 X X Don't update NC
9 # 0 0 X Don't update NC
10 # 0 1 0 Don't update NC
11 # 0 1 1 Add a STALE NC entry
20 ROUTER_INTF
="veth-router"
22 ROUTER_ADDR
="2000:20::1"
23 HOST_ADDR
="2000:20::2"
25 ROUTER_ADDR_WITH_MASK
="${ROUTER_ADDR}/${SUBNET_WIDTH}"
26 HOST_ADDR_WITH_MASK
="${HOST_ADDR}/${SUBNET_WIDTH}"
37 if [ ${rc} -eq ${expected} ]; then
38 printf " TEST: %-60s [ OK ]\n" "${msg}"
39 nsuccess
=$
((nsuccess
+1))
43 printf " TEST: %-60s [FAIL]\n" "${msg}"
44 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
46 echo "hit enter to continue, 'q' to quit"
48 [ "$a" = "q" ] && exit 1
52 if [ "${PAUSE}" = "yes" ]; then
54 echo "hit enter to continue, 'q' to quit"
56 [ "$a" = "q" ] && exit 1
64 local drop_unsolicited_na
=$1
65 local accept_untracked_na
=$2
68 # Setup two namespaces and a veth tunnel across them.
69 # On end of the tunnel is a router and the other end is a host.
70 setup_ns HOST_NS ROUTER_NS
71 IP_HOST
="ip -6 -netns ${HOST_NS}"
72 IP_HOST_EXEC
="ip netns exec ${HOST_NS}"
73 IP_ROUTER
="ip -6 -netns ${ROUTER_NS}"
74 IP_ROUTER_EXEC
="ip netns exec ${ROUTER_NS}"
76 ${IP_ROUTER} link add
${ROUTER_INTF} type veth \
77 peer name
${HOST_INTF} netns
${HOST_NS}
79 # Enable IPv6 on both router and host, and configure static addresses.
80 # The router here is the DUT
81 # Setup router configuration as specified by the arguments.
82 # forwarding=0 case is to check that a non-router
83 # doesn't add neighbour entries.
84 ROUTER_CONF
=net.ipv6.conf.
${ROUTER_INTF}
85 ${IP_ROUTER_EXEC} sysctl
-qw \
86 ${ROUTER_CONF}.forwarding
=${forwarding}
87 ${IP_ROUTER_EXEC} sysctl
-qw \
88 ${ROUTER_CONF}.drop_unsolicited_na
=${drop_unsolicited_na}
89 ${IP_ROUTER_EXEC} sysctl
-qw \
90 ${ROUTER_CONF}.accept_untracked_na
=${accept_untracked_na}
91 ${IP_ROUTER_EXEC} sysctl
-qw ${ROUTER_CONF}.disable_ipv6
=0
92 ${IP_ROUTER} addr add ${ROUTER_ADDR_WITH_MASK} dev ${ROUTER_INTF}
94 # Turn on ndisc_notify on host interface so that
95 # the host sends unsolicited NAs.
96 HOST_CONF
=net.ipv6.conf.
${HOST_INTF}
97 ${IP_HOST_EXEC} sysctl
-qw ${HOST_CONF}.ndisc_notify
=1
98 ${IP_HOST_EXEC} sysctl
-qw ${HOST_CONF}.disable_ipv6
=0
99 ${IP_HOST} addr add ${HOST_ADDR_WITH_MASK} dev ${HOST_INTF}
106 tcpdump_stdout
=`mktemp`
107 tcpdump_stderr
=`mktemp`
108 ${IP_ROUTER_EXEC} timeout
15s \
109 tcpdump
--immediate-mode -tpni ${ROUTER_INTF} -c 1 \
110 "icmp6 && icmp6[0] == 136 && src ${HOST_ADDR}" \
111 > ${tcpdump_stdout} 2> /dev
/null
118 [[ ! -z ${tcpdump_stdout} ]] && rm -f ${tcpdump_stdout}
119 [[ ! -z ${tcpdump_stderr} ]] && rm -f ${tcpdump_stderr}
128 ip netns del
${HOST_NS}
129 ip netns del
${ROUTER_NS}
134 ${IP_ROUTER} link
set dev
${ROUTER_INTF} up
135 ${IP_HOST} link
set dev
${HOST_INTF} up
140 local drop_unsolicited_na
=$1
141 local accept_untracked_na
=$2
144 neigh_show_output
=$
(${IP_ROUTER} neigh show \
145 to
${HOST_ADDR} dev
${ROUTER_INTF} nud stale
)
146 if [ ${drop_unsolicited_na} -eq 0 ] && \
147 [ ${accept_untracked_na} -eq 1 ] && \
148 [ ${forwarding} -eq 1 ]; then
149 # Neighbour entry expected to be present for 011 case
150 [[ ${neigh_show_output} ]]
152 # Neighbour entry expected to be absent for all other cases
153 [[ -z ${neigh_show_output} ]]
157 test_unsolicited_na_common
()
159 # Setup the test bed, but keep links down
162 # Bring the link up, wait for the NA,
163 # and add a delay to ensure neighbour processing is done.
167 # Verify the neighbour table
168 verify_ndisc
$1 $2 $3
172 test_unsolicited_na_combination
() {
173 test_unsolicited_na_common
$1 $2 $3
174 test_msg
=("test_unsolicited_na: "
175 "drop_unsolicited_na=$1 "
176 "accept_untracked_na=$2 "
178 log_test $?
0 "${test_msg[*]}"
182 test_unsolicited_na_combinations
() {
183 # Args: drop_unsolicited_na accept_untracked_na forwarding
186 test_unsolicited_na_combination
0 1 1
189 test_unsolicited_na_combination
0 0 0
190 test_unsolicited_na_combination
0 0 1
191 test_unsolicited_na_combination
0 1 0
192 test_unsolicited_na_combination
1 0 0
193 test_unsolicited_na_combination
1 0 1
194 test_unsolicited_na_combination
1 1 0
195 test_unsolicited_na_combination
1 1 1
198 ###############################################################################
206 -P Pause after each test before cleanup
210 ###############################################################################
216 p
) PAUSE_ON_FAIL
=yes;;
223 # make sure we don't pause twice
224 [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL
=no
226 if [ "$(id -u)" -ne 0 ];then
227 echo "SKIP: Need root privileges"
231 if [ ! -x "$(command -v ip)" ]; then
232 echo "SKIP: Could not run test without ip tool"
236 if [ ! -x "$(command -v tcpdump)" ]; then
237 echo "SKIP: Could not run test without tcpdump tool"
244 test_unsolicited_na_combinations
246 printf "\nTests passed: %3d\n" ${nsuccess}
247 printf "Tests failed: %3d\n" ${nfail}