xref: /freebsd/tests/sys/netinet6/proxy_ndp.sh (revision e6bfd18d21b225af6a0ed67ceeaf1293b7b9eba5)
1#!/usr/bin/env atf-sh
2#-
3# SPDX-License-Identifier: BSD-2-Clause
4#
5# Copyright (c) 2022 KUROSAWA Takahiro <takahiro.kurosawa@gmail.com>
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28# $FreeBSD$
29#
30
31. $(atf_get_srcdir)/../common/vnet.subr
32
33atf_test_case "pndp_add_gu_success" "cleanup"
34pndp_add_gu_success_head() {
35	atf_set descr 'Test proxy ndp record addition'
36	atf_set require.user root
37}
38
39pndp_add_gu_success_body() {
40
41	vnet_init
42
43	jname="v6t-pndp_add_success"
44
45	epair0=$(vnet_mkepair)
46
47	vnet_mkjail ${jname} ${epair0}a
48	jexec ${jname} ndp -i ${epair0}a -- -disabled
49	jexec ${jname} ifconfig ${epair0}a up
50
51	jexec ${jname} ifconfig ${epair0}a inet6 2001:db8::1/64
52	proxy_mac=`jexec ${jname} ifconfig ${epair0}a ether | awk '$1~/ether/{print$2}'`
53
54	# wait for DAD to complete
55	while [ `jexec ${jname} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
56		sleep 0.1
57	done
58
59	atf_check jexec ${jname} ndp -s 2001:db8::2 ${proxy_mac} proxy
60	while [ `jexec ${jname} ifmcstat | grep -c undefined` != "0" ]; do
61		sleep 0.1
62	done
63
64	# checking the output of ndp -an is covered by ndp.sh.
65	# we check the output of ifmcstat output here.
66	t=`jexec ${jname} ifmcstat -i ${epair0}a -f inet6 | grep -A1 'group ff02::1:ff00:2'`
67	atf_check -o match:'mcast-macaddr 33:33:ff:00:00:02' echo $t
68}
69
70pndp_add_gu_success_cleanup() {
71	vnet_cleanup
72}
73
74atf_test_case "pndp_del_gu_success" "cleanup"
75pndp_del_gu_success_head() {
76	atf_set descr 'Test proxy ndp record deletion'
77	atf_set require.user root
78}
79
80pndp_del_gu_success_body() {
81
82	vnet_init
83
84	jname="v6t-pndp_del_gu_success"
85
86	epair0=$(vnet_mkepair)
87
88	vnet_mkjail ${jname} ${epair0}a
89
90	jexec ${jname} ndp -i ${epair0}a -- -disabled
91	jexec ${jname} ifconfig ${epair0}a up
92
93	jexec ${jname} ifconfig ${epair0}a inet6 2001:db8::1/64
94	proxy_mac=`jexec ${jname} ifconfig ${epair0}a ether | awk '$1~/ether/{print$2}'`
95
96	# wait for DAD to complete
97	while [ `jexec ${jname} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
98		sleep 0.1
99	done
100
101	atf_check jexec ${jname} ndp -s 2001:db8::2 ${proxy_mac} proxy
102	while [ `jexec ${jname} ifmcstat | grep -c undefined` != "0" ]; do
103		sleep 0.1
104	done
105	jexec ${jname} ping -c1 -t1 2001:db8::2
106
107	atf_check -o match:"2001:db8::2 \(2001:db8::2\) deleted" jexec ${jname} ndp -nd 2001:db8::2
108	while [ `jexec ${jname} ifmcstat | grep -c undefined` != "0" ]; do
109		sleep 0.1
110	done
111	atf_check \
112	    -o not-match:'group ff02::1:ff00:2' \
113	    -o not-match:'mcast-macaddr 33:33:ff:00:00:02' \
114	    jexec ${jname} ifmcstat -i ${epair0}a -f inet6
115}
116
117pndp_del_gu_success_cleanup() {
118	vnet_cleanup
119}
120
121atf_test_case "pndp_ifdestroy_success" "cleanup"
122pndp_ifdetroy_success_head() {
123	atf_set descr 'Test interface destruction with proxy ndp'
124	atf_set require.user root
125}
126
127pndp_ifdestroy_success_body() {
128
129	vnet_init
130
131	jname="v6t-pndp_ifdestroy_success"
132
133	epair0=$(vnet_mkepair)
134
135	vnet_mkjail ${jname} ${epair0}a
136
137	jexec ${jname} ndp -i ${epair0}a -- -disabled
138	jexec ${jname} ifconfig ${epair0}a up
139
140	jexec ${jname} ifconfig ${epair0}a inet6 2001:db8::1/64
141	proxy_mac=`jexec ${jname} ifconfig ${epair0}a ether | awk '$1~/ether/{print$2}'`
142
143	# wait for DAD to complete
144	while [ `jexec ${jname} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
145		sleep 0.1
146	done
147
148	atf_check jexec ${jname} ndp -s 2001:db8::2 ${proxy_mac} proxy
149	while [ `jexec ${jname} ifmcstat | grep -c undefined` != "0" ]; do
150		sleep 0.1
151	done
152
153	atf_check jexec ${jname} ifconfig ${epair0}a destroy
154}
155
156pndp_ifdestroy_success_cleanup() {
157	vnet_cleanup
158}
159
160atf_test_case "pndp_neighbor_advert" "cleanup"
161pndp_neighbor_advert_head() {
162	atf_set descr 'Test Neighbor Advertisement for proxy ndp'
163	atf_set require.user root
164}
165
166pndp_neighbor_advert_body() {
167
168	vnet_init
169
170	jname_a="v6t-pndp_neighbor_advert_a"	# NA sender (w/proxy ndp entry)
171	jname_b="v6t-pndp_neighbor_advert_b"	# NA receiver (checker)
172	proxy_addr="2001:db8::aaaa"
173
174	epair0=$(vnet_mkepair)
175
176	vnet_mkjail ${jname_a} ${epair0}a
177	jexec ${jname_a} ndp -i ${epair0}a -- -disabled
178	jexec ${jname_a} ifconfig ${epair0}a up
179	jexec ${jname_a} ifconfig ${epair0}a inet6 2001:db8::1/64
180	proxy_mac=`jexec ${jname_a} ifconfig ${epair0}a ether | awk '$1~/ether/{print$2}'`
181	# wait for DAD to complete
182	while [ `jexec ${jname_a} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
183		sleep 0.1
184	done
185	atf_check jexec ${jname_a} ndp -s ${proxy_addr} ${proxy_mac} proxy
186	while [ `jexec ${jname_a} ifmcstat | grep -c undefined` != "0" ]; do
187		sleep 0.1
188	done
189
190	vnet_mkjail ${jname_b} ${epair0}b
191	jexec ${jname_b} ndp -i ${epair0}b -- -disabled
192	jexec ${jname_b} ifconfig ${epair0}b up
193	jexec ${jname_b} ifconfig ${epair0}b inet6 2001:db8::2/64
194	# wait for DAD to complete
195	while [ `jexec ${jname_b} ifconfig | grep inet6 | grep -c tentative` != "0" ]; do
196		sleep 0.1
197	done
198
199	jexec ${jname_b} ndp -nc
200	# jname_b sends a NS before ICMPv6 Echo Request for the proxy address.
201	# jname_a responds with a NA resolving the proxy address.
202	# Then there must be a NDP entry of the proxy address in jname_b.
203	jexec ${jname_b} ping -c1 -t1 ${proxy_addr}
204	atf_check -o match:"${proxy_addr} +${proxy_mac} +${epair0}b" \
205	    jexec ${jname_b} ndp -an
206}
207
208pndp_neighbor_advert_cleanup() {
209	vnet_cleanup
210}
211
212atf_init_test_cases()
213{
214
215	atf_add_test_case "pndp_add_gu_success"
216	atf_add_test_case "pndp_del_gu_success"
217	atf_add_test_case "pndp_ifdestroy_success"
218	atf_add_test_case "pndp_neighbor_advert"
219}
220
221# end
222
223