1ea3eca5cSKristof Provost# 24d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause 3ea3eca5cSKristof Provost# 4ea3eca5cSKristof Provost# Copyright (c) 2021 Rubicon Communications, LLC (Netgate) 5ea3eca5cSKristof Provost# 6ea3eca5cSKristof Provost# Redistribution and use in source and binary forms, with or without 7ea3eca5cSKristof Provost# modification, are permitted provided that the following conditions 8ea3eca5cSKristof Provost# are met: 9ea3eca5cSKristof Provost# 1. Redistributions of source code must retain the above copyright 10ea3eca5cSKristof Provost# notice, this list of conditions and the following disclaimer. 11ea3eca5cSKristof Provost# 2. Redistributions in binary form must reproduce the above copyright 12ea3eca5cSKristof Provost# notice, this list of conditions and the following disclaimer in the 13ea3eca5cSKristof Provost# documentation and/or other materials provided with the distribution. 14ea3eca5cSKristof Provost# 15ea3eca5cSKristof Provost# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16ea3eca5cSKristof Provost# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17ea3eca5cSKristof Provost# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18ea3eca5cSKristof Provost# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19ea3eca5cSKristof Provost# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20ea3eca5cSKristof Provost# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21ea3eca5cSKristof Provost# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22ea3eca5cSKristof Provost# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23ea3eca5cSKristof Provost# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24ea3eca5cSKristof Provost# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25ea3eca5cSKristof Provost# SUCH DAMAGE. 26ea3eca5cSKristof Provost 27ea3eca5cSKristof Provost. $(atf_get_srcdir)/utils.subr 28ea3eca5cSKristof Provost. $(atf_get_srcdir)/runner.subr 29ea3eca5cSKristof Provost 3074e6b014SKristof Provostinterface_removal_head() 3174e6b014SKristof Provost{ 3274e6b014SKristof Provost atf_set descr 'Test removing interfaces with dummynet delayed traffic' 3374e6b014SKristof Provost atf_set require.user root 3474e6b014SKristof Provost} 3574e6b014SKristof Provost 3674e6b014SKristof Provostinterface_removal_body() 3774e6b014SKristof Provost{ 3874e6b014SKristof Provost fw=$1 3974e6b014SKristof Provost firewall_init $fw 4074e6b014SKristof Provost dummynet_init $fw 4174e6b014SKristof Provost 4274e6b014SKristof Provost epair=$(vnet_mkepair) 4374e6b014SKristof Provost vnet_mkjail alcatraz ${epair}b 4474e6b014SKristof Provost 4574e6b014SKristof Provost ifconfig ${epair}a 192.0.2.1/24 up 4674e6b014SKristof Provost jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up 4774e6b014SKristof Provost 4874e6b014SKristof Provost # Sanity check 4974e6b014SKristof Provost atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2 5074e6b014SKristof Provost 5174e6b014SKristof Provost jexec alcatraz dnctl pipe 1 config delay 1500 5274e6b014SKristof Provost 5374e6b014SKristof Provost firewall_config alcatraz ${fw} \ 5474e6b014SKristof Provost "ipfw" \ 5574e6b014SKristof Provost "ipfw add 1000 pipe 1 ip from any to any" \ 5674e6b014SKristof Provost "pf" \ 574a6b9284SDoug Rabson "pass on ${epair}b dnpipe 1" 5874e6b014SKristof Provost 5974e6b014SKristof Provost # single ping succeeds just fine 6074e6b014SKristof Provost atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2 6174e6b014SKristof Provost 6274e6b014SKristof Provost # Send traffic that'll still be pending when we remove the interface 6374e6b014SKristof Provost ping -c 5 -s 1200 192.0.2.2 & 6474e6b014SKristof Provost sleep 1 # Give ping the chance to start. 6574e6b014SKristof Provost 6674e6b014SKristof Provost # Remove the interface, but keep the jail around for a bit 6774e6b014SKristof Provost ifconfig ${epair}a destroy 6874e6b014SKristof Provost 6974e6b014SKristof Provost sleep 3 7074e6b014SKristof Provost} 7174e6b014SKristof Provost 7274e6b014SKristof Provostinterface_removal_cleanup() 7374e6b014SKristof Provost{ 7474e6b014SKristof Provost firewall_cleanup $1 7574e6b014SKristof Provost} 7674e6b014SKristof Provost 77ea3eca5cSKristof Provostpipe_head() 78ea3eca5cSKristof Provost{ 79ea3eca5cSKristof Provost atf_set descr 'Basic pipe test' 80ea3eca5cSKristof Provost atf_set require.user root 81ea3eca5cSKristof Provost} 82ea3eca5cSKristof Provost 83ea3eca5cSKristof Provostpipe_body() 84ea3eca5cSKristof Provost{ 85ea3eca5cSKristof Provost fw=$1 86ea3eca5cSKristof Provost firewall_init $fw 87ea3eca5cSKristof Provost dummynet_init $fw 88ea3eca5cSKristof Provost 89ea3eca5cSKristof Provost epair=$(vnet_mkepair) 90ea3eca5cSKristof Provost vnet_mkjail alcatraz ${epair}b 91ea3eca5cSKristof Provost 92ea3eca5cSKristof Provost ifconfig ${epair}a 192.0.2.1/24 up 93ea3eca5cSKristof Provost jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up 94ea3eca5cSKristof Provost 95ea3eca5cSKristof Provost # Sanity check 96ea3eca5cSKristof Provost atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2 97ea3eca5cSKristof Provost 98ea3eca5cSKristof Provost jexec alcatraz dnctl pipe 1 config bw 30Byte/s 99ea3eca5cSKristof Provost 100ea3eca5cSKristof Provost firewall_config alcatraz ${fw} \ 101ea3eca5cSKristof Provost "ipfw" \ 102ab55fa11SKristof Provost "ipfw add 1000 pipe 1 ip from any to any" \ 103ab55fa11SKristof Provost "pf" \ 1044a6b9284SDoug Rabson "pass on ${epair}b dnpipe 1" 105ea3eca5cSKristof Provost 106ea3eca5cSKristof Provost # single ping succeeds just fine 107ea3eca5cSKristof Provost atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2 108ea3eca5cSKristof Provost 109ea3eca5cSKristof Provost # Saturate the link 110ea3eca5cSKristof Provost ping -i .1 -c 5 -s 1200 192.0.2.2 111ea3eca5cSKristof Provost 112ea3eca5cSKristof Provost # We should now be hitting the limits and get this packet dropped. 113ea3eca5cSKristof Provost atf_check -s exit:2 -o ignore ping -c 1 -s 1200 192.0.2.2 114ea3eca5cSKristof Provost} 115ea3eca5cSKristof Provost 116ea3eca5cSKristof Provostpipe_cleanup() 117ea3eca5cSKristof Provost{ 118ea3eca5cSKristof Provost firewall_cleanup $1 119ea3eca5cSKristof Provost} 120ea3eca5cSKristof Provost 1215fda5913SKristof Provostpipe_v6_head() 1225fda5913SKristof Provost{ 1235fda5913SKristof Provost atf_set descr 'Basic IPv6 pipe test' 1245fda5913SKristof Provost atf_set require.user root 1255fda5913SKristof Provost} 1265fda5913SKristof Provost 1275fda5913SKristof Provostpipe_v6_body() 1285fda5913SKristof Provost{ 1295fda5913SKristof Provost fw=$1 1305fda5913SKristof Provost firewall_init $fw 1315fda5913SKristof Provost dummynet_init $fw 1325fda5913SKristof Provost 1335fda5913SKristof Provost epair=$(vnet_mkepair) 1345fda5913SKristof Provost vnet_mkjail alcatraz ${epair}b 1355fda5913SKristof Provost 1365fda5913SKristof Provost ifconfig ${epair}a inet6 2001:db8:42::1/64 up no_dad 1375fda5913SKristof Provost jexec alcatraz ifconfig ${epair}b inet6 2001:db8:42::2/64 up no_dad 1385fda5913SKristof Provost 1395fda5913SKristof Provost # Sanity check 1405fda5913SKristof Provost atf_check -s exit:0 -o ignore ping6 -i .1 -c 3 -s 1200 2001:db8:42::2 1415fda5913SKristof Provost 1425fda5913SKristof Provost jexec alcatraz dnctl pipe 1 config bw 100Byte/s 1435fda5913SKristof Provost 1445fda5913SKristof Provost firewall_config alcatraz ${fw} \ 1455fda5913SKristof Provost "ipfw" \ 146ab55fa11SKristof Provost "ipfw add 1000 pipe 1 ip6 from any to any" \ 147ab55fa11SKristof Provost "pf" \ 1484a6b9284SDoug Rabson "pass on ${epair}b dnpipe 1" 1495fda5913SKristof Provost 1505fda5913SKristof Provost # Single ping succeeds 1515fda5913SKristof Provost atf_check -s exit:0 -o ignore ping6 -c 1 2001:db8:42::2 1525fda5913SKristof Provost 1535fda5913SKristof Provost # Saturate the link 1545fda5913SKristof Provost ping6 -i .1 -c 5 -s 1200 2001:db8:42::2 1555fda5913SKristof Provost 1565fda5913SKristof Provost # We should now be hitting the limit and get this packet dropped. 1575fda5913SKristof Provost atf_check -s exit:2 -o ignore ping6 -c 1 -s 1200 2001:db8:42::2 1585fda5913SKristof Provost} 1595fda5913SKristof Provost 1605fda5913SKristof Provostpipe_v6_cleanup() 1615fda5913SKristof Provost{ 1625fda5913SKristof Provost firewall_cleanup $1 1635fda5913SKristof Provost} 1645fda5913SKristof Provost 165c90b9a5eSKristof Provostcodel_head() 166c90b9a5eSKristof Provost{ 167c90b9a5eSKristof Provost atf_set descr 'FQ_CODEL basic test' 168c90b9a5eSKristof Provost atf_set require.user root 169c90b9a5eSKristof Provost} 170c90b9a5eSKristof Provost 171c90b9a5eSKristof Provostcodel_body() 172c90b9a5eSKristof Provost{ 173c90b9a5eSKristof Provost fw=$1 174c90b9a5eSKristof Provost firewall_init $fw 175c90b9a5eSKristof Provost dummynet_init $fw 176c90b9a5eSKristof Provost 177c90b9a5eSKristof Provost epair=$(vnet_mkepair) 178c90b9a5eSKristof Provost vnet_mkjail alcatraz ${epair}b 179c90b9a5eSKristof Provost 180c90b9a5eSKristof Provost ifconfig ${epair}a 192.0.2.1/24 up 181c90b9a5eSKristof Provost jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up 182c90b9a5eSKristof Provost 183c90b9a5eSKristof Provost # Sanity check 184c90b9a5eSKristof Provost atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2 185c90b9a5eSKristof Provost 186c90b9a5eSKristof Provost jexec alcatraz dnctl pipe 1 config bw 10Mb queue 100 droptail 187c90b9a5eSKristof Provost jexec alcatraz dnctl sched 1 config pipe 1 type fq_codel target 0ms interval 0ms quantum 1514 limit 10240 flows 1024 ecn 188c90b9a5eSKristof Provost jexec alcatraz dnctl queue 1 config pipe 1 droptail 189c90b9a5eSKristof Provost 190c90b9a5eSKristof Provost firewall_config alcatraz ${fw} \ 191c90b9a5eSKristof Provost "ipfw" \ 192c90b9a5eSKristof Provost "ipfw add 1000 queue 1 ip from any to any" \ 193c90b9a5eSKristof Provost "pf" \ 194c90b9a5eSKristof Provost "pass dnqueue 1" 195c90b9a5eSKristof Provost 196c90b9a5eSKristof Provost # single ping succeeds just fine 197c90b9a5eSKristof Provost atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2 198c90b9a5eSKristof Provost} 199c90b9a5eSKristof Provost 200c90b9a5eSKristof Provostcodel_cleanup() 201c90b9a5eSKristof Provost{ 202c90b9a5eSKristof Provost firewall_cleanup $1 203c90b9a5eSKristof Provost} 204c90b9a5eSKristof Provost 2051e1bb578SKristof Provostwf2q_heap_head() 2061e1bb578SKristof Provost{ 2071e1bb578SKristof Provost atf_set descr 'Test WF2Q+, attempting to provoke use-after-free' 2081e1bb578SKristof Provost atf_set require.user root 2091e1bb578SKristof Provost} 2101e1bb578SKristof Provost 2111e1bb578SKristof Provostwf2q_heap_body() 2121e1bb578SKristof Provost{ 2131e1bb578SKristof Provost fw=$1 2141e1bb578SKristof Provost firewall_init $fw 2151e1bb578SKristof Provost dummynet_init $fw 2161e1bb578SKristof Provost 2171e1bb578SKristof Provost j=dummynet_wf2q_heap_${fw}_ 2181e1bb578SKristof Provost 2191e1bb578SKristof Provost epair=$(vnet_mkepair) 2201e1bb578SKristof Provost epair_other=$(vnet_mkepair) 2211e1bb578SKristof Provost vnet_mkjail ${j}a ${epair}a 2221e1bb578SKristof Provost vnet_mkjail ${j}b ${epair}b ${epair_other}b 2231e1bb578SKristof Provost 2241e1bb578SKristof Provost jexec ${j}a ifconfig ${epair}a up mtu 9000 2251e1bb578SKristof Provost va=$(jexec ${j}a ifconfig vlan create vlan 42 vlandev ${epair}a) 2261e1bb578SKristof Provost jexec ${j}a ifconfig ${va} 192.0.2.1/24 up #mtu 8000 2271e1bb578SKristof Provost 2281e1bb578SKristof Provost jexec ${j}b ifconfig ${epair}b up mtu 9000 2291e1bb578SKristof Provost vb=$(jexec ${j}b ifconfig vlan create vlan 42 vlandev ${epair}b) 2301e1bb578SKristof Provost jexec ${j}b ifconfig ${vb} 192.0.2.2/24 up #mtu 8000 2311e1bb578SKristof Provost jexec ${j}b ifconfig ${epair_other}b up 2321e1bb578SKristof Provost 2331e1bb578SKristof Provost # Sanity check 2341e1bb578SKristof Provost atf_check -s exit:0 -o ignore \ 2351e1bb578SKristof Provost jexec ${j}b ping -c 1 192.0.2.1 2361e1bb578SKristof Provost 2371e1bb578SKristof Provost jexec ${j}b dnctl pipe 1 config bw 10Mb queue 100 delay 500 droptail 2381e1bb578SKristof Provost jexec ${j}b dnctl sched 1 config pipe 1 type wf2q+ 2391e1bb578SKristof Provost jexec ${j}b dnctl queue 1 config pipe 1 droptail 2401e1bb578SKristof Provost 2411e1bb578SKristof Provost firewall_config ${j}b ${fw} \ 2421e1bb578SKristof Provost "pf" \ 2431e1bb578SKristof Provost "pass dnqueue 1" 2441e1bb578SKristof Provost 2451e1bb578SKristof Provost jexec ${j}a ping -f 192.0.2.2 & 2461e1bb578SKristof Provost sleep 1 2471e1bb578SKristof Provost 2481e1bb578SKristof Provost jexec ${j}b ifconfig ${vb} destroy 2491e1bb578SKristof Provost 2501e1bb578SKristof Provost sleep 2 2511e1bb578SKristof Provost} 2521e1bb578SKristof Provost 2531e1bb578SKristof Provostwf2q_heap_cleanup() 2541e1bb578SKristof Provost{ 2551e1bb578SKristof Provost firewall_cleanup $1 2561e1bb578SKristof Provost} 2571e1bb578SKristof Provost 258cb6bfef9SKristof Provostqueue_head() 259cb6bfef9SKristof Provost{ 260cb6bfef9SKristof Provost atf_set descr 'Basic queue test' 261cb6bfef9SKristof Provost atf_set require.user root 262cb6bfef9SKristof Provost} 263cb6bfef9SKristof Provost 264cb6bfef9SKristof Provostqueue_body() 265cb6bfef9SKristof Provost{ 266cb6bfef9SKristof Provost fw=$1 267b256d2dcSLi-Wen Hsu 268b256d2dcSLi-Wen Hsu if [ $fw = "ipfw" ] && [ "$(atf_config_get ci false)" = "true" ]; then 269b256d2dcSLi-Wen Hsu atf_skip "https://bugs.freebsd.org/264805" 270b256d2dcSLi-Wen Hsu fi 271b256d2dcSLi-Wen Hsu 272cb6bfef9SKristof Provost firewall_init $fw 273cb6bfef9SKristof Provost dummynet_init $fw 274cb6bfef9SKristof Provost 275cb6bfef9SKristof Provost epair=$(vnet_mkepair) 276cb6bfef9SKristof Provost vnet_mkjail alcatraz ${epair}b 277cb6bfef9SKristof Provost 278cb6bfef9SKristof Provost ifconfig ${epair}a 192.0.2.1/24 up 279cb6bfef9SKristof Provost jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up 280b0fcf4d5SKristof Provost jexec alcatraz /usr/sbin/inetd -p ${PWD}/inetd-alcatraz.pid \ 281cb6bfef9SKristof Provost $(atf_get_srcdir)/../pf/echo_inetd.conf 282cb6bfef9SKristof Provost 283cb6bfef9SKristof Provost # Sanity check 284cb6bfef9SKristof Provost atf_check -s exit:0 -o ignore ping -i .1 -c 3 -s 1200 192.0.2.2 285cb6bfef9SKristof Provost reply=$(echo "foo" | nc -N 192.0.2.2 7) 286cb6bfef9SKristof Provost if [ "$reply" != "foo" ]; 287cb6bfef9SKristof Provost then 288cb6bfef9SKristof Provost atf_fail "Echo sanity check failed" 289cb6bfef9SKristof Provost fi 290cb6bfef9SKristof Provost 291cb6bfef9SKristof Provost jexec alcatraz dnctl pipe 1 config bw 1MByte/s 292cb6bfef9SKristof Provost jexec alcatraz dnctl sched 1 config pipe 1 type wf2q+ 293cb6bfef9SKristof Provost jexec alcatraz dnctl queue 100 config sched 1 weight 99 mask all 294cb6bfef9SKristof Provost jexec alcatraz dnctl queue 200 config sched 1 weight 1 mask all 295cb6bfef9SKristof Provost 296cb6bfef9SKristof Provost firewall_config alcatraz ${fw} \ 297cb6bfef9SKristof Provost "ipfw" \ 298cb6bfef9SKristof Provost "ipfw add 1000 queue 100 tcp from 192.0.2.2 to any out" \ 299cb6bfef9SKristof Provost "ipfw add 1001 queue 200 icmp from 192.0.2.2 to any out" \ 300ab55fa11SKristof Provost "ipfw add 1002 allow ip from any to any" \ 301ab55fa11SKristof Provost "pf" \ 302ab55fa11SKristof Provost "pass in proto tcp dnqueue (0, 100)" \ 303ab55fa11SKristof Provost "pass in proto icmp dnqueue (0, 200)" 304cb6bfef9SKristof Provost 305cb6bfef9SKristof Provost # Single ping succeeds 306cb6bfef9SKristof Provost atf_check -s exit:0 -o ignore ping -c 1 192.0.2.2 307cb6bfef9SKristof Provost 308cb6bfef9SKristof Provost # Unsaturated TCP succeeds 309cb6bfef9SKristof Provost reply=$(echo "foo" | nc -w 5 -N 192.0.2.2 7) 310cb6bfef9SKristof Provost if [ "$reply" != "foo" ]; 311cb6bfef9SKristof Provost then 312cb6bfef9SKristof Provost atf_fail "Unsaturated echo failed" 313cb6bfef9SKristof Provost fi 314cb6bfef9SKristof Provost 315cb6bfef9SKristof Provost # Saturate the link 316cb6bfef9SKristof Provost ping -f -s 1300 192.0.2.2 & 317cb6bfef9SKristof Provost 318cb6bfef9SKristof Provost # Allow this to fill the queue 319cb6bfef9SKristof Provost sleep 1 320cb6bfef9SKristof Provost 321cb6bfef9SKristof Provost # TCP should still just pass 322cb6bfef9SKristof Provost fails=0 323*a46c121dSKristof Provost for i in `seq 1 5` 324cb6bfef9SKristof Provost do 325cb6bfef9SKristof Provost result=$(dd if=/dev/zero bs=1024 count=2000 | timeout 3 nc -w 5 -N 192.0.2.2 7 | wc -c) 326cb6bfef9SKristof Provost if [ $result -ne 2048000 ]; 327cb6bfef9SKristof Provost then 328cb6bfef9SKristof Provost echo "Failed to prioritise TCP traffic. Got only $result bytes" 329cb6bfef9SKristof Provost fails=$(( ${fails} + 1 )) 330cb6bfef9SKristof Provost fi 331cb6bfef9SKristof Provost done 332*a46c121dSKristof Provost if [ ${fails} -gt 2 ]; 333cb6bfef9SKristof Provost then 334cb6bfef9SKristof Provost atf_fail "We failed prioritisation ${fails} times" 335cb6bfef9SKristof Provost fi 336cb6bfef9SKristof Provost 337cb6bfef9SKristof Provost # This will fail if we reverse the pola^W priority 338cb6bfef9SKristof Provost firewall_config alcatraz ${fw} \ 339cb6bfef9SKristof Provost "ipfw" \ 340cb6bfef9SKristof Provost "ipfw add 1000 queue 200 tcp from 192.0.2.2 to any out" \ 341cb6bfef9SKristof Provost "ipfw add 1001 queue 100 icmp from 192.0.2.2 to any out" \ 342ab55fa11SKristof Provost "ipfw add 1002 allow ip from any to any" \ 343ab55fa11SKristof Provost "pf" \ 344ab55fa11SKristof Provost "pass in proto tcp dnqueue (0, 200)" \ 345ab55fa11SKristof Provost "pass in proto icmp dnqueue (0, 100)" 346cb6bfef9SKristof Provost 347cb6bfef9SKristof Provost jexec alcatraz ping -f -s 1300 192.0.2.1 & 348cb6bfef9SKristof Provost sleep 1 349cb6bfef9SKristof Provost 350cb6bfef9SKristof Provost fails=0 351*a46c121dSKristof Provost for i in `seq 1 5` 352cb6bfef9SKristof Provost do 353cb6bfef9SKristof Provost result=$(dd if=/dev/zero bs=1024 count=2000 | timeout 3 nc -w 5 -N 192.0.2.2 7 | wc -c) 354cb6bfef9SKristof Provost if [ $result -ne 2048000 ]; 355cb6bfef9SKristof Provost then 356cb6bfef9SKristof Provost echo "Failed to prioritise TCP traffic. Got only $result bytes" 357cb6bfef9SKristof Provost fails=$(( ${fails} + 1 )) 358cb6bfef9SKristof Provost fi 359cb6bfef9SKristof Provost done 360cb6bfef9SKristof Provost if [ ${fails} -lt 3 ]; 361cb6bfef9SKristof Provost then 362cb6bfef9SKristof Provost atf_fail "We failed reversed prioritisation only ${fails} times." 363cb6bfef9SKristof Provost fi 364cb6bfef9SKristof Provost} 365cb6bfef9SKristof Provost 366cb6bfef9SKristof Provostqueue_cleanup() 367cb6bfef9SKristof Provost{ 368cb6bfef9SKristof Provost firewall_cleanup $1 369cb6bfef9SKristof Provost} 370cb6bfef9SKristof Provost 37112184311SKristof Provostqueue_v6_head() 37212184311SKristof Provost{ 37312184311SKristof Provost atf_set descr 'Basic queue test' 37412184311SKristof Provost atf_set require.user root 37512184311SKristof Provost} 37612184311SKristof Provost 37712184311SKristof Provostqueue_v6_body() 37812184311SKristof Provost{ 37912184311SKristof Provost fw=$1 38012184311SKristof Provost firewall_init $fw 38112184311SKristof Provost dummynet_init $fw 38212184311SKristof Provost 38312184311SKristof Provost epair=$(vnet_mkepair) 38412184311SKristof Provost vnet_mkjail alcatraz ${epair}b 38512184311SKristof Provost 38612184311SKristof Provost ifconfig ${epair}a inet6 2001:db8:42::1/64 no_dad up 38712184311SKristof Provost jexec alcatraz ifconfig ${epair}b inet6 2001:db8:42::2 no_dad up 388b0fcf4d5SKristof Provost jexec alcatraz /usr/sbin/inetd -p ${PWD}/inetd-alcatraz.pid \ 38912184311SKristof Provost $(atf_get_srcdir)/../pf/echo_inetd.conf 39075d15e89SGleb Smirnoff jexec alcatraz sysctl net.inet6.icmp6.errppslimit=0 39112184311SKristof Provost 39212184311SKristof Provost # Sanity check 39312184311SKristof Provost atf_check -s exit:0 -o ignore ping6 -i .1 -c 3 -s 1200 2001:db8:42::2 39412184311SKristof Provost reply=$(echo "foo" | nc -N 2001:db8:42::2 7) 39512184311SKristof Provost if [ "$reply" != "foo" ]; 39612184311SKristof Provost then 39712184311SKristof Provost atf_fail "Echo sanity check failed" 39812184311SKristof Provost fi 39912184311SKristof Provost 40012184311SKristof Provost jexec alcatraz dnctl pipe 1 config bw 1MByte/s 40112184311SKristof Provost jexec alcatraz dnctl sched 1 config pipe 1 type wf2q+ 40212184311SKristof Provost jexec alcatraz dnctl queue 100 config sched 1 weight 99 mask all 40312184311SKristof Provost jexec alcatraz dnctl queue 200 config sched 1 weight 1 mask all 40412184311SKristof Provost 40512184311SKristof Provost firewall_config alcatraz ${fw} \ 40612184311SKristof Provost "ipfw" \ 40712184311SKristof Provost "ipfw add 1001 queue 100 tcp from 2001:db8:42::2 to any out" \ 40812184311SKristof Provost "ipfw add 1000 queue 200 ipv6-icmp from 2001:db8:42::2 to any out" \ 40912184311SKristof Provost "ipfw add 1002 allow ip6 from any to any" \ 41012184311SKristof Provost "pf" \ 411ab55fa11SKristof Provost "pass in proto tcp dnqueue (0, 100)" \ 412ab55fa11SKristof Provost "pass in proto icmp6 dnqueue (0, 200)" 41312184311SKristof Provost 41412184311SKristof Provost # Single ping succeeds 41512184311SKristof Provost atf_check -s exit:0 -o ignore ping6 -c 1 2001:db8:42::2 41612184311SKristof Provost 41712184311SKristof Provost # Unsaturated TCP succeeds 41812184311SKristof Provost reply=$(echo "foo" | nc -w 5 -N 2001:db8:42::2 7) 41912184311SKristof Provost if [ "$reply" != "foo" ]; 42012184311SKristof Provost then 42112184311SKristof Provost atf_fail "Unsaturated echo failed" 42212184311SKristof Provost fi 42312184311SKristof Provost 42412184311SKristof Provost # Saturate the link 42512184311SKristof Provost ping6 -f -s 1200 2001:db8:42::2 & 42612184311SKristof Provost 42712184311SKristof Provost # Allow this to fill the queue 42812184311SKristof Provost sleep 1 42912184311SKristof Provost 43012184311SKristof Provost # TCP should still just pass 43112184311SKristof Provost fails=0 432*a46c121dSKristof Provost for i in `seq 1 5` 43312184311SKristof Provost do 43412184311SKristof Provost result=$(dd if=/dev/zero bs=1024 count=1000 | timeout 3 nc -w 5 -N 2001:db8:42::2 7 | wc -c) 43512184311SKristof Provost if [ $result -ne 1024000 ]; 43612184311SKristof Provost then 43712184311SKristof Provost echo "Failed to prioritise TCP traffic. Got only $result bytes" 43812184311SKristof Provost fails=$(( ${fails} + 1 )) 43912184311SKristof Provost fi 44012184311SKristof Provost done 441*a46c121dSKristof Provost if [ ${fails} -gt 2 ]; 44212184311SKristof Provost then 44312184311SKristof Provost atf_fail "We failed prioritisation ${fails} times" 44412184311SKristof Provost fi 44512184311SKristof Provost 44612184311SKristof Provost # What happens if we prioritise ICMP over TCP? 44712184311SKristof Provost firewall_config alcatraz ${fw} \ 44812184311SKristof Provost "ipfw" \ 44912184311SKristof Provost "ipfw add 1001 queue 200 tcp from 2001:db8:42::2 to any out" \ 45012184311SKristof Provost "ipfw add 1000 queue 100 ipv6-icmp from 2001:db8:42::2 to any out" \ 45112184311SKristof Provost "ipfw add 1002 allow ip6 from any to any" \ 45212184311SKristof Provost "pf" \ 453ab55fa11SKristof Provost "pass in proto tcp dnqueue (0, 200)" \ 454ab55fa11SKristof Provost "pass in proto icmp6 dnqueue (0, 100)" 45512184311SKristof Provost 45612184311SKristof Provost fails=0 457*a46c121dSKristof Provost for i in `seq 1 5` 45812184311SKristof Provost do 45912184311SKristof Provost result=$(dd if=/dev/zero bs=1024 count=1000 | timeout 3 nc -w 5 -N 2001:db8:42::2 7 | wc -c) 46012184311SKristof Provost if [ $result -ne 1024000 ]; 46112184311SKristof Provost then 46212184311SKristof Provost echo "Failed to prioritise TCP traffic. Got only $result bytes" 46312184311SKristof Provost fails=$(( ${fails} + 1 )) 46412184311SKristof Provost fi 46512184311SKristof Provost done 46612184311SKristof Provost if [ ${fails} -lt 3 ]; 46712184311SKristof Provost then 46812184311SKristof Provost atf_fail "We failed reversed prioritisation only ${fails} times." 46912184311SKristof Provost fi 47012184311SKristof Provost} 47112184311SKristof Provost 47212184311SKristof Provostqueue_v6_cleanup() 47312184311SKristof Provost{ 47412184311SKristof Provost firewall_cleanup $1 47512184311SKristof Provost} 47612184311SKristof Provost 4774ee0f6d8SKristof Provostnat_head() 4784ee0f6d8SKristof Provost{ 4794ee0f6d8SKristof Provost atf_set descr 'Basic dummynet + NAT test' 4804ee0f6d8SKristof Provost atf_set require.user root 4814ee0f6d8SKristof Provost} 4824ee0f6d8SKristof Provost 4834ee0f6d8SKristof Provostnat_body() 4844ee0f6d8SKristof Provost{ 4854ee0f6d8SKristof Provost fw=$1 4864ee0f6d8SKristof Provost firewall_init $fw 4874ee0f6d8SKristof Provost dummynet_init $fw 4884ee0f6d8SKristof Provost nat_init $fw 4894ee0f6d8SKristof Provost 4904ee0f6d8SKristof Provost epair=$(vnet_mkepair) 4914ee0f6d8SKristof Provost epair_two=$(vnet_mkepair) 4924ee0f6d8SKristof Provost 4934ee0f6d8SKristof Provost ifconfig ${epair}a 192.0.2.2/24 up 4944ee0f6d8SKristof Provost route add -net 198.51.100.0/24 192.0.2.1 4954ee0f6d8SKristof Provost 4964ee0f6d8SKristof Provost vnet_mkjail gw ${epair}b ${epair_two}a 4974ee0f6d8SKristof Provost jexec gw ifconfig ${epair}b 192.0.2.1/24 up 4984ee0f6d8SKristof Provost jexec gw ifconfig ${epair_two}a 198.51.100.1/24 up 4994ee0f6d8SKristof Provost jexec gw sysctl net.inet.ip.forwarding=1 5004ee0f6d8SKristof Provost 5014ee0f6d8SKristof Provost vnet_mkjail srv ${epair_two}b 5024ee0f6d8SKristof Provost jexec srv ifconfig ${epair_two}b 198.51.100.2/24 up 5034ee0f6d8SKristof Provost 5044ee0f6d8SKristof Provost jexec gw dnctl pipe 1 config bw 300Byte/s 5054ee0f6d8SKristof Provost 5064ee0f6d8SKristof Provost firewall_config gw $fw \ 5074ee0f6d8SKristof Provost "pf" \ 5084ee0f6d8SKristof Provost "nat on ${epair_two}a inet from 192.0.2.0/24 to any -> (${epair_two}a)" \ 5094ee0f6d8SKristof Provost "pass dnpipe 1" 5104ee0f6d8SKristof Provost 5114ee0f6d8SKristof Provost # We've deliberately not set a route to 192.0.2.0/24 on srv, so the 5124ee0f6d8SKristof Provost # only way it can respond to this is if NAT is applied correctly. 5134ee0f6d8SKristof Provost atf_check -s exit:0 -o ignore ping -c 1 198.51.100.2 5144ee0f6d8SKristof Provost} 5154ee0f6d8SKristof Provost 5164ee0f6d8SKristof Provostnat_cleanup() 5174ee0f6d8SKristof Provost{ 5184ee0f6d8SKristof Provost firewall_cleanup $1 5194ee0f6d8SKristof Provost} 5204ee0f6d8SKristof Provost 52131cf66d7SRichard Scheffeneggerpls_basic_head() 52231cf66d7SRichard Scheffenegger{ 52331cf66d7SRichard Scheffenegger atf_set descr 'Basic dummynet packet loss rate test' 52431cf66d7SRichard Scheffenegger atf_set require.user root 52531cf66d7SRichard Scheffenegger} 52631cf66d7SRichard Scheffenegger 52731cf66d7SRichard Scheffeneggerpls_basic_body() 52831cf66d7SRichard Scheffenegger{ 52931cf66d7SRichard Scheffenegger fw=$1 53031cf66d7SRichard Scheffenegger firewall_init $fw 53131cf66d7SRichard Scheffenegger dummynet_init $fw 53231cf66d7SRichard Scheffenegger 53331cf66d7SRichard Scheffenegger epair=$(vnet_mkepair) 53431cf66d7SRichard Scheffenegger vnet_mkjail alcatraz ${epair}b 53531cf66d7SRichard Scheffenegger 53631cf66d7SRichard Scheffenegger ifconfig ${epair}a 192.0.2.1/24 up 53731cf66d7SRichard Scheffenegger jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up 53831cf66d7SRichard Scheffenegger 53931cf66d7SRichard Scheffenegger firewall_config alcatraz ${fw} \ 54031cf66d7SRichard Scheffenegger "ipfw" \ 54131cf66d7SRichard Scheffenegger "ipfw add 65432 ip from any to any" \ 54231cf66d7SRichard Scheffenegger "pf" \ 54331cf66d7SRichard Scheffenegger "pass on ${epair}b" 54431cf66d7SRichard Scheffenegger 54531cf66d7SRichard Scheffenegger # Sanity check 54631cf66d7SRichard Scheffenegger atf_check -s exit:0 -o match:'100 packets transmitted, 100 packets received' ping -i .1 -c 100 192.0.2.2 54731cf66d7SRichard Scheffenegger 54831cf66d7SRichard Scheffenegger jexec alcatraz dnctl pipe 1 config plr 0.1 54931cf66d7SRichard Scheffenegger 55031cf66d7SRichard Scheffenegger firewall_config alcatraz ${fw} \ 55131cf66d7SRichard Scheffenegger "ipfw" \ 55231cf66d7SRichard Scheffenegger "ipfw add 1000 pipe 1 ip from 192.0.2.1 to 192.0.2.2" \ 55331cf66d7SRichard Scheffenegger "pf" \ 55431cf66d7SRichard Scheffenegger "pass on ${epair}b dnpipe 1" 55531cf66d7SRichard Scheffenegger 55631cf66d7SRichard Scheffenegger # check if the expected number of pings 55731cf66d7SRichard Scheffenegger # are dropped (84 - 96 responses). 55831cf66d7SRichard Scheffenegger # repeat up to 6 times if the initial 55931cf66d7SRichard Scheffenegger # checks fail 5602144e31dSKristof Provost atf_check -s exit:0 -o match:'100 packets transmitted, (8[4-9]|9[0-6]) packets received' -r 20:10 ping -i 0.010 -c 100 192.0.2.2 56131cf66d7SRichard Scheffenegger} 56231cf66d7SRichard Scheffenegger 56331cf66d7SRichard Scheffeneggerpls_basic_cleanup() 56431cf66d7SRichard Scheffenegger{ 56531cf66d7SRichard Scheffenegger firewall_cleanup $1 56631cf66d7SRichard Scheffenegger} 56731cf66d7SRichard Scheffenegger 56831cf66d7SRichard Scheffeneggerpls_gilbert_head() 56931cf66d7SRichard Scheffenegger{ 57031cf66d7SRichard Scheffenegger atf_set descr 'dummynet Gilbert-Elliott packet loss model test' 57131cf66d7SRichard Scheffenegger atf_set require.user root 57231cf66d7SRichard Scheffenegger} 57331cf66d7SRichard Scheffenegger 57431cf66d7SRichard Scheffeneggerpls_gilbert_body() 57531cf66d7SRichard Scheffenegger{ 57631cf66d7SRichard Scheffenegger fw=$1 57731cf66d7SRichard Scheffenegger firewall_init $fw 57831cf66d7SRichard Scheffenegger dummynet_init $fw 57931cf66d7SRichard Scheffenegger 58031cf66d7SRichard Scheffenegger epair=$(vnet_mkepair) 58131cf66d7SRichard Scheffenegger vnet_mkjail alcatraz ${epair}b 58231cf66d7SRichard Scheffenegger 58331cf66d7SRichard Scheffenegger ifconfig ${epair}a 192.0.2.1/24 up 58431cf66d7SRichard Scheffenegger jexec alcatraz ifconfig ${epair}b 192.0.2.2/24 up 58531cf66d7SRichard Scheffenegger 58631cf66d7SRichard Scheffenegger firewall_config alcatraz ${fw} \ 58731cf66d7SRichard Scheffenegger "ipfw" \ 58831cf66d7SRichard Scheffenegger "ipfw add 65432 ip from any to any" \ 58931cf66d7SRichard Scheffenegger "pf" \ 59031cf66d7SRichard Scheffenegger "pass on ${epair}b" 59131cf66d7SRichard Scheffenegger 59231cf66d7SRichard Scheffenegger # Sanity check 59331cf66d7SRichard Scheffenegger atf_check -s exit:0 -o match:'100 packets transmitted, 100 packets received' ping -i .1 -c 100 192.0.2.2 59431cf66d7SRichard Scheffenegger 59531cf66d7SRichard Scheffenegger jexec alcatraz dnctl pipe 1 config plr 0.01,0.1,0.8,0.2 59631cf66d7SRichard Scheffenegger 59731cf66d7SRichard Scheffenegger firewall_config alcatraz ${fw} \ 59831cf66d7SRichard Scheffenegger "ipfw" \ 59931cf66d7SRichard Scheffenegger "ipfw add 1000 pipe 1 ip from 192.0.2.1 to 192.0.2.2" \ 60031cf66d7SRichard Scheffenegger "pf" \ 60131cf66d7SRichard Scheffenegger "pass on ${epair}b dnpipe 1" 60231cf66d7SRichard Scheffenegger 60331cf66d7SRichard Scheffenegger # check if the expected number of pings 60431cf66d7SRichard Scheffenegger # are dropped (70 - 85 responses). 60531cf66d7SRichard Scheffenegger # repeat up to 6 times if the initial 60631cf66d7SRichard Scheffenegger # checks fail 6072144e31dSKristof Provost atf_check -s exit:0 -o match:'100 packets transmitted, (7[0-9]|8[0-5]) packets received' -r 20:10 ping -i 0.010 -c 100 192.0.2.2 60831cf66d7SRichard Scheffenegger} 60931cf66d7SRichard Scheffenegger 61031cf66d7SRichard Scheffeneggerpls_gilbert_cleanup() 61131cf66d7SRichard Scheffenegger{ 61231cf66d7SRichard Scheffenegger firewall_cleanup $1 61331cf66d7SRichard Scheffenegger} 61431cf66d7SRichard Scheffenegger 61531cf66d7SRichard Scheffenegger 61631cf66d7SRichard Scheffenegger 617ea3eca5cSKristof Provostsetup_tests \ 61874e6b014SKristof Provost interface_removal \ 61974e6b014SKristof Provost ipfw \ 62074e6b014SKristof Provost pf \ 621ea3eca5cSKristof Provost pipe \ 6225fda5913SKristof Provost ipfw \ 623ab55fa11SKristof Provost pf \ 6245fda5913SKristof Provost pipe_v6 \ 625cb6bfef9SKristof Provost ipfw \ 626ab55fa11SKristof Provost pf \ 627c90b9a5eSKristof Provost codel \ 628c90b9a5eSKristof Provost ipfw \ 629c90b9a5eSKristof Provost pf \ 6301e1bb578SKristof Provost wf2q_heap \ 6311e1bb578SKristof Provost pf \ 632cb6bfef9SKristof Provost queue \ 63312184311SKristof Provost ipfw \ 634ab55fa11SKristof Provost pf \ 63512184311SKristof Provost queue_v6 \ 636ab55fa11SKristof Provost ipfw \ 6374ee0f6d8SKristof Provost pf \ 6384ee0f6d8SKristof Provost nat \ 63931cf66d7SRichard Scheffenegger pf \ 64031cf66d7SRichard Scheffenegger pls_basic \ 64131cf66d7SRichard Scheffenegger ipfw \ 64231cf66d7SRichard Scheffenegger pf \ 64331cf66d7SRichard Scheffenegger pls_gilbert \ 64431cf66d7SRichard Scheffenegger ipfw \ 645ab55fa11SKristof Provost pf 646