3 # SPDX-License-Identifier: BSD-2-Clause
5 # Copyright (c) 2020 Alexander V. Chernikov
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 . $(atf_get_srcdir)/../common/vnet.subr
33 atf_test_case "fwd_ip6_gu_icmp_iface_fast_success" "cleanup"
34 fwd_ip6_gu_icmp_iface_fast_success_head() {
36 atf_set descr 'Test valid IPv6 global unicast fast-forwarding to interface'
37 atf_set require.user root
38 atf_set require.progs scapy
41 fwd_ip6_gu_icmp_iface_fast_success_body() {
44 id=`printf "%x" ${ids}`
45 if [ $$ -gt 65535 ]; then
46 xl=`printf "%x" $(($$ - 65535))`
55 ip6a="2001:db8:6666:0000:${yl}:${id}:1:${xl}"
56 ip6b="2001:db8:6666:0000:${yl}:${id}:2:${xl}"
59 src_ip="2001:db8:6666:0000:${yl}:${id}:3:${xl}"
61 script_name="../common/sender.py"
65 ifconfig ${epair}a inet6 ${ip6a}/${plen}
67 jname="v6t-${id}-${yl}-${xl}"
68 vnet_mkjail ${jname} ${epair}b
69 jexec ${jname} ifconfig ${epair}b up
70 jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/${plen}
72 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
74 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
76 # wait for DAD to complete
77 while [ `jexec ${jname} ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
80 while [ `ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
84 jexec ${jname} sysctl net.inet6.ip6.forwarding=1
85 # As we're doing router-on-the-stick, turn sending IP redirects off:
86 jexec ${jname} sysctl net.inet6.ip6.redirect=0
88 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
89 --test_name fwd_ip6_icmp \
90 --smac ${our_mac} --dmac ${jail_mac} \
91 --sip ${src_ip} --dip ${ip6a} \
94 # check counters are valid
95 atf_check -o match:'1 packet forwarded' jexec ${jname} netstat -sp ip6
98 fwd_ip6_gu_icmp_iface_fast_success_cleanup() {
103 atf_test_case "fwd_ip6_gu_icmp_gw_gu_fast_success" "cleanup"
104 fwd_ip6_gu_icmp_gw_gu_fast_success_head() {
106 atf_set descr 'Test valid IPv6 global unicast fast-forwarding to GU gw'
107 atf_set require.user root
108 atf_set require.progs scapy
111 fwd_ip6_gu_icmp_gw_gu_fast_success_body() {
114 id=`printf "%x" ${ids}`
115 if [ $$ -gt 65535 ]; then
116 xl=`printf "%x" $(($$ - 65535))`
125 ip6a="2001:db8:6666:0000:${yl}:${id}:1:${xl}"
126 ip6b="2001:db8:6666:0000:${yl}:${id}:2:${xl}"
129 src_ip="2001:db8:6666:0000:${yl}:${id}:3:${xl}"
130 dst_ip="2001:db8:6666:0000:${yl}:${id}:4:${xl}"
132 script_name="../common/sender.py"
134 epair=$(vnet_mkepair)
135 ifconfig ${epair}a up
136 ifconfig ${epair}a inet6 ${ip6a}/${plen}
138 jname="v6t-${id}-${yl}-${xl}"
139 vnet_mkjail ${jname} ${epair}b
140 jexec ${jname} ifconfig ${epair}b up
141 jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/${plen}
143 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
145 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
147 # wait for DAD to complete
148 while [ `jexec ${jname} ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
151 while [ `ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
155 # Add static route back to us
156 jexec ${jname} route add -6 -host ${dst_ip} ${ip6a}
158 jexec ${jname} sysctl net.inet6.ip6.forwarding=1
159 # As we're doing router-on-the-stick, turn sending IP redirects off:
160 jexec ${jname} sysctl net.inet6.ip6.redirect=0
162 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
163 --test_name fwd_ip6_icmp \
164 --smac ${our_mac} --dmac ${jail_mac} \
165 --sip ${src_ip} --dip ${dst_ip} \
168 # check counters are valid
169 atf_check -o match:'1 packet forwarded' jexec ${jname} netstat -sp ip6
172 fwd_ip6_gu_icmp_gw_gu_fast_success_cleanup() {
177 atf_test_case "fwd_ip6_gu_icmp_gw_ll_fast_success" "cleanup"
178 fwd_ip6_gu_icmp_gw_ll_fast_success_head() {
180 atf_set descr 'Test valid IPv6 global unicast fast-forwarding to LL gw'
181 atf_set require.user root
182 atf_set require.progs scapy
185 fwd_ip6_gu_icmp_gw_ll_fast_success_body() {
188 id=`printf "%x" ${ids}`
189 if [ $$ -gt 65535 ]; then
190 xl=`printf "%x" $(($$ - 65535))`
199 ip6a="2001:db8:6666:0000:${yl}:${id}:1:${xl}"
200 ip6b="2001:db8:6666:0000:${yl}:${id}:2:${xl}"
203 src_ip="2001:db8:6666:0000:${yl}:${id}:3:${xl}"
204 dst_ip="2001:db8:6666:0000:${yl}:${id}:4:${xl}"
206 script_name="../common/sender.py"
208 epair=$(vnet_mkepair)
209 ifconfig ${epair}a up
210 ifconfig ${epair}a inet6 ${ip6a}/${plen}
212 jname="v6t-${id}-${yl}-${xl}"
213 vnet_mkjail ${jname} ${epair}b
214 jexec ${jname} ifconfig ${epair}b up
215 jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/${plen}
217 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
219 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
220 our_ll_ip=`ifconfig ${epair}a inet6 | awk '$1~/inet6/&& $2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
222 # wait for DAD to complete
223 while [ `jexec ${jname} ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
226 while [ `ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
230 # Add static route back to us
231 atf_check -s exit:0 -o ignore jexec ${jname} route add -6 -host ${dst_ip} ${our_ll_ip}%${epair}b
233 jexec ${jname} sysctl net.inet6.ip6.forwarding=1
234 # As we're doing router-on-the-stick, turn sending IP redirects off:
235 jexec ${jname} sysctl net.inet6.ip6.redirect=0
237 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
238 --test_name fwd_ip6_icmp \
239 --smac ${our_mac} --dmac ${jail_mac} \
240 --sip ${src_ip} --dip ${dst_ip} \
243 # check counters are valid
244 atf_check -o match:'1 packet forwarded' jexec ${jname} netstat -sp ip6
247 fwd_ip6_gu_icmp_gw_ll_fast_success_cleanup() {
252 atf_test_case "fwd_ip6_gu_icmp_iface_slow_success" "cleanup"
253 fwd_ip6_gu_icmp_iface_slow_success_head() {
255 atf_set descr 'Test valid IPv6 global unicast fast-forwarding to interface'
256 atf_set require.user root
257 atf_set require.progs scapy
260 fwd_ip6_gu_icmp_iface_slow_success_body() {
263 id=`printf "%x" ${ids}`
264 if [ $$ -gt 65535 ]; then
265 xl=`printf "%x" $(($$ - 65535))`
274 ip6a="2001:db8:6666:0000:${yl}:${id}:1:${xl}"
275 ip6b="2001:db8:6666:0000:${yl}:${id}:2:${xl}"
278 src_ip="2001:db8:6666:0000:${yl}:${id}:3:${xl}"
280 script_name="../common/sender.py"
282 epair=$(vnet_mkepair)
283 ifconfig ${epair}a up
284 ifconfig ${epair}a inet6 ${ip6a}/${plen}
286 jname="v6t-${id}-${yl}-${xl}"
287 vnet_mkjail ${jname} ${epair}b
288 jexec ${jname} ifconfig ${epair}b up
289 jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/${plen}
291 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
293 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
295 # wait for DAD to complete
296 while [ `jexec ${jname} ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
299 while [ `ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
303 jexec ${jname} sysctl net.inet6.ip6.forwarding=1
304 # Do not turn off route redirects to ensure slow path is on
306 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
307 --test_name fwd_ip6_icmp \
308 --smac ${our_mac} --dmac ${jail_mac} \
309 --sip ${src_ip} --dip ${ip6a} \
312 # check counters are valid
313 atf_check -o match:'1 packet forwarded' jexec ${jname} netstat -sp ip6
316 fwd_ip6_gu_icmp_iface_slow_success_cleanup() {
321 atf_test_case "fwd_ip6_gu_icmp_gw_gu_slow_success" "cleanup"
322 fwd_ip6_gu_icmp_gw_gu_slow_success_head() {
324 atf_set descr 'Test valid IPv6 global unicast fast-forwarding to GU gw'
325 atf_set require.user root
326 atf_set require.progs scapy
329 fwd_ip6_gu_icmp_gw_gu_slow_success_body() {
332 id=`printf "%x" ${ids}`
333 if [ $$ -gt 65535 ]; then
334 xl=`printf "%x" $(($$ - 65535))`
343 ip6a="2001:db8:6666:0000:${yl}:${id}:1:${xl}"
344 ip6b="2001:db8:6666:0000:${yl}:${id}:2:${xl}"
347 src_ip="2001:db8:6666:0000:${yl}:${id}:3:${xl}"
348 dst_ip="2001:db8:6666:0000:${yl}:${id}:4:${xl}"
350 script_name="../common/sender.py"
352 epair=$(vnet_mkepair)
353 ifconfig ${epair}a up
354 ifconfig ${epair}a inet6 ${ip6a}/${plen}
356 jname="v6t-${id}-${yl}-${xl}"
357 vnet_mkjail ${jname} ${epair}b
358 jexec ${jname} ifconfig ${epair}b up
359 jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/${plen}
361 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
363 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
365 # wait for DAD to complete
366 while [ `jexec ${jname} ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
369 while [ `ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
373 # Add static route back to us
374 jexec ${jname} route add -6 -host ${dst_ip} ${ip6a}
376 jexec ${jname} sysctl net.inet6.ip6.forwarding=1
377 # Do not turn off route redirects to ensure slow path is on
379 # atf_check -s exit:0
380 $(atf_get_srcdir)/${script_name} \
381 --test_name fwd_ip6_icmp \
382 --smac ${our_mac} --dmac ${jail_mac} \
383 --sip ${src_ip} --dip ${dst_ip} \
385 jexec ${jname} netstat -sp ip6
387 # check counters are valid
388 atf_check -o match:'1 packet forwarded' jexec ${jname} netstat -sp ip6
391 fwd_ip6_gu_icmp_gw_gu_slow_success_cleanup() {
396 atf_test_case "fwd_ip6_gu_icmp_gw_ll_slow_success" "cleanup"
397 fwd_ip6_gu_icmp_gw_ll_slow_success_head() {
399 atf_set descr 'Test valid IPv6 global unicast fast-forwarding to LL gw'
400 atf_set require.user root
401 atf_set require.progs scapy
404 fwd_ip6_gu_icmp_gw_ll_slow_success_body() {
407 id=`printf "%x" ${ids}`
408 if [ $$ -gt 65535 ]; then
409 xl=`printf "%x" $(($$ - 65535))`
418 ip6a="2001:db8:6666:0000:${yl}:${id}:1:${xl}"
419 ip6b="2001:db8:6666:0000:${yl}:${id}:2:${xl}"
422 src_ip="2001:db8:6666:0000:${yl}:${id}:3:${xl}"
423 dst_ip="2001:db8:6666:0000:${yl}:${id}:4:${xl}"
425 script_name="../common/sender.py"
427 epair=$(vnet_mkepair)
428 ifconfig ${epair}a up
429 ifconfig ${epair}a inet6 ${ip6a}/${plen}
431 jname="v6t-${id}-${yl}-${xl}"
432 vnet_mkjail ${jname} ${epair}b
433 jexec ${jname} ifconfig ${epair}b up
434 jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/${plen}
436 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
438 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
439 our_ll_ip=`ifconfig ${epair}a inet6 | awk '$1~/inet6/&& $2~/^fe80:/{print$2}' | awk -F% '{print$1}'`
441 # wait for DAD to complete
442 while [ `jexec ${jname} ifconfig ${epair}b inet6 | grep -c tentative` != "0" ]; do
445 while [ `ifconfig ${epair}a inet6 | grep -c tentative` != "0" ]; do
449 # Add static route back to us
450 atf_check -s exit:0 -o ignore jexec ${jname} route add -6 -host ${dst_ip} ${our_ll_ip}%${epair}b
452 jexec ${jname} sysctl net.inet6.ip6.forwarding=1
453 # Do not turn off route redirects to ensure slow path is on
455 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
456 --test_name fwd_ip6_icmp \
457 --smac ${our_mac} --dmac ${jail_mac} \
458 --sip ${src_ip} --dip ${dst_ip} \
461 # check counters are valid
462 atf_check -o match:'1 packet forwarded' jexec ${jname} netstat -sp ip6
465 fwd_ip6_gu_icmp_gw_ll_slow_success_cleanup() {
470 atf_init_test_cases()
473 atf_add_test_case "fwd_ip6_gu_icmp_iface_fast_success"
474 atf_add_test_case "fwd_ip6_gu_icmp_gw_gu_fast_success"
475 atf_add_test_case "fwd_ip6_gu_icmp_gw_ll_fast_success"
476 atf_add_test_case "fwd_ip6_gu_icmp_iface_slow_success"
477 atf_add_test_case "fwd_ip6_gu_icmp_gw_gu_slow_success"
478 atf_add_test_case "fwd_ip6_gu_icmp_gw_ll_slow_success"