pf tests: Move Sniffer to its own file

Make it easier to re-use the sniffer class in other test support
scripts.
This commit is contained in:
Kristof Provost 2019-03-21 08:15:46 +00:00
parent 64af73aade
commit d1805f60af
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=345367
3 changed files with 27 additions and 22 deletions

View File

@ -20,6 +20,7 @@ ATF_TESTS_SH+= anchor \
${PACKAGE}FILES+= utils.subr \
echo_inetd.conf \
sniffer.py \
pft_ping.py \
CVE-2019-5597.py

View File

@ -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)

View File

@ -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)