From nobody Wed May 28 21:55:51 2025 X-Original-To: dev-commits-src-main@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 4b73Gc4SrKz5xJvx; Wed, 28 May 2025 21:55:52 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4b73Gc0NK3z476t; Wed, 28 May 2025 21:55:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748469352; 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=/G9YkOCSCppah3pOrCFhVnjs09jNIfIReGC8vEn/dRE=; b=aCS1B7o5DOKFzTFP6EoFLM4srcVkGCaNKiVv1FgrSkXbOQwGRoDwGLJoKLxUPshI9JEIqb +bcrCxD4lALMwzfY2NAKd+sT6u8TGzszbZMeTaHVaoGCyCazTtZunsRjZGLmJQQc80TANw eoPYlpgRiRPMA0cDS+WZwiMEUIBjg+Rq/+YQQhgmiszaI+0preqkPhr4ecrNI+8fegvazU z4o5mlju8kDiY6BXdNSxkHtIOw9JUJbID2bF0hJflH3+snNrM822c8jcKr/lQ1Lg76vhhu SxgawLcv1JWng7SinUr/eH4DMJOrWGBeRCxeNQ18dPBcZFe16sERgO2XN2WjUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1748469352; a=rsa-sha256; cv=none; b=HBvoQFHApb02MShQnmxBE0dsxd0kNkMoFr+mrcoseQJudsFypLR2kTi0aa+vrEz5oL4NNx yq2M+YMFYoNi1ZssSsKuyKn8FZhhNRnJ8oXxQpCfE0u1It2x8BA1WB0OIfUFCSTMUxOU0l f+s9EMt0xzB2HapwJyn4Yu7GxL5XSWGvFaYfpeR9PWwxpULrlqPVwYmxGNXI79TxZgPywf poOwGixeQBrUEQiQczuXh+/UernFr8Ici5YIcEL06qnDohSqVdOP+lUEyke4ckkGXvqmcy zGGc3BLvDmnUQ+uli8EuJcFnLdNO0/F0ObCvQ+W32Eb9M4eoe5M+svfI3DYWpw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1748469352; 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=/G9YkOCSCppah3pOrCFhVnjs09jNIfIReGC8vEn/dRE=; b=sMncqolL+WUviC3m7Ze8aXZUww79/a65gGnMAkC/3+htNMhxzjzTq45Rf5/HwVy1Cad3Lv ye8HZkecYnJK3v/3gIDGEPMwqDibZJE18a+za0VDLTH+D2yIfc/8hxlVwv5SaiJvJhQywP sQgFw9wI+ObOHL2IGiCGP8ulALlPFe+rAbc+wO/+bCGkqXUqWnZBGYFc/HPPlDJlz16CXG 3T7hd3oIW54fWNaaZPmLwqLE3TdANAP8Dv2AwYojQliB2/HJxf1a/xmelgGMzFKJ3j+QjK 5UxMX4v4DJmpWuQ/r8OYh631z7JoVJXHnLvmyWvIZbEAoHc1d7kaq1+9NfLdOg== 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 4b73Gb6ctyzvqg; Wed, 28 May 2025 21:55:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 54SLtpCS054968; Wed, 28 May 2025 21:55:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 54SLtp1R054965; Wed, 28 May 2025 21:55:51 GMT (envelope-from git) Date: Wed, 28 May 2025 21:55:51 GMT Message-Id: <202505282155.54SLtp1R054965@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: 63cc817adde5 - main - pf tests: deduplicate DelayedSend List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 63cc817adde5aec0f6446e44c1eee0a7d5908dfd Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=63cc817adde5aec0f6446e44c1eee0a7d5908dfd commit 63cc817adde5aec0f6446e44c1eee0a7d5908dfd Author: Kristof Provost AuthorDate: 2025-05-26 13:34:06 +0000 Commit: Kristof Provost CommitDate: 2025-05-28 21:40:37 +0000 pf tests: deduplicate DelayedSend We had a few copies of the DelayedSend class around. Introduce a python utils file (utils.py), move DelayedSend into that and use it in each test that wants it. Sponsored by: Rubicon Communications, LLC ("Netgate") --- tests/sys/netpfil/pf/Makefile | 3 ++- tests/sys/netpfil/pf/frag6.py | 15 +-------------- tests/sys/netpfil/pf/nat64.py | 15 +-------------- tests/sys/netpfil/pf/nat66.py | 15 +-------------- tests/sys/netpfil/pf/tcp.py | 17 +---------------- tests/sys/netpfil/pf/utils.py | 41 +++++++++++++++++++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 59 deletions(-) diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile index b6c7a2703b7a..d70631a9de53 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -81,7 +81,8 @@ ${PACKAGE}FILES+= \ pft_ether.py \ pft_read_ipfix.py \ rdr-srcport.py \ - utils.subr + utils.subr \ + utils.py ${PACKAGE}FILESMODE_bsnmpd.conf= 0555 ${PACKAGE}FILESMODE_CVE-2019-5597.py= 0555 diff --git a/tests/sys/netpfil/pf/frag6.py b/tests/sys/netpfil/pf/frag6.py index de14fec528fd..0ed980f96fdd 100644 --- a/tests/sys/netpfil/pf/frag6.py +++ b/tests/sys/netpfil/pf/frag6.py @@ -1,24 +1,11 @@ import pytest import logging -import threading -import time import random logging.getLogger("scapy").setLevel(logging.CRITICAL) +from utils import DelayedSend from atf_python.sys.net.tools import ToolsHelper from atf_python.sys.net.vnet import VnetTestTemplate -class DelayedSend(threading.Thread): - def __init__(self, packet): - threading.Thread.__init__(self) - self._packet = packet - - self.start() - - def run(self): - import scapy.all as sp - time.sleep(1) - sp.send(self._packet) - class TestFrag6(VnetTestTemplate): REQUIRED_MODULES = ["pf", "dummymbuf"] TOPOLOGY = { diff --git a/tests/sys/netpfil/pf/nat64.py b/tests/sys/netpfil/pf/nat64.py index e64b7bbd573b..32fd8f4245a1 100644 --- a/tests/sys/netpfil/pf/nat64.py +++ b/tests/sys/netpfil/pf/nat64.py @@ -28,23 +28,10 @@ import pytest import selectors import socket import sys -import threading -import time +from utils import DelayedSend from atf_python.sys.net.tools import ToolsHelper from atf_python.sys.net.vnet import VnetTestTemplate -class DelayedSend(threading.Thread): - def __init__(self, packet): - threading.Thread.__init__(self) - self._packet = packet - - self.start() - - def run(self): - import scapy.all as sp - time.sleep(1) - sp.send(self._packet) - class TestNAT64(VnetTestTemplate): REQUIRED_MODULES = [ "pf" ] TOPOLOGY = { diff --git a/tests/sys/netpfil/pf/nat66.py b/tests/sys/netpfil/pf/nat66.py index f93512b5b99c..16b4ef3dd02b 100644 --- a/tests/sys/netpfil/pf/nat66.py +++ b/tests/sys/netpfil/pf/nat66.py @@ -29,23 +29,10 @@ import ipaddress import pytest import re import socket -import threading -import time +from utils import DelayedSend from atf_python.sys.net.tools import ToolsHelper from atf_python.sys.net.vnet import VnetTestTemplate -class DelayedSend(threading.Thread): - def __init__(self, packet): - threading.Thread.__init__(self) - self._packet = packet - - self.start() - - def run(self): - import scapy.all as sp - time.sleep(1) - sp.send(self._packet) - class TestNAT66(VnetTestTemplate): REQUIRED_MODULES = [ "pf" ] TOPOLOGY = { diff --git a/tests/sys/netpfil/pf/tcp.py b/tests/sys/netpfil/pf/tcp.py index 49a9ef4e0e66..53e0658f419c 100644 --- a/tests/sys/netpfil/pf/tcp.py +++ b/tests/sys/netpfil/pf/tcp.py @@ -29,23 +29,10 @@ import pytest import random import socket import selectors -import threading -import time +from utils import DelayedSend from atf_python.sys.net.tools import ToolsHelper from atf_python.sys.net.vnet import VnetTestTemplate -class DelayedSend(threading.Thread): - def __init__(self, packet): - threading.Thread.__init__(self) - self._packet = packet - - self.start() - - def run(self): - import scapy.all as sp - time.sleep(1) - sp.send(self._packet) - class TCPClient: def __init__(self, src, dst, sport, dport, sp): self.src = src @@ -136,8 +123,6 @@ class TestTcp(VnetTestTemplate): # Import in the correct vnet, so at to not confuse Scapy import scapy.all as sp - #time.sleep(30) - a = TCPClient("192.0.2.3", "192.0.2.2", 1234, 1234, sp) a.connect() a.send(b"foo") diff --git a/tests/sys/netpfil/pf/utils.py b/tests/sys/netpfil/pf/utils.py new file mode 100644 index 000000000000..3cd8278f7cf7 --- /dev/null +++ b/tests/sys/netpfil/pf/utils.py @@ -0,0 +1,41 @@ +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2025 Rubicon Communications, LLC (Netgate) +# +# 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 threading +import time + +class DelayedSend(threading.Thread): + def __init__(self, packet): + threading.Thread.__init__(self) + self._packet = packet + + self.start() + + def run(self): + import scapy.all as sp + time.sleep(1) + sp.send(self._packet) +