aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristof Provost <kp@FreeBSD.org>2019-03-21 08:15:46 +0000
committerKristof Provost <kp@FreeBSD.org>2021-01-03 20:26:48 +0000
commita343d1c8acfc78abfd7f12823c5297c8ca2ee4f4 (patch)
tree222c6eaa2cbab18742494d5868702b912066c78f
parentcc136589fadb85996f9ba772a236fa500b6901dd (diff)
downloadsrc-a343d1c8acfc78abfd7f12823c5297c8ca2ee4f4.tar.gz
src-a343d1c8acfc78abfd7f12823c5297c8ca2ee4f4.zip
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)
-rw-r--r--tests/sys/netpfil/pf/Makefile1
-rw-r--r--tests/sys/netpfil/pf/pft_ping.py23
-rw-r--r--tests/sys/netpfil/pf/sniffer.py25
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)