From owner-svn-src-all@freebsd.org Mon Oct 21 09:33:48 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 0FD3F15241C; Mon, 21 Oct 2019 09:33:48 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46xWfh0BB5z41WP; Mon, 21 Oct 2019 09:33:48 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DD5822206A; Mon, 21 Oct 2019 09:33:47 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9L9XlIN062779; Mon, 21 Oct 2019 09:33:47 GMT (envelope-from bz@FreeBSD.org) Received: (from bz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9L9Xkig062769; Mon, 21 Oct 2019 09:33:46 GMT (envelope-from bz@FreeBSD.org) Message-Id: <201910210933.x9L9Xkig062769@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: bz set sender to bz@FreeBSD.org using -f From: "Bjoern A. Zeeb" Date: Mon, 21 Oct 2019 09:33:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353794 - in head: etc/mtree tests/sys tests/sys/netinet6 tests/sys/netinet6/frag6 X-SVN-Group: head X-SVN-Commit-Author: bz X-SVN-Commit-Paths: in head: etc/mtree tests/sys tests/sys/netinet6 tests/sys/netinet6/frag6 X-SVN-Commit-Revision: 353794 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Oct 2019 09:33:48 -0000 Author: bz Date: Mon Oct 21 09:33:45 2019 New Revision: 353794 URL: https://svnweb.freebsd.org/changeset/base/353794 Log: frag6: import a set of test cases In order to ensure that changing the frag6 code does not change behaviour or break code a set of test cases were implemented. Like some other test cases these use Scapy to generate packets and possibly wait for expected answers. In most cases we do check the global and per interface (netstat) statistics output using the libxo output and grep to validate fields and numbers. This is a bit hackish but we currently have no better way to match a selected number of stats only (we have to ignore some of the ND6 variables; otherwise we could use the entire list). Test cases include atomic fragments, single fragments, multi-fragments, and try to cover most error cases in the code currently. In addition vnet teardown is tested to not panic. A separate set (not in-tree currently) of probes were used in order to make sure that the test cases actually test what they should. The "sniffer" code was copied and adjusted from the netpfil version as we sometimes will not get packets or have longer timeouts to deal with. Sponsored by: Netflix Added: head/tests/sys/netinet6/ head/tests/sys/netinet6/Makefile (contents, props changed) head/tests/sys/netinet6/frag6/ head/tests/sys/netinet6/frag6/Makefile (contents, props changed) head/tests/sys/netinet6/frag6/frag6.subr (contents, props changed) head/tests/sys/netinet6/frag6/frag6_01.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_01.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_02.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_02.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_03.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_03.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_04.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_04.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_05.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_05.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_06.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_06.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_07.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_07.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_08.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_08.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_09.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_09.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_10.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_10.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_11.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_11.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_12.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_12.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_13.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_13.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_14.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_14.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_15.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_15.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_16.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_16.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_17.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_17.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_18.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_18.sh (contents, props changed) head/tests/sys/netinet6/frag6/frag6_19.py (contents, props changed) head/tests/sys/netinet6/frag6/frag6_19.sh (contents, props changed) head/tests/sys/netinet6/frag6/sniffer.py (contents, props changed) Modified: head/etc/mtree/BSD.tests.dist head/tests/sys/Makefile Modified: head/etc/mtree/BSD.tests.dist ============================================================================== --- head/etc/mtree/BSD.tests.dist Mon Oct 21 08:48:47 2019 (r353793) +++ head/etc/mtree/BSD.tests.dist Mon Oct 21 09:33:45 2019 (r353794) @@ -792,6 +792,10 @@ .. netinet .. + netinet6 + frag6 + .. + .. netipsec tunnel .. Modified: head/tests/sys/Makefile ============================================================================== --- head/tests/sys/Makefile Mon Oct 21 08:48:47 2019 (r353793) +++ head/tests/sys/Makefile Mon Oct 21 09:33:45 2019 (r353794) @@ -20,6 +20,7 @@ TESTS_SUBDIRS+= kqueue TESTS_SUBDIRS+= mac TESTS_SUBDIRS+= mqueue TESTS_SUBDIRS+= netinet +TESTS_SUBDIRS+= netinet6 TESTS_SUBDIRS+= netipsec TESTS_SUBDIRS+= netmap TESTS_SUBDIRS+= netpfil Added: head/tests/sys/netinet6/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/netinet6/Makefile Mon Oct 21 09:33:45 2019 (r353794) @@ -0,0 +1,7 @@ +# $FreeBSD$ + +TESTSDIR= ${TESTSBASE}/sys/netinet6 + +TESTS_SUBDIRS+= frag6 + +.include Added: head/tests/sys/netinet6/frag6/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/netinet6/frag6/Makefile Mon Oct 21 09:33:45 2019 (r353794) @@ -0,0 +1,76 @@ +# $FreeBSD$ + +PACKAGE= tests + +TESTSDIR= ${TESTSBASE}/sys/netinet6/frag6 +FILESDIR= ${TESTSDIR} + +# We split these up so they can run in parallel. +# Seems kyua is not running the test cases from one file in parallel. +# Otherwise we could cat the files together into one shell file. +ATF_TESTS_SH= \ + frag6_01 \ + frag6_02 \ + frag6_03 \ + frag6_04 \ + frag6_05 \ + frag6_06 \ + frag6_07 \ + frag6_08 \ + frag6_09 \ + frag6_10 \ + frag6_11 \ + frag6_12 \ + frag6_13 \ + frag6_14 \ + frag6_15 \ + frag6_16 \ + frag6_17 \ + frag6_18 \ + frag6_19 + +${PACKAGE}FILES+= frag6.subr +${PACKAGE}FILES+= sniffer.py +${PACKAGE}FILES+= frag6_01.py +${PACKAGE}FILES+= frag6_02.py +${PACKAGE}FILES+= frag6_03.py +${PACKAGE}FILES+= frag6_04.py +${PACKAGE}FILES+= frag6_05.py +${PACKAGE}FILES+= frag6_06.py +${PACKAGE}FILES+= frag6_07.py +${PACKAGE}FILES+= frag6_08.py +${PACKAGE}FILES+= frag6_09.py +${PACKAGE}FILES+= frag6_10.py +${PACKAGE}FILES+= frag6_11.py +${PACKAGE}FILES+= frag6_12.py +${PACKAGE}FILES+= frag6_13.py +${PACKAGE}FILES+= frag6_14.py +${PACKAGE}FILES+= frag6_15.py +${PACKAGE}FILES+= frag6_16.py +${PACKAGE}FILES+= frag6_17.py +${PACKAGE}FILES+= frag6_18.py +${PACKAGE}FILES+= frag6_19.py + +${PACKAGE}FILESMODE_frag6.subr= 0444 +${PACKAGE}FILESMODE_sniffer.py= 0555 +${PACKAGE}FILESMODE_frag6_01.py= 0555 +${PACKAGE}FILESMODE_frag6_02.py= 0555 +${PACKAGE}FILESMODE_frag6_03.py= 0555 +${PACKAGE}FILESMODE_frag6_04.py= 0555 +${PACKAGE}FILESMODE_frag6_05.py= 0555 +${PACKAGE}FILESMODE_frag6_06.py= 0555 +${PACKAGE}FILESMODE_frag6_07.py= 0555 +${PACKAGE}FILESMODE_frag6_08.py= 0555 +${PACKAGE}FILESMODE_frag6_09.py= 0555 +${PACKAGE}FILESMODE_frag6_10.py= 0555 +${PACKAGE}FILESMODE_frag6_11.py= 0555 +${PACKAGE}FILESMODE_frag6_12.py= 0555 +${PACKAGE}FILESMODE_frag6_13.py= 0555 +${PACKAGE}FILESMODE_frag6_14.py= 0555 +${PACKAGE}FILESMODE_frag6_15.py= 0555 +${PACKAGE}FILESMODE_frag6_16.py= 0555 +${PACKAGE}FILESMODE_frag6_17.py= 0555 +${PACKAGE}FILESMODE_frag6_18.py= 0555 +${PACKAGE}FILESMODE_frag6_19.py= 0555 + +.include Added: head/tests/sys/netinet6/frag6/frag6.subr ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/netinet6/frag6/frag6.subr Mon Oct 21 09:33:45 2019 (r353794) @@ -0,0 +1,122 @@ +# $FreeBSD$ +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2019 Netflix, Inc. +# +# 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 + +frag6_head() +{ + atf_set descr 'Test IPv6 fragmentation code' + atf_set require.user root + atf_set require.progs scapy +} + +frag6_body() +{ + ids=${1:="65533"} + shift + id=`printf "%x" ${ids}` + if [ $$ -gt 65535 ]; then + xl=`printf "%x" $(($$ - 65535))` + yl="1" + else + xl=`printf "%x" $$` + yl="" + fi + + vnet_init + + ip6a="2001:db8:6666:6666:${yl}:${id}:1:${xl}" + ip6b="2001:db8:6666:6666:${yl}:${id}:2:${xl}" + + epair=$(vnet_mkepair) + ifconfig ${epair}a mtu 131071 up + ifconfig ${epair}a inet6 ${ip6a}/64 + + jname="v6t-${id}-${yl}-${xl}" + vnet_mkjail ${jname} ${epair}b + jexec ${jname} ifconfig ${epair}b mtu 131071 up + jexec ${jname} ifconfig ${epair}b inet6 ${ip6b}/64 + + # Let IPv6 ND do its thing. + #ping6 -q -c 1 ff02::1%${epair}a + #ping6 -q -c 1 ${ip6b} + sleep 3 + + # We need to try to make sure all expiry happened, otherwise there might + # be global fragments queued. (This still does not rule out that there + # are no other fragments queued anywhere else in the system). + i=0 + while test $i -lt 60; do + nf=`sysctl -n net.inet6.ip6.frag6_nfrags` + case ${nf} in + 0) break ;; + esac + sleep 1 + i=$((i + 1)) + done + case ${nf} in + 0) ;; + *) atf_fail "Global frag6_nfrags count is not zero but ${nf}" ;; + esac + + pretestf=$2 + case "${pretestf}" in + "") ;; + [A-Za-z0-9_]*) + eval ${pretestf} "${jname}" "${epair}b" + ;; + esac + + # Clear statistics. + jexec ${jname} netstat -z -s > /dev/null + + # Run fragment tests. + pyname=$(atf_get ident) + pyname=${pyname%*_[0-9]} + atf_check -s exit:0 $(atf_get_srcdir)/${pyname}.py \ + --sendif ${epair}a \ + --recvif ${epair}a \ + --src ${ip6a} \ + --to ${ip6b} + + checkf=$1 + case "${checkf}" in + "") ;; + [A-Za-z0-9_]*) + eval ${checkf} "${jname}" "${epair}b" + ;; + esac +} + +frag6_cleanup() +{ + + vnet_cleanup +} + +# end Added: head/tests/sys/netinet6/frag6/frag6_01.py ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/netinet6/frag6/frag6_01.py Mon Oct 21 09:33:45 2019 (r353794) @@ -0,0 +1,115 @@ +#!/usr/bin/env python +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2019 Netflix, Inc. +# +# 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. +# +# $FreeBSD$ +# + +import argparse +import scapy.all as sp +import socket +import sys +from sniffer import Sniffer +from time import sleep + +def check_icmp6_error(args, packet): + ip6 = packet.getlayer(sp.IPv6) + if not ip6: + return False + oip6 = sp.IPv6(src=args.src[0], dst=args.to[0]) + if ip6.dst != oip6.src: + return False + icmp6 = packet.getlayer(sp.ICMPv6ParamProblem) + if not icmp6: + return False + # ICMP6_PARAMPROB_HEADER 0 + if icmp6.code != 0: + return False + # Should we check the payload as well? + # We are running in a very isolated environment and nothing else + # should trigger an ICMPv6 Param Prob so leave it. + #icmp6.display() + return True + +def main(): + parser = argparse.ArgumentParser("frag6.py", + description="IPv6 fragementation test tool") + parser.add_argument('--sendif', nargs=1, + required=True, + help='The interface through which the packet will be sent') + parser.add_argument('--recvif', nargs=1, + required=True, + help='The interface on which to check for the packet') + parser.add_argument('--src', nargs=1, + required=True, + help='The source IP address') + parser.add_argument('--to', nargs=1, + required=True, + help='The destination IP address') + parser.add_argument('--debug', + required=False, action='store_true', + help='Enable test debugging') + + args = parser.parse_args() + + + # Start sniffing on recvif + sniffer = Sniffer(args, check_icmp6_error) + + + ######################################################################## + # + # A single start fragment with zero length IPv6 header (jumbo). + # Make sure we do hit the Fragment case, which is tricky as the + # jumbogram needs to be > 64k. + # + # A: Jumbo-Fragment not allowed. + # R: ICMPv6 param problem. + # + #data = "6" * (65536 - 2 - 6 - 8 - 8) + data = "6" * 65512 + ip6f01 = sp.Ether() / \ + sp.IPv6(src=args.src[0], dst=args.to[0], plen=0) / \ + sp.IPv6ExtHdrHopByHop(options=sp.Jumbo(jumboplen=65536)) / \ + sp.IPv6ExtHdrFragment(offset=0, m=1, id=6) / \ + sp.UDP(dport=3456, sport=6543) / \ + data + if args.debug : + ip6f01.display() + sp.sendp(ip6f01, iface=args.sendif[0], verbose=False) + + # We should only need to sleep 0.10 but it seems scapy + # takes time for this one. + sleep(75) + sniffer.setEnd() + sniffer.join() + if not sniffer.foundCorrectPacket: + sys.exit(1) + + sys.exit(0) + +if __name__ == '__main__': + main() Added: head/tests/sys/netinet6/frag6/frag6_01.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/netinet6/frag6/frag6_01.sh Mon Oct 21 09:33:45 2019 (r353794) @@ -0,0 +1,223 @@ +# $FreeBSD$ +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2019 Netflix, Inc. +# +# 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)/frag6.subr + +atf_test_case "frag6_01" "cleanup" +frag6_01_head() { + frag6_head 1 +} + +frag6_01_check_stats() { + + local jname ifname + jname=$1 + ifname=$2 + + case "${jname}" in + "") echo "ERROR: jname is empty"; return ;; + esac + case "${ifname}" in + "") echo "ERROR: ifname is empty"; return ;; + esac + + # Defaults are: IPV6_FRAGTTL 120 slowtimo ticks. + # pfslowtimo() is run at hz/2. So this takes 60s. + # This is awefully long for a test case. + # The Python script has to wait for this already to get the ICMPv6 + # hence we do not sleep here anymore. + + + # + # Check selection of global UDP stats. + # + cat < ${HOME}/filter-${jname}.txt + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 9) ;; + *) jexec ${jname} netstat -s -p udp --libxo xml,pretty + atf_fail "Global UDP statistics do not match: ${count} != 9" ;; + esac + + # + # Check selection of global IPv6 stats. + # + cat < ${HOME}/filter-${jname}.txt + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 20) ;; + *) jexec ${jname} netstat -s -p ip6 --libxo xml,pretty + atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;; + esac + + # + # Check selection of global ICMPv6 stats. + # + cat < ${HOME}/filter-${jname}.txt + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 22) ;; + *) jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty + atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;; + esac + + # + # Check selection of interface IPv6 stats. + # XXX-BZ TODO FIXME reassembly-failed should be 1? + # + cat < ${HOME}/filter-${jname}.txt + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 14) ;; + *) jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty + atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;; + esac + + # + # Check selection of interface ICMPv6 stats. + # + cat < ${HOME}/filter-${jname}.txt + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 21) ;; + *) jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty + atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;; + esac +} + +frag6_01_body() { + + atf_skip "Sending IPv6 Jumbograms needs 1 kernel changes and BPF fixes" + + frag6_body 1 frag6_01_check_stats +} + +frag6_01_cleanup() { + frag6_cleanup 1 +} + +atf_init_test_cases() +{ + atf_add_test_case "frag6_01" +} Added: head/tests/sys/netinet6/frag6/frag6_02.py ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/netinet6/frag6/frag6_02.py Mon Oct 21 09:33:45 2019 (r353794) @@ -0,0 +1,108 @@ +#!/usr/bin/env python +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2019 Netflix, Inc. +# +# 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. +# +# $FreeBSD$ +# + +import argparse +import scapy.all as sp +import socket +import sys +from sniffer import Sniffer +from time import sleep + +def check_icmp6_error(args, packet): + ip6 = packet.getlayer(sp.IPv6) + if not ip6: + return False + oip6 = sp.IPv6(src=args.src[0], dst=args.to[0]) + if ip6.dst != oip6.src: + return False + icmp6 = packet.getlayer(sp.ICMPv6ParamProblem) + if not icmp6: + return False + # ICMP6_PARAMPROB_HEADER 0 + if icmp6.code != 0: + return False + # Should we check the payload as well? + # We are running in a very isolated environment and nothing else + # should trigger an ICMPv6 Param Prob so leave it. + #icmp6.display() + return True + +def main(): + parser = argparse.ArgumentParser("frag6.py", + description="IPv6 fragementation test tool") + parser.add_argument('--sendif', nargs=1, + required=True, + help='The interface through which the packet will be sent') + parser.add_argument('--recvif', nargs=1, + required=True, + help='The interface on which to check for the packet') + parser.add_argument('--src', nargs=1, + required=True, + help='The source IP address') + parser.add_argument('--to', nargs=1, + required=True, + help='The destination IP address') + parser.add_argument('--debug', + required=False, action='store_true', + help='Enable test debugging') + + args = parser.parse_args() + + + # Start sniffing on recvif + sniffer = Sniffer(args, check_icmp6_error) + + + ######################################################################## + # + # A single start fragment with payload length not % 8. + # + # A: Error handling in code. + # R: ICMPv6 param problem. + # + data = "6" * 1287 + ip6f01 = sp.Ether() / \ + sp.IPv6(src=args.src[0], dst=args.to[0]) / \ + sp.IPv6ExtHdrFragment(offset=0, m=1, id=5) / \ + sp.UDP(dport=3456, sport=6543) / \ + data + if args.debug : + ip6f01.display() + sp.sendp(ip6f01, iface=args.sendif[0], verbose=False) + + sleep(0.10) + sniffer.join() + if not sniffer.foundCorrectPacket: + sys.exit(1) + + sys.exit(0) + +if __name__ == '__main__': + main() Added: head/tests/sys/netinet6/frag6/frag6_02.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/netinet6/frag6/frag6_02.sh Mon Oct 21 09:33:45 2019 (r353794) @@ -0,0 +1,220 @@ +# $FreeBSD$ +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2019 Netflix, Inc. +# +# 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)/frag6.subr + +atf_test_case "frag6_02" "cleanup" +frag6_02_head() { + frag6_head 2 +} + +frag6_02_check_stats() { + + local jname ifname + jname=$1 + ifname=$2 + + case "${jname}" in + "") echo "ERROR: jname is empty"; return ;; + esac + case "${ifname}" in + "") echo "ERROR: ifname is empty"; return ;; + esac + + # Defaults are: IPV6_FRAGTTL 120 slowtimo ticks. + # pfslowtimo() is run at hz/2. So this takes 60s. + # This is awefully long for a test case. + # The Python script has to wait for this already to get the ICMPv6 + # hence we do not sleep here anymore. + + + # + # Check selection of global UDP stats. + # + cat < ${HOME}/filter-${jname}.txt + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p udp --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 9) ;; + *) jexec ${jname} netstat -s -p udp --libxo xml,pretty + atf_fail "Global UDP statistics do not match: ${count} != 9" ;; + esac + + # + # Check selection of global IPv6 stats. + # XXX-TODO no global stats for this case? + # + cat < ${HOME}/filter-${jname}.txt + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p ip6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 20) ;; + *) jexec ${jname} netstat -s -p ip6 --libxo xml,pretty + atf_fail "Global IPv6 statistics do not match: ${count} != 20" ;; + esac + + # + # Check selection of global ICMPv6 stats. + # + cat < ${HOME}/filter-${jname}.txt + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 22) ;; + *) jexec ${jname} netstat -s -p icmp6 --libxo xml,pretty + atf_fail "Global ICMPv6 statistics do not match: ${count} != 22" ;; + esac + + # + # Check selection of interface IPv6 stats. + # + cat < ${HOME}/filter-${jname}.txt + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 +EOF + count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 14) ;; + *) jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty + atf_fail "Interface IPv6 statistics do not match: ${count} != 14" ;; + esac + + # + # Check selection of interface ICMPv6 stats. + # + cat < ${HOME}/filter-${jname}.txt + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 +EOF + count=`jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` + rm -f ${HOME}/filter-${jname}.txt + case ${count} in + 21) ;; + *) jexec ${jname} netstat -s -p icmp6 -I ${ifname} --libxo xml,pretty + atf_fail "Interface ICMPv6 statistics do not match: ${count} != 21" ;; + esac +} + +frag6_02_body() { + frag6_body 2 frag6_02_check_stats +} + +frag6_02_cleanup() { + frag6_cleanup 2 +} + +atf_init_test_cases() +{ + atf_add_test_case "frag6_02" +} Added: head/tests/sys/netinet6/frag6/frag6_03.py ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/netinet6/frag6/frag6_03.py Mon Oct 21 09:33:45 2019 (r353794) @@ -0,0 +1,106 @@ +#!/usr/bin/env python +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2019 Netflix, Inc. +# +# 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. +# +# $FreeBSD$ +# + +import argparse +import scapy.all as sp +import socket +import sys +from sniffer import Sniffer +from time import sleep + +def check_icmp6_error(args, packet): + ip6 = packet.getlayer(sp.IPv6) + if not ip6: + return False + oip6 = sp.IPv6(src=args.src[0], dst=args.to[0]) + if ip6.dst != oip6.src: + return False + icmp6 = packet.getlayer(sp.ICMPv6DestUnreach) + if not icmp6: + return False + # ICMP6_DST_UNREACH_NOPORT 4 + if icmp6.code != 4: + return False + # Should we check the payload as well? + # We are running in a very isolated environment and nothing else + # should trigger an ICMPv6 Dest Unreach / Port Unreach so leave it. + #icmp6.display() + return True + +def main(): + parser = argparse.ArgumentParser("frag6.py", + description="IPv6 fragementation test tool") + parser.add_argument('--sendif', nargs=1, + required=True, + help='The interface through which the packet will be sent') + parser.add_argument('--recvif', nargs=1, + required=True, + help='The interface on which to check for the packet') + parser.add_argument('--src', nargs=1, + required=True, + help='The source IP address') + parser.add_argument('--to', nargs=1, + required=True, + help='The destination IP address') + parser.add_argument('--debug', + required=False, action='store_true', + help='Enable test debugging') + + args = parser.parse_args() + + + # Start sniffing on recvif + sniffer = Sniffer(args, check_icmp6_error) + + *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***