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
This commit is contained in:
Fernando Fernandez Mancera 2022-07-11 13:34:07 +02:00
parent 1784fc9fa1
commit 4655b7c308

View file

@ -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,