xref: /freebsd/tests/sys/netpfil/common/fragments.sh (revision d0b2dbfa0ecf2bbc9709efc5e20baf8e4b44bbbf)
13e1ebe7fSKristof Provost#-
2*4d846d26SWarner Losh# SPDX-License-Identifier: BSD-2-Clause
33e1ebe7fSKristof Provost#
43e1ebe7fSKristof Provost# Copyright (c) 2019 Ahsan Barkati
53e1ebe7fSKristof Provost#
63e1ebe7fSKristof Provost# Redistribution and use in source and binary forms, with or without
73e1ebe7fSKristof Provost# modification, are permitted provided that the following conditions
83e1ebe7fSKristof Provost# are met:
93e1ebe7fSKristof Provost# 1. Redistributions of source code must retain the above copyright
103e1ebe7fSKristof Provost#    notice, this list of conditions and the following disclaimer.
113e1ebe7fSKristof Provost# 2. Redistributions in binary form must reproduce the above copyright
123e1ebe7fSKristof Provost#    notice, this list of conditions and the following disclaimer in the
133e1ebe7fSKristof Provost#    documentation and/or other materials provided with the distribution.
143e1ebe7fSKristof Provost#
153e1ebe7fSKristof Provost# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
163e1ebe7fSKristof Provost# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
173e1ebe7fSKristof Provost# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
183e1ebe7fSKristof Provost# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
193e1ebe7fSKristof Provost# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
203e1ebe7fSKristof Provost# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
213e1ebe7fSKristof Provost# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
223e1ebe7fSKristof Provost# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
233e1ebe7fSKristof Provost# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
243e1ebe7fSKristof Provost# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
253e1ebe7fSKristof Provost# SUCH DAMAGE.
263e1ebe7fSKristof Provost#
273e1ebe7fSKristof Provost#
283e1ebe7fSKristof Provost
293e1ebe7fSKristof Provost. $(atf_get_srcdir)/utils.subr
303e1ebe7fSKristof Provost. $(atf_get_srcdir)/runner.subr
313e1ebe7fSKristof Provost
323e1ebe7fSKristof Provostfragments_head()
333e1ebe7fSKristof Provost{
343e1ebe7fSKristof Provost	atf_set descr 'Too many fragments test'
353e1ebe7fSKristof Provost	atf_set require.user root
363e1ebe7fSKristof Provost}
373e1ebe7fSKristof Provost
383e1ebe7fSKristof Provostfragments_body()
393e1ebe7fSKristof Provost{
403e1ebe7fSKristof Provost	firewall=$1
413e1ebe7fSKristof Provost	firewall_init $firewall
423e1ebe7fSKristof Provost
433e1ebe7fSKristof Provost	epair=$(vnet_mkepair)
443e1ebe7fSKristof Provost	ifconfig ${epair}b inet 192.0.2.1/24 up
453e1ebe7fSKristof Provost
463e1ebe7fSKristof Provost	vnet_mkjail iron ${epair}a
473e1ebe7fSKristof Provost	jexec iron ifconfig ${epair}a 192.0.2.2/24 up
483e1ebe7fSKristof Provost
493e1ebe7fSKristof Provost	ifconfig ${epair}b mtu 200
503e1ebe7fSKristof Provost	jexec iron ifconfig ${epair}a mtu 200
513e1ebe7fSKristof Provost
523e1ebe7fSKristof Provost	firewall_config "iron" ${firewall} \
533e1ebe7fSKristof Provost		"pf" \
543e1ebe7fSKristof Provost			"scrub all fragment reassemble" \
553e1ebe7fSKristof Provost		"ipfw" \
563e1ebe7fSKristof Provost			"ipfw -q add 100 reass all from any to any in" \
573e1ebe7fSKristof Provost		"ipf" \
583e1ebe7fSKristof Provost			"pass in all with frags"
593e1ebe7fSKristof Provost
603e1ebe7fSKristof Provost	jexec iron sysctl net.inet.ip.maxfragsperpacket=1024
613e1ebe7fSKristof Provost
623e1ebe7fSKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 -t 1 192.0.2.2
633e1ebe7fSKristof Provost	atf_check -s exit:0 -o ignore ping -c 1 -s 800 192.0.2.2
643e1ebe7fSKristof Provost
653e1ebe7fSKristof Provost	# Too many fragments should fail
663e1ebe7fSKristof Provost	atf_check -s exit:2 -o ignore ping -c 1 -s 20000 192.0.2.2
673e1ebe7fSKristof Provost}
683e1ebe7fSKristof Provost
693e1ebe7fSKristof Provostfragments_cleanup()
703e1ebe7fSKristof Provost{
713e1ebe7fSKristof Provost	firewall=$1
723e1ebe7fSKristof Provost	firewall_cleanup $firewall
733e1ebe7fSKristof Provost}
743e1ebe7fSKristof Provost
753e1ebe7fSKristof Provostsetup_tests \
763e1ebe7fSKristof Provost		"fragments" \
773e1ebe7fSKristof Provost			"pf" \
783e1ebe7fSKristof Provost			"ipfw" \
793e1ebe7fSKristof Provost			"ipf"
80