Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 3 Jan 2021 22:18:48 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: a343d1c8acfc - stable/12 - pf tests: Move Sniffer to its own file
Message-ID:  <202101032218.103MImBF020491@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=a343d1c8acfc78abfd7f12823c5297c8ca2ee4f4

commit a343d1c8acfc78abfd7f12823c5297c8ca2ee4f4
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2019-03-21 08:15:46 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-01-03 20:26:48 +0000

    pf tests: Move Sniffer to its own file
    
    Make it easier to re-use the sniffer class in other test support
    scripts.
    
    (cherry picked from commit d1805f60afc3f3c65f5d2bb360ed1ab55ea705da)
---
 tests/sys/netpfil/pf/Makefile    |  1 +
 tests/sys/netpfil/pf/pft_ping.py | 23 +----------------------
 tests/sys/netpfil/pf/sniffer.py  | 25 +++++++++++++++++++++++++
 3 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile
index 9bb40b911d4c..115a38666cc7 100644
--- a/tests/sys/netpfil/pf/Makefile
+++ b/tests/sys/netpfil/pf/Makefile
@@ -22,6 +22,7 @@ ATF_TESTS_SH+=	anchor \
 
 ${PACKAGE}FILES+=	utils.subr \
 			echo_inetd.conf \
+			sniffer.py \
 			pft_ping.py \
 			CVE-2019-5597.py
 
diff --git a/tests/sys/netpfil/pf/pft_ping.py b/tests/sys/netpfil/pf/pft_ping.py
index 0b70c2235894..e77d0835134f 100644
--- a/tests/sys/netpfil/pf/pft_ping.py
+++ b/tests/sys/netpfil/pf/pft_ping.py
@@ -3,31 +3,10 @@
 import argparse
 import scapy.all as sp
 import sys
-import threading
+from sniffer import Sniffer
 
 PAYLOAD_MAGIC = 0x42c0ffee
 
-class Sniffer(threading.Thread):
-	def __init__(self, args, check_function):
-		threading.Thread.__init__(self)
-
-		self._args = args
-		self._recvif = args.recvif[0]
-		self._check_function = check_function
-		self.foundCorrectPacket = False
-
-		self.start()
-
-	def _checkPacket(self, packet):
-		ret = self._check_function(self._args, packet)
-		if ret:
-			self.foundCorrectPacket = True
-		return ret
-
-	def run(self):
-		self.packets = sp.sniff(iface=self._recvif,
-				stop_filter=self._checkPacket, timeout=3)
-
 def check_ping_request(args, packet):
 	if args.ip6:
 		return check_ping6_request(args, packet)
diff --git a/tests/sys/netpfil/pf/sniffer.py b/tests/sys/netpfil/pf/sniffer.py
new file mode 100644
index 000000000000..c71f6e1f5729
--- /dev/null
+++ b/tests/sys/netpfil/pf/sniffer.py
@@ -0,0 +1,25 @@
+# $FreeBSD$
+
+import threading
+import scapy.all as sp
+
+class Sniffer(threading.Thread):
+	def __init__(self, args, check_function):
+		threading.Thread.__init__(self)
+
+		self._args = args
+		self._recvif = args.recvif[0]
+		self._check_function = check_function
+		self.foundCorrectPacket = False
+
+		self.start()
+
+	def _checkPacket(self, packet):
+		ret = self._check_function(self._args, packet)
+		if ret:
+			self.foundCorrectPacket = True
+		return ret
+
+	def run(self):
+		self.packets = sp.sniff(iface=self._recvif,
+				stop_filter=self._checkPacket, timeout=3)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202101032218.103MImBF020491>