libnm-core: drop :interface-name properties on virtual NMSetting types

Remove the virtual :interface-name properties and their getters, and
use property overrides to do backward-compat handling when
serializing/deserializing.

Now when constructing an NMConnection from a hash, if the virtual
property is set and the NMSettingConnection property isn't, then the
override for NMSettingConnection:interface-name will set that property
to the value of the virtual interface-name. And when converting an
NMConnection to a hash, the overrides for the virtual properties will
return the value of NMSettingConnection:interface-name.
This commit is contained in:
Dan Winship 2014-08-04 19:57:20 -04:00
parent 40bb402898
commit 6217c1e74c
15 changed files with 203 additions and 383 deletions

View file

@ -510,58 +510,6 @@ nm_connection_diff (NMConnection *a,
return *out_settings ? FALSE : TRUE;
}
static gboolean
_normalize_virtual_iface_name (NMConnection *self)
{
NMConnectionPrivate *priv = NM_CONNECTION_GET_PRIVATE (self);
GHashTableIter h_iter;
NMSetting *setting;
NMSettingConnection *s_con;
const char *interface_name;
char *virtual_iface_name = NULL;
gboolean was_modified = FALSE;
const char *prop_name = NULL;
/* search for settings that might need normalization of the interface name. */
g_hash_table_iter_init (&h_iter, priv->settings);
while ( !prop_name
&& g_hash_table_iter_next (&h_iter, NULL, (void **) &setting)) {
if (NM_IS_SETTING_BOND (setting))
prop_name = NM_SETTING_BOND_INTERFACE_NAME;
else if (NM_IS_SETTING_BRIDGE (setting))
prop_name = NM_SETTING_BRIDGE_INTERFACE_NAME;
else if (NM_IS_SETTING_TEAM (setting))
prop_name = NM_SETTING_TEAM_INTERFACE_NAME;
else if (NM_IS_SETTING_VLAN (setting))
prop_name = NM_SETTING_VLAN_INTERFACE_NAME;
}
if (!prop_name)
return FALSE;
s_con = nm_connection_get_setting_connection (self);
g_return_val_if_fail (s_con, FALSE);
interface_name = nm_setting_connection_get_interface_name (s_con);
/* read the potential virtual_iface_name from the setting. */
g_object_get (setting, prop_name, &virtual_iface_name, NULL);
if (g_strcmp0 (interface_name, virtual_iface_name) != 0) {
if (interface_name) {
/* interface_name is set and overwrites the virtual_iface_name. */
g_object_set (setting, prop_name, interface_name, NULL);
} else {
/* interface in NMSettingConnection must be set. */
g_object_set (s_con, NM_SETTING_CONNECTION_INTERFACE_NAME, virtual_iface_name, NULL);
}
was_modified = TRUE;
}
g_free (virtual_iface_name);
return was_modified;
}
static gboolean
_normalize_connection_type (NMConnection *self)
{
@ -924,7 +872,6 @@ nm_connection_normalize (NMConnection *connection,
* errors, because in that case we rather fail without touching the settings. */
was_modified |= _normalize_connection_type (connection);
was_modified |= _normalize_virtual_iface_name (connection);
was_modified |= _normalize_connection_slave_type (connection);
was_modified |= _normalize_ip_config (connection, parameters);
was_modified |= _normalize_infiniband_mtu (connection, parameters);

View file

@ -67,13 +67,11 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BOND)
#define NM_SETTING_BOND_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BOND, NMSettingBondPrivate))
typedef struct {
char *interface_name;
GHashTable *options;
} NMSettingBondPrivate;
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_OPTIONS,
LAST_PROP
};
@ -131,20 +129,6 @@ nm_setting_bond_new (void)
return (NMSetting *) g_object_new (NM_TYPE_SETTING_BOND, NULL);
}
/**
* nm_setting_bond_get_interface_name:
* @setting: the #NMSettingBond
*
* Returns: the #NMSettingBond:interface-name property of the setting
**/
const char *
nm_setting_bond_get_interface_name (NMSettingBond *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BOND (setting), NULL);
return NM_SETTING_BOND_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_bond_get_num_options:
* @setting: the #NMSettingBond
@ -662,13 +646,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
}
}
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_BOND_SETTING_NAME, NM_SETTING_BOND_INTERFACE_NAME,
NM_SETTING_BOND_ERROR,
NM_SETTING_BOND_ERROR_INVALID_PROPERTY,
NM_SETTING_BOND_ERROR_MISSING_PROPERTY,
all_settings, error);
return _nm_setting_verify_required_virtual_interface_name (all_settings, error);
}
static void
@ -687,7 +665,6 @@ finalize (GObject *object)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
g_free (priv->interface_name);
g_hash_table_destroy (priv->options);
G_OBJECT_CLASS (nm_setting_bond_parent_class)->finalize (object);
@ -707,10 +684,6 @@ set_property (GObject *object, guint prop_id,
GHashTable *new_hash;
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_free (priv->interface_name);
priv->interface_name = g_value_dup_string (value);
break;
case PROP_OPTIONS:
/* Must make a deep copy of the hash table here... */
g_hash_table_remove_all (priv->options);
@ -729,12 +702,8 @@ get_property (GObject *object, guint prop_id,
GValue *value, GParamSpec *pspec)
{
NMSettingBondPrivate *priv = NM_SETTING_BOND_GET_PRIVATE (object);
NMSettingBond *setting = NM_SETTING_BOND (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, nm_setting_bond_get_interface_name (setting));
break;
case PROP_OPTIONS:
g_value_set_boxed (value, priv->options);
break;
@ -759,19 +728,6 @@ nm_setting_bond_class_init (NMSettingBondClass *setting_class)
parent_class->verify = verify;
/* Properties */
/**
* NMSettingBond:interface-name:
*
* The name of the virtual in-kernel bonding network interface
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_BOND_INTERFACE_NAME, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBond:options:
*
@ -786,4 +742,8 @@ nm_setting_bond_class_init (NMSettingBondClass *setting_class)
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_add_dbus_only_property (parent_class, "interface-name", G_TYPE_STRING,
_nm_setting_get_deprecated_virtual_interface_name,
_nm_setting_set_deprecated_virtual_interface_name);
}

View file

@ -57,7 +57,6 @@ typedef enum {
#define NM_SETTING_BOND_ERROR nm_setting_bond_error_quark ()
GQuark nm_setting_bond_error_quark (void);
#define NM_SETTING_BOND_INTERFACE_NAME "interface-name"
#define NM_SETTING_BOND_OPTIONS "options"
/* Valid options for the 'options' property */
@ -90,7 +89,6 @@ typedef struct {
GType nm_setting_bond_get_type (void);
NMSetting * nm_setting_bond_new (void);
const char * nm_setting_bond_get_interface_name (NMSettingBond *setting);
guint32 nm_setting_bond_get_num_options (NMSettingBond *setting);
gboolean nm_setting_bond_get_option (NMSettingBond *setting,
guint32 idx,

View file

@ -65,7 +65,6 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_BRIDGE)
#define NM_SETTING_BRIDGE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_BRIDGE, NMSettingBridgePrivate))
typedef struct {
char * interface_name;
GByteArray *mac_address;
gboolean stp;
guint16 priority;
@ -77,7 +76,6 @@ typedef struct {
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_MAC_ADDRESS,
PROP_STP,
PROP_PRIORITY,
@ -101,20 +99,6 @@ nm_setting_bridge_new (void)
return (NMSetting *) g_object_new (NM_TYPE_SETTING_BRIDGE, NULL);
}
/**
* nm_setting_bridge_get_interface_name:
* @setting: the #NMSettingBridge
*
* Returns: the #NMSettingBridge:interface-name property of the setting
**/
const char *
nm_setting_bridge_get_interface_name (NMSettingBridge *setting)
{
g_return_val_if_fail (NM_IS_SETTING_BRIDGE (setting), 0);
return NM_SETTING_BRIDGE_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_bridge_get_mac_address:
* @setting: the #NMSettingBridge
@ -288,13 +272,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
error))
return FALSE;
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_BRIDGE_SETTING_NAME, NM_SETTING_BRIDGE_INTERFACE_NAME,
NM_SETTING_BRIDGE_ERROR,
NM_SETTING_BRIDGE_ERROR_INVALID_PROPERTY,
NM_SETTING_BRIDGE_ERROR_MISSING_PROPERTY,
all_settings, error);
return _nm_setting_verify_required_virtual_interface_name (all_settings, error);
}
static void
@ -307,8 +285,6 @@ finalize (GObject *object)
{
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
g_free (priv->interface_name);
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
@ -322,10 +298,6 @@ set_property (GObject *object, guint prop_id,
NMSettingBridgePrivate *priv = NM_SETTING_BRIDGE_GET_PRIVATE (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_free (priv->interface_name);
priv->interface_name = g_value_dup_string (value);
break;
case PROP_MAC_ADDRESS:
if (priv->mac_address)
g_byte_array_free (priv->mac_address, TRUE);
@ -363,9 +335,6 @@ get_property (GObject *object, guint prop_id,
NMSettingBridge *setting = NM_SETTING_BRIDGE (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, nm_setting_bridge_get_interface_name (setting));
break;
case PROP_MAC_ADDRESS:
g_value_set_boxed (value, nm_setting_bridge_get_mac_address (setting));
break;
@ -408,19 +377,6 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *setting_class)
parent_class->verify = verify;
/* Properties */
/**
* NMSettingBridge:interface-name:
*
* The name of the virtual in-kernel bridging network interface
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_BRIDGE_INTERFACE_NAME, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingBridge:mac-address:
*
@ -521,4 +477,8 @@ nm_setting_bridge_class_init (NMSettingBridgeClass *setting_class)
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_add_dbus_only_property (parent_class, "interface-name", G_TYPE_STRING,
_nm_setting_get_deprecated_virtual_interface_name,
_nm_setting_set_deprecated_virtual_interface_name);
}

View file

@ -55,7 +55,6 @@ typedef enum {
#define NM_SETTING_BRIDGE_ERROR nm_setting_bridge_error_quark ()
GQuark nm_setting_bridge_error_quark (void);
#define NM_SETTING_BRIDGE_INTERFACE_NAME "interface-name"
#define NM_SETTING_BRIDGE_MAC_ADDRESS "mac-address"
#define NM_SETTING_BRIDGE_STP "stp"
#define NM_SETTING_BRIDGE_PRIORITY "priority"
@ -79,8 +78,6 @@ GType nm_setting_bridge_get_type (void);
NMSetting * nm_setting_bridge_new (void);
const char * nm_setting_bridge_get_interface_name (NMSettingBridge *setting);
const GByteArray *nm_setting_bridge_get_mac_address (NMSettingBridge *setting);
gboolean nm_setting_bridge_get_stp (NMSettingBridge *setting);

View file

@ -949,6 +949,52 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return TRUE;
}
static gboolean
nm_setting_connection_no_interface_name (NMSetting *setting,
GHashTable *connection_hash,
const char *property,
GError **error)
{
GHashTable *setting_hash;
const char *interface_name;
GValue *value;
/* Check if there's a deprecated virtual interface-name property to steal */
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_BOND_SETTING_NAME);
if (!setting_hash)
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_BRIDGE_SETTING_NAME);
if (!setting_hash)
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_TEAM_SETTING_NAME);
if (!setting_hash)
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_VLAN_SETTING_NAME);
if (!setting_hash)
return TRUE;
/* All of the deprecated virtual interface name properties were named "interface-name". */
value = g_hash_table_lookup (setting_hash, "interface-name");
if (!value)
return TRUE;
interface_name = g_value_get_string (value);
if (!interface_name)
return TRUE;
if (!nm_utils_iface_valid_name (interface_name)) {
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return FALSE;
}
g_object_set (G_OBJECT (setting),
NM_SETTING_CONNECTION_INTERFACE_NAME, interface_name,
NULL);
return TRUE;
}
static gboolean
compare_property (NMSetting *setting,
NMSetting *other,
@ -1204,6 +1250,10 @@ nm_setting_connection_class_init (NMSettingConnectionClass *setting_class)
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_override_property (parent_class, NM_SETTING_CONNECTION_INTERFACE_NAME,
G_TYPE_STRING,
NULL, NULL,
nm_setting_connection_no_interface_name);
/**
* NMSettingConnection:type:

View file

@ -101,15 +101,18 @@ NMSetting * _nm_setting_find_in_list_required (GSList *all_settings,
const char *error_prefix_setting_name,
const char *error_prefix_property_name);
NMSettingVerifyResult _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name,
gboolean allow_missing,
const char *setting_name,
const char *setting_property,
GQuark error_quark,
gint e_invalid_property,
gint e_missing_property,
GSList *all_settings,
GError **error);
NMSettingVerifyResult _nm_setting_verify_required_virtual_interface_name (GSList *all_settings,
GError **error);
gboolean _nm_setting_get_deprecated_virtual_interface_name (NMSetting *setting,
NMConnection *connection,
const char *property,
GValue *value);
gboolean _nm_setting_set_deprecated_virtual_interface_name (NMSetting *setting,
GHashTable *connection_hash,
const char *property,
const GValue *value,
GError **error);
NMSettingVerifyResult _nm_setting_verify (NMSetting *setting,
GSList *all_settings,

View file

@ -63,13 +63,11 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_TEAM)
#define NM_SETTING_TEAM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_TEAM, NMSettingTeamPrivate))
typedef struct {
char *interface_name;
char *config;
} NMSettingTeamPrivate;
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_CONFIG,
LAST_PROP
};
@ -87,20 +85,6 @@ nm_setting_team_new (void)
return (NMSetting *) g_object_new (NM_TYPE_SETTING_TEAM, NULL);
}
/**
* nm_setting_team_get_interface_name:
* @setting: the #NMSettingTeam
*
* Returns: the #NMSettingTeam:interface-name property of the setting
**/
const char *
nm_setting_team_get_interface_name (NMSettingTeam *setting)
{
g_return_val_if_fail (NM_IS_SETTING_TEAM (setting), NULL);
return NM_SETTING_TEAM_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_team_get_config:
* @setting: the #NMSettingTeam
@ -118,15 +102,7 @@ nm_setting_team_get_config (NMSettingTeam *setting)
static gboolean
verify (NMSetting *setting, GSList *all_settings, GError **error)
{
NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, FALSE,
NM_SETTING_TEAM_SETTING_NAME, NM_SETTING_TEAM_INTERFACE_NAME,
NM_SETTING_TEAM_ERROR,
NM_SETTING_TEAM_ERROR_INVALID_PROPERTY,
NM_SETTING_TEAM_ERROR_MISSING_PROPERTY,
all_settings, error);
return _nm_setting_verify_required_virtual_interface_name (all_settings, error);
}
static void
@ -139,7 +115,6 @@ finalize (GObject *object)
{
NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (object);
g_free (priv->interface_name);
g_free (priv->config);
G_OBJECT_CLASS (nm_setting_team_parent_class)->finalize (object);
@ -152,10 +127,6 @@ set_property (GObject *object, guint prop_id,
NMSettingTeamPrivate *priv = NM_SETTING_TEAM_GET_PRIVATE (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_free (priv->interface_name);
priv->interface_name = g_value_dup_string (value);
break;
case PROP_CONFIG:
g_free (priv->config);
priv->config = g_value_dup_string (value);
@ -173,9 +144,6 @@ get_property (GObject *object, guint prop_id,
NMSettingTeam *setting = NM_SETTING_TEAM (object);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, nm_setting_team_get_interface_name (setting));
break;
case PROP_CONFIG:
g_value_set_string (value, nm_setting_team_get_config (setting));
break;
@ -200,19 +168,6 @@ nm_setting_team_class_init (NMSettingTeamClass *setting_class)
parent_class->verify = verify;
/* Properties */
/**
* NMSettingTeam:interface-name:
*
* The name of the virtual in-kernel team network interface
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_TEAM_INTERFACE_NAME, "", "",
NULL,
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingTeam:config:
*
@ -228,4 +183,8 @@ nm_setting_team_class_init (NMSettingTeamClass *setting_class)
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_add_dbus_only_property (parent_class, "interface-name", G_TYPE_STRING,
_nm_setting_get_deprecated_virtual_interface_name,
_nm_setting_set_deprecated_virtual_interface_name);
}

View file

@ -54,7 +54,6 @@ typedef enum {
#define NM_SETTING_TEAM_ERROR nm_setting_team_error_quark ()
GQuark nm_setting_team_error_quark (void);
#define NM_SETTING_TEAM_INTERFACE_NAME "interface-name"
#define NM_SETTING_TEAM_CONFIG "config"
typedef struct {
@ -72,7 +71,6 @@ GType nm_setting_team_get_type (void);
NMSetting * nm_setting_team_new (void);
const char * nm_setting_team_get_interface_name (NMSettingTeam *setting);
const char * nm_setting_team_get_config (NMSettingTeam *setting);
G_END_DECLS

View file

@ -63,7 +63,6 @@ NM_SETTING_REGISTER_TYPE (NM_TYPE_SETTING_VLAN)
#define NM_SETTING_VLAN_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_SETTING_VLAN, NMSettingVlanPrivate))
typedef struct {
char *interface_name;
char *parent;
guint32 id;
guint32 flags;
@ -73,7 +72,6 @@ typedef struct {
enum {
PROP_0,
PROP_INTERFACE_NAME,
PROP_PARENT,
PROP_ID,
PROP_FLAGS,
@ -103,19 +101,6 @@ nm_setting_vlan_new (void)
return (NMSetting *) g_object_new (NM_TYPE_SETTING_VLAN, NULL);
}
/**
* nm_setting_vlan_get_interface_name:
* @setting: the #NMSettingVlan
*
* Returns: the #NMSettingVlan:interface_name property of the setting
**/
const char *
nm_setting_vlan_get_interface_name (NMSettingVlan *setting)
{
g_return_val_if_fail (NM_IS_SETTING_VLAN (setting), NULL);
return NM_SETTING_VLAN_GET_PRIVATE (setting)->interface_name;
}
/**
* nm_setting_vlan_get_parent:
* @setting: the #NMSettingVlan
@ -586,17 +571,7 @@ verify (NMSetting *setting, GSList *all_settings, GError **error)
return FALSE;
}
/* If interface_name is specified, it must be a valid interface name. We
* don't check that it matches parent and/or id, because we allow
* renaming vlans to arbitrary names.
*/
return _nm_setting_verify_deprecated_virtual_iface_name (
priv->interface_name, TRUE,
NM_SETTING_VLAN_SETTING_NAME, NM_SETTING_VLAN_INTERFACE_NAME,
NM_SETTING_VLAN_ERROR,
NM_SETTING_VLAN_ERROR_INVALID_PROPERTY,
NM_SETTING_VLAN_ERROR_MISSING_PROPERTY,
all_settings, error);
return TRUE;
}
static GSList *
@ -622,10 +597,6 @@ set_property (GObject *object, guint prop_id,
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_free (priv->interface_name);
priv->interface_name = g_value_dup_string (value);
break;
case PROP_PARENT:
g_free (priv->parent);
priv->parent = g_value_dup_string (value);
@ -673,9 +644,6 @@ get_property (GObject *object, guint prop_id,
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
switch (prop_id) {
case PROP_INTERFACE_NAME:
g_value_set_string (value, priv->interface_name);
break;
case PROP_PARENT:
g_value_set_string (value, priv->parent);
break;
@ -703,7 +671,6 @@ finalize (GObject *object)
NMSettingVlan *setting = NM_SETTING_VLAN (object);
NMSettingVlanPrivate *priv = NM_SETTING_VLAN_GET_PRIVATE (setting);
g_free (priv->interface_name);
g_free (priv->parent);
g_slist_free_full (priv->ingress_priority_map, g_free);
g_slist_free_full (priv->egress_priority_map, g_free);
@ -727,24 +694,6 @@ nm_setting_vlan_class_init (NMSettingVlanClass *setting_class)
/* Properties */
/**
* NMSettingVlan:interface-name:
*
* If given, specifies the kernel name of the VLAN interface. If not given,
* a default name will be constructed from the interface described by the
* parent interface and the #NMSettingVlan:id property, eg "eth2.1". The
* parent interface may be given by the #NMSettingVlan:parent property or by
* the #NMSettingWired:mac-address property of an #NMSettingWired setting.
**/
g_object_class_install_property
(object_class, PROP_INTERFACE_NAME,
g_param_spec_string (NM_SETTING_VLAN_INTERFACE_NAME, "", "",
NULL,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
/**
* NMSettingVlan:parent:
*
@ -824,4 +773,8 @@ nm_setting_vlan_class_init (NMSettingVlanClass *setting_class)
G_PARAM_READWRITE |
NM_SETTING_PARAM_INFERRABLE |
G_PARAM_STATIC_STRINGS));
_nm_setting_class_add_dbus_only_property (parent_class, "interface-name", G_TYPE_STRING,
_nm_setting_get_deprecated_virtual_interface_name,
_nm_setting_set_deprecated_virtual_interface_name);
}

View file

@ -59,7 +59,6 @@ typedef enum {
#define NM_SETTING_VLAN_ERROR nm_setting_vlan_error_quark ()
GQuark nm_setting_vlan_error_quark (void);
#define NM_SETTING_VLAN_INTERFACE_NAME "interface-name"
#define NM_SETTING_VLAN_PARENT "parent"
#define NM_SETTING_VLAN_ID "id"
#define NM_SETTING_VLAN_FLAGS "flags"
@ -113,7 +112,6 @@ typedef enum {
GType nm_setting_vlan_get_type (void);
NMSetting *nm_setting_vlan_new (void);
const char *nm_setting_vlan_get_interface_name (NMSettingVlan *setting);
const char *nm_setting_vlan_get_parent (NMSettingVlan *setting);
guint32 nm_setting_vlan_get_id (NMSettingVlan *setting);
guint32 nm_setting_vlan_get_flags (NMSettingVlan *setting);

View file

@ -273,6 +273,19 @@ nm_setting_lookup_type_by_quark (GQuark error_quark)
return G_TYPE_INVALID;
}
static GQuark
_nm_setting_lookup_error_quark (const char *name)
{
SettingInfo *info;
g_return_val_if_fail (name != NULL, 0);
_ensure_registered ();
info = g_hash_table_lookup (registered_settings, name);
return info ? info->error_quark : 0;
}
gint
_nm_setting_compare_priority (gconstpointer a, gconstpointer b)
{
@ -1623,41 +1636,15 @@ _nm_setting_find_in_list_required (GSList *all_settings,
}
NMSettingVerifyResult
_nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name,
gboolean allow_missing,
const char *setting_name,
const char *setting_property,
GQuark error_quark,
gint e_invalid_property,
gint e_missing_property,
GSList *all_settings,
GError **error)
_nm_setting_verify_required_virtual_interface_name (GSList *all_settings,
GError **error)
{
NMSettingConnection *s_con;
const char *con_name;
if (!all_settings) {
/* nm_setting_verify() was called without passing on any other settings.
* Perform a relaxed verification, the setting might be valid when checked
* together with a NMSettingConnection as part of a NMConnection. */
if (interface_name && !nm_utils_iface_valid_name (interface_name)) {
/* Only if the interace name is invalid, there is an normalizable warning */
g_set_error_literal (error,
error_quark,
e_invalid_property,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", setting_name, setting_property);
return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
return NM_SETTING_VERIFY_SUCCESS;
}
const char *interface_name;
s_con = NM_SETTING_CONNECTION (nm_setting_find_in_list (all_settings, NM_SETTING_CONNECTION_SETTING_NAME));
con_name = s_con ? nm_setting_connection_get_interface_name (s_con) : NULL;
if (!interface_name && !con_name) {
if (allow_missing)
return NM_SETTING_VERIFY_SUCCESS;
interface_name = s_con ? nm_setting_connection_get_interface_name (s_con) : NULL;
if (!interface_name) {
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
@ -1665,48 +1652,69 @@ _nm_setting_verify_deprecated_virtual_iface_name (const char *interface_name,
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return NM_SETTING_VERIFY_ERROR;
}
if (!con_name && !nm_utils_iface_valid_name (interface_name)) {
/* the interface_name is invalid, we cannot normalize it. Only do this if !con_name,
* because if con_name is set, it can overwrite interface_name. */
g_set_error_literal (error,
error_quark,
e_invalid_property,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", setting_name, setting_property);
return NM_SETTING_VERIFY_ERROR;
}
if (!con_name) {
/* NMSettingConnection has interface not set, it should be normalized to interface_name */
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY,
_("property is missing"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
if (!nm_utils_iface_valid_name (con_name)) {
/* NMSettingConnection:interface_name is invalid, we cannot normalize it. */
g_set_error_literal (error,
NM_SETTING_CONNECTION_ERROR,
NM_SETTING_CONNECTION_ERROR_INVALID_PROPERTY,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME);
return NM_SETTING_VERIFY_ERROR;
}
if (interface_name && strcmp (con_name, interface_name) != 0) {
/* con_name and interface_name are different. It can be normalized by setting interface_name
* to con_name. */
g_set_error_literal (error,
error_quark,
e_invalid_property,
_("property is invalid"));
g_prefix_error (error, "%s.%s: ", setting_name, setting_property);
return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
return NM_SETTING_VERIFY_SUCCESS;
}
gboolean
_nm_setting_get_deprecated_virtual_interface_name (NMSetting *setting,
NMConnection *connection,
const char *property,
GValue *value)
{
NMSettingConnection *s_con;
s_con = nm_connection_get_setting_connection (connection);
g_return_val_if_fail (s_con != NULL, FALSE);
if (nm_setting_connection_get_interface_name (s_con)) {
g_value_set_string (value, nm_setting_connection_get_interface_name (s_con));
return TRUE;
} else
return FALSE;
}
gboolean
_nm_setting_set_deprecated_virtual_interface_name (NMSetting *setting,
GHashTable *connection_hash,
const char *property,
const GValue *value,
GError **error)
{
const char *interface_name;
GQuark error_domain;
char *error_enum_name;
GEnumClass *enum_class;
GEnumValue *enum_val;
int error_code = 0;
/* If the virtual setting type hash contains an interface name, it must be
* valid (even if it's going to be ignored in favor of
* NMSettingConnection:interface-name). Other than that, we don't have to
* check anything here; NMSettingConnection:interface-name will do the rest.
*/
interface_name = g_value_get_string (value);
if (!interface_name || nm_utils_iface_valid_name (interface_name))
return TRUE;
/* For compatibility reasons, we have to use the right error domain... */
error_domain = _nm_setting_lookup_error_quark (nm_setting_get_name (setting));
error_enum_name = g_strdup_printf ("%sError", G_OBJECT_TYPE_NAME (setting));
enum_class = g_type_class_ref (g_type_from_name (error_enum_name));
g_free (error_enum_name);
if (enum_class) {
enum_val = g_enum_get_value_by_nick (enum_class, "InvalidProperty");
if (enum_val)
error_code = enum_val->value;
g_type_class_unref (enum_class);
}
g_set_error_literal (error, error_domain, error_code,
_("invalid value in compatibility property"));
g_prefix_error (error, "%s.%s: ", nm_setting_get_name (setting), property);
return FALSE;
}
/*****************************************************************************/
static void

View file

@ -2668,42 +2668,18 @@ test_setting_old_uuid (void)
g_assert (success == TRUE);
}
static void
test_connection_normalize_connection_interface_name (void)
{
NMConnection *con;
NMSettingConnection *s_con;
NMSettingBond *s_bond;
con = nmtst_create_minimal_connection ("test1",
"22001632-bbb4-4616-b277-363dce3dfb5b",
NM_SETTING_BOND_SETTING_NAME,
&s_con);
s_bond = nm_connection_get_setting_bond (con);
g_object_set (G_OBJECT (s_bond),
NM_SETTING_BOND_INTERFACE_NAME, "bond-x",
NULL);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, NULL);
/* for backward compatiblity, normalizes the interface name */
nmtst_assert_connection_verifies_after_normalization (con, NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, "bond-x");
g_object_unref (con);
}
/*
* Test normalization of interface-name
**/
static void
test_connection_normalize_virtual_iface_name (void)
{
gs_unref_object NMConnection *con = NULL;
NMConnection *con = NULL;
NMSettingConnection *s_con;
NMSettingVlan *s_vlan;
GHashTable *connection_hash, *setting_hash;
GValue *value;
GError *error = NULL;
const char *IFACE_NAME = "iface";
const char *IFACE_VIRT = "iface-X";
@ -2729,33 +2705,55 @@ test_connection_normalize_virtual_iface_name (void)
NULL);
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, IFACE_NAME, NULL);
g_object_set (G_OBJECT (s_vlan), NM_SETTING_VLAN_INTERFACE_NAME, IFACE_VIRT, NULL);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_VIRT);
nmtst_assert_connection_verifies_after_normalization (con, NM_SETTING_VLAN_ERROR, NM_SETTING_VLAN_ERROR_INVALID_PROPERTY);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_NAME);
connection_hash = nm_connection_to_dbus (con, NM_CONNECTION_SERIALIZE_ALL);
g_object_unref (con);
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, IFACE_NAME, NULL);
g_object_set (G_OBJECT (s_vlan), NM_SETTING_VLAN_INTERFACE_NAME, NULL, NULL);
/* Serialized form should include vlan.interface-name as well. */
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_VLAN_SETTING_NAME);
g_assert (setting_hash != NULL);
value = g_hash_table_lookup (setting_hash, "interface-name");
g_assert (value != NULL);
g_assert (G_VALUE_HOLDS_STRING (value));
g_assert_cmpstr (g_value_get_string (value), ==, IFACE_NAME);
/* If vlan.interface-name is invalid, deserialization should fail, with the
* correct error.
*/
g_value_set_string (value, ":::this-is-not-a-valid-interface-name:::");
con = nm_simple_connection_new_from_dbus (connection_hash, &error);
g_assert_error (error, NM_SETTING_VLAN_ERROR, NM_SETTING_VLAN_ERROR_INVALID_PROPERTY);
g_clear_error (&error);
/* If vlan.interface-name is valid, but doesn't match, it will be ignored. */
g_value_set_string (value, IFACE_VIRT);
con = nm_simple_connection_new_from_dbus (connection_hash, &error);
g_assert_no_error (error);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, NULL);
nmtst_assert_connection_verifies_without_normalization (con);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, NULL);
s_con = nm_connection_get_setting_connection (con);
g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, IFACE_NAME);
g_object_unref (con);
/* But removing connection.interface-name should result in vlan.connection-name
* being "promoted".
*/
setting_hash = g_hash_table_lookup (connection_hash, NM_SETTING_CONNECTION_SETTING_NAME);
g_assert (setting_hash != NULL);
g_hash_table_remove (setting_hash, NM_SETTING_CONNECTION_INTERFACE_NAME);
g_object_set (G_OBJECT (s_con), NM_SETTING_CONNECTION_INTERFACE_NAME, NULL, NULL);
g_object_set (G_OBJECT (s_vlan), NM_SETTING_VLAN_INTERFACE_NAME, IFACE_NAME, NULL);
con = nm_simple_connection_new_from_dbus (connection_hash, &error);
g_assert_no_error (error);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, NULL);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_NAME);
nmtst_assert_connection_verifies_after_normalization (con, NM_SETTING_CONNECTION_ERROR, NM_SETTING_CONNECTION_ERROR_MISSING_PROPERTY);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_NAME);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_VIRT);
s_con = nm_connection_get_setting_connection (con);
g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, IFACE_VIRT);
g_object_unref (con);
g_hash_table_unref (connection_hash);
}
static void
@ -3227,7 +3225,6 @@ int main (int argc, char **argv)
g_test_add_func ("/core/general/test_connection_replace_settings_from_connection", test_connection_replace_settings_from_connection);
g_test_add_func ("/core/general/test_connection_replace_settings_bad", test_connection_replace_settings_bad);
g_test_add_func ("/core/general/test_connection_new_from_dbus", test_connection_new_from_dbus);
g_test_add_func ("/core/general/test_connection_normalize_connection_interface_name", test_connection_normalize_connection_interface_name);
g_test_add_func ("/core/general/test_connection_normalize_virtual_iface_name", test_connection_normalize_virtual_iface_name);
g_test_add_func ("/core/general/test_connection_normalize_type", test_connection_normalize_type);
g_test_add_func ("/core/general/test_connection_normalize_slave_type_1", test_connection_normalize_slave_type_1);

