From 7ede2a7a63e5ec45895cb80525da4115e6db55b2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 25 Apr 2016 21:27:10 +0200 Subject: [PATCH] device: generate stable UUID for default-wired-connection Generate a stable connection UUID for the default-wired-connection. Otherwise, on every reboot, the UUID changes although the generated connection is the same. But also hash into the UUID the machine-id, the device name and the hardware address. So, the UUID is only the same if the connection is identical in every aspect. Also, the UUID is used as Network_ID for the stable-privacy address generation mode. It is bad to re-create different UUIDs on every boot as it causes different addresses. (cherry picked from commit 89cf9429a76d8230bde8d2ca169e42bfb8803634) --- src/devices/nm-device-ethernet.c | 20 ++++++++++++++++---- src/settings/nm-settings.c | 8 +++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 6225ae7bf6..acf822a2e5 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1433,7 +1433,9 @@ new_default_connection (NMDevice *self) const GSList *connections; NMSetting *setting; const char *hw_address; - char *defname, *uuid; + gs_free char *defname = NULL; + gs_free char *uuid = NULL; + gs_free char *machine_id = NULL; if (nm_config_get_no_auto_default_for_device (nm_config_get (), self)) return NULL; @@ -1448,7 +1450,19 @@ new_default_connection (NMDevice *self) connections = nm_connection_provider_get_connections (nm_connection_provider_get ()); defname = nm_device_ethernet_utils_get_default_wired_name (connections); - uuid = nm_utils_uuid_generate (); + if (!defname) + return NULL; + + machine_id = nm_utils_machine_id_read (); + + /* Create a stable UUID. The UUID is also the Network_ID for stable-privacy addr-gen-mode, + * thus when it changes we will also generate different IPv6 addresses. */ + uuid = _nm_utils_uuid_generate_from_strings ("default-wired", + machine_id ?: "", + defname, + hw_address, + NULL); + g_object_set (setting, NM_SETTING_CONNECTION_ID, defname, NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME, @@ -1457,8 +1471,6 @@ new_default_connection (NMDevice *self) NM_SETTING_CONNECTION_UUID, uuid, NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL), NULL); - g_free (uuid); - g_free (defname); /* Lock the connection to the device */ setting = nm_setting_wired_new (); diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index 7475eb5fae..93c4d26274 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -1996,9 +1996,11 @@ device_realized (NMDevice *device, GParamSpec *pspec, NMSettings *self) g_object_unref (connection); if (!added) { - _LOGW ("(%s) couldn't create default wired connection: %s", - nm_device_get_iface (device), - error->message); + if (!g_error_matches (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_UUID_EXISTS)) { + _LOGW ("(%s) couldn't create default wired connection: %s", + nm_device_get_iface (device), + error->message); + } g_clear_error (&error); return; }