diff options
author | Thomas Haller <thaller@redhat.com> | 2016-06-21 16:41:05 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-06-30 08:29:54 +0200 |
commit | 3f3ea1df21d3fe686e435f9c0afc3ed5dcd97253 (patch) | |
tree | 52a5f7d68a91be61ea79f6a32c544240196acf0a | |
parent | c7cee12189d8fe64bc9037d5b9daaf1c887e0466 (diff) | |
download | NetworkManager-3f3ea1df21d3fe686e435f9c0afc3ed5dcd97253.tar.gz |
libnm: add NMSettingConnection:stable-id property
This new property be used as token to generate stable-ids instead
of the connection's UUID.
Later, this will be used by ipv6.addr-gen-mode=stable-privacy,
ethernet.cloned-mac-address=stable, and wifi.cloned-mac-address=stable
setting. Those generate stable addresses based on the connection's
UUID, but allow to use the stable-id instead.
This allows multiple connections to generate the same addresses
-- on the same machine, because in the above cases a machine
dependant key is also hashed.
-rw-r--r-- | clients/cli/settings.c | 71 | ||||
-rw-r--r-- | libnm-core/nm-setting-connection.c | 52 | ||||
-rw-r--r-- | libnm-core/nm-setting-connection.h | 3 | ||||
-rw-r--r-- | libnm-core/tests/test-general.c | 1 | ||||
-rw-r--r-- | libnm/libnm.ver | 1 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/reader.c | 4 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/writer.c | 1 |
7 files changed, 102 insertions, 31 deletions
diff --git a/clients/cli/settings.c b/clients/cli/settings.c index 08a5d087e1..6573e0b2bc 100644 --- a/clients/cli/settings.c +++ b/clients/cli/settings.c @@ -44,26 +44,28 @@ NmcOutputField nmc_fields_setting_connection[] = { SETTING_FIELD ("name"), /* 0 */ SETTING_FIELD (NM_SETTING_CONNECTION_ID), /* 1 */ SETTING_FIELD (NM_SETTING_CONNECTION_UUID), /* 2 */ - SETTING_FIELD (NM_SETTING_CONNECTION_INTERFACE_NAME), /* 3 */ - SETTING_FIELD (NM_SETTING_CONNECTION_TYPE), /* 4 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT), /* 5 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), /* 6 */ - SETTING_FIELD (NM_SETTING_CONNECTION_TIMESTAMP), /* 7 */ - SETTING_FIELD (NM_SETTING_CONNECTION_READ_ONLY), /* 8 */ - SETTING_FIELD (NM_SETTING_CONNECTION_PERMISSIONS), /* 9 */ - SETTING_FIELD (NM_SETTING_CONNECTION_ZONE), /* 10 */ - SETTING_FIELD (NM_SETTING_CONNECTION_MASTER), /* 11 */ - SETTING_FIELD (NM_SETTING_CONNECTION_SLAVE_TYPE), /* 12 */ - SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), /* 13 */ - SETTING_FIELD (NM_SETTING_CONNECTION_SECONDARIES), /* 14 */ - SETTING_FIELD (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), /* 15 */ - SETTING_FIELD (NM_SETTING_CONNECTION_METERED), /* 16 */ - SETTING_FIELD (NM_SETTING_CONNECTION_LLDP), /* 17 */ + SETTING_FIELD (NM_SETTING_CONNECTION_STABLE_ID), /* 3 */ + SETTING_FIELD (NM_SETTING_CONNECTION_INTERFACE_NAME), /* 4 */ + SETTING_FIELD (NM_SETTING_CONNECTION_TYPE), /* 5 */ + SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT), /* 6 */ + SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY), /* 7 */ + SETTING_FIELD (NM_SETTING_CONNECTION_TIMESTAMP), /* 8 */ + SETTING_FIELD (NM_SETTING_CONNECTION_READ_ONLY), /* 9 */ + SETTING_FIELD (NM_SETTING_CONNECTION_PERMISSIONS), /* 10 */ + SETTING_FIELD (NM_SETTING_CONNECTION_ZONE), /* 11 */ + SETTING_FIELD (NM_SETTING_CONNECTION_MASTER), /* 12 */ + SETTING_FIELD (NM_SETTING_CONNECTION_SLAVE_TYPE), /* 13 */ + SETTING_FIELD (NM_SETTING_CONNECTION_AUTOCONNECT_SLAVES), /* 14 */ + SETTING_FIELD (NM_SETTING_CONNECTION_SECONDARIES), /* 15 */ + SETTING_FIELD (NM_SETTING_CONNECTION_GATEWAY_PING_TIMEOUT), /* 16 */ + SETTING_FIELD (NM_SETTING_CONNECTION_METERED), /* 17 */ + SETTING_FIELD (NM_SETTING_CONNECTION_LLDP), /* 18 */ {NULL, NULL, 0, NULL, FALSE, FALSE, 0} }; #define NMC_FIELDS_SETTING_CONNECTION_ALL "name"","\ NM_SETTING_CONNECTION_ID","\ NM_SETTING_CONNECTION_UUID","\ + NM_SETTING_CONNECTION_STABLE_ID","\ NM_SETTING_CONNECTION_INTERFACE_NAME","\ NM_SETTING_CONNECTION_TYPE","\ NM_SETTING_CONNECTION_AUTOCONNECT","\ @@ -1252,6 +1254,7 @@ DEFINE_SECRET_FLAGS_GETTER (nmc_property_cdma_get_password_flags, NM_SETTING_CDM /* --- NM_SETTING_CONNECTION_SETTING_NAME property get functions --- */ DEFINE_GETTER (nmc_property_connection_get_id, NM_SETTING_CONNECTION_ID) DEFINE_GETTER (nmc_property_connection_get_uuid, NM_SETTING_CONNECTION_UUID) +DEFINE_GETTER (nmc_property_connection_get_stable_id, NM_SETTING_CONNECTION_STABLE_ID) DEFINE_GETTER (nmc_property_connection_get_interface_name, NM_SETTING_CONNECTION_INTERFACE_NAME) DEFINE_GETTER (nmc_property_connection_get_type, NM_SETTING_CONNECTION_TYPE) DEFINE_GETTER (nmc_property_connection_get_autoconnect, NM_SETTING_CONNECTION_AUTOCONNECT) @@ -6217,6 +6220,13 @@ nmc_properties_init (void) NULL, NULL, NULL); + nmc_add_prop_funcs (GLUE (CONNECTION, STABLE_ID), + nmc_property_connection_get_stable_id, + nmc_property_set_string, + NULL, + NULL, + NULL, + NULL); nmc_add_prop_funcs (GLUE (CONNECTION, INTERFACE_NAME), nmc_property_connection_get_interface_name, nmc_property_set_ifname, @@ -8063,21 +8073,22 @@ setting_connection_details (NMSetting *setting, NmCli *nmc, const char *one_pro set_val_str (arr, 0, g_strdup (nm_setting_get_name (setting))); set_val_str (arr, 1, nmc_property_connection_get_id (setting, NMC_PROPERTY_GET_PRETTY)); set_val_str (arr, 2, nmc_property_connection_get_uuid (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 3, nmc_property_connection_get_interface_name (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 4, nmc_property_connection_get_type (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 5, nmc_property_connection_get_autoconnect (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 6, nmc_property_connection_get_autoconnect_priority (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 7, nmc_property_connection_get_timestamp (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 8, nmc_property_connection_get_read_only (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 9, nmc_property_connection_get_permissions (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 10, nmc_property_connection_get_zone (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 11, nmc_property_connection_get_master (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 12, nmc_property_connection_get_slave_type (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 13, nmc_property_connection_get_autoconnect_slaves (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 14, nmc_property_connection_get_secondaries (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 15, nmc_property_connection_get_gateway_ping_timeout (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 16, nmc_property_connection_get_metered (setting, NMC_PROPERTY_GET_PRETTY)); - set_val_str (arr, 17, nmc_property_connection_get_lldp (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 3, nmc_property_connection_get_stable_id (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 4, nmc_property_connection_get_interface_name (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 5, nmc_property_connection_get_type (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 6, nmc_property_connection_get_autoconnect (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 7, nmc_property_connection_get_autoconnect_priority (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 8, nmc_property_connection_get_timestamp (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 9, nmc_property_connection_get_read_only (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 10, nmc_property_connection_get_permissions (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 11, nmc_property_connection_get_zone (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 12, nmc_property_connection_get_master (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 13, nmc_property_connection_get_slave_type (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 14, nmc_property_connection_get_autoconnect_slaves (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 15, nmc_property_connection_get_secondaries (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 16, nmc_property_connection_get_gateway_ping_timeout (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 17, nmc_property_connection_get_metered (setting, NMC_PROPERTY_GET_PRETTY)); + set_val_str (arr, 18, nmc_property_connection_get_lldp (setting, NMC_PROPERTY_GET_PRETTY)); g_ptr_array_add (nmc->output_data, arr); print_data (nmc); /* Print all data */ diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index e1cd913aad..681a9e2f0e 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -63,6 +63,7 @@ typedef struct { typedef struct { char *id; char *uuid; + char *stable_id; char *interface_name; char *type; char *master; @@ -99,6 +100,7 @@ enum { PROP_GATEWAY_PING_TIMEOUT, PROP_METERED, PROP_LLDP, + PROP_STABLE_ID, LAST_PROP }; @@ -231,6 +233,24 @@ nm_setting_connection_get_uuid (NMSettingConnection *setting) } /** + * nm_setting_connection_get_stable_id: + * @setting: the #NMSettingConnection + * + * Returns the #NMSettingConnection:stable_id property of the connection. + * + * Returns: the stable-id for the connection + * + * Since: 1.4 + **/ +const char * +nm_setting_connection_get_stable_id (NMSettingConnection *setting) +{ + g_return_val_if_fail (NM_IS_SETTING_CONNECTION (setting), NULL); + + return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->stable_id; +} + +/** * nm_setting_connection_get_interface_name: * @setting: the #NMSettingConnection * @@ -1128,6 +1148,7 @@ finalize (GObject *object) g_free (priv->id); g_free (priv->uuid); + g_free (priv->stable_id); g_free (priv->interface_name); g_free (priv->type); g_free (priv->zone); @@ -1174,6 +1195,10 @@ set_property (GObject *object, guint prop_id, g_free (priv->uuid); priv->uuid = g_value_dup_string (value); break; + case PROP_STABLE_ID: + g_free (priv->stable_id); + priv->stable_id = g_value_dup_string (value); + break; case PROP_INTERFACE_NAME: g_free (priv->interface_name); priv->interface_name = g_value_dup_string (value); @@ -1260,6 +1285,9 @@ get_property (GObject *object, guint prop_id, case PROP_UUID: g_value_set_string (value, nm_setting_connection_get_uuid (setting)); break; + case PROP_STABLE_ID: + g_value_set_string (value, nm_setting_connection_get_stable_id (setting)); + break; case PROP_INTERFACE_NAME: g_value_set_string (value, nm_setting_connection_get_interface_name (setting)); break; @@ -1368,7 +1396,7 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) * property: uuid * variable: UUID(+) * description: UUID for the connection profile. When missing, NetworkManager - * creates the UUID itself (by hashing the file). + * creates the UUID itself (by hashing the filename). * ---end--- */ g_object_class_install_property @@ -1380,6 +1408,28 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class) G_PARAM_STATIC_STRINGS)); /** + * NMSettingConnection:stable-id: + * + * This token to generate stable IDs for the connection. If unset, + * the UUID will be used instead. + * + * Since: 1.4 + **/ + /* ---ifcfg-rh--- + * property: stable-id + * variable: STABLE_ID(+) + * description: Token to generate stable IDs. + * ---end--- + */ + g_object_class_install_property + (object_class, PROP_STABLE_ID, + g_param_spec_string (NM_SETTING_CONNECTION_STABLE_ID, "", "", + NULL, + G_PARAM_READWRITE | + NM_SETTING_PARAM_FUZZY_IGNORE | + G_PARAM_STATIC_STRINGS)); + + /** * NMSettingConnection:interface-name: * * The name of the network interface this connection is bound to. If not diff --git a/libnm-core/nm-setting-connection.h b/libnm-core/nm-setting-connection.h index 0d4966f05a..67263d1f01 100644 --- a/libnm-core/nm-setting-connection.h +++ b/libnm-core/nm-setting-connection.h @@ -46,6 +46,7 @@ G_BEGIN_DECLS #define NM_SETTING_CONNECTION_ID "id" #define NM_SETTING_CONNECTION_UUID "uuid" +#define NM_SETTING_CONNECTION_STABLE_ID "stable-id" #define NM_SETTING_CONNECTION_INTERFACE_NAME "interface-name" #define NM_SETTING_CONNECTION_TYPE "type" #define NM_SETTING_CONNECTION_AUTOCONNECT "autoconnect" @@ -116,6 +117,8 @@ GType nm_setting_connection_get_type (void); NMSetting * nm_setting_connection_new (void); const char *nm_setting_connection_get_id (NMSettingConnection *setting); const char *nm_setting_connection_get_uuid (NMSettingConnection *setting); +NM_AVAILABLE_IN_1_4 +const char *nm_setting_connection_get_stable_id (NMSettingConnection *setting); const char *nm_setting_connection_get_interface_name (NMSettingConnection *setting); const char *nm_setting_connection_get_connection_type (NMSettingConnection *setting); gboolean nm_setting_connection_get_autoconnect (NMSettingConnection *setting); diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 9aaf82977d..7ff6b8d235 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -1916,6 +1916,7 @@ test_connection_diff_a_only (void) { NM_SETTING_CONNECTION_SETTING_NAME, { { NM_SETTING_CONNECTION_ID, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_UUID, NM_SETTING_DIFF_RESULT_IN_A }, + { NM_SETTING_CONNECTION_STABLE_ID, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_INTERFACE_NAME, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_TYPE, NM_SETTING_DIFF_RESULT_IN_A }, { NM_SETTING_CONNECTION_TIMESTAMP, NM_SETTING_DIFF_RESULT_IN_A }, diff --git a/libnm/libnm.ver b/libnm/libnm.ver index 41f650f008..47f6598ff6 100644 --- a/libnm/libnm.ver +++ b/libnm/libnm.ver @@ -1066,6 +1066,7 @@ libnm_1_2_4 { libnm_1_4_0 { global: nm_device_team_get_config; + nm_setting_connection_get_stable_id; nm_setting_ip6_config_get_token; nm_setting_ip_config_get_dns_priority; nm_vpn_editor_plugin_get_plugin_info; diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index b933e1a5fa..192327043b 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -128,6 +128,7 @@ make_connection_setting (const char *file, NMSettingConnectionLldp lldp; const char *ifcfg_name = NULL; char *new_id, *uuid = NULL, *zone = NULL, *value; + gs_free char *stable_id = NULL; ifcfg_name = utils_get_ifcfg_name (file, TRUE); if (!ifcfg_name) @@ -146,9 +147,12 @@ make_connection_setting (const char *file, uuid = nm_utils_uuid_generate_from_string (ifcfg->fileName, -1, NM_UTILS_UUID_TYPE_LEGACY, NULL); } + stable_id = svGetValue (ifcfg, "STABLE_ID", FALSE); + g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, type, NM_SETTING_CONNECTION_UUID, uuid, + NM_SETTING_CONNECTION_STABLE_ID, stable_id, NULL); g_free (uuid); diff --git a/src/settings/plugins/ifcfg-rh/writer.c b/src/settings/plugins/ifcfg-rh/writer.c index 2864078a48..2de8a9a1f7 100644 --- a/src/settings/plugins/ifcfg-rh/writer.c +++ b/src/settings/plugins/ifcfg-rh/writer.c @@ -1800,6 +1800,7 @@ write_connection_setting (NMSettingConnection *s_con, shvarFile *ifcfg) svSetValue (ifcfg, "NAME", nm_setting_connection_get_id (s_con), FALSE); svSetValue (ifcfg, "UUID", nm_setting_connection_get_uuid (s_con), FALSE); + svSetValue (ifcfg, "STABLE_ID", nm_setting_connection_get_stable_id (s_con), FALSE); svSetValue (ifcfg, "DEVICE", nm_setting_connection_get_interface_name (s_con), FALSE); svSetValue (ifcfg, "ONBOOT", nm_setting_connection_get_autoconnect (s_con) ? "yes" : "no", |