#-1# SPDX-License-Identifier: BSD-2-Clause2#3# Copyright (c) 2019 Ahsan Barkati4#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.25#26#2728. $(atf_get_srcdir)/utils.subr29. $(atf_get_srcdir)/runner.subr3031tos_head()32{33atf_set descr 'set-tos test'34atf_set require.user root35atf_set require.progs python3 scapy36}3738tos_body()39{40firewall=$141firewall_init $firewall4243epair_send=$(vnet_mkepair)44ifconfig ${epair_send}a 192.0.2.1/24 up4546epair_recv=$(vnet_mkepair)47ifconfig ${epair_recv}a up4849vnet_mkjail iron ${epair_send}b ${epair_recv}b50jexec iron ifconfig ${epair_send}b 192.0.2.2/24 up51jexec iron ifconfig ${epair_recv}b 198.51.100.2/24 up52jexec iron sysctl net.inet.ip.forwarding=153jexec iron arp -s 198.51.100.3 00:01:02:03:04:0554route add -net 198.51.100.0/24 192.0.2.25556# Check if the firewall is able to set the ToS bits57firewall_config "iron" ${firewall} \58"pf" \59"scrub out proto icmp set-tos 36" \60"ipfw" \61"ipfw -q add 100 setdscp 9 ip from any to any"62# dscp is set to 9 because last two bits are for63# EN and hence tos would be 366465atf_check -s exit:0 $(atf_get_srcdir)/pft_ping.py \66--sendif ${epair_send}a \67--to 198.51.100.3 \68--recvif ${epair_recv}a \69--expect-tc 367071# Check if the firewall is able to set the ToS bits72# and persists the EN bits (if already set)73firewall_config "iron" ${firewall} \74"pf" \75"scrub out proto icmp set-tos 36" \76"ipfw" \77"ipfw -q add 100 setdscp 9 ip from any to any"7879atf_check -s exit:0 $(atf_get_srcdir)/pft_ping.py \80--sendif ${epair_send}a \81--to 198.51.100.3 \82--recvif ${epair_recv}a \83--send-tc 3 \84--expect-tc 398586# Check if the firewall is able to filter the87# packets based on the ToS value88firewall_config "iron" ${firewall} \89"pf" \90"block all tos 36" \91"ipfw" \92"ipfw -q add 100 deny all from any to any dscp 9"9394atf_check -s exit:1 $(atf_get_srcdir)/pft_ping.py \95--sendif ${epair_send}a \96--to 198.51.100.3 \97--recvif ${epair_recv}a \98--send-tc 3699100atf_check -s exit:0 $(atf_get_srcdir)/pft_ping.py \101--sendif ${epair_send}a \102--to 198.51.100.3 \103--recvif ${epair_recv}a \104--send-tc 32105}106107tos_cleanup()108{109firewall=$1110firewall_cleanup $firewall111}112113setup_tests \114"tos" \115"pf" \116"ipfw"117118119