This repository has been archived on 2025-03-20. You can view files and clone it, but cannot push or open issues or pull requests.
sonic-buildimage/src/scapy.patch/0002-Check-if-the-network-interface-still-exists.patch
Stepan Blyshchak 4426f7715f
[scapy] update scapy to 2.4.5 and patch it (#10457)
Why I did it
Running warm-reboot in a loop for 500 times leads to this error on 318-th iteration:

Apr  2 15:56:27.346747 sonic INFO swss#/supervisord: restore_neighbors Traceback (most recent call last):
Apr  2 15:56:27.346747 sonic INFO swss#/supervisord: restore_neighbors   File "/usr/bin/restore_neighbors.py", line 24, in <module>
Apr  2 15:56:27.346747 sonic INFO swss#/supervisord: restore_neighbors     from scapy.all import conf, in6_getnsma, inet_pton, inet_ntop, in6_getnsmac, get_if_hwaddr, Ether, ARP, IPv6, ICMPv6ND_NS, ICMPv6NDOptSrcLLAddr
Apr  2 15:56:27.346795 sonic INFO swss#/supervisord: restore_neighbors   File "/usr/local/lib/python3.7/dist-packages/scapy/all.py", line 25, in <module>
Apr  2 15:56:27.346956 sonic INFO swss#/supervisord: restore_neighbors     from scapy.route import *
Apr  2 15:56:27.346995 sonic INFO swss#/supervisord: restore_neighbors   File "/usr/local/lib/python3.7/dist-packages/scapy/route.py", line 205, in <module>
Apr  2 15:56:27.347089 sonic INFO swss#/supervisord: restore_neighbors     conf.iface = get_working_if()
Apr  2 15:56:27.347129 sonic INFO swss#/supervisord: restore_neighbors   File "/usr/local/lib/python3.7/dist-packages/scapy/arch/linux.py", line 128, in get_working_if
Apr  2 15:56:27.347213 sonic INFO swss#/supervisord: restore_neighbors     ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
Apr  2 15:56:27.347250 sonic INFO swss#/supervisord: restore_neighbors   File "/usr/local/lib/python3.7/dist-packages/scapy/arch/common.py", line 31, in get_if
Apr  2 15:56:27.347345 sonic INFO swss#/supervisord: restore_neighbors     return ioctl(sck, cmd, struct.pack("16s16x", iff.encode("utf8")))
Apr  2 15:56:27.347365 sonic INFO swss#/supervisord: restore_neighbors OSError: [Errno 19] No such device
The issue was reported to scapy devs secdev/scapy#3369, the fix is secdev/scapy#3371, however there is no released scapy version with this fix right now, thus decided to build scapy v2.4.5 from sources and apply the fix in a form of a patch.

Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
2022-04-07 14:23:35 +03:00

43 lines
1.6 KiB
Diff

From 7ffd8101c1e535f9c3225db2c319958a64412686 Mon Sep 17 00:00:00 2001
From: Guillaume Valadon <guillaume@valadon.net>
Date: Tue, 14 Sep 2021 19:34:43 +0200
Subject: [PATCH] Check if the network interface still exists
Signed-off-by: Stepan Blyschak <stepanb@nvidia.com>
---
scapy/arch/linux.py | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/scapy/arch/linux.py b/scapy/arch/linux.py
index 94fac8f0..b86e98ab 100644
--- a/scapy/arch/linux.py
+++ b/scapy/arch/linux.py
@@ -414,13 +414,17 @@ class LinuxInterfaceProvider(InterfaceProvider):
data = {}
ips = in6_getifaddr()
for i in _get_if_list():
- ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
- index = get_if_index(i)
- mac = scapy.utils.str2mac(
- get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1]
- )
- ip = None # type: Optional[str]
- ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i))
+ try:
+ ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
+ index = get_if_index(i)
+ mac = scapy.utils.str2mac(
+ get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1]
+ )
+ ip = None # type: Optional[str]
+ ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i))
+ except IOError:
+ warning("Interface %s does not exist!", i)
+ continue
if ip == "0.0.0.0":
ip = None
ifflags = FlagValue(ifflags, _iff_flags)
--
2.14.1