Merge ~danilogondolfo/network-manager/+git/network-manager:fix_veth_activation_on_boot into network-manager:ubuntu/jammy

Proposed by Danilo Egea Gondolfo
Status: Work in progress
Proposed branch: ~danilogondolfo/network-manager/+git/network-manager:fix_veth_activation_on_boot
Merge into: network-manager:ubuntu/jammy
Diff against target: 231 lines (+192/-2)
5 files modified
debian/changelog (+7/-2)
debian/patches/lp2032824/0001-veth-fix-veth-activation-on-booting.patch (+56/-0)
debian/patches/lp2032824/0002-veth-drop-iface-peer-check-during-create_and_realize.patch (+42/-0)
debian/patches/lp2032824/0003-veth-fix-detection-of-existing-interfaces-in-create_.patch (+84/-0)
debian/patches/series (+3/-0)
Reviewer Review Type Date Requested Status
Network-manager Pending
Review via email: mp+450447@code.launchpad.net
To post a comment you must log in.

Unmerged commits

264a4fc... by Danilo Egea Gondolfo

Changelog

41355b8... by Danilo Egea Gondolfo

debian/patches/lp2032824 (LP: #2032824)

Fix for VETHs pairs activation on startup.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index d62c327..29b5ef4 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,8 +1,13 @@
6-network-manager (1.36.6-0ubuntu3) UNRELEASED; urgency=medium
7+network-manager (1.36.6-0ubuntu3) jammy; urgency=medium
8
9+ [ Jeremy Bicha ]
10 * Fix network-manager-config-connectivity-ubuntu.postinst
11
12- -- Jeremy Bicha <jbicha@ubuntu.com> Tue, 29 Nov 2022 15:47:37 -0500
13+ [ Danilo Egea Gondolfo ]
14+ * debian/patches/lp2032824 (LP: #2032824)
15+ Fix for VETHs pairs activation on startup.
16+
17+ -- Danilo Egea Gondolfo <danilo.egea.gondolfo@canonical.com> Thu, 31 Aug 2023 12:06:20 +0100
18
19 network-manager (1.36.6-0ubuntu2) jammy; urgency=medium
20
21diff --git a/debian/patches/lp2032824/0001-veth-fix-veth-activation-on-booting.patch b/debian/patches/lp2032824/0001-veth-fix-veth-activation-on-booting.patch
22new file mode 100644
23index 0000000..aaca951
24--- /dev/null
25+++ b/debian/patches/lp2032824/0001-veth-fix-veth-activation-on-booting.patch
26@@ -0,0 +1,56 @@
27+From 5eaeb69c4050bb41b7467ee037bb7fbd937eec47 Mon Sep 17 00:00:00 2001
28+From: Fernando Fernandez Mancera <ffmancera@riseup.net>
29+Date: Mon, 11 Jul 2022 13:34:07 +0200
30+Subject: [PATCH 1/3] veth: fix veth activation on booting
31+
32+When creating one profile for each veth during activation the creation
33+of the veth could fail. When the link for the first profile is created
34+the link for the peer is generated in kernel. Therefore when trying to
35+activate the second profile it will fail because the link already
36+exists. NetworkManager must check if the link already exists and
37+corresponds to the same veth, if so, it should skip the link creation.
38+
39+https://bugzilla.redhat.com/show_bug.cgi?id=2036023
40+https://bugzilla.redhat.com/show_bug.cgi?id=2105956
41+
42+Origin: https://gitlab.freedesktop.org/piotrdrag/NetworkManager/-/commit/4655b7c308461ae1f86d592ea6d45e00a2820423
43+---
44+ src/core/devices/nm-device-veth.c | 15 +++++++++++----
45+ 1 file changed, 11 insertions(+), 4 deletions(-)
46+
47+diff --git a/src/core/devices/nm-device-veth.c b/src/core/devices/nm-device-veth.c
48+index 8c95a293d4..63dfd8bbc4 100644
49+--- a/src/core/devices/nm-device-veth.c
50++++ b/src/core/devices/nm-device-veth.c
51+@@ -82,6 +82,8 @@ create_and_realize(NMDevice *device,
52+ GError **error)
53+ {
54+ const char *iface = nm_device_get_iface(device);
55++ const char *peer;
56++ NMDevice *peer_device;
57+ NMSettingVeth *s_veth;
58+ int r;
59+
60+@@ -96,10 +98,15 @@ create_and_realize(NMDevice *device,
61+ return FALSE;
62+ }
63+
64+- r = nm_platform_link_veth_add(nm_device_get_platform(device),
65+- iface,
66+- nm_setting_veth_get_peer(s_veth),
67+- out_plink);
68++ peer = nm_setting_veth_get_peer(s_veth);
69++ peer_device = nm_manager_get_device(NM_MANAGER_GET, peer, NM_DEVICE_TYPE_VETH);
70++ if (peer_device) {
71++ /* The veth device and its peer already exist. No need to create it again. */
72++ if (nm_streq0(nm_device_get_iface(nm_device_parent_get_device(peer_device)), iface))
73++ return TRUE;
74++ }
75++
76++ r = nm_platform_link_veth_add(nm_device_get_platform(device), iface, peer, out_plink);
77+ if (r < 0) {
78+ g_set_error(error,
79+ NM_DEVICE_ERROR,
80+--
81+2.40.1
82+
83diff --git a/debian/patches/lp2032824/0002-veth-drop-iface-peer-check-during-create_and_realize.patch b/debian/patches/lp2032824/0002-veth-drop-iface-peer-check-during-create_and_realize.patch
84new file mode 100644
85index 0000000..0630ada
86--- /dev/null
87+++ b/debian/patches/lp2032824/0002-veth-drop-iface-peer-check-during-create_and_realize.patch
88@@ -0,0 +1,42 @@
89+From 88d1637c17a0e5f40a3c78b407bd5e84729eec4b Mon Sep 17 00:00:00 2001
90+From: Fernando Fernandez Mancera <ffmancera@riseup.net>
91+Date: Tue, 27 Sep 2022 12:26:14 +0200
92+Subject: [PATCH 2/3] veth: drop iface peer check during create_and_realize()
93+
94+When fetching the parent device, if the system is slow, NetworkManager
95+can hit a race condition where the property is still NULL. In that case,
96+NetworkManager should create the veth link.
97+
98+Checking that the peer device exists, it is type NM_DEVICE_TYPE_VETH and
99+it have a parent device is enough to know that we can skip the link
100+creation.
101+
102+https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1399
103+
104+https://bugzilla.redhat.com/show_bug.cgi?id=2129829
105+
106+Fixes: 4655b7c30846 ('veth: fix veth activation on booting')
107+
108+Origin: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/07e0ab48d194b8bd6663a34887c2e753720ae4d3
109+---
110+ src/core/devices/nm-device-veth.c | 4 ++--
111+ 1 file changed, 2 insertions(+), 2 deletions(-)
112+
113+diff --git a/src/core/devices/nm-device-veth.c b/src/core/devices/nm-device-veth.c
114+index 63dfd8bbc4..c3482e7885 100644
115+--- a/src/core/devices/nm-device-veth.c
116++++ b/src/core/devices/nm-device-veth.c
117+@@ -101,8 +101,8 @@ create_and_realize(NMDevice *device,
118+ peer = nm_setting_veth_get_peer(s_veth);
119+ peer_device = nm_manager_get_device(NM_MANAGER_GET, peer, NM_DEVICE_TYPE_VETH);
120+ if (peer_device) {
121+- /* The veth device and its peer already exist. No need to create it again. */
122+- if (nm_streq0(nm_device_get_iface(nm_device_parent_get_device(peer_device)), iface))
123++ if (nm_device_parent_get_device(peer_device))
124++ /* The veth device and its peer already exist. No need to create it again. */
125+ return TRUE;
126+ }
127+
128+--
129+2.40.1
130+
131diff --git a/debian/patches/lp2032824/0003-veth-fix-detection-of-existing-interfaces-in-create_.patch b/debian/patches/lp2032824/0003-veth-fix-detection-of-existing-interfaces-in-create_.patch
132new file mode 100644
133index 0000000..ffe12e6
134--- /dev/null
135+++ b/debian/patches/lp2032824/0003-veth-fix-detection-of-existing-interfaces-in-create_.patch
136@@ -0,0 +1,84 @@
137+From 55a38b791aa13892fa23e2c52ed4a92fe9e80ae1 Mon Sep 17 00:00:00 2001
138+From: Beniamino Galvani <bgalvani@redhat.com>
139+Date: Fri, 16 Dec 2022 10:13:18 +0100
140+Subject: [PATCH 3/3] veth: fix detection of existing interfaces in
141+ create_and_realize()
142+
143+The current implementation only checks that a device with name equal
144+to veth.peer exists and it has a parent device; it doesn't check that
145+its parent is actually the device we want to create. So for example,
146+if the profile specifies interface-name A and peer B, while in
147+platform we have a veth pair {B,C}, we'll skip the interface creation
148+and the device will remain without a ifindex, leading to a crash
149+later. Fix this by adding the missing check.
150+
151+While at it, don't implement the check by inspecting NMDevices but
152+look directly at the platform cache; that seems more robust because
153+devices are often updated from platform events via idle handlers and
154+so the information there could be outdated.
155+
156+Fixes: 07e0ab48d194 ('veth: drop iface peer check during create_and_realize()')
157+
158+https://bugzilla.redhat.com/show_bug.cgi?id=2129829
159+
160+Origin: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/commit/50f738bde5b441b5ca52024c1a0998399b87337b
161+---
162+ src/core/devices/nm-device-veth.c | 32 ++++++++++++++++++++-----------
163+ 1 file changed, 21 insertions(+), 11 deletions(-)
164+
165+diff --git a/src/core/devices/nm-device-veth.c b/src/core/devices/nm-device-veth.c
166+index c3482e7885..17115d3362 100644
167+--- a/src/core/devices/nm-device-veth.c
168++++ b/src/core/devices/nm-device-veth.c
169+@@ -81,11 +81,13 @@ create_and_realize(NMDevice *device,
170+ const NMPlatformLink **out_plink,
171+ GError **error)
172+ {
173+- const char *iface = nm_device_get_iface(device);
174+- const char *peer;
175+- NMDevice *peer_device;
176+- NMSettingVeth *s_veth;
177+- int r;
178++ NMPlatform *platform = nm_device_get_platform(device);
179++ const char *iface = nm_device_get_iface(device);
180++ NMSettingVeth *s_veth;
181++ const NMPlatformLink *plink;
182++ const NMPlatformLink *peer_plink;
183++ int peer_ifindex;
184++ int r;
185+
186+ s_veth = _nm_connection_get_setting(connection, NM_TYPE_SETTING_VETH);
187+ if (!s_veth) {
188+@@ -98,15 +100,23 @@ create_and_realize(NMDevice *device,
189+ return FALSE;
190+ }
191+
192+- peer = nm_setting_veth_get_peer(s_veth);
193+- peer_device = nm_manager_get_device(NM_MANAGER_GET, peer, NM_DEVICE_TYPE_VETH);
194+- if (peer_device) {
195+- if (nm_device_parent_get_device(peer_device))
196+- /* The veth device and its peer already exist. No need to create it again. */
197++ /* For veths, users can define two connection profiles referencing each
198++ * other as 'veth.peer'. Only the first to be activated will actually
199++ * create the veth pair; the other must detect that interfaces already
200++ * exist and proceed. */
201++ plink = nm_platform_link_get_by_ifname(platform, iface);
202++ if (plink && nm_platform_link_veth_get_properties(platform, plink->ifindex, &peer_ifindex)) {
203++ peer_plink = nm_platform_link_get(platform, peer_ifindex);
204++ if (peer_plink && peer_plink->type == NM_LINK_TYPE_VETH
205++ && nm_streq0(peer_plink->name, nm_setting_veth_get_peer(s_veth))) {
206+ return TRUE;
207++ }
208+ }
209+
210+- r = nm_platform_link_veth_add(nm_device_get_platform(device), iface, peer, out_plink);
211++ r = nm_platform_link_veth_add(nm_device_get_platform(device),
212++ iface,
213++ nm_setting_veth_get_peer(s_veth),
214++ out_plink);
215+ if (r < 0) {
216+ g_set_error(error,
217+ NM_DEVICE_ERROR,
218+--
219+2.40.1
220+
221diff --git a/debian/patches/series b/debian/patches/series
222index ac219c1..58e3655 100644
223--- a/debian/patches/series
224+++ b/debian/patches/series
225@@ -4,3 +4,6 @@ Force-online-state-with-unmanaged-devices.patch
226 # Ubuntu patches
227 Provide-access-to-some-of-NM-s-interfaces-to-whoopsie.patch
228 Update-dnsmasq-parameters.patch
229+lp2032824/0001-veth-fix-veth-activation-on-booting.patch
230+lp2032824/0002-veth-drop-iface-peer-check-during-create_and_realize.patch
231+lp2032824/0003-veth-fix-detection-of-existing-interfaces-in-create_.patch

Subscribers

People subscribed via source and target branches