Path: blob/main/tests/sys/netpfil/pf/max_pkt_rate.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}a inet 192.0.2.2/24 up3334vnet_mkjail alcatraz ${epair}b35jexec alcatraz ifconfig ${epair}b inet 192.0.2.1/24 up3637# Sanity check38atf_check -s exit:0 -o ignore \39ping -c 1 192.0.2.14041jexec alcatraz pfctl -e42}4344common_test()45{46# One ping will pass47atf_check -s exit:0 -o ignore \48ping -c 1 192.0.2.14950# As will a second51atf_check -s exit:0 -o ignore \52ping -c 1 192.0.2.15354# But the third should fail55atf_check -s exit:2 -o ignore \56ping -c 1 192.0.2.15758# But three seconds later we can ping again59sleep 360atf_check -s exit:0 -o ignore \61ping -c 1 192.0.2.162}6364atf_test_case "basic" "cleanup"65basic_head()66{67atf_set descr 'Basic maximum packet rate test'68atf_set require.user root69}7071basic_body()72{73pft_init7475common_setup7677pft_set_rules alcatraz \78"block" \79"pass in proto icmp max-pkt-rate 2/2"8081common_test82}8384basic_cleanup()85{86pft_cleanup87}8889atf_test_case "anchor" "cleanup"90anchor_head()91{92atf_set descr 'maximum packet rate on anchor'93atf_set require.user root94}9596anchor_body()97{98pft_init99100common_setup101102pft_set_rules alcatraz \103"block" \104"anchor \"foo\" proto icmp max-pkt-rate 2/2 {\n \105pass \n \106}"107108common_test109}110111anchor_cleanup()112{113pft_cleanup114}115116atf_init_test_cases()117{118atf_add_test_case "basic"119atf_add_test_case "anchor"120}121122123