diff --git a/tests/scripts/dual_tor_sniffer.py b/tests/scripts/dual_tor_sniffer.py index 4fe1b685061..d8fa76df728 100644 --- a/tests/scripts/dual_tor_sniffer.py +++ b/tests/scripts/dual_tor_sniffer.py @@ -5,9 +5,19 @@ import scapy.all as scapyall +class L2ListenAllSocket(scapyall.conf.L2listen): + """Read packets at layer2 using Linux PF_PACKET sockets on all ports.""" + + def __init__(self, *args, **kwargs): + # HACK: Set the socket bind to NOOP, so the packet sockets created + # will not bind to any interface and it will listen on all interfaces + # by default. + socket.bind = lambda _: None + super(L2ListenAllSocket, self).__init__(*args, **kwargs) + + class Sniffer(object): def __init__(self, filter=None, timeout=60): - self.ifaces = [iface for _, iface in socket.if_nameindex() if iface.startswith("eth")] self.filter = filter self.timeout = timeout self.packets = [] @@ -17,7 +27,7 @@ def sniff(self): logging.debug("scapy sniffer started: filter={}, timeout={}".format( self.filter, self.timeout)) scapyall.sniff( - iface=self.ifaces, + L2socket=L2ListenAllSocket, filter=self.filter, prn=self.process_pkt, timeout=self.timeout)