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_ip_icmp_iface_fast_success" "cleanup"
34 fwd_ip_icmp_iface_fast_success_head() {
36 atf_set descr 'Test valid IPv4 on-stick fastforwarding to iface'
37 atf_set require.user root
38 atf_set require.progs scapy
41 fwd_ip_icmp_iface_fast_success_body() {
50 script_name="../common/sender.py"
54 ifconfig ${epair}a inet ${ip4a}/${plen}
56 jname="v4t-fwd_ip_icmp_iface_fast_success"
57 vnet_mkjail ${jname} ${epair}b
58 jexec ${jname} ifconfig ${epair}b up
59 jexec ${jname} ifconfig ${epair}b inet ${ip4b}/${plen}
63 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
65 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
67 jexec ${jname} sysctl net.inet.ip.forwarding=1
68 # As we're doing router-on-the-stick, turn sending IP redirects off:
69 jexec ${jname} sysctl net.inet.ip.redirect=0
71 # echo "LOCAL: ${local_ip} ${local_mac}"
72 # echo "REMOTE: ${remote_rtr_ip} ${remote_rtr_mac}"
74 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
75 --test_name fwd_ip_icmp_fast \
76 --smac ${our_mac} --dmac ${jail_mac} \
77 --sip ${src_ip} --dip ${ip4a} \
80 # check counters are valid
81 atf_check -o match:'1 packet forwarded \(1 packet fast forwarded\)' jexec ${jname} netstat -sp ip
84 fwd_ip_icmp_iface_fast_success_cleanup() {
89 atf_test_case "fwd_ip_icmp_gw_fast_success" "cleanup"
90 fwd_ip_icmp_gw_fast_success_head() {
92 atf_set descr 'Test valid IPv4 on-stick fastforwarding to gw'
93 atf_set require.user root
94 atf_set require.progs scapy
97 fwd_ip_icmp_gw_fast_success_body() {
107 script_name="../common/sender.py"
109 epair=$(vnet_mkepair)
110 ifconfig ${epair}a up
111 ifconfig ${epair}a inet ${ip4a}/${plen}
113 jname="v4t-fwd_ip_icmp_gw_fast_success"
114 vnet_mkjail ${jname} ${epair}b
115 jexec ${jname} ifconfig ${epair}b up
116 jexec ${jname} ifconfig ${epair}b inet ${ip4b}/${plen}
120 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
122 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
124 jexec ${jname} sysctl net.inet.ip.forwarding=1
125 # As we're doing router-on-the-stick, turn sending IP redirects off:
126 jexec ${jname} sysctl net.inet.ip.redirect=0
129 jexec ${jname} route -4 add -host ${dst_ip} ${ip4a}
131 # echo "LOCAL: ${local_ip} ${local_mac}"
132 # echo "REMOTE: ${remote_rtr_ip} ${remote_rtr_mac}"
134 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
135 --test_name fwd_ip_icmp_fast \
136 --smac ${our_mac} --dmac ${jail_mac} \
137 --sip ${src_ip} --dip ${dst_ip} \
140 # check counters are valid
141 atf_check -o match:'1 packet forwarded \(1 packet fast forwarded\)' jexec ${jname} netstat -sp ip
144 fwd_ip_icmp_gw_fast_success_cleanup() {
149 atf_test_case "fwd_ip_icmp_iface_slow_success" "cleanup"
150 fwd_ip_icmp_iface_slow_success_head() {
152 atf_set descr 'Test valid IPv4 on-stick "slow" forwarding to iface'
153 atf_set require.user root
154 atf_set require.progs scapy
157 fwd_ip_icmp_iface_slow_success_body() {
166 script_name="../common/sender.py"
168 epair=$(vnet_mkepair)
169 ifconfig ${epair}a up
170 ifconfig ${epair}a inet ${ip4a}/${plen}
172 jname="v4t-fwd_ip_icmp_iface_slow_success"
173 vnet_mkjail ${jname} ${epair}b
174 jexec ${jname} ifconfig ${epair}b up
175 jexec ${jname} ifconfig ${epair}b inet ${ip4b}/${plen}
179 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
181 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
183 jexec ${jname} sysctl net.inet.ip.forwarding=1
184 # As we're doing router-on-the-stick, turn sending IP redirects off:
185 jexec ${jname} sysctl net.inet.ip.redirect=0
187 # Generate packet with options to force slow-path
188 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
189 --test_name fwd_ip_icmp_slow \
190 --smac ${our_mac} --dmac ${jail_mac} \
191 --sip ${src_ip} --dip ${ip4a} \
194 # check counters are valid
195 atf_check -o match:'1 packet forwarded \(0 packets fast forwarded\)' jexec ${jname} netstat -sp ip
198 fwd_ip_icmp_iface_slow_success_cleanup() {
203 atf_test_case "fwd_ip_icmp_gw_slow_success" "cleanup"
204 fwd_ip_icmp_gw_slow_success_head() {
206 atf_set descr 'Test valid IPv4 on-stick "slow" forwarding to gw'
207 atf_set require.user root
208 atf_set require.progs scapy
211 fwd_ip_icmp_gw_slow_success_body() {
221 script_name="../common/sender.py"
223 epair=$(vnet_mkepair)
224 ifconfig ${epair}a up
225 ifconfig ${epair}a inet ${ip4a}/${plen}
227 jname="v4t-fwd_ip_icmp_gw_slow_success"
228 vnet_mkjail ${jname} ${epair}b
229 jexec ${jname} ifconfig ${epair}b up
230 jexec ${jname} ifconfig ${epair}b inet ${ip4b}/${plen}
234 jail_mac=`jexec ${jname} ifconfig ${epair}b ether | awk '$1~/ether/{print$2}'`
236 our_mac=`ifconfig ${epair}a ether | awk '$1~/ether/{print$2}'`
238 jexec ${jname} sysctl net.inet.ip.forwarding=1
239 # As we're doing router-on-the-stick, turn sending IP redirects off:
240 jexec ${jname} sysctl net.inet.ip.redirect=0
243 jexec ${jname} route -4 add -host ${dst_ip} ${ip4a}
245 # echo "LOCAL: ${local_ip} ${local_mac}"
246 # echo "REMOTE: ${remote_rtr_ip} ${remote_rtr_mac}"
248 atf_check -s exit:0 $(atf_get_srcdir)/${script_name} \
249 --test_name fwd_ip_icmp_fast \
250 --smac ${our_mac} --dmac ${jail_mac} \
251 --sip ${src_ip} --dip ${dst_ip} \
254 # check counters are valid
255 atf_check -o match:'1 packet forwarded \(1 packet fast forwarded\)' jexec ${jname} netstat -sp ip
258 fwd_ip_icmp_gw_slow_success_cleanup() {
263 atf_init_test_cases()
266 atf_add_test_case "fwd_ip_icmp_iface_fast_success"
267 atf_add_test_case "fwd_ip_icmp_gw_fast_success"
268 atf_add_test_case "fwd_ip_icmp_iface_slow_success"
269 atf_add_test_case "fwd_ip_icmp_gw_slow_success"