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
30 . $(atf_get_srcdir)/../common/vnet.subr
32 atf_test_case "fwd_ip_icmp_iface_fast_success" "cleanup"
33 fwd_ip_icmp_iface_fast_success_head() {
35 atf_set descr 'Test valid IPv4 on-stick fastforwarding to iface'
36 atf_set require.user root
37 atf_set require.progs scapy
40 fwd_ip_icmp_iface_fast_success_body() {
49 script_name="../common/sender.py"
53 ifconfig ${epair}a inet ${ip4a}/${plen}
55 jname="v4t-fwd_ip_icmp_iface_fast_success"
56 vnet_mkjail ${jname} ${epair}b
57 jexec ${jname} ifconfig ${epair}b up
58 jexec ${jname} ifconfig ${epair}b inet ${ip4b}/${plen}
62 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
64 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
66 jexec ${jname} sysctl net.inet.ip.forwarding=1
67 # As we're doing router-on-the-stick, turn sending IP redirects off:
68 jexec ${jname} sysctl net.inet.ip.redirect=0
70 # echo "LOCAL: ${local_ip} ${local_mac}"
71 # echo "REMOTE: ${remote_rtr_ip} ${remote_rtr_mac}"
73 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
74 --test_name fwd_ip_icmp_fast \
75 --smac ${our_mac} --dmac ${jail_mac} \
76 --sip ${src_ip} --dip ${ip4a} \
79 # check counters are valid
80 atf_check -o match:'1 packet forwarded \(1 packet fast forwarded\)' jexec ${jname} netstat -sp ip
83 fwd_ip_icmp_iface_fast_success_cleanup() {
88 atf_test_case "fwd_ip_icmp_gw_fast_success" "cleanup"
89 fwd_ip_icmp_gw_fast_success_head() {
91 atf_set descr 'Test valid IPv4 on-stick fastforwarding to gw'
92 atf_set require.user root
93 atf_set require.progs scapy
96 fwd_ip_icmp_gw_fast_success_body() {
106 script_name="../common/sender.py"
108 epair=$(vnet_mkepair)
109 ifconfig ${epair}a up
110 ifconfig ${epair}a inet ${ip4a}/${plen}
112 jname="v4t-fwd_ip_icmp_gw_fast_success"
113 vnet_mkjail ${jname} ${epair}b
114 jexec ${jname} ifconfig ${epair}b up
115 jexec ${jname} ifconfig ${epair}b inet ${ip4b}/${plen}
119 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
121 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
123 jexec ${jname} sysctl net.inet.ip.forwarding=1
124 # As we're doing router-on-the-stick, turn sending IP redirects off:
125 jexec ${jname} sysctl net.inet.ip.redirect=0
128 jexec ${jname} route -4 add -host ${dst_ip} ${ip4a}
130 # echo "LOCAL: ${local_ip} ${local_mac}"
131 # echo "REMOTE: ${remote_rtr_ip} ${remote_rtr_mac}"
133 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
134 --test_name fwd_ip_icmp_fast \
135 --smac ${our_mac} --dmac ${jail_mac} \
136 --sip ${src_ip} --dip ${dst_ip} \
139 # check counters are valid
140 atf_check -o match:'1 packet forwarded \(1 packet fast forwarded\)' jexec ${jname} netstat -sp ip
143 fwd_ip_icmp_gw_fast_success_cleanup() {
148 atf_test_case "fwd_ip_icmp_iface_slow_success" "cleanup"
149 fwd_ip_icmp_iface_slow_success_head() {
151 atf_set descr 'Test valid IPv4 on-stick "slow" forwarding to iface'
152 atf_set require.user root
153 atf_set require.progs scapy
156 fwd_ip_icmp_iface_slow_success_body() {
165 script_name="../common/sender.py"
167 epair=$(vnet_mkepair)
168 ifconfig ${epair}a up
169 ifconfig ${epair}a inet ${ip4a}/${plen}
171 jname="v4t-fwd_ip_icmp_iface_slow_success"
172 vnet_mkjail ${jname} ${epair}b
173 jexec ${jname} ifconfig ${epair}b up
174 jexec ${jname} ifconfig ${epair}b inet ${ip4b}/${plen}
178 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
180 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
182 jexec ${jname} sysctl net.inet.ip.forwarding=1
183 # As we're doing router-on-the-stick, turn sending IP redirects off:
184 jexec ${jname} sysctl net.inet.ip.redirect=0
186 # Generate packet with options to force slow-path
187 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
188 --test_name fwd_ip_icmp_slow \
189 --smac ${our_mac} --dmac ${jail_mac} \
190 --sip ${src_ip} --dip ${ip4a} \
193 # check counters are valid
194 atf_check -o match:'1 packet forwarded \(0 packets fast forwarded\)' jexec ${jname} netstat -sp ip
197 fwd_ip_icmp_iface_slow_success_cleanup() {
202 atf_test_case "fwd_ip_icmp_gw_slow_success" "cleanup"
203 fwd_ip_icmp_gw_slow_success_head() {
205 atf_set descr 'Test valid IPv4 on-stick "slow" forwarding to gw'
206 atf_set require.user root
207 atf_set require.progs scapy
210 fwd_ip_icmp_gw_slow_success_body() {
220 script_name="../common/sender.py"
222 epair=$(vnet_mkepair)
223 ifconfig ${epair}a up
224 ifconfig ${epair}a inet ${ip4a}/${plen}
226 jname="v4t-fwd_ip_icmp_gw_slow_success"
227 vnet_mkjail ${jname} ${epair}b
228 jexec ${jname} ifconfig ${epair}b up
229 jexec ${jname} ifconfig ${epair}b inet ${ip4b}/${plen}
233 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
235 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
237 jexec ${jname} sysctl net.inet.ip.forwarding=1
238 # As we're doing router-on-the-stick, turn sending IP redirects off:
239 jexec ${jname} sysctl net.inet.ip.redirect=0
242 jexec ${jname} route -4 add -host ${dst_ip} ${ip4a}
244 # echo "LOCAL: ${local_ip} ${local_mac}"
245 # echo "REMOTE: ${remote_rtr_ip} ${remote_rtr_mac}"
247 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
248 --test_name fwd_ip_icmp_fast \
249 --smac ${our_mac} --dmac ${jail_mac} \
250 --sip ${src_ip} --dip ${dst_ip} \
253 # check counters are valid
254 atf_check -o match:'1 packet forwarded \(1 packet fast forwarded\)' jexec ${jname} netstat -sp ip
257 fwd_ip_icmp_gw_slow_success_cleanup() {
262 atf_init_test_cases()
265 atf_add_test_case "fwd_ip_icmp_iface_fast_success"
266 atf_add_test_case "fwd_ip_icmp_gw_fast_success"
267 atf_add_test_case "fwd_ip_icmp_iface_slow_success"
268 atf_add_test_case "fwd_ip_icmp_gw_slow_success"