xref: /freebsd/tests/sys/netpfil/pf/synproxy.sh (revision 06aac31aecb6028d346abc6b6cd54f58c12a1a32)
1# $FreeBSD$
2
3. $(atf_get_srcdir)/utils.subr
4
5atf_test_case "synproxy" "cleanup"
6synproxy_head()
7{
8	atf_set descr 'Basic synproxy test'
9	atf_set require.user root
10}
11
12synproxy_body()
13{
14	pft_init
15
16	epair=$(vnet_mkepair)
17	ifconfig ${epair}a 192.0.2.1/24 up
18	route add -net 198.51.100.0/24 192.0.2.2
19
20	link=$(vnet_mkepair)
21
22	vnet_mkjail alcatraz ${epair}b ${link}a
23	jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up
24	jexec alcatraz ifconfig ${link}a 198.51.100.1/24 up
25	jexec alcatraz sysctl net.inet.ip.forwarding=1
26
27	vnet_mkjail singsing ${link}b
28	jexec singsing ifconfig ${link}b 198.51.100.2/24 up
29	jexec singsing route add default 198.51.100.1
30
31	jexec singsing /usr/sbin/inetd $(atf_get_srcdir)/echo_inetd.conf
32
33	jexec alcatraz pfctl -e
34	pft_set_rules alcatraz "set fail-policy return" \
35		"scrub in all fragment reassemble" \
36		"pass out quick on ${epair}b all no state allow-opts" \
37		"pass in quick on ${epair}b proto tcp from any to any port 7 synproxy state" \
38		"pass in quick on ${epair}b all no state"
39
40	# Sanity check, can we ping singing
41	atf_check -s exit:0 -o ignore ping -c 1 198.51.100.2
42
43	# Check that we can talk to the singsing jail, after synproxying
44	reply=$(echo ping | nc -N 198.51.100.2 7)
45	if [ "${reply}" != "ping" ];
46	then
47		atf_fail "echo failed"
48	fi
49}
50
51synproxy_cleanup()
52{
53	pft_cleanup
54}
55
56atf_init_test_cases()
57{
58	atf_add_test_case "synproxy"
59}
60