xref: /freebsd-src/tests/sys/netpfil/pf/loginterface.sh (revision 470a2b3346612fbf2f6415ec8df63c92703035dd)
1*470a2b33SKristof Provost#
2*470a2b33SKristof Provost# SPDX-License-Identifier: BSD-2-Clause
3*470a2b33SKristof Provost#
4*470a2b33SKristof Provost# Copyright (c) 2024 Rubicon Communications, LLC (Netgate)
5*470a2b33SKristof Provost#
6*470a2b33SKristof Provost# Redistribution and use in source and binary forms, with or without
7*470a2b33SKristof Provost# modification, are permitted provided that the following conditions
8*470a2b33SKristof Provost# are met:
9*470a2b33SKristof Provost# 1. Redistributions of source code must retain the above copyright
10*470a2b33SKristof Provost#    notice, this list of conditions and the following disclaimer.
11*470a2b33SKristof Provost# 2. Redistributions in binary form must reproduce the above copyright
12*470a2b33SKristof Provost#    notice, this list of conditions and the following disclaimer in the
13*470a2b33SKristof Provost#    documentation and/or other materials provided with the distribution.
14*470a2b33SKristof Provost#
15*470a2b33SKristof Provost# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*470a2b33SKristof Provost# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*470a2b33SKristof Provost# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*470a2b33SKristof Provost# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*470a2b33SKristof Provost# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*470a2b33SKristof Provost# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*470a2b33SKristof Provost# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*470a2b33SKristof Provost# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*470a2b33SKristof Provost# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*470a2b33SKristof Provost# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*470a2b33SKristof Provost# SUCH DAMAGE.
26*470a2b33SKristof Provost
27*470a2b33SKristof Provost. $(atf_get_srcdir)/utils.subr
28*470a2b33SKristof Provost
29*470a2b33SKristof Provost
30*470a2b33SKristof Provostatf_test_case "basic" "cleanup"
31*470a2b33SKristof Provostbasic_head()
32*470a2b33SKristof Provost{
33*470a2b33SKristof Provost	atf_set descr 'Basic loginterface test'
34*470a2b33SKristof Provost	atf_set require.user root
35*470a2b33SKristof Provost}
36*470a2b33SKristof Provost
37*470a2b33SKristof Provostbasic_body()
38*470a2b33SKristof Provost{
39*470a2b33SKristof Provost	pft_init
40*470a2b33SKristof Provost
41*470a2b33SKristof Provost	epair=$(vnet_mkepair)
42*470a2b33SKristof Provost
43*470a2b33SKristof Provost	ifconfig ${epair}a 192.0.2.2/24 up
44*470a2b33SKristof Provost
45*470a2b33SKristof Provost	vnet_mkjail alcatraz ${epair}b
46*470a2b33SKristof Provost	jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up
47*470a2b33SKristof Provost
48*470a2b33SKristof Provost	# Sanity check
49*470a2b33SKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1
50*470a2b33SKristof Provost
51*470a2b33SKristof Provost	# No interface stats until we configure a loginterface
52*470a2b33SKristof Provost	atf_check -o not-match:"Interface Stats for" \
53*470a2b33SKristof Provost		jexec alcatraz pfctl -s info
54*470a2b33SKristof Provost
55*470a2b33SKristof Provost	jexec alcatraz pfctl -e
56*470a2b33SKristof Provost	pft_set_rules alcatraz \
57*470a2b33SKristof Provost		"set loginterface ${epair}b" \
58*470a2b33SKristof Provost		"pass"
59*470a2b33SKristof Provost
60*470a2b33SKristof Provost	# We do get Interface Stats listed when we've configured a loginterface
61*470a2b33SKristof Provost	atf_check -o match:"Interface Stats for ${epair}b" \
62*470a2b33SKristof Provost		jexec alcatraz pfctl -s info
63*470a2b33SKristof Provost
64*470a2b33SKristof Provost	# And after we've sent traffic there's non-zero counters
65*470a2b33SKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1
66*470a2b33SKristof Provost
67*470a2b33SKristof Provost	atf_check -o match:"Interface Stats for ${epair}b" \
68*470a2b33SKristof Provost		jexec alcatraz pfctl -s info
69*470a2b33SKristof Provost	atf_check -o match:"Passed                               1" \
70*470a2b33SKristof Provost		jexec alcatraz pfctl -s info
71*470a2b33SKristof Provost
72*470a2b33SKristof Provost	# And no interface stats once we remove the loginterface
73*470a2b33SKristof Provost	pft_set_rules alcatraz \
74*470a2b33SKristof Provost		"pass"
75*470a2b33SKristof Provost	atf_check -o not-match:"Interface Stats for ${epair}b" \
76*470a2b33SKristof Provost		jexec alcatraz pfctl -s info
77*470a2b33SKristof Provost}
78*470a2b33SKristof Provost
79*470a2b33SKristof Provostbasic_cleanup()
80*470a2b33SKristof Provost{
81*470a2b33SKristof Provost	pft_cleanup
82*470a2b33SKristof Provost}
83*470a2b33SKristof Provost
84*470a2b33SKristof Provostatf_init_test_cases()
85*470a2b33SKristof Provost{
86*470a2b33SKristof Provost	atf_add_test_case "basic"
87*470a2b33SKristof Provost}
88