settings: simplify property setter from GVariant to NMSettingConnection:interface-name

The interface-name property has several deprecated aliases, like
"bridge.interface-name". For backward compatibility, we keep handling
them.

In particular, the "missing_from_dbus_fcn" handler is set. This handles
the case where GVariant only contains the deprecated form, but not
"connection.interface-name".

Previously, from_dbus_fcn() would check whether the deprecated form was
present, and -- only if that form was invalid -- prefer it. The idea was
to fail validation if the deprecated property was invalid.

I think that is not necessary. Just completely ignore the deprecated property,
if the new property is present.

What might make sense is to check whether the deprecated and the new
form are both present, that they are identical. However, I don't think
that is worth the effort.
This commit is contained in:
Thomas Haller 2020-02-17 17:40:17 +01:00
parent 47a654d398
commit f725209bb4
2 changed files with 4 additions and 30 deletions

View file

@ -1279,32 +1279,6 @@ find_virtual_interface_name (GVariant *connection_dict,
return interface_name;
}
static gboolean
nm_setting_connection_set_interface_name (NMSetting *setting,
GVariant *connection_dict,
const char *property,
GVariant *value,
NMSettingParseFlags parse_flags,
GError **error)
{
const char *interface_name;
gs_unref_variant GVariant *variant_to_free = NULL;
/* For compatibility reasons, if there is an invalid virtual interface name,
* we need to make verification fail, even if that virtual name would be
* overridden by a valid connection.interface-name.
*/
interface_name = find_virtual_interface_name (connection_dict, &variant_to_free);
if (!interface_name || nm_utils_ifname_valid_kernel (interface_name, NULL))
interface_name = g_variant_get_string (value, NULL);
g_object_set (G_OBJECT (setting),
NM_SETTING_CONNECTION_INTERFACE_NAME, interface_name,
NULL);
return TRUE;
}
static gboolean
nm_setting_connection_no_interface_name (NMSetting *setting,
GVariant *connection_dict,
@ -1765,7 +1739,6 @@ nm_setting_connection_class_init (NMSettingConnectionClass *klass)
obj_properties[PROP_INTERFACE_NAME],
NM_SETT_INFO_PROPERT_TYPE (
.dbus_type = G_VARIANT_TYPE_STRING,
.from_dbus_fcn = nm_setting_connection_set_interface_name,
.missing_from_dbus_fcn = nm_setting_connection_no_interface_name,
));

View file

@ -4647,7 +4647,7 @@ test_connection_normalize_virtual_iface_name (void)
g_variant_unref (setting_dict);
g_variant_unref (var);
/* If vlan.interface-name is invalid, deserialization will fail. */
/* If vlan.interface-name will be ignored. */
NMTST_VARIANT_EDITOR (connection_dict,
NMTST_VARIANT_CHANGE_PROPERTY (NM_SETTING_VLAN_SETTING_NAME,
"interface-name",
@ -4656,8 +4656,9 @@ test_connection_normalize_virtual_iface_name (void)
);
con = _connection_new_from_dbus (connection_dict, &error);
g_assert_error (error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY);
g_clear_error (&error);
nmtst_assert_success (con, error);
g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
g_clear_object (&con);
/* If vlan.interface-name is valid, but doesn't match, it will be ignored. */
NMTST_VARIANT_EDITOR (connection_dict,