summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2022-10-07 15:16:52 +0200
committerThomas Haller <thaller@redhat.com>2022-10-11 09:03:17 +0200
commitb5e7e48bc185cb4e544efa8be9144e2bda63081c (patch)
treee2add6bae29002846c29f482db56e1b73e47acb8
parenta9bc3ec08b0bce54cc661ffe01a47a1b2b35c81b (diff)
glib-aux: add and use nm_uuid_generate_from_strings_old()
For a long time we have a function like nm_uuid_generate_from_strings(). This was recently reworked and renamed, but it preserved behavior. Preserving behavior is important for this function, because for the existing users, we need to keep generating the same UUIDs. Originally, this function was a variadic function with NULL sentinel. That means, when you write nm_uuid_generate_from_strings(uuid_type, type_arg, v1, v2, v3, NULL); and v2 happens to be NULL, then v3 is ignored. That is most likely not what the user intended. Maybe they had a bug and v2 should not be NULL. But nm_uuid_generate_from_strings() should not require that all arguments are non-NULL and it should not ignore arguments after the first NULL. For example, one user works around this via uuid = nm_uuid_generate_from_strings_old("ibft", s_hwaddr, s_vlanid ? "V" : "v", s_vlanid ? s_vlanid : "", s_ipaddr ? "A" : "DHCP", s_ipaddr ? s_ipaddr : ""); which is cumbersome and ugly. That will be fixed next, by adding a function that doesn't suffer from this problem. But "this problem" is part of the API of the function, we cannot just change it. Instead, rename it and all users, so they can keep doing the same. New users of course should no longer use the "old" function.
-rw-r--r--src/core/devices/nm-device-ethernet.c10
-rw-r--r--src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c3
-rw-r--r--src/libnm-core-impl/nm-keyfile.c5
-rw-r--r--src/libnm-glib-aux/nm-uuid.c2
-rw-r--r--src/libnm-glib-aux/nm-uuid.h6
-rw-r--r--src/nm-initrd-generator/nmi-ibft-reader.c14
6 files changed, 19 insertions, 21 deletions
diff --git a/src/core/devices/nm-device-ethernet.c b/src/core/devices/nm-device-ethernet.c
index dff6466a2e..414bfa7b4b 100644
--- a/src/core/devices/nm-device-ethernet.c
+++ b/src/core/devices/nm-device-ethernet.c
@@ -1725,12 +1725,10 @@ new_default_connection(NMDevice *self)
/* 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_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3,
- &nm_uuid_ns_1,
- "default-wired",
- nm_utils_machine_id_str(),
- defname,
- perm_hw_addr ?: iface);
+ uuid = nm_uuid_generate_from_strings_old("default-wired",
+ nm_utils_machine_id_str(),
+ defname,
+ perm_hw_addr ?: iface);
g_object_set(setting,
NM_SETTING_CONNECTION_ID,
diff --git a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c
index eec529ce6c..28923ae6e1 100644
--- a/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c
+++ b/src/core/settings/plugins/keyfile/tests/test-keyfile-settings.c
@@ -2296,8 +2296,7 @@ test_read_missing_id_uuid(void)
gs_free char *expected_uuid = NULL;
const char *FILENAME = TEST_KEYFILES_DIR "/Test_Missing_ID_UUID";
- expected_uuid =
- nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3, &nm_uuid_ns_1, "keyfile", FILENAME);
+ expected_uuid = nm_uuid_generate_from_strings_old("keyfile", FILENAME);
connection = keyfile_read_connection_from_file(FILENAME);
diff --git a/src/libnm-core-impl/nm-keyfile.c b/src/libnm-core-impl/nm-keyfile.c
index d8dd27821f..ae6d892c28 100644
--- a/src/libnm-core-impl/nm-keyfile.c
+++ b/src/libnm-core-impl/nm-keyfile.c
@@ -3800,10 +3800,7 @@ nm_keyfile_read_ensure_uuid(NMConnection *connection, const char *fallback_uuid_
if (nm_setting_connection_get_uuid(s_con))
return FALSE;
- hashed_uuid = nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3,
- &nm_uuid_ns_1,
- "keyfile",
- fallback_uuid_seed);
+ hashed_uuid = nm_uuid_generate_from_strings_old("keyfile", fallback_uuid_seed);
g_object_set(s_con, NM_SETTING_CONNECTION_UUID, hashed_uuid, NULL);
return TRUE;
}
diff --git a/src/libnm-glib-aux/nm-uuid.c b/src/libnm-glib-aux/nm-uuid.c
index ae0f7233e7..34c3be335b 100644
--- a/src/libnm-glib-aux/nm-uuid.c
+++ b/src/libnm-glib-aux/nm-uuid.c
@@ -12,7 +12,7 @@
const NMUuid nm_uuid_ns_zero =
NM_UUID_INIT(00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00, 00);
-/* arbitrarily chosen namespace UUID for some uses of nm_uuid_generate_from_strings().
+/* arbitrarily chosen namespace UUID for some uses of nm_uuid_generate_from_strings_old().
* Try not to re-use this namespace, instead, generate a unique one. */
const NMUuid nm_uuid_ns_1 =
NM_UUID_INIT(b4, 25, e9, fb, 75, 98, 44, b4, 9e, 3b, 5a, 2e, 3a, aa, 49, 05);
diff --git a/src/libnm-glib-aux/nm-uuid.h b/src/libnm-glib-aux/nm-uuid.h
index 770d7af1ae..4e0941ffb7 100644
--- a/src/libnm-glib-aux/nm-uuid.h
+++ b/src/libnm-glib-aux/nm-uuid.h
@@ -130,6 +130,12 @@ char *nm_uuid_generate_from_strings_strv(NMUuidType uuid_type,
#define nm_uuid_generate_from_strings(uuid_type, type_args, ...) \
nm_uuid_generate_from_strings_strv((uuid_type), (type_args), NM_MAKE_STRV(__VA_ARGS__))
+/* Legacy function. Don't use for new code. */
+#define nm_uuid_generate_from_strings_old(uuid_type, type_args, ...) \
+ nm_uuid_generate_from_strings_strv(NM_UUID_TYPE_VERSION3, \
+ &nm_uuid_ns_1, \
+ NM_MAKE_STRV(__VA_ARGS__))
+
/*****************************************************************************/
#endif /* __NM_UUID_H__ */
diff --git a/src/nm-initrd-generator/nmi-ibft-reader.c b/src/nm-initrd-generator/nmi-ibft-reader.c
index c0915a8f01..2a3bbdfbcb 100644
--- a/src/nm-initrd-generator/nmi-ibft-reader.c
+++ b/src/nm-initrd-generator/nmi-ibft-reader.c
@@ -307,14 +307,12 @@ connection_setting_add(GHashTable *nic,
s_index ? " " : "",
s_index ? s_index : "");
- uuid = nm_uuid_generate_from_strings(NM_UUID_TYPE_VERSION3,
- &nm_uuid_ns_1,
- "ibft",
- s_hwaddr,
- s_vlanid ? "V" : "v",
- s_vlanid ? s_vlanid : "",
- s_ipaddr ? "A" : "DHCP",
- s_ipaddr ? s_ipaddr : "");
+ uuid = nm_uuid_generate_from_strings_old("ibft",
+ s_hwaddr,
+ s_vlanid ? "V" : "v",
+ s_vlanid ? s_vlanid : "",
+ s_ipaddr ? "A" : "DHCP",
+ s_ipaddr ? s_ipaddr : "");
s_con = (NMSetting *) nm_connection_get_setting_connection(connection);
if (!s_con) {