diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile index 68f54c801297..99b22399231e 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -1,33 +1,34 @@ # $FreeBSD$ PACKAGE= tests TESTSDIR= ${TESTSBASE}/sys/netpfil/pf TESTS_SUBDIRS+= ioctl -ATF_TESTS_SH+= anchor \ +ATF_TESTS_SH+= altq \ + anchor \ checksum \ forward \ fragmentation \ icmp \ names \ nat \ pass_block \ pfsync \ rdr \ route_to \ set_skip \ set_tos \ src_track \ synproxy \ table ${PACKAGE}FILES+= CVE-2019-5597.py \ CVE-2019-5598.py \ echo_inetd.conf \ utils.subr ${PACKAGE}FILESMODE_CVE-2019-5597.py= 0555 ${PACKAGE}FILESMODE_CVE-2019-5598.py= 0555 .include diff --git a/tests/sys/netpfil/pf/altq.sh b/tests/sys/netpfil/pf/altq.sh new file mode 100644 index 000000000000..89da4c0deb6f --- /dev/null +++ b/tests/sys/netpfil/pf/altq.sh @@ -0,0 +1,49 @@ +. $(atf_get_srcdir)/utils.subr + +atf_test_case "hfsc" "cleanup" +hfsc_head() +{ + atf_set descr 'Basic HFSC test' + atf_set require.user root +} + +hfsc_body() +{ + altq_init + is_altq_supported hfsc + + epair=$(vnet_mkepair) + vnet_mkjail altq_hfsc ${epair}b + + ifconfig ${epair}a 192.0.2.1/24 up + jexec altq_hfsc ifconfig ${epair}b 192.0.2.2/24 up + + # Sanity check + atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2 + + jexec altq_hfsc pfctl -e + pft_set_rules altq_hfsc \ + "altq on ${epair}b bandwidth 100b hfsc queue { default }" \ + "queue default hfsc(default linkshare 80b)" \ + "pass proto icmp " + + # single ping succeeds just fine + atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2 + + # "Saturate the link" + ping -i .1 -c 5 -s 1200 192.0.2.2 + + # We should now be hitting the limits and get this packet dropped. + atf_check -s exit:2 -o ignore ping -c 1 -s 1200 192.0.2.2 +} + +hfsc_cleanup() +{ + altq_cleanup +} + +atf_init_test_cases() +{ + atf_add_test_case "hfsc" +} + diff --git a/tests/sys/netpfil/pf/utils.subr b/tests/sys/netpfil/pf/utils.subr index 62e85d5cc463..d7df2a6747da 100644 --- a/tests/sys/netpfil/pf/utils.subr +++ b/tests/sys/netpfil/pf/utils.subr @@ -1,81 +1,105 @@ # $FreeBSD$ # Utility functions ## # SPDX-License-Identifier: BSD-2-Clause-FreeBSD # # Copyright (c) 2017 Kristof Provost # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. . $(atf_get_srcdir)/../../common/vnet.subr pft_init() { vnet_init if [ ! -c /dev/pf ]; then atf_skip "This test requires pf" fi } pfsynct_init() { pft_init if ! kldstat -q -m pfsync; then atf_skip "This test requires pfsync" fi } pft_set_rules() { jname=$1 shift if [ $jname == "noflush" ]; then jname=$1 shift else # Flush all states, rules, fragments, ... jexec ${jname} pfctl -F all fi while [ $# -gt 0 ]; do printf "$1\n" shift done | jexec ${jname} pfctl -f - if [ $? -ne 0 ]; then atf_fail "Failed to set PF rules in ${jname}" fi } pft_cleanup() { vnet_cleanup } pfsynct_cleanup() { pft_cleanup } + +is_altq_supported() +{ + sysctl -q kern.features.altq >/dev/null || \ + atf_skip "Test requires ALTQ" + + while [ -n "$1" ] + do + sysctl -q kern.features.altq.${1} >/dev/null || \ + atf_skip "Test required ALTQ_${1}" + shift + done +} + +altq_init() +{ + pft_init + is_altq_supported +} + +altq_cleanup() +{ + pft_cleanup +}