etc/protocols - sync with NetBSD-8
[minix.git] / tests / net / arp / t_dad.sh
blobd72017e9058d1eb6982905bac9b1f9ab2ffa2765
1 # $NetBSD: t_dad.sh,v 1.6 2015/08/25 02:24:34 ozaki-r Exp $
3 # Copyright (c) 2015 The NetBSD Foundation, Inc.
4 # All rights reserved.
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.
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 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
31 SOCKLOCAL=unix://commsock1
32 SOCKPEER=unix://commsock2
34 DEBUG=false
36 atf_test_case dad_basic cleanup
37 atf_test_case dad_duplicated cleanup
39 dad_basic_head()
41 atf_set "descr" "Tests for IPv4 DAD basic behavior"
42 atf_set "require.progs" "rump_server"
45 dad_duplicated_head()
47 atf_set "descr" "Tests for IPv4 DAD duplicated state"
48 atf_set "require.progs" "rump_server"
51 setup_server()
53 local sock=$1
54 local ip=$2
56 export RUMP_SERVER=$sock
58 atf_check -s exit:0 rump.ifconfig shmif0 create
59 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
60 atf_check -s exit:0 rump.ifconfig shmif0 inet $ip/24
61 atf_check -s exit:0 rump.ifconfig shmif0 up
62 atf_check -s exit:0 rump.ifconfig -w 10
64 $DEBUG && rump.ifconfig shmif0
67 make_pkt_str()
69 local target=$1
70 local sender=$2
71 pkt="> ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42:"
72 pkt="$pkt Request who-has $target tell $sender, length 28"
73 echo $pkt
76 extract_new_packets()
78 local old=./old
80 if [ ! -f $old ]; then
81 old=/dev/null
84 shmif_dumpbus -p - bus1 2>/dev/null| \
85 tcpdump -n -e -r - 2>/dev/null > ./new
86 diff -u $old ./new |grep '^+' |cut -d '+' -f 2 > ./diff
87 mv -f ./new ./old
88 cat ./diff
91 dad_basic_body()
93 local pkt=
95 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
96 export RUMP_SERVER=$SOCKLOCAL
98 atf_check -s exit:0 rump.ifconfig shmif0 create
99 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
100 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
101 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
102 $DEBUG && rump.ifconfig shmif0
104 atf_check -s exit:0 rump.ifconfig shmif0 up
105 rump.ifconfig shmif0 > ./out
106 $DEBUG && cat ./out
108 # The primary address doesn't start with tentative state
109 atf_check -s not-exit:0 -x "cat ./out |grep 10.0.0.1 |grep -q tentative"
110 # The alias address starts with tentative state
111 # XXX we have no stable way to check this, so skip for now
112 #atf_check -s exit:0 -x "cat ./out |grep 10.0.0.2 |grep -q tentative"
114 atf_check -s exit:0 sleep 2
115 extract_new_packets > ./out
116 $DEBUG && cat ./out
118 # Check DAD probe packets
119 pkt=$(make_pkt_str 10.0.0.2 0.0.0.0)
120 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
121 # No DAD for the primary address
122 pkt=$(make_pkt_str 10.0.0.1 0.0.0.0)
123 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
125 # Waiting for DAD complete
126 atf_check -s exit:0 rump.ifconfig -w 10
127 # Give a chance to send a DAD announce packet
128 atf_check -s exit:0 sleep 1
129 extract_new_packets > ./out
130 $DEBUG && cat ./out
132 # Check the DAD announce packet
133 pkt=$(make_pkt_str 10.0.0.2 10.0.0.2)
134 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
135 # The alias address left tentative
136 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.2 |grep -q tentative"
139 # Add a new address on the fly
141 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24 alias
143 # The new address starts with tentative state
144 # XXX we have no stable way to check this, so skip for now
145 #atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -q tentative"
147 # Check DAD probe packets
148 atf_check -s exit:0 sleep 2
149 extract_new_packets > ./out
150 $DEBUG && cat ./out
151 pkt=$(make_pkt_str 10.0.0.3 0.0.0.0)
152 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
154 # Waiting for DAD complete
155 atf_check -s exit:0 rump.ifconfig -w 10
156 # Give a chance to send a DAD announce packet
157 atf_check -s exit:0 sleep 1
158 extract_new_packets > ./out
159 $DEBUG && cat ./out
161 # Check the DAD announce packet
162 pkt=$(make_pkt_str 10.0.0.3 10.0.0.3)
163 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
164 # The new address left tentative
165 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -q tentative"
168 dad_duplicated_body()
170 local localip1=10.0.1.1
171 local localip2=10.0.1.11
172 local peerip=10.0.1.2
174 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
175 atf_check -s exit:0 ${inetserver} $SOCKPEER
177 setup_server $SOCKLOCAL $localip1
178 setup_server $SOCKPEER $peerip
180 export RUMP_SERVER=$SOCKLOCAL
182 # The primary address isn't marked as duplicated
183 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip1 |grep -q duplicated"
186 # Add a new address duplicated with the peer server
188 atf_check -s exit:0 rump.ifconfig shmif0 inet $peerip alias
189 atf_check -s exit:0 sleep 1
191 # The new address is marked as duplicated
192 atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $peerip |grep -q duplicated"
194 # A unique address isn't marked as duplicated
195 atf_check -s exit:0 rump.ifconfig shmif0 inet $localip2 alias
196 atf_check -s exit:0 sleep 1
197 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q duplicated"
200 cleanup()
202 env RUMP_SERVER=$SOCKLOCAL rump.halt
203 env RUMP_SERVER=$SOCKPEER rump.halt
206 dump_local()
208 export RUMP_SERVER=$SOCKLOCAL
209 rump.netstat -nr
210 rump.arp -n -a
211 rump.ifconfig
212 $HIJACKING dmesg
215 dump_peer()
217 export RUMP_SERVER=$SOCKPEER
218 rump.netstat -nr
219 rump.arp -n -a
220 rump.ifconfig
221 $HIJACKING dmesg
224 dump()
226 dump_local
227 dump_peer
228 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
231 dad_basic_cleanup()
233 $DEBUG && dump_local
234 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
235 env RUMP_SERVER=$SOCKLOCAL rump.halt
238 dad_duplicated_cleanup()
240 $DEBUG && dump
241 cleanup
244 atf_init_test_cases()
246 atf_add_test_case dad_basic
247 atf_add_test_case dad_duplicated