From 4655b7c308461ae1f86d592ea6d45e00a2820423 Mon Sep 17 00:00:00 2001 From: Fernando Fernandez Mancera Date: Mon, 11 Jul 2022 13:34:07 +0200 Subject: [PATCH] veth: fix veth activation on booting When creating one profile for each veth during activation the creation of the veth could fail. When the link for the first profile is created the link for the peer is generated in kernel. Therefore when trying to activate the second profile it will fail because the link already exists. NetworkManager must check if the link already exists and corresponds to the same veth, if so, it should skip the link creation. https://bugzilla.redhat.com/show_bug.cgi?id=2036023 https://bugzilla.redhat.com/show_bug.cgi?id=2105956 --- src/core/devices/nm-device-veth.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/core/devices/nm-device-veth.c b/src/core/devices/nm-device-veth.c index 8c95a293d4..63dfd8bbc4 100644 --- a/src/core/devices/nm-device-veth.c +++ b/src/core/devices/nm-device-veth.c @@ -82,6 +82,8 @@ create_and_realize(NMDevice *device, GError **error) { const char *iface = nm_device_get_iface(device); + const char *peer; + NMDevice *peer_device; NMSettingVeth *s_veth; int r; @@ -96,10 +98,15 @@ create_and_realize(NMDevice *device, return FALSE; } - r = nm_platform_link_veth_add(nm_device_get_platform(device), - iface, - nm_setting_veth_get_peer(s_veth), - out_plink); + peer = nm_setting_veth_get_peer(s_veth); + peer_device = nm_manager_get_device(NM_MANAGER_GET, peer, NM_DEVICE_TYPE_VETH); + if (peer_device) { + /* The veth device and its peer already exist. No need to create it again. */ + if (nm_streq0(nm_device_get_iface(nm_device_parent_get_device(peer_device)), iface)) + return TRUE; + } + + r = nm_platform_link_veth_add(nm_device_get_platform(device), iface, peer, out_plink); if (r < 0) { g_set_error(error, NM_DEVICE_ERROR,