t_dad.sh revision 1.3 1 # $NetBSD: t_dad.sh,v 1.3 2015/07/31 00:23:54 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
28 inetserver="rump_server -lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_shmif"
29 HIJACKING="env LD_PRELOAD=/usr/lib/librumphijack.so RUMPHIJACK=sysctl=yes"
30
31 SOCKLOCAL=unix://commsock1
32 SOCKPEER=unix://commsock2
33
34 DEBUG=false
35
36 atf_test_case dad_basic cleanup
37 atf_test_case dad_duplicated cleanup
38
39 dad_basic_head()
40 {
41 atf_set "descr" "Tests for IPv4 DAD basic behavior"
42 atf_set "require.progs" "rump_server"
43 }
44
45 dad_duplicated_head()
46 {
47 atf_set "descr" "Tests for IPv4 DAD duplicated state"
48 atf_set "require.progs" "rump_server"
49 }
50
51 setup_server()
52 {
53 local sock=$1
54 local ip=$2
55
56 export RUMP_SERVER=$sock
57
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
63
64 $DEBUG && rump.ifconfig shmif0
65 }
66
67 make_pkt_str()
68 {
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
74 }
75
76 dad_basic_body()
77 {
78 local pkt=
79
80 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
81 export RUMP_SERVER=$SOCKLOCAL
82
83 atf_check -s exit:0 rump.ifconfig shmif0 create
84 atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus1
85 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.1/24
86 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.2/24 alias
87 atf_check -s exit:0 rump.ifconfig shmif0 up
88 $DEBUG && rump.ifconfig shmif0
89
90 atf_check -s exit:0 sleep 1
91
92 # The primary address is not tentative from the beginning
93 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.1 |grep -q tentative"
94 # The alias address is still tentative
95 atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.2 |grep -q tentative"
96
97 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - > ./out
98
99 # Check DAD probe packets
100 pkt=$(make_pkt_str 10.0.0.2 0.0.0.0)
101 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
102 # No DAD for the primary address
103 pkt=$(make_pkt_str 10.0.0.1 0.0.0.0)
104 atf_check -s not-exit:0 -x "cat ./out |grep -q '$pkt'"
105
106 # Waiting for DAD complete
107 atf_check -s exit:0 rump.ifconfig -w 10
108 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - |tail -1 > ./out
109
110 # Check the DAD announce packet
111 pkt=$(make_pkt_str 10.0.0.2 10.0.0.2)
112 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
113 # The alias address left tentative
114 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.2 |grep -q tentative"
115
116 #
117 # Add a new address on the fly
118 #
119 atf_check -s exit:0 rump.ifconfig shmif0 inet 10.0.0.3/24 alias
120
121 atf_check -s exit:0 sleep 1
122
123 # The new address is still tentative
124 atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -q tentative"
125
126 # Check DAD probe packets
127 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - |tail -1 > ./out
128 pkt=$(make_pkt_str 10.0.0.3 0.0.0.0)
129 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
130
131 # Waiting for DAD complete
132 atf_check -s exit:0 rump.ifconfig -w 10
133 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r - |tail -1 > ./out
134
135 # Check the DAD announce packet
136 pkt=$(make_pkt_str 10.0.0.3 10.0.0.3)
137 atf_check -s exit:0 -x "cat ./out |grep -q '$pkt'"
138 # The new address left tentative
139 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep 10.0.0.3 |grep -q tentative"
140 }
141
142 dad_duplicated_body()
143 {
144 local localip1=10.0.1.1
145 local localip2=10.0.1.11
146 local peerip=10.0.1.2
147
148 atf_check -s exit:0 ${inetserver} $SOCKLOCAL
149 atf_check -s exit:0 ${inetserver} $SOCKPEER
150
151 setup_server $SOCKLOCAL $localip1
152 setup_server $SOCKPEER $peerip
153
154 export RUMP_SERVER=$SOCKLOCAL
155
156 # The primary address isn't marked as duplicated
157 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip1 |grep -q duplicated"
158
159 #
160 # Add a new address duplicated with the peer server
161 #
162 atf_check -s exit:0 rump.ifconfig shmif0 inet $peerip alias
163 atf_check -s exit:0 sleep 1
164
165 # The new address is marked as duplicated
166 atf_check -s exit:0 -x "rump.ifconfig shmif0 |grep $peerip |grep -q duplicated"
167
168 # A unique address isn't marked as duplicated
169 atf_check -s exit:0 rump.ifconfig shmif0 inet $localip2 alias
170 atf_check -s exit:0 sleep 1
171 atf_check -s not-exit:0 -x "rump.ifconfig shmif0 |grep $localip2 |grep -q duplicated"
172 }
173
174 cleanup()
175 {
176 env RUMP_SERVER=$SOCKLOCAL rump.halt
177 env RUMP_SERVER=$SOCKPEER rump.halt
178 }
179
180 dump_local()
181 {
182 export RUMP_SERVER=$SOCKLOCAL
183 rump.netstat -nr
184 rump.arp -n -a
185 rump.ifconfig
186 $HIJACKING dmesg
187 }
188
189 dump_peer()
190 {
191 export RUMP_SERVER=$SOCKPEER
192 rump.netstat -nr
193 rump.arp -n -a
194 rump.ifconfig
195 $HIJACKING dmesg
196 }
197
198 dump()
199 {
200 dump_local
201 dump_peer
202 shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
203 }
204
205 dad_basic_cleanup()
206 {
207 $DEBUG && dump_local
208 $DEBUG && shmif_dumpbus -p - bus1 2>/dev/null| tcpdump -n -e -r -
209 env RUMP_SERVER=$SOCKLOCAL rump.halt
210 }
211
212 dad_duplicated_cleanup()
213 {
214 $DEBUG && dump
215 cleanup
216 }
217
218 atf_init_test_cases()
219 {
220 atf_add_test_case dad_basic
221 atf_add_test_case dad_duplicated
222 }
223