mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-15 12:34:55 +00:00
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.
This commit is contained in:
parent
a9bc3ec08b
commit
b5e7e48bc1
|
@ -1725,9 +1725,7 @@ 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",
|
||||
uuid = nm_uuid_generate_from_strings_old("default-wired",
|
||||
nm_utils_machine_id_str(),
|
||||
defname,
|
||||
perm_hw_addr ?: iface);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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__ */
|
||||
|
|
|
@ -307,9 +307,7 @@ 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",
|
||||
uuid = nm_uuid_generate_from_strings_old("ibft",
|
||||
s_hwaddr,
|
||||
s_vlanid ? "V" : "v",
|
||||
s_vlanid ? s_vlanid : "",
|
||||
|
|
Loading…
Reference in a new issue