View file

@ -472,7 +472,6 @@ global:
nm_setting_bond_add_option;
nm_setting_bond_error_get_type;
nm_setting_bond_error_quark;
nm_setting_bond_get_interface_name;
nm_setting_bond_get_num_options;
nm_setting_bond_get_option;
nm_setting_bond_get_option_by_name;
@ -487,7 +486,6 @@ global:
nm_setting_bridge_get_ageing_time;
nm_setting_bridge_get_forward_delay;
nm_setting_bridge_get_hello_time;
nm_setting_bridge_get_interface_name;
nm_setting_bridge_get_mac_address;
nm_setting_bridge_get_max_age;
nm_setting_bridge_get_priority;
@ -728,7 +726,6 @@ global:
nm_setting_team_error_get_type;
nm_setting_team_error_quark;
nm_setting_team_get_config;
nm_setting_team_get_interface_name;
nm_setting_team_get_type;
nm_setting_team_new;
nm_setting_team_port_error_get_type;
@ -745,7 +742,6 @@ global:
nm_setting_vlan_error_quark;
nm_setting_vlan_get_flags;
nm_setting_vlan_get_id;
nm_setting_vlan_get_interface_name;
nm_setting_vlan_get_num_priorities;
nm_setting_vlan_get_parent;
nm_setting_vlan_get_priority;

View file

@ -2980,10 +2980,6 @@ test_write_bridge_main (void)
g_assert (s_bridge);
nm_connection_add_setting (connection, NM_SETTING (s_bridge));
g_object_set (s_bridge,
NM_SETTING_BRIDGE_INTERFACE_NAME, "br0",
NULL);
/* IP4 setting */
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
g_assert (s_ip4);