diff options
author | Thomas Haller <thaller@redhat.com> | 2016-04-25 21:27:10 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-04-26 12:50:16 +0200 |
commit | 89cf9429a76d8230bde8d2ca169e42bfb8803634 (patch) | |
tree | dca2d57a4fa4be4983637aaa85d09d27c90d6040 | |
parent | 54233b6f3b700b7cbdc9c9f05a51777892f580e1 (diff) | |
download | NetworkManager-89cf9429a76d8230bde8d2ca169e42bfb8803634.tar.gz |
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.
-rw-r--r-- | src/devices/nm-device-ethernet.c | 20 | ||||
-rw-r--r-- | 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 281f299f1f..3b8ac5b5df 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -1982,9 +1982,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; } |