. $(atf_get_srcdir)/../common/utils.subr
divert_init()
{
if ! kldstat -q -m ipdivert; then
atf_skip "This test requires ipdivert"
fi
}
atf_test_case "in_div" "cleanup"
in_div_head()
{
atf_set descr 'Test inbound > diverted | divapp terminated'
atf_set require.user root
}
in_div_body()
{
firewall_init "ipfw"
divert_init
epair=$(vnet_mkepair)
vnet_mkjail div ${epair}b
ifconfig ${epair}a 192.0.2.1/24 up
jexec div ifconfig ${epair}b 192.0.2.2/24 up
jexec div ipfw add 65534 allow all from any to any
atf_check -s exit:0 -o ignore ping -c3 192.0.2.2
jexec div ipfw add 100 divert 2000 icmp from any to any in icmptypes 8
jexec div $(atf_get_srcdir)/../common/divapp 2000 &
divapp_pid=$!
sleep 1
atf_check -s not-exit:0 -o ignore ping -c1 -t1 192.0.2.2
wait $divapp_pid
}
in_div_cleanup()
{
firewall_cleanup "ipfw"
}
atf_test_case "in_div_in" "cleanup"
in_div_in_head()
{
atf_set descr 'Test inbound > diverted > inbound | host terminated'
atf_set require.user root
}
in_div_in_body()
{
firewall_init "ipfw"
divert_init
epair=$(vnet_mkepair)
vnet_mkjail div ${epair}b
ifconfig ${epair}a 192.0.2.1/24 up
jexec div ifconfig ${epair}b 192.0.2.2/24 up
jexec div ipfw add 65534 allow all from any to any
atf_check -s exit:0 -o ignore ping -c3 192.0.2.2
jexec div ipfw add 100 divert 2000 icmp from any to any in icmptypes 8
jexec div $(atf_get_srcdir)/../common/divapp 2000 divert-back &
divapp_pid=$!
sleep 1
atf_check -s exit:0 -o ignore ping -c1 192.0.2.2
wait $divapp_pid
}
in_div_in_cleanup()
{
firewall_cleanup "ipfw"
}
atf_test_case "out_div" "cleanup"
out_div_head()
{
atf_set descr 'Test outbound > diverted | divapp terminated'
atf_set require.user root
}
out_div_body()
{
firewall_init "ipfw"
divert_init
epair=$(vnet_mkepair)
vnet_mkjail div ${epair}b
ifconfig ${epair}a 192.0.2.1/24 up
jexec div ifconfig ${epair}b 192.0.2.2/24 up
jexec div ipfw add 65534 allow all from any to any
atf_check -s exit:0 -o ignore ping -c3 192.0.2.2
jexec div ipfw add 100 divert 2000 icmp from any to any out icmptypes 0
jexec div $(atf_get_srcdir)/../common/divapp 2000 &
divapp_pid=$!
sleep 1
atf_check -s not-exit:0 -o ignore ping -c1 -t1 192.0.2.2
wait $divapp_pid
}
out_div_cleanup()
{
firewall_cleanup "ipfw"
}
atf_test_case "out_div_out" "cleanup"
out_div_out_head()
{
atf_set descr 'Test outbound > diverted > outbound | network terminated'
atf_set require.user root
}
out_div_out_body()
{
firewall_init "ipfw"
divert_init
epair=$(vnet_mkepair)
vnet_mkjail div ${epair}b
ifconfig ${epair}a 192.0.2.1/24 up
jexec div ifconfig ${epair}b 192.0.2.2/24 up
jexec div ipfw add 65534 allow all from any to any
atf_check -s exit:0 -o ignore ping -c3 192.0.2.2
jexec div ipfw add 100 divert 2000 icmp from any to any out icmptypes 0
jexec div $(atf_get_srcdir)/../common/divapp 2000 divert-back &
divapp_pid=$!
sleep 1
atf_check -s exit:0 -o ignore ping -c1 192.0.2.2
wait $divapp_pid
}
out_div_out_cleanup()
{
firewall_cleanup "ipfw"
}
atf_test_case "in_div_in_fwd_out_div_out" "cleanup"
in_div_in_fwd_out_div_out_head()
{
atf_set descr 'Test inbound > diverted > inbound > forwarded > outbound > diverted > outbound | network terminated'
atf_set require.user root
}
in_div_in_fwd_out_div_out_body()
{
firewall_init "ipfw"
divert_init
epair0=$(vnet_mkepair)
epair1=$(vnet_mkepair)
vnet_mkjail router ${epair0}b ${epair1}a
ifconfig ${epair0}a 192.0.2.1/24 up
jexec router sysctl net.inet.ip.forwarding=1
jexec router ifconfig ${epair0}b 192.0.2.2/24 up
jexec router ifconfig ${epair1}a 198.51.100.1/24 up
jexec router ipfw add 65534 allow all from any to any
vnet_mkjail site ${epair1}b
jexec site ifconfig ${epair1}b 198.51.100.2/24 up
jexec site ipfw add 65534 allow all from any to any
jexec site route add default 198.51.100.1
route add -net 198.51.100.0/24 192.0.2.2
atf_check -s exit:0 -o ignore ping -c3 192.0.2.2
atf_check -s exit:0 -o ignore ping -c3 198.51.100.2
jexec router ipfw add 100 divert 2001 icmp from any to any in icmptypes 8
jexec router ipfw add 200 divert 2002 icmp from any to any out icmptypes 8
jexec router $(atf_get_srcdir)/../common/divapp 2001 divert-back &
indivapp_pid=$!
jexec router $(atf_get_srcdir)/../common/divapp 2002 divert-back &
outdivapp_pid=$!
sleep 1
atf_check -s exit:0 -o ignore ping -c1 198.51.100.2
wait $indivapp_pid && wait $outdivapp_pid
}
in_div_in_fwd_out_div_out_cleanup()
{
firewall_cleanup "ipfw"
}
atf_init_test_cases()
{
atf_add_test_case "in_div"
atf_add_test_case "in_div_in"
atf_add_test_case "out_div"
atf_add_test_case "out_div_out"
atf_add_test_case "in_div_in_fwd_out_div_out"
}