The pft_ping.py and sniffer.py tool is moved from tests/sys/netpfil/pf to tests/sys/netpfil/common directory because these tools are to be used in common for all the firewalls. Submitted by: Ahsan Barkati Reviewed by: kp, thj Sponsored by: Google, Inc. (GSoC 2019) Differential Revision: https://reviews.freebsd.org/D21276
26 lines
556 B
Python
26 lines
556 B
Python
# $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)
|