From d1805f60afc3f3c65f5d2bb360ed1ab55ea705da Mon Sep 17 00:00:00 2001 From: Kristof Provost Date: Thu, 21 Mar 2019 08:15:46 +0000 Subject: [PATCH] pf tests: Move Sniffer to its own file Make it easier to re-use the sniffer class in other test support scripts. --- 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(-) create mode 100644 tests/sys/netpfil/pf/sniffer.py diff --git a/tests/sys/netpfil/pf/Makefile b/tests/sys/netpfil/pf/Makefile index b774e44071ed..84a40a16699c 100644 --- a/tests/sys/netpfil/pf/Makefile +++ b/tests/sys/netpfil/pf/Makefile @@ -20,6 +20,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)