mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 14:10:36 +01:00
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.
This commit is contained in:
parent
c7cee12189
commit
3f3ea1df21
7 changed files with 102 additions and 31 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
};
|
||||
|
|
@ -230,6 +232,24 @@ nm_setting_connection_get_uuid (NMSettingConnection *setting)
|
|||
return NM_SETTING_CONNECTION_GET_PRIVATE (setting)->uuid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
@ -1379,6 +1407,28 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
|
|||
NM_SETTING_PARAM_FUZZY_IGNORE |
|
||||
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:
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue