]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - contrib/netbsd-tests/net/route/t_change.sh
MFC r305358,r305449,r305451,r306367,r306397,r309474:
[FreeBSD/stable/10.git] / contrib / netbsd-tests / net / route / t_change.sh
1 #       $NetBSD: t_change.sh,v 1.8 2016/08/10 23:00:39 roy Exp $
2 #
3 # Copyright (c) 2011 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 netserver=\
29 "rump_server -lrumpdev -lrumpnet -lrumpnet_net \
30         -lrumpnet_netinet -lrumpnet_shmif"
31 export RUMP_SERVER=unix://commsock
32
33 DEBUG=false
34
35 atf_test_case route_change_reject2blackhole cleanup
36 route_change_reject2blackhole_head()
37 {
38
39         atf_set "descr" "Change a reject route to blackhole"
40         atf_set "require.progs" "rump_server"
41 }
42
43 route_change_reject2blackhole_body()
44 {
45
46         atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
47
48         atf_check -s exit:0 -o ignore \
49             rump.route add 207.46.197.32 127.0.0.1 -reject
50         atf_check -s exit:0 -o match:UGHR -x \
51             "rump.route -n show -inet | grep ^207.46"
52         atf_check -s exit:0 -o ignore \
53             rump.route change 207.46.197.32 127.0.0.1 -blackhole
54         atf_check -s exit:0 -o match:' UGHBS ' -e ignore -x \
55             "rump.netstat -rn -f inet | grep ^207.46"
56 }
57
58 route_change_reject2blackhole_cleanup()
59 {
60
61         env RUMP_SERVER=unix://commsock rump.halt
62 }
63
64 atf_test_case route_change_gateway cleanup
65 route_change_gateway_head()
66 {
67
68         atf_set "descr" "Change the gateway of a route"
69         atf_set "require.progs" "rump_server"
70 }
71
72 route_change_gateway_body()
73 {
74
75         atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
76
77         atf_check -s exit:0 rump.ifconfig shmif0 create
78         atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
79         atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
80
81         atf_check -s exit:0 -o ignore \
82             rump.route add -net 192.168.0.0/24 10.0.0.1
83         atf_check -s exit:0 -o match:'10.0.0.1' -x \
84             "rump.route -n show -inet | grep ^192.168"
85         atf_check -s exit:0 -o ignore \
86             rump.route change -net 192.168.0.0/24 10.0.0.254
87         atf_check -s exit:0 -o match:'10.0.0.254' -x \
88             "rump.route -n show -inet | grep ^192.168"
89 }
90
91 route_change_gateway_cleanup()
92 {
93
94         env RUMP_SERVER=unix://commsock rump.halt
95 }
96
97 atf_test_case route_change_ifa cleanup
98 route_change_ifa_head()
99 {
100
101         atf_set "descr" "Change the ifa (local address) of a route"
102         atf_set "require.progs" "rump_server"
103 }
104
105 route_change_ifa_body()
106 {
107
108         atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
109
110         atf_check -s exit:0 rump.ifconfig shmif0 create
111         atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
112         atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24
113         atf_check -s exit:0 rump.ifconfig shmif0 alias 10.0.0.11/24
114         atf_check -s exit:0 rump.ifconfig shmif0 up
115
116         atf_check -s exit:0 -o ignore \
117             rump.route add -net 192.168.0.0/24 10.0.0.1
118         atf_check -s exit:0 -o match:'10.0.0.1' -x \
119             "rump.route -n show -inet | grep ^192.168"
120         $DEBUG && rump.route -n show -inet
121         cat >./expect <<-EOF
122    route to: 192.168.0.1
123 destination: 192.168.0.0
124        mask: 255.255.255.0
125     gateway: 10.0.0.1
126  local addr: 10.0.0.10
127   interface: shmif0
128       flags: <UP,GATEWAY,DONE,STATIC>
129  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
130         EOF
131         rump.route -n get 192.168.0.1 > ./output
132         $DEBUG && cat ./expect ./output
133         sed -i '$d' ./output
134         atf_check -s exit:0 diff ./expect ./output
135
136         # Change the local address of the route
137         atf_check -s exit:0 -o ignore \
138             rump.route change -net 192.168.0.0/24 10.0.0.1 -ifa 10.0.0.11
139         $DEBUG && rump.route -n show -inet
140         cat >./expect <<-EOF
141    route to: 192.168.0.1
142 destination: 192.168.0.0
143        mask: 255.255.255.0
144     gateway: 10.0.0.1
145  local addr: 10.0.0.11
146   interface: shmif0
147       flags: <UP,GATEWAY,DONE,STATIC>
148  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
149         EOF
150         rump.route -n get 192.168.0.1 > ./output
151         $DEBUG && cat ./expect ./output
152         sed -i '$d' ./output
153         atf_check -s exit:0 diff ./expect ./output
154 }
155
156 route_change_ifa_cleanup()
157 {
158
159         env RUMP_SERVER=unix://commsock rump.halt
160 }
161
162 atf_test_case route_change_ifp cleanup
163 route_change_ifp_head()
164 {
165
166         atf_set "descr" "Change a route based on an interface (ifp)"
167         atf_set "require.progs" "rump_server"
168 }
169
170 route_change_ifp_body()
171 {
172
173         atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
174
175         atf_check -s exit:0 rump.ifconfig shmif0 create
176         atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
177         atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
178
179         atf_check -s exit:0 rump.ifconfig shmif1 create
180         atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus
181         atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24 up
182
183         atf_check -s exit:0 -o ignore \
184             rump.route add -net 192.168.0.0/24 10.0.0.1
185         atf_check -s exit:0 -o match:'10.0.0.1' -x \
186             "rump.route -n show -inet | grep ^192.168"
187         $DEBUG && rump.route -n show -inet
188         cat >./expect <<-EOF
189    route to: 192.168.0.1
190 destination: 192.168.0.0
191        mask: 255.255.255.0
192     gateway: 10.0.0.1
193  local addr: 10.0.0.10
194   interface: shmif0
195       flags: <UP,GATEWAY,DONE,STATIC>
196  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
197         EOF
198         rump.route -n get 192.168.0.1 > ./output
199         $DEBUG && cat ./expect ./output
200         sed -i '$d' ./output
201         atf_check -s exit:0 diff ./expect ./output
202
203         # Change a route based on an interface
204         atf_check -s exit:0 -o ignore \
205             rump.route change -net 192.168.0.0/24 10.0.0.1 -ifp shmif1
206         $DEBUG && rump.route -n show -inet
207         cat >./expect <<-EOF
208    route to: 192.168.0.1
209 destination: 192.168.0.0
210        mask: 255.255.255.0
211     gateway: 10.0.0.1
212  local addr: 10.0.0.11
213   interface: shmif1
214       flags: <UP,GATEWAY,DONE,STATIC>
215  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
216         EOF
217         rump.route -n get 192.168.0.1 > ./output
218         $DEBUG && cat ./expect ./output
219         sed -i '$d' ./output
220         atf_check -s exit:0 diff ./expect ./output
221 }
222
223 route_change_ifp_cleanup()
224 {
225
226         env RUMP_SERVER=unix://commsock rump.halt
227 }
228
229 atf_test_case route_change_ifp_ifa cleanup
230 route_change_ifp_head()
231 {
232
233         atf_set "descr" "Change a route with -ifp and -ifa"
234         atf_set "require.progs" "rump_server"
235 }
236
237 route_change_ifp_ifa_body()
238 {
239
240         atf_check -s exit:0 ${netserver} ${RUMP_SERVER}
241
242         atf_check -s exit:0 rump.ifconfig shmif0 create
243         atf_check -s exit:0 rump.ifconfig shmif0 linkstr bus
244         atf_check -s exit:0 rump.ifconfig shmif0 10.0.0.10/24 up
245
246         atf_check -s exit:0 rump.ifconfig shmif1 create
247         atf_check -s exit:0 rump.ifconfig shmif1 linkstr bus
248         atf_check -s exit:0 rump.ifconfig shmif1 10.0.0.11/24 up
249
250         atf_check -s exit:0 -o ignore \
251             rump.route add -net 192.168.0.0/24 10.0.0.1
252         atf_check -s exit:0 -o match:'10.0.0.1' -x \
253             "rump.route -n show -inet | grep ^192.168"
254         $DEBUG && rump.route -n show -inet
255         cat >./expect <<-EOF
256    route to: 192.168.0.1
257 destination: 192.168.0.0
258        mask: 255.255.255.0
259     gateway: 10.0.0.1
260  local addr: 10.0.0.10
261   interface: shmif0
262       flags: <UP,GATEWAY,DONE,STATIC>
263  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
264         EOF
265         rump.route -n get 192.168.0.1 > ./output
266         $DEBUG && cat ./expect ./output
267         sed -i '$d' ./output
268         atf_check -s exit:0 diff ./expect ./output
269
270         # Change a route with -ifa and -ifp
271         atf_check -s exit:0 -o ignore \
272             rump.route change -net 192.168.0.0/24 -ifa 10.0.0.1 -ifp shmif1
273         $DEBUG && rump.route -n show -inet
274         cat >./expect <<-EOF
275    route to: 192.168.0.1
276 destination: 192.168.0.0
277        mask: 255.255.255.0
278     gateway: 10.0.0.1
279  local addr: 10.0.0.11
280   interface: shmif1
281       flags: <UP,GATEWAY,DONE,STATIC>
282  recvpipe  sendpipe  ssthresh  rtt,msec    rttvar  hopcount      mtu     expire
283         EOF
284         rump.route -n get 192.168.0.1 > ./output
285         $DEBUG && cat ./expect ./output
286         sed -i '$d' ./output
287         atf_check -s exit:0 diff ./expect ./output
288 }
289
290 route_change_ifp_ifa_cleanup()
291 {
292
293         env RUMP_SERVER=unix://commsock rump.halt
294 }
295
296 atf_init_test_cases()
297 {
298
299         atf_add_test_case route_change_reject2blackhole
300         atf_add_test_case route_change_gateway
301         atf_add_test_case route_change_ifa
302         atf_add_test_case route_change_ifp
303         atf_add_test_case route_change_ifp_ifa
304 }