summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-04-21 12:55:23 +0200
committerThomas Haller <thaller@redhat.com>2023-04-21 12:55:23 +0200
commit194c0d4b31e7f5ee2855a3bd4c450bdec8e7a33a (patch)
tree55ba96c7c2d5f11aaf2617ed093e19e66b0fd228
parent48a3682a75bed6e65836341d1a13be5ed3f77939 (diff)
parent7deea767d3c12a6fbf14fb09aed8938cc602bf62 (diff)
downloadNetworkManager-194c0d4b31e7f5ee2855a3bd4c450bdec8e7a33a.tar.gz
core: merge branch 'th/stable-id-default'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1610
-rw-r--r--NEWS3
-rw-r--r--src/core/nm-core-utils.c59
-rw-r--r--src/core/tests/test-core.c4
-rw-r--r--src/libnm-core-impl/nm-setting-connection.c25
-rw-r--r--src/libnmc-setting/settings-docs.h.in2
-rw-r--r--src/nmcli/gen-metadata-nm-settings-nmcli.xml.in2
6 files changed, 52 insertions, 43 deletions
diff --git a/NEWS b/NEWS
index ab74091a2a..11df54b83f 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,9 @@ subject to change and not guaranteed to be compatible with
the later release.
USE AT YOUR OWN RISK. NOT RECOMMENDED FOR PRODUCTION USE!
+* Setting "connection.stable-id=default${CONNECTION}" changed behavior to
+ be identical to the built-in default value when the stable-id is not set.
+
=============================================
NetworkManager-1.42
Overview of changes since NetworkManager-1.40
diff --git a/src/core/nm-core-utils.c b/src/core/nm-core-utils.c
index 628947a969..f12a731694 100644
--- a/src/core/nm-core-utils.c
+++ b/src/core/nm-core-utils.c
@@ -3360,7 +3360,7 @@ nm_utils_stable_id_generated_complete(const char *stable_id_generated)
}
static void
-_stable_id_append(GString *str, const char *substitution)
+_stable_id_append(NMStrBuf *str, const char *substitution)
{
if (!substitution) {
/* Would have been nicer to append "=NIL;" to differentiate between
@@ -3369,7 +3369,7 @@ _stable_id_append(GString *str, const char *substitution)
* Can't do that now, as it would change behavior. */
substitution = "";
}
- g_string_append_printf(str, "=%zu{%s}", strlen(substitution), substitution);
+ nm_str_buf_append_printf(str, "=%zu{%s}", strlen(substitution), substitution);
}
NMUtilsStableType
@@ -3380,8 +3380,9 @@ nm_utils_stable_id_parse(const char *stable_id,
const char *uuid,
char **out_generated)
{
- gsize i, idx_start;
- GString *str = NULL;
+ nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT_A(NM_UTILS_GET_NEXT_REALLOC_SIZE_232, FALSE);
+ gsize i;
+ gsize idx_start;
g_return_val_if_fail(out_generated, NM_UTILS_STABLE_TYPE_RANDOM);
@@ -3390,6 +3391,14 @@ nm_utils_stable_id_parse(const char *stable_id,
return NM_UTILS_STABLE_TYPE_UUID;
}
+ if (nm_streq(stable_id, "default${CONNECTION}")) {
+ /* This changed behavior in 1.44. Explicitly setting "default${CONNECTION}"
+ * the same as the built-in default that we get by not configuring
+ * the property. */
+ *out_generated = NULL;
+ return NM_UTILS_STABLE_TYPE_UUID;
+ }
+
/* the stable-id allows for some dynamic by performing text-substitutions
* of ${...} patterns.
*
@@ -3397,7 +3406,7 @@ nm_utils_stable_id_parse(const char *stable_id,
* In contrast however, the process is unambiguous so that the resulting
* effective id differs if:
* - the original, untranslated stable-id differs
- * - or any of the subsitutions differs.
+ * - or any of the substitution differs.
*
* The reason for that is, for example if you specify "${CONNECTION}" in the
* stable-id, then the resulting ID should be always(!) unique for this connection.
@@ -3434,28 +3443,26 @@ nm_utils_stable_id_parse(const char *stable_id,
continue;
}
-#define CHECK_PREFIX(prefix) \
- ({ \
- gboolean _match = FALSE; \
- \
- if (NM_STR_HAS_PREFIX(&stable_id[i], "" prefix "")) { \
- _match = TRUE; \
- if (!str) \
- str = g_string_sized_new(256); \
- i += NM_STRLEN(prefix); \
- g_string_append_len(str, &(stable_id)[idx_start], i - idx_start); \
- idx_start = i; \
- } \
- _match; \
+#define CHECK_PREFIX(prefix) \
+ ({ \
+ gboolean _match = FALSE; \
+ \
+ if (NM_STR_HAS_PREFIX(&stable_id[i], "" prefix "")) { \
+ _match = TRUE; \
+ i += NM_STRLEN(prefix); \
+ nm_str_buf_append_len(&str, &(stable_id)[idx_start], i - idx_start); \
+ idx_start = i; \
+ } \
+ _match; \
})
if (CHECK_PREFIX("${CONNECTION}"))
- _stable_id_append(str, uuid);
+ _stable_id_append(&str, uuid);
else if (CHECK_PREFIX("${BOOT}"))
- _stable_id_append(str, bootid);
+ _stable_id_append(&str, bootid);
else if (CHECK_PREFIX("${DEVICE}"))
- _stable_id_append(str, deviceid);
+ _stable_id_append(&str, deviceid);
else if (CHECK_PREFIX("${MAC}"))
- _stable_id_append(str, hwaddr);
+ _stable_id_append(&str, hwaddr);
else if (g_str_has_prefix(&stable_id[i], "${RANDOM}")) {
/* RANDOM makes not so much sense for cloned-mac-address
* as the result is similar to specifying "cloned-mac-address=random".
@@ -3468,8 +3475,6 @@ nm_utils_stable_id_parse(const char *stable_id,
* by toggling only the stable-id property of the connection.
* With RANDOM being the most short-lived, ~non-stable~ variant.
*/
- if (str)
- g_string_free(str, TRUE);
*out_generated = NULL;
return NM_UTILS_STABLE_TYPE_RANDOM;
} else {
@@ -3488,14 +3493,14 @@ nm_utils_stable_id_parse(const char *stable_id,
}
#undef CHECK_PREFIX
- if (!str) {
+ if (str.len == 0) {
*out_generated = NULL;
return NM_UTILS_STABLE_TYPE_STABLE_ID;
}
if (idx_start < i)
- g_string_append_len(str, &stable_id[idx_start], i - idx_start);
- *out_generated = g_string_free(str, FALSE);
+ nm_str_buf_append_len(&str, &stable_id[idx_start], i - idx_start);
+ *out_generated = nm_str_buf_finalize(&str, NULL);
return NM_UTILS_STABLE_TYPE_GENERATED;
}
diff --git a/src/core/tests/test-core.c b/src/core/tests/test-core.c
index 887803bffe..bd6425d95c 100644
--- a/src/core/tests/test-core.c
+++ b/src/core/tests/test-core.c
@@ -2109,7 +2109,7 @@ do_test_stable_id_parse(const char *stable_id,
g_assert(!expected_generated);
if (expected_stable_type == NM_UTILS_STABLE_TYPE_UUID)
- g_assert(!stable_id);
+ g_assert(NM_IN_STRSET(stable_id, NULL, "default${CONNECTION}"));
else
g_assert(stable_id);
@@ -2137,6 +2137,7 @@ test_stable_id_parse(void)
#define _parse_random(stable_id) \
do_test_stable_id_parse("" stable_id "", NM_UTILS_STABLE_TYPE_RANDOM, NULL)
do_test_stable_id_parse(NULL, NM_UTILS_STABLE_TYPE_UUID, NULL);
+ do_test_stable_id_parse("default${CONNECTION}", NM_UTILS_STABLE_TYPE_UUID, NULL);
_parse_stable_id("");
_parse_stable_id("a");
_parse_stable_id("a$");
@@ -2151,6 +2152,7 @@ test_stable_id_parse(void)
_parse_stable_id("a$${CONNECTION}");
_parse_stable_id("a$${CONNECTION}x");
_parse_generated("${CONNECTION}", "${CONNECTION}=11{_CONNECTION}");
+ _parse_generated(" ${CONNECTION}", " ${CONNECTION}=11{_CONNECTION}");
_parse_generated("${${CONNECTION}", "${${CONNECTION}=11{_CONNECTION}");
_parse_generated("${CONNECTION}x", "${CONNECTION}=11{_CONNECTION}x");
_parse_generated("x${CONNECTION}", "x${CONNECTION}=11{_CONNECTION}");
diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c
index 3cbcd9cdb2..3c26ab5d17 100644
--- a/src/libnm-core-impl/nm-setting-connection.c
+++ b/src/libnm-core-impl/nm-setting-connection.c
@@ -1913,22 +1913,21 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass)
* The per-host key is the identity of your machine and stored in /var/lib/NetworkManager/secret_key.
* See NetworkManager(8) manual about the secret-key and the host identity.
*
- * The '$' character is treated special to perform dynamic substitutions
- * at runtime. Currently, supported are "${CONNECTION}", "${DEVICE}", "${MAC}",
- * "${BOOT}", "${RANDOM}".
- * These effectively create unique IDs per-connection, per-device, per-boot,
- * or every time. Note that "${DEVICE}" corresponds to the interface name of the
- * device and "${MAC}" is the permanent MAC address of the device.
+ * The '$' character is treated special to perform dynamic substitutions at
+ * activation time. Currently, supported are "${CONNECTION}", "${DEVICE}",
+ * "${MAC}", "${BOOT}", "${RANDOM}". These effectively create unique IDs
+ * per-connection, per-device, per-boot, or every time. The "${CONNECTION}"
+ * uses the profile's connection.uuid, the "${DEVICE}" uses the interface
+ * name of the device and "${MAC}" the permanent MAC address of the device.
* Any unrecognized patterns following '$' are treated verbatim, however
- * are reserved for future use. You are thus advised to avoid '$' or
- * escape it as "$$".
- * For example, set it to "${CONNECTION}-${BOOT}-${DEVICE}" to create a unique id for
- * this connection that changes with every reboot and differs depending on the
- * interface where the profile activates.
+ * are reserved for future use. You are thus advised to avoid '$' or escape
+ * it as "$$". For example, set it to "${CONNECTION}-${BOOT}-${DEVICE}" to
+ * create a unique id for this connection that changes with every reboot
+ * and differs depending on the interface where the profile activates.
*
* If the value is unset, a global connection default is consulted. If the
- * value is still unset, the default is similar to "${CONNECTION}" and uses
- * a unique, fixed ID for the connection.
+ * value is still unset, the default is "default${CONNECTION}" go generate
+ * an ID unique per connection profile.
*
* Since: 1.4
**/
diff --git a/src/libnmc-setting/settings-docs.h.in b/src/libnmc-setting/settings-docs.h.in
index a37e73189c..46cff80956 100644
--- a/src/libnmc-setting/settings-docs.h.in
+++ b/src/libnmc-setting/settings-docs.h.in
@@ -21,7 +21,7 @@
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_READ_ONLY N_("This property is deprecated and has no meaning.")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SECONDARIES N_("List of connection UUIDs that should be activated when the base connection itself is activated. Currently, only VPN connections are supported.")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_SLAVE_TYPE N_("Setting name of the device type of this slave's master connection (eg, \"bond\"), or NULL if this connection is not a slave.")
-#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used to derive the DHCP client identifier with ipv4.dhcp-client-id=stable, the DHCPv6 DUID with ipv6.dhcp-duid=stable-[llt,ll,uuid] and the DHCP IAID with ipv4.iaid=stable and ipv6.iaid=stable. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device's name is included, so that different interfaces yield different addresses. The per-host key is the identity of your machine and stored in /var/lib/NetworkManager/secret_key. See NetworkManager(8) manual about the secret-key and the host identity. The '$' character is treated special to perform dynamic substitutions at runtime. Currently, supported are \"${CONNECTION}\", \"${DEVICE}\", \"${MAC}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-device, per-boot, or every time. Note that \"${DEVICE}\" corresponds to the interface name of the device and \"${MAC}\" is the permanent MAC address of the device. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}-${BOOT}-${DEVICE}\" to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is similar to \"${CONNECTION}\" and uses a unique, fixed ID for the connection.")
+#define DESCRIBE_DOC_NM_SETTING_CONNECTION_STABLE_ID N_("This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used to derive the DHCP client identifier with ipv4.dhcp-client-id=stable, the DHCPv6 DUID with ipv6.dhcp-duid=stable-[llt,ll,uuid] and the DHCP IAID with ipv4.iaid=stable and ipv6.iaid=stable. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device's name is included, so that different interfaces yield different addresses. The per-host key is the identity of your machine and stored in /var/lib/NetworkManager/secret_key. See NetworkManager(8) manual about the secret-key and the host identity. The '$' character is treated special to perform dynamic substitutions at activation time. Currently, supported are \"${CONNECTION}\", \"${DEVICE}\", \"${MAC}\", \"${BOOT}\", \"${RANDOM}\". These effectively create unique IDs per-connection, per-device, per-boot, or every time. The \"${CONNECTION}\" uses the profile's connection.uuid, the \"${DEVICE}\" uses the interface name of the device and \"${MAC}\" the permanent MAC address of the device. Any unrecognized patterns following '$' are treated verbatim, however are reserved for future use. You are thus advised to avoid '$' or escape it as \"$$\". For example, set it to \"${CONNECTION}-${BOOT}-${DEVICE}\" to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is \"default${CONNECTION}\" go generate an ID unique per connection profile.")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_TIMESTAMP N_("The time, in seconds since the Unix Epoch, that the connection was last _successfully_ fully activated. NetworkManager updates the connection timestamp periodically when the connection is active to ensure that an active connection has the latest timestamp. The property is only meant for reading (changes to this property will not be preserved).")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_TYPE N_("Base type of the connection. For hardware-dependent connections, should contain the setting name of the hardware-type specific setting (ie, \"802-3-ethernet\" or \"802-11-wireless\" or \"bluetooth\", etc), and for non-hardware dependent connections like VPN or otherwise, should contain the setting name of that setting type (ie, \"vpn\" or \"bridge\", etc).")
#define DESCRIBE_DOC_NM_SETTING_CONNECTION_UUID N_("The connection.uuid is the real identifier of a profile. It cannot change and it must be unique. It is therefore often best to refer to a profile by UUID, for example with `nmcli connection up uuid $UUID`. The UUID cannot be changed, except in offline mode. In that case, the special values \"new\", \"generate\" and \"\" are allowed to generate a new random UUID.")
diff --git a/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in b/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in
index cff9a18a39..19bf9073ca 100644
--- a/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in
+++ b/src/nmcli/gen-metadata-nm-settings-nmcli.xml.in
@@ -367,7 +367,7 @@
<property name="uuid"
description="The connection.uuid is the real identifier of a profile. It cannot change and it must be unique. It is therefore often best to refer to a profile by UUID, for example with `nmcli connection up uuid $UUID`. The UUID cannot be changed, except in offline mode. In that case, the special values &quot;new&quot;, &quot;generate&quot; and &quot;&quot; are allowed to generate a new random UUID." />
<property name="stable-id"
- description="This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used to derive the DHCP client identifier with ipv4.dhcp-client-id=stable, the DHCPv6 DUID with ipv6.dhcp-duid=stable-[llt,ll,uuid] and the DHCP IAID with ipv4.iaid=stable and ipv6.iaid=stable. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device&apos;s name is included, so that different interfaces yield different addresses. The per-host key is the identity of your machine and stored in /var/lib/NetworkManager/secret_key. See NetworkManager(8) manual about the secret-key and the host identity. The &apos;$&apos; character is treated special to perform dynamic substitutions at runtime. Currently, supported are &quot;${CONNECTION}&quot;, &quot;${DEVICE}&quot;, &quot;${MAC}&quot;, &quot;${BOOT}&quot;, &quot;${RANDOM}&quot;. These effectively create unique IDs per-connection, per-device, per-boot, or every time. Note that &quot;${DEVICE}&quot; corresponds to the interface name of the device and &quot;${MAC}&quot; is the permanent MAC address of the device. Any unrecognized patterns following &apos;$&apos; are treated verbatim, however are reserved for future use. You are thus advised to avoid &apos;$&apos; or escape it as &quot;$$&quot;. For example, set it to &quot;${CONNECTION}-${BOOT}-${DEVICE}&quot; to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is similar to &quot;${CONNECTION}&quot; and uses a unique, fixed ID for the connection." />
+ description="This represents the identity of the connection used for various purposes. It allows to configure multiple profiles to share the identity. Also, the stable-id can contain placeholders that are substituted dynamically and deterministically depending on the context. The stable-id is used for generating IPv6 stable private addresses with ipv6.addr-gen-mode=stable-privacy. It is also used to seed the generated cloned MAC address for ethernet.cloned-mac-address=stable and wifi.cloned-mac-address=stable. It is also used to derive the DHCP client identifier with ipv4.dhcp-client-id=stable, the DHCPv6 DUID with ipv6.dhcp-duid=stable-[llt,ll,uuid] and the DHCP IAID with ipv4.iaid=stable and ipv6.iaid=stable. Note that depending on the context where it is used, other parameters are also seeded into the generation algorithm. For example, a per-host key is commonly also included, so that different systems end up generating different IDs. Or with ipv6.addr-gen-mode=stable-privacy, also the device&apos;s name is included, so that different interfaces yield different addresses. The per-host key is the identity of your machine and stored in /var/lib/NetworkManager/secret_key. See NetworkManager(8) manual about the secret-key and the host identity. The &apos;$&apos; character is treated special to perform dynamic substitutions at activation time. Currently, supported are &quot;${CONNECTION}&quot;, &quot;${DEVICE}&quot;, &quot;${MAC}&quot;, &quot;${BOOT}&quot;, &quot;${RANDOM}&quot;. These effectively create unique IDs per-connection, per-device, per-boot, or every time. The &quot;${CONNECTION}&quot; uses the profile&apos;s connection.uuid, the &quot;${DEVICE}&quot; uses the interface name of the device and &quot;${MAC}&quot; the permanent MAC address of the device. Any unrecognized patterns following &apos;$&apos; are treated verbatim, however are reserved for future use. You are thus advised to avoid &apos;$&apos; or escape it as &quot;$$&quot;. For example, set it to &quot;${CONNECTION}-${BOOT}-${DEVICE}&quot; to create a unique id for this connection that changes with every reboot and differs depending on the interface where the profile activates. If the value is unset, a global connection default is consulted. If the value is still unset, the default is &quot;default${CONNECTION}&quot; go generate an ID unique per connection profile." />
<property name="type"
alias="type"
description="Base type of the connection. For hardware-dependent connections, should contain the setting name of the hardware-type specific setting (ie, &quot;802-3-ethernet&quot; or &quot;802-11-wireless&quot; or &quot;bluetooth&quot;, etc), and for non-hardware dependent connections like VPN or otherwise, should contain the setting name of that setting type (ie, &quot;vpn&quot; or &quot;bridge&quot;, etc)." />