xref: /minix3/tests/net/ndp/t_dad.sh (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1#	$NetBSD: t_dad.sh,v 1.4 2015/08/24 02:02:25 ozaki-r Exp $
2#
3# Copyright (c) 2015 The NetBSD Foundation, Inc.
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10#    notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12#    notice, this list of conditions and the following disclaimer in the
13#    documentation and/or other materials provided with the distribution.
14#
15# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25# POSSIBILITY OF SUCH DAMAGE.
26#
27
28inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet"
29inetserver="$inetserver -lrumpnet_netinet6 -lrumpnet_shmif"
30HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
31
32SOCKLOCAL=unix://commsock1
33SOCKPEER=unix://commsock2
34
35DEBUG=false
36
37atf_test_case dad_basic cleanup
38atf_test_case dad_duplicated cleanup
39
40dad_basic_head()
41{
42	atf_set "descr" "Tests for IPv6 DAD basic behavior"
43	atf_set "require.progs" "rump_server"
44}
45
46dad_duplicated_head()
47{
48	atf_set "descr" "Tests for IPv6 DAD duplicated state"
49	atf_set "require.progs" "rump_server"
50}
51
52setup_server()
53{
54	local sock=$1
55	local ip=$2
56
57	export RUMP_SERVER=$sock
58
59	atf_check -s exit:0 rump.ifconfig shmif0 create
60	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
61	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $ip
62	atf_check -s exit:0 rump.ifconfig shmif0 up
63	atf_check -s exit:0 rump.ifconfig -w 10
64
65	$DEBUG && rump.ifconfig shmif0
66}
67
68make_ns_pkt_str()
69{
70	local id=$1
71	local target=$2
72	pkt="33:33:ff:00:00:0${id}, ethertype IPv6 (0x86dd), length 78: ::"
73	pkt="$pkt > ff02::1:ff00:${id}: ICMP6, neighbor solicitation,"
74	pkt="$pkt who has $target, length 24"
75	echo $pkt
76}
77
78extract_new_packets()
79{
80	local old=./old
81
82	if [ ! -f $old ]; then
83		old=/dev/null
84	fi
85
86	shmif_dumpbus -p - bus1 2>/dev/null| \
87	    tcpdump -n -e -r - 2>/dev/null > ./new
88	diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
89	mv -f ./new ./old
90	cat ./diff
91}
92
93dad_basic_body()
94{
95	local pkt=
96	local localip1=fc00::1
97	local localip2=fc00::2
98	local localip3=fc00::3
99
100	atf_check -s exit:0 ${inetserver} $SOCKLOCAL
101	export RUMP_SERVER=$SOCKLOCAL
102
103	atf_check -s exit:0 rump.ifconfig shmif0 create
104	atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
105	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip1
106	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
107	$DEBUG && rump.ifconfig shmif0
108
109	atf_check -s exit:0 rump.ifconfig shmif0 up
110	rump.ifconfig shmif0 > ./out
111	$DEBUG && cat ./out
112
113	# The primary address doesn't start with tentative state
114	atf_check -s not-exit:0 -x "cat ./out |grep $localip1 |grep -q tentative"
115	# The alias address starts with tentative state
116	# XXX we have no stable way to check this, so skip for now
117	#atf_check -s exit:0 -x "cat ./out |grep $localip2 |grep -q tentative"
118
119	atf_check -s exit:0 sleep 2
120	extract_new_packets > ./out
121	$DEBUG && cat ./out
122
123	# Check DAD probe packets (Neighbor Solicitation Message)
124	pkt=$(make_ns_pkt_str 2 $localip2)
125	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
126	# No DAD for the primary address
127	pkt=$(make_ns_pkt_str 1 $localip1)
128	atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
129
130	# Waiting for DAD complete
131	atf_check -s exit:0 rump.ifconfig -w 10
132	extract_new_packets > ./out
133	$DEBUG && cat ./out
134
135	# IPv6 DAD doesn't announce (Neighbor Advertisement Message)
136
137	# The alias address left tentative
138	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q tentative"
139
140	#
141	# Add a new address on the fly
142	#
143	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip3
144
145	# The new address starts with tentative state
146	# XXX we have no stable way to check this, so skip for now
147	#atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
148
149	# Check DAD probe packets (Neighbor Solicitation Message)
150	atf_check -s exit:0 sleep 2
151	extract_new_packets > ./out
152	$DEBUG && cat ./out
153	pkt=$(make_ns_pkt_str 3 $localip3)
154	atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
155
156	# Waiting for DAD complete
157	atf_check -s exit:0 rump.ifconfig -w 10
158	extract_new_packets > ./out
159	$DEBUG && cat ./out
160
161	# IPv6 DAD doesn't announce (Neighbor Advertisement Message)
162
163	# The new address left tentative
164	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip3 |grep -q tentative"
165}
166
167dad_duplicated_body()
168{
169	local localip1=fc00::1
170	local localip2=fc00::11
171	local peerip=fc00::2
172
173	atf_check -s exit:0 ${inetserver} $SOCKLOCAL
174	atf_check -s exit:0 ${inetserver} $SOCKPEER
175
176	setup_server $SOCKLOCAL $localip1
177	setup_server $SOCKPEER $peerip
178
179	export RUMP_SERVER=$SOCKLOCAL
180
181	# The primary address isn't marked as duplicated
182	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip1 |grep -q duplicated"
183
184	#
185	# Add a new address duplicated with the peer server
186	#
187	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $peerip
188	atf_check -s exit:0 sleep 1
189
190	# The new address is marked as duplicated
191	atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $peerip |grep -q duplicated"
192
193	# A unique address isn't marked as duplicated
194	atf_check -s exit:0 rump.ifconfig shmif0 inet6 $localip2
195	atf_check -s exit:0 sleep 1
196	atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q duplicated"
197}
198
199cleanup()
200{
201	gdb -ex bt /usr/bin/rump_server rump_server.core
202	gdb -ex bt /usr/sbin/arp arp.core
203	env RUMP_SERVER=$SOCKLOCAL rump.halt
204	env RUMP_SERVER=$SOCKPEER rump.halt
205}
206
207dump_local()
208{
209	export RUMP_SERVER=$SOCKLOCAL
210	rump.netstat -nr
211	rump.arp -n -a
212	rump.ifconfig
213	$HIJACKING dmesg
214}
215
216dump_peer()
217{
218	export RUMP_SERVER=$SOCKPEER
219	rump.netstat -nr
220	rump.arp -n -a
221	rump.ifconfig
222	$HIJACKING dmesg
223}
224
225dump()
226{
227	dump_local
228	dump_peer
229	shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
230}
231
232dad_basic_cleanup()
233{
234	$DEBUG && dump_local
235	$DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
236	env RUMP_SERVER=$SOCKLOCAL rump.halt
237}
238
239dad_duplicated_cleanup()
240{
241	$DEBUG && dump
242	cleanup
243}
244
245atf_init_test_cases()
246{
247	atf_add_test_case dad_basic
248	atf_add_test_case dad_duplicated
249}
250