mirror of
https://github.com/freebsd/freebsd-src
synced 2024-10-04 23:50:27 +00:00
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:
parent
64af73aade
commit
d1805f60af
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=345367
|
@ -20,6 +20,7 @@ ATF_TESTS_SH+= anchor \
|
|||
|
||||
${PACKAGE}FILES+= utils.subr \
|
||||
echo_inetd.conf \
|
||||
sniffer.py \
|
||||
pft_ping.py \
|
||||
CVE-2019-5597.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)
|
||||
|
|
25
tests/sys/netpfil/pf/sniffer.py
Normal file
25
tests/sys/netpfil/pf/sniffer.py
Normal 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)
|
Loading…
Reference in a new issue