libnm: add special ignore function for NMSettInfoPropertType.compare_fcn()

This commit is contained in:
Thomas Haller 2021-06-29 17:03:37 +02:00
parent b78fb1c615
commit c7262c2290
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
7 changed files with 44 additions and 12 deletions

View file

@ -994,7 +994,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass)
"address-labels",
NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING_ARRAY,
.to_dbus_fcn = ip4_address_labels_get,
.compare_fcn = _nm_setting_property_compare_fcn_default, ));
.compare_fcn = _nm_setting_property_compare_fcn_ignore, ));
/* ---dbus---
* property: address-data
@ -1010,7 +1010,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass)
"address-data",
NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"),
.to_dbus_fcn = ip4_address_data_get,
.compare_fcn = _nm_setting_property_compare_fcn_default,
.compare_fcn = _nm_setting_property_compare_fcn_ignore,
.from_dbus_fcn = ip4_address_data_set, ));
/* ---dbus---
@ -1065,7 +1065,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass)
"route-data",
NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"),
.to_dbus_fcn = ip4_route_data_get,
.compare_fcn = _nm_setting_property_compare_fcn_default,
.compare_fcn = _nm_setting_property_compare_fcn_ignore,
.from_dbus_fcn = ip4_route_data_set, ));
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);

View file

@ -1062,7 +1062,7 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass)
"address-data",
NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"),
.to_dbus_fcn = ip6_address_data_get,
.compare_fcn = _nm_setting_property_compare_fcn_default,
.compare_fcn = _nm_setting_property_compare_fcn_ignore,
.from_dbus_fcn = ip6_address_data_set, ));
/* ---dbus---
@ -1105,7 +1105,7 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass)
"route-data",
NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"),
.to_dbus_fcn = ip6_route_data_get,
.compare_fcn = _nm_setting_property_compare_fcn_default,
.compare_fcn = _nm_setting_property_compare_fcn_ignore,
.from_dbus_fcn = ip6_route_data_set, ));
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);

View file

@ -303,6 +303,14 @@ gboolean _nm_setting_aggregate(NMSetting *setting, NMConnectionAggregateType typ
gboolean _nm_setting_slave_type_is_valid(const char *slave_type, const char **out_port_type);
NMTernary _nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMConnection * con_a,
NMSetting * set_a,
NMConnection * con_b,
NMSetting * set_b,
NMSettingCompareFlags flags);
NMTernary _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMConnection * con_a,

View file

@ -1926,7 +1926,7 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass)
"security",
NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING,
.to_dbus_fcn = nm_setting_wireless_get_security,
.compare_fcn = _nm_setting_property_compare_fcn_default, ));
.compare_fcn = _nm_setting_property_compare_fcn_ignore, ));
/**
* NMSettingWireless:wake-on-wlan:

View file

@ -1714,6 +1714,18 @@ _nm_setting_should_compare_secret_property(NMSetting * setting,
/*****************************************************************************/
NMTernary
_nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
NMConnection * con_a,
NMSetting * set_a,
NMConnection * con_b,
NMSetting * set_b,
NMSettingCompareFlags flags)
{
return NM_TERNARY_DEFAULT;
}
NMTernary
_nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info,
const NMSettInfoProperty *property_info,
@ -1726,7 +1738,7 @@ _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info,
const GParamSpec *param_spec = property_info->param_spec;
if (!param_spec)
return NM_TERNARY_DEFAULT;
return nm_assert_unreachable_val(NM_TERNARY_DEFAULT);
if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_FUZZY)
&& NM_FLAGS_ANY(param_spec->flags, NM_SETTING_PARAM_FUZZY_IGNORE | NM_SETTING_PARAM_SECRET))
@ -2730,7 +2742,7 @@ _nm_setting_get_deprecated_virtual_interface_name(const NMSettInfoSetting *
const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name =
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING,
.compare_fcn = _nm_setting_property_compare_fcn_default,
.compare_fcn = _nm_setting_property_compare_fcn_ignore,
.to_dbus_fcn =
_nm_setting_get_deprecated_virtual_interface_name, );
@ -2738,13 +2750,13 @@ const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i =
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(
G_VARIANT_TYPE_INT32,
/* No functions set. This property type is to silently ignore the value on D-Bus. */
.compare_fcn = _nm_setting_property_compare_fcn_default, );
.compare_fcn = _nm_setting_property_compare_fcn_ignore);
const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u =
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(
G_VARIANT_TYPE_UINT32,
/* No functions set. This property type is to silently ignore the value on D-Bus. */
.compare_fcn = _nm_setting_property_compare_fcn_default, );
.compare_fcn = _nm_setting_property_compare_fcn_ignore);
const NMSettInfoPropertType nm_sett_info_propert_type_plain_i =
NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_INT32,

View file

@ -4121,7 +4121,7 @@ _nm_utils_hwaddr_cloned_data_set(NMSetting * setting,
const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address =
NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING,
.compare_fcn = _nm_setting_property_compare_fcn_default,
.compare_fcn = _nm_setting_property_compare_fcn_ignore,
.to_dbus_fcn = _nm_utils_hwaddr_cloned_data_synth,
.from_dbus_fcn = _nm_utils_hwaddr_cloned_data_set, );

View file

@ -4525,7 +4525,19 @@ check_done:;
g_assert_not_reached();
if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_default) {
/* pass */
g_assert(sip->param_spec);
} else if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_ignore) {
if (NM_IN_SET(sip->property_type,
&nm_sett_info_propert_type_deprecated_ignore_i,
&nm_sett_info_propert_type_deprecated_ignore_u,
&nm_sett_info_propert_type_assigned_mac_address)) {
/* pass */
} else if (!sip->param_spec) {
/* pass */
} else {
/* ignoring a property for comparison make only sense in very specific cases. */
g_assert_not_reached();
}
} else if (sip->property_type->compare_fcn) {
/* pass */
} else {