From nobody Tue Jan 16 08:51:58 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4TDjRy5Qzyz57B4g; Tue, 16 Jan 2024 08:51:58 +0000 (UTC) (envelope-from git@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) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4TDjRy3Kmgz4Q1X; Tue, 16 Jan 2024 08:51:58 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705395118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9NG1rSJ9aalxtDXSOKCyb18tr5EMt0LOmi9BmhY1hfg=; b=bvpqeqDewKQLrphKVcFeGimsSEnws4DQwWsnHTKK6SwL/ISGUKFZGeMNn4k12J4DFCCRJQ S+FZpxrq/ryGVHopTkqb/JYO6w+Fk+exPhYT1z9Yw5sgReeWtK8tUtAKk+AOvZOWOnKPJe 9CK3c4pYhEmreRoCRp+DgpiRTseu41p9seCB6PdHAmgI5AT9q4xKaVLT8O0zTqqzP5cMv7 sJoZCIrOyNI/+Vi6HZHHr9E5UZwlYkP92NxiuTOp0ES5ECr7DX5SSdg1+hPBe7Gbibr8iz ouQ2SdyzihqSkLMHwNAZaVckqroDUVvWu2LwC061Aw27w2fWjRU1Du7ORslUqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1705395118; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9NG1rSJ9aalxtDXSOKCyb18tr5EMt0LOmi9BmhY1hfg=; b=GIwmM+EIAOILqQrRSmmIqnpBxuYZAOFqVNJqUt7yx8MEtZ7Po3rvd4inktJ0Qy5Vd9NBH3 GJsigdpJpGnrCwJKlpSU/n4KPLHZzWOtHxAC3UZCGRMEICrBsk5nxSZPazmqt4YQWW/vsz RD0kwyUCUjdLYZtUgOpLXYEO+IiYzn7mciNQmmjCU6LRpARHNb/kcMpu2Xw0O2Bx3rimku IwgixDk9vKrWf/VgqtbYn7IwnY55FBsBxAVCFXnF66HCr7gXfVJ0BGr9iq+N9qoZcVOEqA I43hWj3tuv4yODUKON3Sj8pNSNRafIgLmuodREx7GipKyoVEX0n5PBf2dvPoOg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1705395118; a=rsa-sha256; cv=none; b=q9h727G/6jaIXhGU4Jbaw5P7wG+PMrnl/joTqck7i7O5fVD3rNUSbLL3hB0dM+FJ8UkYXk 46ccCF8f9JJyp5WPZtshJggdU18FTRaPsefRtscoIcyJpurdr8omgsbe1NXLvfQA0yXpo5 SmoIxEMHvaYFEO7Gw7/n0ls67gzhcW3ws0GnRb9oxqbUDpUeFPzPF/qRaoi14ovI4hyY7B G4Awsk0xihFXFprCMaZhGaveJH+F9kVSEVEc1Efq+BLymrgcvTDhkbWJ6x67roprlMlqOq +6Kj5oHgcuSic42hA/FcdnqQ71HbulvJRmurm+GibxNwc0/QxEL/6O6nIG8Ncg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4TDjRy29VQzYS2; Tue, 16 Jan 2024 08:51:58 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 40G8pwic077132; Tue, 16 Jan 2024 08:51:58 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 40G8pwpO077129; Tue, 16 Jan 2024 08:51:58 GMT (envelope-from git) Date: Tue, 16 Jan 2024 08:51:58 GMT Message-Id: <202401160851.40G8pwpO077129@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: 6bd36d1cf4e9 - main - pf tests: pflow functionality test List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6bd36d1cf4e98f11661642331fddb5d30dced68d Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=6bd36d1cf4e98f11661642331fddb5d30dced68d commit 6bd36d1cf4e98f11661642331fddb5d30dced68d Author: Kristof Provost AuthorDate: 2023-12-04 15:11:35 +0000 Commit: Kristof Provost CommitDate: 2024-01-16 08:45:54 +0000 pf tests: pflow functionality test Test that we actually send netflow messages when configured to do so. We do not yet inspect the generated netflow messages. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D43111 --- tests/sys/netpfil/pf/Makefile | 2 + tests/sys/netpfil/pf/pflow.sh | 62 +++++++++++++++++++++++++++ tests/sys/netpfil/pf/pft_read_ipfix.py | 78 ++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile index a1a40cf4d8f4..f1a2fff5a45d 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -63,6 +63,7 @@ ${PACKAGE}FILES+= CVE-2019-5597.py \ frag-overreplace.py \ pfsync_defer.py \ pft_ether.py \ + pft_read_ipfix.py \ utils.subr ${PACKAGE}FILESMODE_CVE-2019-5597.py= 0555 @@ -73,5 +74,6 @@ ${PACKAGE}FILESMODE_frag-overlimit.py= 0555 ${PACKAGE}FILESMODE_frag-overreplace.py= 0555 ${PACKAGE}FILESMODE_pfsync_defer.py= 0555 ${PACKAGE}FILESMODE_pft_ether.py= 0555 +${PACKAGE}FILESMODE_pft_read_ipfix.py= 0555 .include diff --git a/tests/sys/netpfil/pf/pflow.sh b/tests/sys/netpfil/pf/pflow.sh index 3ae4fedf3a93..73e041fca693 100644 --- a/tests/sys/netpfil/pf/pflow.sh +++ b/tests/sys/netpfil/pf/pflow.sh @@ -74,7 +74,69 @@ basic_cleanup() pft_cleanup } +atf_test_case "state_defaults" "cleanup" +state_defaults_head() +{ + atf_set descr 'Test set state-defaults pflow' + atf_set require.user root + atf_set require.progs scapy +} + +state_defaults_body() +{ + pflow_init + + epair=$(vnet_mkepair) + ifconfig ${epair}a 192.0.2.2/24 up + + vnet_mkjail alcatraz ${epair}b + jexec alcatraz ifconfig ${epair}b 192.0.2.1/24 up + + # Sanity check + atf_check -s exit:0 -o ignore ping -c 1 192.0.2.1 + + jexec alcatraz pfctl -e + pft_set_rules alcatraz \ + "pass" + + pflow=$(jexec alcatraz pflowctl -c) + jexec alcatraz pflowctl -s ${pflow} dst 192.0.2.2:2055 + + # No flow data is generated because no states are marked for it. + ping -c 1 192.0.2.1 + # Flush states to force pflow creation + jexec alcatraz pfctl -Fstates + + atf_check -o match:"No data" \ + $(atf_get_srcdir)/pft_read_ipfix.py --recvif ${epair}a --port 2055 + + # Expect pflow output with state-defaults pflow + pft_set_rules alcatraz \ + "set state-defaults pflow" \ + "pass" + + ping -c 1 192.0.2.1 + + # We default to version 5 + atf_check -o match:"^v=5.*" \ + $(atf_get_srcdir)/pft_read_ipfix.py --recvif ${epair}a --port 2055 + + # Switch to version 10 + jexec alcatraz pflowctl -s ${pflow} proto 10 + + ping -c 1 192.0.2.1 + + atf_check -o match:"^v=10.*" \ + $(atf_get_srcdir)/pft_read_ipfix.py --recvif ${epair}a --port 2055 +} + +state_defaults_cleanup() +{ + pft_cleanup +} + atf_init_test_cases() { atf_add_test_case "basic" + atf_add_test_case "state_defaults" } diff --git a/tests/sys/netpfil/pf/pft_read_ipfix.py b/tests/sys/netpfil/pf/pft_read_ipfix.py new file mode 100644 index 000000000000..64d4fcb3c523 --- /dev/null +++ b/tests/sys/netpfil/pf/pft_read_ipfix.py @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright © 2023. Rubicon Communications, LLC (Netgate). All Rights Reserved. +# +# 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. +# + +import argparse +import logging +logging.getLogger("scapy").setLevel(logging.CRITICAL) +import scapy.all as sp + +def receive(recvif, recvport): + pkts = sp.sniff(iface=recvif, timeout=65) + + if len(pkts) == 0: + print("No data") + return + + for pkt in pkts: + udp = pkt.getlayer(sp.UDP) + if not udp: + continue + + if udp.dport != recvport: + continue + + hdr = pkt.getlayer(sp.NetflowHeader) + + if hdr.version == 5: + v5hdr = pkt.getlayer(sp.NetflowHeaderV5) + out="" + for i in range(1, v5hdr.count + 1): + r = pkt.getlayer(sp.NetflowRecordV5, nb=i) + out = "%s,proto=%d,src=%s,dst=%s,srcport=%d,dstport=%d" % (out, r.prot, r.src, r.dst, r.srcport, r.dstport) + print("v=%d,count=%d%s" % (hdr.version, v5hdr.count, out)) + elif hdr.version == 10: + print("v=10") + return + +def main(): + parser = argparse.ArgumentParser("pft_read_ipfix.py", + description="IPFix test tool") + parser.add_argument('--recvif', nargs=1, + required=True, + help='The interface on which to look for packets') + parser.add_argument('--port', nargs=1, + required=True, + help='The port number') + + args = parser.parse_args() + + receive(args.recvif[0], int(args.port[0])) + +if __name__ == '__main__': + main() +