xref: /freebsd/tests/sys/netpfil/pf/set_tos.sh (revision 36d7818975359fd2aacb19e4f9442a841dc954bb)
1# $FreeBSD$
2
3. $(atf_get_srcdir)/utils.subr
4
5atf_test_case "v4" "cleanup"
6v4_head()
7{
8	atf_set descr 'set-tos test'
9	atf_set require.user root
10
11	# We need scapy to be installed for out test scripts to work
12	atf_set require.progs scapy
13}
14
15v4_body()
16{
17	if [ `uname -p` = "i386" ]; then
18		atf_skip "https://bugs.freebsd.org/239380"
19	fi
20
21	pft_init
22
23	epair_send=$(vnet_mkepair)
24	ifconfig ${epair_send}a 192.0.2.1/24 up
25
26	epair_recv=$(vnet_mkepair)
27	ifconfig ${epair_recv}a up
28
29	vnet_mkjail alcatraz ${epair_send}b ${epair_recv}b
30	jexec alcatraz ifconfig ${epair_send}b 192.0.2.2/24 up
31	jexec alcatraz ifconfig ${epair_recv}b 198.51.100.2/24 up
32	jexec alcatraz sysctl net.inet.ip.forwarding=1
33	jexec alcatraz arp -s 198.51.100.3 00:01:02:03:04:05
34	route add -net 198.51.100.0/24 192.0.2.2
35
36	jexec alcatraz pfctl -e
37
38	# No change is done if not requested
39	pft_set_rules alcatraz "scrub out proto icmp"
40	atf_check -s exit:1 -o ignore $(atf_get_srcdir)/pft_ping.py \
41		--sendif ${epair_send}a \
42		--to 198.51.100.3 \
43		--recvif ${epair_recv}a \
44		--expect-tos 42
45
46	# The requested ToS is set
47	pft_set_rules alcatraz "scrub out proto icmp set-tos 42"
48	atf_check -s exit:0 $(atf_get_srcdir)/pft_ping.py \
49		--sendif ${epair_send}a \
50		--to 198.51.100.3 \
51		--recvif ${epair_recv}a \
52		--expect-tos 42
53
54	# ToS is not changed if the scrub rule does not match
55	pft_set_rules alcatraz "scrub out proto tcp set-tos 42"
56	atf_check -s exit:1 -o ignore $(atf_get_srcdir)/pft_ping.py \
57		--sendif ${epair_send}a \
58		--to 198.51.100.3 \
59		--recvif ${epair_recv}a \
60		--expect-tos 42
61
62	# Multiple scrub rules match as expected
63	pft_set_rules alcatraz "scrub out proto tcp set-tos 13" \
64		"scrub out proto icmp set-tos 14"
65	atf_check -s exit:0 $(atf_get_srcdir)/pft_ping.py \
66		--sendif ${epair_send}a \
67		--to 198.51.100.3 \
68		--recvif ${epair_recv}a \
69		--expect-tos 14
70
71	# And this works even if the packet already has ToS values set
72	atf_check -s exit:0 $(atf_get_srcdir)/pft_ping.py \
73		--sendif ${epair_send}a \
74		--to 198.51.100.3 \
75		--recvif ${epair_recv}a \
76		--send-tos 42 \
77		--expect-tos 14
78
79	# ToS values are unmolested if the packets do not match a scrub rule
80	pft_set_rules alcatraz "scrub out proto tcp set-tos 13"
81	atf_check -s exit:0 $(atf_get_srcdir)/pft_ping.py \
82		--sendif ${epair_send}a \
83		--to 198.51.100.3 \
84		--recvif ${epair_recv}a \
85		--send-tos 42 \
86		--expect-tos 42
87}
88
89v4_cleanup()
90{
91	pft_cleanup
92}
93
94atf_init_test_cases()
95{
96	atf_add_test_case "v4"
97}
98