1 # $NetBSD: t_dad.sh,v 1.7 2016/08/10 22:05:07 kre Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
28 inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
29 inetserver="${inetserver} -lrumpdev"
30 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
32 SOCKLOCAL=unix://commsock1
33 SOCKPEER=unix://commsock2
37 atf_test_case dad_basic cleanup
38 atf_test_case dad_duplicated cleanup
42 atf_set "descr" "Tests for IPv4 DAD basic behavior"
43 atf_set "require.progs" "rump_server"
48 atf_set "descr" "Tests for IPv4 DAD duplicated state"
49 atf_set "require.progs" "rump_server"
57 export RUMP_SERVER=$sock
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 inet $ip/24
62 atf_check -s exit:0 rump.ifconfig shmif0 up
63 atf_check -s exit:0 rump.ifconfig -w 10
65 $DEBUG && rump.ifconfig shmif0
72 pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
73 pkt="$pkt Request who-has $target tell $sender, length 28"
81 if [ ! -f $old ]; then
85 shmif_dumpbus -p - bus1 2>/dev/null| \
86 tcpdump -n -e -r - 2>/dev/null > ./new
87 diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
96 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
97 export RUMP_SERVER=$SOCKLOCAL
99 atf_check -s exit:0 rump.ifconfig shmif0 create
100 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
101 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
102 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
103 $DEBUG && rump.ifconfig shmif0
105 atf_check -s exit:0 rump.ifconfig shmif0 up
106 rump.ifconfig shmif0 > ./out
109 # The primary address doesn't start with tentative state
110 atf_check -s not-exit:0 -x "cat ./out |grep 10.0.0.1 |grep -q tentative"
111 # The alias address starts with tentative state
112 # XXX we have no stable way to check this, so skip for now
113 #atf_check -s exit:0 -x "cat ./out |grep 10.0.0.2 |grep -q tentative"
115 atf_check -s exit:0 sleep 2
116 extract_new_packets > ./out
119 # Check DAD probe packets
120 pkt=$(make_pkt_str 10.0.0.2 0.0.0.0)
121 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
122 # No DAD for the primary address
123 pkt=$(make_pkt_str 10.0.0.1 0.0.0.0)
124 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
126 # Waiting for DAD complete
127 atf_check -s exit:0 rump.ifconfig -w 10
128 # Give a chance to send a DAD announce packet
129 atf_check -s exit:0 sleep 1
130 extract_new_packets > ./out
133 # Check the DAD announce packet
134 pkt=$(make_pkt_str 10.0.0.2 10.0.0.2)
135 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
136 # The alias address left tentative
137 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.2 |grep -q tentative"
140 # Add a new address on the fly
142 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24 alias
144 # The new address starts with tentative state
145 # XXX we have no stable way to check this, so skip for now
146 #atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -q tentative"
148 # Check DAD probe packets
149 atf_check -s exit:0 sleep 2
150 extract_new_packets > ./out
152 pkt=$(make_pkt_str 10.0.0.3 0.0.0.0)
153 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
155 # Waiting for DAD complete
156 atf_check -s exit:0 rump.ifconfig -w 10
157 # Give a chance to send a DAD announce packet
158 atf_check -s exit:0 sleep 1
159 extract_new_packets > ./out
162 # Check the DAD announce packet
163 pkt=$(make_pkt_str 10.0.0.3 10.0.0.3)
164 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
165 # The new address left tentative
166 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -q tentative"
169 dad_duplicated_body()
171 local localip1=10.0.1.1
172 local localip2=10.0.1.11
173 local peerip=10.0.1.2
175 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
176 atf_check -s exit:0 ${inetserver} $SOCKPEER
178 setup_server $SOCKLOCAL $localip1
179 setup_server $SOCKPEER $peerip
181 export RUMP_SERVER=$SOCKLOCAL
183 # The primary address isn't marked as duplicated
184 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip1 |grep -q duplicated"
187 # Add a new address duplicated with the peer server
189 atf_check -s exit:0 rump.ifconfig shmif0 inet $peerip alias
190 atf_check -s exit:0 sleep 1
192 # The new address is marked as duplicated
193 atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $peerip |grep -q duplicated"
195 # A unique address isn't marked as duplicated
196 atf_check -s exit:0 rump.ifconfig shmif0 inet $localip2 alias
197 atf_check -s exit:0 sleep 1
198 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q duplicated"
203 env RUMP_SERVER=$SOCKLOCAL rump.halt
204 env RUMP_SERVER=$SOCKPEER rump.halt
209 export RUMP_SERVER=$SOCKLOCAL
218 export RUMP_SERVER=$SOCKPEER
229 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
235 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
236 env RUMP_SERVER=$SOCKLOCAL rump.halt
239 dad_duplicated_cleanup()
245 atf_init_test_cases()
247 atf_add_test_case dad_basic
248 atf_add_test_case dad_duplicated