Path: blob/main/tests/sys/netpfil/pf/max_pkt_size.sh
39536 views
#1# SPDX-License-Identifier: BSD-2-Clause2#3# Copyright (c) 2025 Rubicon Communications, LLC (Netgate)4#5# Redistribution and use in source and binary forms, with or without6# modification, are permitted provided that the following conditions7# are met:8# 1. Redistributions of source code must retain the above copyright9# notice, this list of conditions and the following disclaimer.10# 2. Redistributions in binary form must reproduce the above copyright11# notice, this list of conditions and the following disclaimer in the12# documentation and/or other materials provided with the distribution.13#14# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND15# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE16# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE17# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE18# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL19# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS20# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)21# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT22# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY23# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF24# SUCH DAMAGE.2526. $(atf_get_srcdir)/utils.subr2728common_setup()29{30epair=$(vnet_mkepair)3132ifconfig ${epair}b 192.0.2.2/24 up3334vnet_mkjail alcatraz ${epair}a35jexec alcatraz ifconfig ${epair}a 192.0.2.1/24 up3637jexec alcatraz pfctl -e38}3940common_test()41{42# Small packets pass43atf_check -s exit:0 -o ignore \44ping -c 1 192.0.2.145atf_check -s exit:0 -o ignore \46ping -c 1 -s 100 192.0.2.14748# Larger packets do not49atf_check -s exit:2 -o ignore \50ping -c 3 -s 101 192.0.2.151atf_check -s exit:2 -o ignore \52ping -c 3 -s 128 192.0.2.153}5455atf_test_case "basic" "cleanup"56basic_head()57{58atf_set descr 'Basic max-pkt-size test'59atf_set require.user root60}6162basic_body()63{64pft_init6566common_setup6768pft_set_rules alcatraz \69"pass max-pkt-size 128"7071common_test7273# We can enforce this on fragmented packets too74pft_set_rules alcatraz \75"pass max-pkt-size 2000"7677atf_check -s exit:0 -o ignore \78ping -c 1 -s 1400 192.0.2.179atf_check -s exit:0 -o ignore \80ping -c 1 -s 1972 192.0.2.181atf_check -s exit:2 -o ignore \82ping -c 1 -s 1973 192.0.2.183atf_check -s exit:2 -o ignore \84ping -c 3 -s 3000 192.0.2.185}8687basic_cleanup()88{89pft_cleanup90}9192atf_test_case "match" "cleanup"93match_head()94{95atf_set descr 'max-pkt-size on match rules'96atf_set require.user root97}9899match_body()100{101pft_init102103common_setup104105pft_set_rules alcatraz \106"match in max-pkt-size 128" \107"pass"108109common_test110}111112match_cleanup()113{114pft_cleanup115}116117atf_init_test_cases()118{119atf_add_test_case "basic"120atf_add_test_case "match"121}122123124