Skip to content

Commit a4f9cf5

Browse files
lolyuvenu-nexthop
authored andcommitted
[dualtor-io] fix dualtor sniffer start slow issue (sonic-net#18758)
Signed-off-by: Longxiang Lyu <lolv@microsoft.com>
1 parent 67cd8d4 commit a4f9cf5

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

tests/scripts/dual_tor_sniffer.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@
55
import scapy.all as scapyall
66

77

8+
class L2ListenAllSocket(scapyall.conf.L2listen):
9+
"""Read packets at layer2 using Linux PF_PACKET sockets on all ports."""
10+
11+
def __init__(self, *args, **kwargs):
12+
# HACK: Set the socket bind to NOOP, so the packet sockets created
13+
# will not bind to any interface and it will listen on all interfaces
14+
# by default.
15+
socket.bind = lambda _: None
16+
super(L2ListenAllSocket, self).__init__(*args, **kwargs)
17+
18+
819
class Sniffer(object):
920
def __init__(self, filter=None, timeout=60):
10-
self.ifaces = [iface for _, iface in socket.if_nameindex() if iface.startswith("eth")]
1121
self.filter = filter
1222
self.timeout = timeout
1323
self.packets = []
@@ -17,7 +27,7 @@ def sniff(self):
1727
logging.debug("scapy sniffer started: filter={}, timeout={}".format(
1828
self.filter, self.timeout))
1929
scapyall.sniff(
20-
iface=self.ifaces,
30+
L2socket=L2ListenAllSocket,
2131
filter=self.filter,
2232
prn=self.process_pkt,
2333
timeout=self.timeout)

0 commit comments

Comments
 (0)