Skip to content

Commit 721a53b

Browse files
stepanblyschakqiluo-msft
authored andcommitted
[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 <[email protected]>
1 parent 0e6f183 commit 721a53b

9 files changed

+101
-1
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161
[submodule "src/redis-dump-load"]
6262
path = src/redis-dump-load
6363
url = https://github.com/p/redis-dump-load.git
64+
[submodule "src/scapy"]
65+
path = src/scapy
66+
url = https://github.com/secdev/scapy.git
6467
[submodule "platform/mellanox/mlnx-sai/SAI-Implementation"]
6568
path = platform/mellanox/mlnx-sai/SAI-Implementation
6669
url = https://github.com/Mellanox/SAI-Implementation

dockers/docker-orchagent/Dockerfile.j2

+8-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ RUN ln -s -f /usr/bin/gcc-8 /usr/bin/aarch64-linux-gnu-gcc
3939

4040
# Dependencies of restore_neighbors.py
4141
RUN pip3 install \
42-
scapy==2.4.4 \
4342
pyroute2==0.5.14 \
4443
netifaces==0.10.9
4544

@@ -56,6 +55,14 @@ RUN apt-get remove -y gcc-8
5655
{{ install_debian_packages(docker_orchagent_debs.split(' ')) }}
5756
{%- endif %}
5857

58+
{% if docker_orchagent_whls.strip() -%}
59+
# Copy locally-built Python wheel dependencies
60+
{{ copy_files("python-wheels/", docker_orchagent_whls.split(' '), "/python-wheels/") }}
61+
62+
# Install locally-built Python wheel dependencies
63+
{{ install_python_wheels(docker_orchagent_whls.split(' ')) }}
64+
{% endif %}
65+
5966
# Clean up
6067
RUN apt-get purge -y \
6168
build-essential \

rules/docker-orchagent.mk

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $(DOCKER_ORCHAGENT)_DBG_DEPENDS = $($(DOCKER_SWSS_LAYER_BUSTER)_DBG_DEPENDS)
1010
$(DOCKER_ORCHAGENT)_DBG_DEPENDS += $(SWSS_DBG) \
1111
$(LIBSWSSCOMMON_DBG) \
1212
$(LIBSAIREDIS_DBG)
13+
$(DOCKER_ORCHAGENT)_PYTHON_WHEELS += $(SCAPY)
1314

1415
$(DOCKER_ORCHAGENT)_DBG_IMAGE_PACKAGES = $($(DOCKER_SWSS_LAYER_BUSTER)_DBG_IMAGE_PACKAGES)
1516

rules/scapy.dep

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
SPATH := $($(SCAPY)_SRC_PATH)
2+
DEP_FILES := $(SONIC_COMMON_FILES_LIST) rules/scapy.mk rules/scapy.dep
3+
DEP_FILES += $(SONIC_COMMON_BASE_FILES_LIST)
4+
SMDEP_FILES := $(addprefix $(SPATH)/,$(shell cd $(SPATH) && git ls-files -- ':!:doc/*'))
5+
6+
$(SCAPY)_CACHE_MODE := GIT_CONTENT_SHA
7+
$(SCAPY)_DEP_FLAGS := $(SONIC_COMMON_FLAGS_LIST)
8+
$(SCAPY)_DEP_FILES := $(DEP_FILES)
9+
$(SCAPY)_SMDEP_FILES := $(SMDEP_FILES)
10+
$(SCAPY)_SMDEP_PATHS := $(SPATH)

rules/scapy.mk

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# scapy python3 wheel
2+
3+
SCAPY = scapy-2.4.5-py2.py3-none-any.whl
4+
$(SCAPY)_SRC_PATH = $(SRC_PATH)/scapy
5+
$(SCAPY)_PYTHON_VERSION = 3
6+
$(SCAPY)_TEST = n
7+
SONIC_PYTHON_WHEELS += $(SCAPY)

src/scapy

Submodule scapy added at 8b63d73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
From 988c808af6065b740006aef0e94496821d41fb98 Mon Sep 17 00:00:00 2001
2+
From: Stepan Blyschak <[email protected]>
3+
Date: Mon, 4 Apr 2022 09:57:39 +0000
4+
Subject: [PATCH] Fix version string generation when scapy is a submodule
5+
6+
Signed-off-by: Stepan Blyschak <[email protected]>
7+
---
8+
scapy/__init__.py | 3 ---
9+
1 file changed, 3 deletions(-)
10+
11+
diff --git a/scapy/__init__.py b/scapy/__init__.py
12+
index f920151e..2adbea19 100644
13+
--- a/scapy/__init__.py
14+
+++ b/scapy/__init__.py
15+
@@ -42,9 +42,6 @@ def _version_from_git_describe():
16+
:raises CalledProcessError: if git is unavailable
17+
:return: Scapy's latest tag
18+
"""
19+
- if not os.path.isdir(os.path.join(os.path.dirname(_SCAPY_PKG_DIR), '.git')): # noqa: E501
20+
- raise ValueError('not in scapy git repo')
21+
-
22+
def _git(cmd):
23+
# type: (str) -> str
24+
process = subprocess.Popen(
25+
--
26+
2.14.1
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
From 7ffd8101c1e535f9c3225db2c319958a64412686 Mon Sep 17 00:00:00 2001
2+
From: Guillaume Valadon <[email protected]>
3+
Date: Tue, 14 Sep 2021 19:34:43 +0200
4+
Subject: [PATCH] Check if the network interface still exists
5+
6+
Signed-off-by: Stepan Blyschak <[email protected]>
7+
---
8+
scapy/arch/linux.py | 18 +++++++++++-------
9+
1 file changed, 11 insertions(+), 7 deletions(-)
10+
11+
diff --git a/scapy/arch/linux.py b/scapy/arch/linux.py
12+
index 94fac8f0..b86e98ab 100644
13+
--- a/scapy/arch/linux.py
14+
+++ b/scapy/arch/linux.py
15+
@@ -414,13 +414,17 @@ class LinuxInterfaceProvider(InterfaceProvider):
16+
data = {}
17+
ips = in6_getifaddr()
18+
for i in _get_if_list():
19+
- ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
20+
- index = get_if_index(i)
21+
- mac = scapy.utils.str2mac(
22+
- get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1]
23+
- )
24+
- ip = None # type: Optional[str]
25+
- ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i))
26+
+ try:
27+
+ ifflags = struct.unpack("16xH14x", get_if(i, SIOCGIFFLAGS))[0]
28+
+ index = get_if_index(i)
29+
+ mac = scapy.utils.str2mac(
30+
+ get_if_raw_hwaddr(i, siocgifhwaddr=SIOCGIFHWADDR)[1]
31+
+ )
32+
+ ip = None # type: Optional[str]
33+
+ ip = inet_ntop(socket.AF_INET, get_if_raw_addr(i))
34+
+ except IOError:
35+
+ warning("Interface %s does not exist!", i)
36+
+ continue
37+
if ip == "0.0.0.0":
38+
ip = None
39+
ifflags = FlagValue(ifflags, _iff_flags)
40+
--
41+
2.14.1
42+

src/scapy.patch/series

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
0001-Fix-version-string-generation-when-scapy-is-a-submod.patch
2+
0002-Check-if-the-network-interface-still-exists.patch

0 commit comments

Comments
 (0)