From d8292d462becf54dc2771c00fd7bf3994f5c1944 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 12:04:00 +0200 Subject: [PATCH 01/18] libnm: pass around property_info instead of property_idx in NMSetting API Various NMSetting API would accept a property_idx parameter. Together with the NMSettInfoSetting instance, this was useful to find the actual NMSettInfoProperty instance. The idea was, to provide the most of the functionality. That is, if you might need the property_idx too, you had it -- after all, the property_info you could lookup yourself. However, - literally zero users care about the property_idx. The care about the property_info. - if the user really, really required the property_idx, then it is a given that it can be easily computed by (property_info - sett_info->property_infos) --- src/libnm-core-impl/nm-setting-bond.c | 19 +- src/libnm-core-impl/nm-setting-bridge-port.c | 18 +- src/libnm-core-impl/nm-setting-bridge.c | 18 +- src/libnm-core-impl/nm-setting-connection.c | 32 +-- src/libnm-core-impl/nm-setting-ip-config.c | 25 ++- src/libnm-core-impl/nm-setting-ip4-config.c | 10 +- src/libnm-core-impl/nm-setting-ip6-config.c | 8 +- .../nm-setting-ovs-external-ids.c | 18 +- src/libnm-core-impl/nm-setting-private.h | 8 +- src/libnm-core-impl/nm-setting-sriov.c | 20 +- src/libnm-core-impl/nm-setting-tc-config.c | 24 +-- src/libnm-core-impl/nm-setting-team-port.c | 21 +- src/libnm-core-impl/nm-setting-team.c | 20 +- src/libnm-core-impl/nm-setting-user.c | 18 +- src/libnm-core-impl/nm-setting-vlan.c | 2 +- src/libnm-core-impl/nm-setting-vpn.c | 30 +-- src/libnm-core-impl/nm-setting-wired.c | 19 +- src/libnm-core-impl/nm-setting-wireguard.c | 26 +-- src/libnm-core-impl/nm-setting-wireless.c | 25 ++- src/libnm-core-impl/nm-setting.c | 186 +++++++++--------- src/libnm-core-impl/nm-team-utils.c | 5 +- src/libnm-core-impl/nm-utils.c | 12 +- src/libnm-core-intern/nm-core-internal.h | 2 +- 23 files changed, 282 insertions(+), 284 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-bond.c b/src/libnm-core-impl/nm-setting-bond.c index 6ef85f633e..b3397a47ea 100644 --- a/src/libnm-core-impl/nm-setting-bond.c +++ b/src/libnm-core-impl/nm-setting-bond.c @@ -1090,20 +1090,19 @@ options_equal(NMSettingBond *s_bond, NMSettingBond *s_bond2, NMSettingCompareFla } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_BOND_OPTIONS)) { + if (property_info->param_spec == obj_properties[PROP_OPTIONS]) return (!set_b || options_equal(NM_SETTING_BOND(set_a), NM_SETTING_BOND(set_b), flags)); - } return NM_SETTING_CLASS(nm_setting_bond_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-bridge-port.c b/src/libnm-core-impl/nm-setting-bridge-port.c index 50be8452d1..28621eee5c 100644 --- a/src/libnm-core-impl/nm-setting-bridge-port.c +++ b/src/libnm-core-impl/nm-setting-bridge-port.c @@ -368,19 +368,19 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingBridgePortPrivate *priv_a; NMSettingBridgePortPrivate *priv_b; guint i; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_BRIDGE_PORT_VLANS)) { + if (property_info->param_spec == obj_properties[PROP_VLANS]) { if (set_b) { priv_a = NM_SETTING_BRIDGE_PORT_GET_PRIVATE(set_a); priv_b = NM_SETTING_BRIDGE_PORT_GET_PRIVATE(set_b); @@ -396,7 +396,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_bridge_port_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c index 4567a28f0a..d4747af1dc 100644 --- a/src/libnm-core-impl/nm-setting-bridge.c +++ b/src/libnm-core-impl/nm-setting-bridge.c @@ -1315,19 +1315,19 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingBridgePrivate *priv_a; NMSettingBridgePrivate *priv_b; guint i; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_BRIDGE_VLANS)) { + if (property_info->param_spec == obj_properties[PROP_VLANS]) { if (set_b) { priv_a = NM_SETTING_BRIDGE_GET_PRIVATE(set_a); priv_b = NM_SETTING_BRIDGE_GET_PRIVATE(set_b); @@ -1343,7 +1343,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_bridge_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 869093f156..4129ed2266 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -622,7 +622,7 @@ nm_setting_connection_get_timestamp(NMSettingConnection *setting) static GVariant * _to_dbus_fcn_timestamp(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -1558,24 +1558,24 @@ nm_setting_connection_no_interface_name(NMSetting * setting, } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_ID) - && nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_CONNECTION_ID)) - return NM_TERNARY_DEFAULT; - - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP) - && nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_CONNECTION_TIMESTAMP)) - return NM_TERNARY_DEFAULT; + if (property_info->param_spec == obj_properties[PROP_ID]) { + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_ID)) + return NM_TERNARY_DEFAULT; + } else if (property_info->param_spec == obj_properties[PROP_TIMESTAMP]) { + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP)) + return NM_TERNARY_DEFAULT; + } return NM_SETTING_CLASS(nm_setting_connection_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index f1e0d7adce..6033fc3688 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -4944,7 +4944,7 @@ nm_setting_ip_config_clear_routing_rules(NMSettingIPConfig *setting) static GVariant * _routing_rules_dbus_only_synth(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -5620,19 +5620,19 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingIPConfigPrivate *a_priv; NMSettingIPConfigPrivate *b_priv; guint i; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_IP_CONFIG_ADDRESSES)) { + if (property_info->param_spec == obj_properties[PROP_ADDRESSES]) { if (set_b) { a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_a); b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_b); @@ -5650,7 +5650,7 @@ compare_property(const NMSettInfoSetting *sett_info, return TRUE; } - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_IP_CONFIG_ROUTES)) { + if (property_info->param_spec == obj_properties[PROP_ROUTES]) { if (set_b) { a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_a); b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_b); @@ -5667,8 +5667,7 @@ compare_property(const NMSettInfoSetting *sett_info, return TRUE; } - if (nm_streq(sett_info->property_infos[property_idx].name, - NM_SETTING_IP_CONFIG_ROUTING_RULES)) { + if (nm_streq(property_info->name, NM_SETTING_IP_CONFIG_ROUTING_RULES)) { if (set_b) { guint n; @@ -5689,7 +5688,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_ip_config_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } static void diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 4b6f92083d..a9713221e4 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -334,7 +334,7 @@ ip4_dns_from_dbus(GVariant *dbus_value, GValue *prop_value) static GVariant * ip4_addresses_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -394,7 +394,7 @@ ip4_addresses_set(NMSetting * setting, static GVariant * ip4_address_labels_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -438,7 +438,7 @@ ip4_address_labels_get(const NMSettInfoSetting * sett_info, static GVariant * ip4_address_data_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -477,7 +477,7 @@ ip4_address_data_set(NMSetting * setting, static GVariant * ip4_routes_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -512,7 +512,7 @@ ip4_routes_set(NMSetting * setting, static GVariant * ip4_route_data_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index 6e0e9897b7..e84ed2894c 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -375,7 +375,7 @@ ip6_dns_from_dbus(GVariant *dbus_value, GValue *prop_value) static GVariant * ip6_addresses_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -420,7 +420,7 @@ ip6_addresses_set(NMSetting * setting, static GVariant * ip6_address_data_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -459,7 +459,7 @@ ip6_address_data_set(NMSetting * setting, static GVariant * ip6_routes_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -494,7 +494,7 @@ ip6_routes_set(NMSetting * setting, static GVariant * ip6_route_data_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-setting-ovs-external-ids.c b/src/libnm-core-impl/nm-setting-ovs-external-ids.c index d8f41a5919..151ec350ec 100644 --- a/src/libnm-core-impl/nm-setting-ovs-external-ids.c +++ b/src/libnm-core-impl/nm-setting-ovs-external-ids.c @@ -387,18 +387,18 @@ connection_type_is_good: } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingOvsExternalIDsPrivate *priv; NMSettingOvsExternalIDsPrivate *pri2; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_OVS_EXTERNAL_IDS_DATA)) { + if (property_info->param_spec == obj_properties[PROP_DATA]) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) return NM_TERNARY_DEFAULT; @@ -411,7 +411,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_ovs_external_ids_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 48f225b6d4..f98d58ccc9 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -70,7 +70,7 @@ struct _NMSettingClass { GError ** error); gboolean (*clear_secrets)(const struct _NMSettInfoSetting *sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMSetting * setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data); @@ -82,7 +82,7 @@ struct _NMSettingClass { * @other may be %NULL, in which case the function only determines whether * the setting should be compared (TRUE) or not (DEFAULT). */ NMTernary (*compare_property)(const struct _NMSettInfoSetting *sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * con_a, NMSetting * set_a, NMConnection * con_b, @@ -326,14 +326,14 @@ void _nm_setting_property_set_property_direct(GObject * object, GParamSpec * pspec); GVariant *_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); GVariant *_nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-setting-sriov.c b/src/libnm-core-impl/nm-setting-sriov.c index e55bc4c53f..8864709c3d 100644 --- a/src/libnm-core-impl/nm-setting-sriov.c +++ b/src/libnm-core-impl/nm-setting-sriov.c @@ -876,7 +876,7 @@ _nm_setting_sriov_sort_vfs(NMSettingSriov *setting) static GVariant * vfs_to_dbus(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -1119,19 +1119,19 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingSriov *a; NMSettingSriov *b; guint i; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_SRIOV_VFS)) { + if (property_info->param_spec == obj_properties[PROP_VFS]) { if (set_b) { a = NM_SETTING_SRIOV(set_a); b = NM_SETTING_SRIOV(set_b); @@ -1147,7 +1147,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_sriov_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-tc-config.c b/src/libnm-core-impl/nm-setting-tc-config.c index a82e65e61b..873bcede89 100644 --- a/src/libnm-core-impl/nm-setting-tc-config.c +++ b/src/libnm-core-impl/nm-setting-tc-config.c @@ -1314,19 +1314,19 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingTCConfig *a_tc_config = NM_SETTING_TC_CONFIG(set_a); NMSettingTCConfig *b_tc_config = NM_SETTING_TC_CONFIG(set_b); guint i; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_TC_CONFIG_QDISCS)) { + if (property_info->param_spec == obj_properties[PROP_QDISCS]) { if (set_b) { if (a_tc_config->qdiscs->len != b_tc_config->qdiscs->len) return FALSE; @@ -1339,7 +1339,7 @@ compare_property(const NMSettInfoSetting *sett_info, return TRUE; } - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_TC_CONFIG_TFILTERS)) { + if (property_info->param_spec == obj_properties[PROP_TFILTERS]) { if (set_b) { if (a_tc_config->tfilters->len != b_tc_config->tfilters->len) return FALSE; @@ -1353,7 +1353,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_tc_config_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /** @@ -1482,7 +1482,7 @@ next: static GVariant * tc_qdiscs_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -1680,7 +1680,7 @@ next: static GVariant * tc_tfilters_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-setting-team-port.c b/src/libnm-core-impl/nm-setting-team-port.c index 11aae92638..d371cda9fe 100644 --- a/src/libnm-core-impl/nm-setting-team-port.c +++ b/src/libnm-core-impl/nm-setting-team-port.c @@ -350,19 +350,18 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingTeamPortPrivate *a_priv; NMSettingTeamPortPrivate *b_priv; - if (nm_streq(sett_info->property_infos[property_idx].name, - NM_SETTING_TEAM_PORT_LINK_WATCHERS)) { + if (property_info->param_spec == obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS]) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) return NM_TERNARY_DEFAULT; if (!set_b) @@ -374,7 +373,7 @@ compare_property(const NMSettInfoSetting *sett_info, TRUE); } - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_TEAM_PORT_CONFIG)) { + if (property_info->param_spec == obj_properties[NM_TEAM_ATTRIBUTE_CONFIG]) { if (set_b) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) { /* If we are trying to match a connection in order to assume it (and thus @@ -395,7 +394,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_team_port_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } static void diff --git a/src/libnm-core-impl/nm-setting-team.c b/src/libnm-core-impl/nm-setting-team.c index 8669c58618..6d4c452661 100644 --- a/src/libnm-core-impl/nm-setting-team.c +++ b/src/libnm-core-impl/nm-setting-team.c @@ -1275,17 +1275,17 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingTeamPrivate *a_priv, *b_priv; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_TEAM_LINK_WATCHERS)) { + if (property_info->param_spec == obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS]) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) return NM_TERNARY_DEFAULT; if (!set_b) @@ -1297,7 +1297,7 @@ compare_property(const NMSettInfoSetting *sett_info, TRUE); } - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_TEAM_CONFIG)) { + if (property_info->param_spec == obj_properties[NM_TEAM_ATTRIBUTE_CONFIG]) { if (set_b) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) { /* If we are trying to match a connection in order to assume it (and thus @@ -1318,7 +1318,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_team_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } static void diff --git a/src/libnm-core-impl/nm-setting-user.c b/src/libnm-core-impl/nm-setting-user.c index d5e028ce53..861c90cd4c 100644 --- a/src/libnm-core-impl/nm-setting-user.c +++ b/src/libnm-core-impl/nm-setting-user.c @@ -397,17 +397,17 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingUserPrivate *priv, *pri2; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_USER_DATA)) { + if (property_info->param_spec == obj_properties[PROP_DATA]) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) return NM_TERNARY_DEFAULT; @@ -424,7 +424,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_user_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-vlan.c b/src/libnm-core-impl/nm-setting-vlan.c index 78eb9924bc..1d2bcb93f0 100644 --- a/src/libnm-core-impl/nm-setting-vlan.c +++ b/src/libnm-core-impl/nm-setting-vlan.c @@ -677,7 +677,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) static GVariant * _override_flags_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index 1df4f66130..d44aa07fa0 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -851,41 +851,41 @@ compare_property_secrets(NMSettingVpn *a, NMSettingVpn *b, NMSettingCompareFlags } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_VPN_SECRETS)) { + if (property_info->param_spec == obj_properties[PROP_SECRETS]) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) return NM_TERNARY_DEFAULT; return compare_property_secrets(NM_SETTING_VPN(set_a), NM_SETTING_VPN(set_b), flags); } return NM_SETTING_CLASS(nm_setting_vpn_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } static gboolean clear_secrets(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMSetting * setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data) { - NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(setting); - GParamSpec * prop_spec = sett_info->property_infos[property_idx].param_spec; + NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(setting); GHashTableIter iter; const char * secret; gboolean changed = TRUE; - if (!prop_spec || !NM_FLAGS_HAS(prop_spec->flags, NM_SETTING_PARAM_SECRET)) + if (!property_info->param_spec + || !NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_SECRET)) return FALSE; - nm_assert(nm_streq(prop_spec->name, NM_SETTING_VPN_SECRETS)); + nm_assert(nm_streq(property_info->param_spec->name, NM_SETTING_VPN_SECRETS)); if (!priv->secrets) return FALSE; @@ -943,7 +943,7 @@ vpn_secrets_from_dbus(NMSetting * setting, static GVariant * vpn_secrets_to_dbus(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 3c0f0302f5..93071e567f 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -976,23 +976,22 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (nm_streq(sett_info->property_infos[property_idx].name, - NM_SETTING_WIRED_CLONED_MAC_ADDRESS)) { + if (property_info->param_spec == obj_properties[PROP_CLONED_MAC_ADDRESS]) { return !set_b || nm_streq0(NM_SETTING_WIRED_GET_PRIVATE(set_a)->cloned_mac_address, NM_SETTING_WIRED_GET_PRIVATE(set_b)->cloned_mac_address); } return NM_SETTING_CLASS(nm_setting_wired_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index a270881edf..e913ccca77 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -1461,7 +1461,7 @@ nm_setting_wireguard_clear_peers(NMSettingWireGuard *self) static GVariant * _peers_dbus_only_synth(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -1842,12 +1842,12 @@ need_secrets(NMSetting *setting) static gboolean clear_secrets(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMSetting * setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data) { - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_WIREGUARD_PEERS)) { + if (nm_streq(property_info->name, NM_SETTING_WIREGUARD_PEERS)) { NMSettingWireGuardPrivate *priv = NM_SETTING_WIREGUARD_GET_PRIVATE(setting); gboolean peers_changed = FALSE; guint i, j; @@ -1894,7 +1894,7 @@ clear_secrets(const NMSettInfoSetting * sett_info, } return NM_SETTING_CLASS(nm_setting_wireguard_parent_class) - ->clear_secrets(sett_info, property_idx, setting, func, user_data); + ->clear_secrets(sett_info, property_info, setting, func, user_data); } static int @@ -1997,19 +1997,19 @@ update_one_secret(NMSetting *setting, const char *key, GVariant *value, GError * } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingWireGuardPrivate *a_priv; NMSettingWireGuardPrivate *b_priv; guint i; - if (nm_streq(sett_info->property_infos[property_idx].name, NM_SETTING_WIREGUARD_PEERS)) { + if (nm_streq(property_info->name, NM_SETTING_WIREGUARD_PEERS)) { if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) return NM_TERNARY_DEFAULT; @@ -2033,7 +2033,7 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_wireguard_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } static void diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index 83f8afc158..a3a5d7f2ff 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -744,7 +744,7 @@ nm_setting_wireless_get_seen_bssid(NMSettingWireless *setting, guint32 i) static GVariant * _to_dbus_fcn_seen_bssids(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -1102,21 +1102,20 @@ mac_addr_rand_ok: } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (sett_info->property_infos[property_idx].param_spec - == obj_properties[PROP_CLONED_MAC_ADDRESS]) { + if (property_info->param_spec == obj_properties[PROP_CLONED_MAC_ADDRESS]) { return !set_b || nm_streq0(NM_SETTING_WIRELESS_GET_PRIVATE(set_a)->cloned_mac_address, NM_SETTING_WIRELESS_GET_PRIVATE(set_b)->cloned_mac_address); } - if (sett_info->property_infos[property_idx].param_spec == obj_properties[PROP_SEEN_BSSIDS]) { + if (property_info->param_spec == obj_properties[PROP_SEEN_BSSIDS]) { return !set_b || (nm_strv_ptrarray_cmp(NM_SETTING_WIRELESS_GET_PRIVATE(set_a)->seen_bssids, NM_SETTING_WIRELESS_GET_PRIVATE(set_b)->seen_bssids) @@ -1124,14 +1123,14 @@ compare_property(const NMSettInfoSetting *sett_info, } return NM_SETTING_CLASS(nm_setting_wireless_parent_class) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); } /*****************************************************************************/ static GVariant * nm_setting_wireless_get_security(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index f6ef8c74ba..f5fb3c7a71 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -471,7 +471,7 @@ const NMSettInfoProperty * _nm_sett_info_setting_get_property_info(const NMSettInfoSetting *sett_info, const char * property_name) { - const NMSettInfoProperty *property; + const NMSettInfoProperty *property_info; gssize idx; nm_assert(property_name); @@ -490,13 +490,13 @@ _nm_sett_info_setting_get_property_info(const NMSettInfoSetting *sett_info, if (idx < 0) return NULL; - property = &sett_info->property_infos[idx]; + property_info = &sett_info->property_infos[idx]; - nm_assert(idx == 0 || strcmp(property[-1].name, property[0].name) < 0); + nm_assert(idx == 0 || strcmp(property_info[-1].name, property_info[0].name) < 0); nm_assert(idx == sett_info->property_infos_len - 1 - || strcmp(property[0].name, property[1].name) < 0); + || strcmp(property_info[0].name, property_info[1].name) < 0); - return property; + return property_info; } const NMSettInfoSetting * @@ -851,14 +851,12 @@ _finalize_direct(NMSetting *setting) GVariant * _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options) { - const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx]; - switch (property_info->property_type->direct_type) { case NM_VALUE_TYPE_BOOL: { @@ -909,38 +907,37 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * GVariant * _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options) { - const NMSettInfoProperty *const property = &sett_info->property_infos[property_idx]; - nm_auto_unset_gvalue GValue prop_value = { + nm_auto_unset_gvalue GValue prop_value = { 0, }; GArray *tmp_array; - nm_assert(property->param_spec); - nm_assert(property->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop); - nm_assert(property->property_type->typdata_to_dbus.gprop_type + nm_assert(property_info->param_spec); + nm_assert(property_info->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop); + nm_assert(property_info->property_type->typdata_to_dbus.gprop_type == NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT - || !property->to_dbus_data.gprop_to_dbus_fcn); + || !property_info->to_dbus_data.gprop_to_dbus_fcn); - g_value_init(&prop_value, property->param_spec->value_type); + g_value_init(&prop_value, property_info->param_spec->value_type); - g_object_get_property(G_OBJECT(setting), property->param_spec->name, &prop_value); + g_object_get_property(G_OBJECT(setting), property_info->param_spec->name, &prop_value); - if (!property->to_dbus_data.including_default - && g_param_value_defaults(property->param_spec, &prop_value)) + if (!property_info->to_dbus_data.including_default + && g_param_value_defaults(property_info->param_spec, &prop_value)) return NULL; - switch (property->property_type->typdata_to_dbus.gprop_type) { + switch (property_info->property_type->typdata_to_dbus.gprop_type) { case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: - if (property->to_dbus_data.gprop_to_dbus_fcn) - return property->to_dbus_data.gprop_to_dbus_fcn(&prop_value); + if (property_info->to_dbus_data.gprop_to_dbus_fcn) + return property_info->to_dbus_data.gprop_to_dbus_fcn(&prop_value); - return g_dbus_gvalue_to_gvariant(&prop_value, property->property_type->dbus_type); + return g_dbus_gvalue_to_gvariant(&prop_value, property_info->property_type->dbus_type); case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES: nm_assert(G_VALUE_HOLDS(&prop_value, G_TYPE_BYTES)); return nm_utils_gbytes_to_variant_ay(g_value_get_boxed(&prop_value)); @@ -966,42 +963,45 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s static GVariant * property_to_dbus(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options, gboolean ignore_flags) { - const NMSettInfoProperty *property = &sett_info->property_infos[property_idx]; - GVariant * variant; + GVariant *variant; - nm_assert(property->property_type->dbus_type); + nm_assert(property_info->property_type->dbus_type); - if (!property->property_type->to_dbus_fcn) { - nm_assert(!property->param_spec); - nm_assert(!property->to_dbus_data.none); + if (!property_info->property_type->to_dbus_fcn) { + nm_assert(!property_info->param_spec); + nm_assert(!property_info->to_dbus_data.none); return NULL; } - if (property->param_spec + if (property_info->param_spec && (!ignore_flags - && !NM_FLAGS_HAS(property->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS))) { - if (!NM_FLAGS_HAS(property->param_spec->flags, G_PARAM_WRITABLE)) + && !NM_FLAGS_HAS(property_info->param_spec->flags, + NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS))) { + if (!NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE)) return NULL; - if (NM_FLAGS_HAS(property->param_spec->flags, NM_SETTING_PARAM_LEGACY) + if (NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_LEGACY) && !_nm_utils_is_manager_process) return NULL; - if (NM_FLAGS_HAS(property->param_spec->flags, NM_SETTING_PARAM_SECRET)) { + if (NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_SECRET)) { NMSettingSecretFlags f = NM_SETTING_SECRET_FLAG_NONE; if (NM_FLAGS_ANY(flags, NM_CONNECTION_SERIALIZE_WITH_SECRETS_AGENT_OWNED | NM_CONNECTION_SERIALIZE_WITH_SECRETS_SYSTEM_OWNED | NM_CONNECTION_SERIALIZE_WITH_SECRETS_NOT_SAVED)) { - if (!nm_setting_get_secret_flags(setting, property->param_spec->name, &f, NULL)) + if (!nm_setting_get_secret_flags(setting, + property_info->param_spec->name, + &f, + NULL)) return NULL; } @@ -1013,26 +1013,28 @@ property_to_dbus(const NMSettInfoSetting * sett_info, } } - variant = property->property_type - ->to_dbus_fcn(sett_info, property_idx, connection, setting, flags, options); + variant = property_info->property_type + ->to_dbus_fcn(sett_info, property_info, connection, setting, flags, options); nm_g_variant_take_ref(variant); - nm_assert(!variant || g_variant_is_of_type(variant, property->property_type->dbus_type)); + nm_assert(!variant || g_variant_is_of_type(variant, property_info->property_type->dbus_type)); return variant; } static gboolean -set_property_from_dbus(const NMSettInfoProperty *property, GVariant *src_value, GValue *dst_value) +set_property_from_dbus(const NMSettInfoProperty *property_info, + GVariant * src_value, + GValue * dst_value) { - nm_assert(property->param_spec); - nm_assert(property->property_type->dbus_type); + nm_assert(property_info->param_spec); + nm_assert(property_info->property_type->dbus_type); - if (property->property_type->gprop_from_dbus_fcn) { + if (property_info->property_type->gprop_from_dbus_fcn) { if (!g_variant_type_equal(g_variant_get_type(src_value), - property->property_type->dbus_type)) + property_info->property_type->dbus_type)) return FALSE; - property->property_type->gprop_from_dbus_fcn(src_value, dst_value); + property_info->property_type->gprop_from_dbus_fcn(src_value, dst_value); } else if (dst_value->g_type == G_TYPE_BYTES) { if (!g_variant_is_of_type(src_value, G_VARIANT_TYPE_BYTESTRING)) return FALSE; @@ -1102,11 +1104,13 @@ _nm_setting_to_dbus(NMSetting * setting, sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); for (j = 0; j < sett_info->property_infos_len; j++) { - gs_unref_variant GVariant *dbus_value = NULL; + const NMSettInfoProperty *property_info = &sett_info->property_infos[j]; + gs_unref_variant GVariant *dbus_value = NULL; - dbus_value = property_to_dbus(sett_info, j, connection, setting, flags, options, FALSE); + dbus_value = + property_to_dbus(sett_info, property_info, connection, setting, flags, options, FALSE); if (dbus_value) { - g_variant_builder_add(&builder, "{sv}", sett_info->property_infos[j].name, dbus_value); + g_variant_builder_add(&builder, "{sv}", property_info->name, dbus_value); } } @@ -1382,19 +1386,21 @@ init_from_dbus(NMSetting * setting, const GVariantType * nm_setting_get_dbus_property_type(NMSetting *setting, const char *property_name) { - const NMSettInfoProperty *property; + const NMSettInfoProperty *property_info; g_return_val_if_fail(NM_IS_SETTING(setting), NULL); g_return_val_if_fail(property_name != NULL, NULL); - property = _nm_setting_class_get_property_info(NM_SETTING_GET_CLASS(setting), property_name); + property_info = + _nm_setting_class_get_property_info(NM_SETTING_GET_CLASS(setting), property_name); - g_return_val_if_fail(property != NULL, NULL); + g_return_val_if_fail(property_info != NULL, NULL); - nm_assert(property->property_type); - nm_assert(g_variant_type_string_is_valid((const char *) property->property_type->dbus_type)); + nm_assert(property_info->property_type); + nm_assert( + g_variant_type_string_is_valid((const char *) property_info->property_type->dbus_type)); - return property->property_type->dbus_type; + return property_info->property_type->dbus_type; } gboolean @@ -1690,16 +1696,15 @@ _nm_setting_should_compare_secret_property(NMSetting * setting, } static NMTernary -compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx]; - const GParamSpec * param_spec = property_info->param_spec; + const GParamSpec *param_spec = property_info->param_spec; if (!param_spec) return NM_TERNARY_DEFAULT; @@ -1732,14 +1737,14 @@ compare_property(const NMSettInfoSetting *sett_info, gs_unref_variant GVariant *value2 = NULL; value1 = property_to_dbus(sett_info, - property_idx, + property_info, con_a, set_a, NM_CONNECTION_SERIALIZE_ALL, NULL, TRUE); value2 = property_to_dbus(sett_info, - property_idx, + property_info, con_b, set_b, NM_CONNECTION_SERIALIZE_ALL, @@ -1753,33 +1758,31 @@ compare_property(const NMSettInfoSetting *sett_info, } static NMTernary -_compare_property(const NMSettInfoSetting *sett_info, - guint property_idx, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +_compare_property(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMTernary compare_result; nm_assert(sett_info); nm_assert(NM_IS_SETTING_CLASS(sett_info->setting_class)); - nm_assert(property_idx < sett_info->property_infos_len); + nm_assert(property_info); nm_assert(NM_SETTING_GET_CLASS(set_a) == sett_info->setting_class); nm_assert(!set_b || NM_SETTING_GET_CLASS(set_b) == sett_info->setting_class); compare_result = NM_SETTING_GET_CLASS(set_a) - ->compare_property(sett_info, property_idx, con_a, set_a, con_b, set_b, flags); + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); nm_assert(NM_IN_SET(compare_result, NM_TERNARY_DEFAULT, NM_TERNARY_FALSE, NM_TERNARY_TRUE)); /* check that the inferable flag and the GObject property flag corresponds. */ - nm_assert(!NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE) - || !sett_info->property_infos[property_idx].param_spec - || NM_FLAGS_HAS(sett_info->property_infos[property_idx].param_spec->flags, - NM_SETTING_PARAM_INFERRABLE) + nm_assert(!NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE) || !property_info->param_spec + || NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_INFERRABLE) || compare_result == NM_TERNARY_DEFAULT); #if NM_MORE_ASSERTS > 10 @@ -1787,7 +1790,7 @@ _compare_property(const NMSettInfoSetting *sett_info, nm_assert(!set_b || compare_result == NM_SETTING_GET_CLASS(set_a)->compare_property(sett_info, - property_idx, + property_info, con_b, set_b, con_a, @@ -1849,7 +1852,8 @@ _nm_setting_compare(NMConnection * con_a, } for (i = 0; i < sett_info->property_infos_len; i++) { - if (_compare_property(sett_info, i, con_a, a, con_b, b, flags) == NM_TERNARY_FALSE) + if (_compare_property(sett_info, &sett_info->property_infos[i], con_a, a, con_b, b, flags) + == NM_TERNARY_FALSE) return FALSE; } @@ -2005,12 +2009,12 @@ _nm_setting_diff(NMConnection * con_a, } } else { for (i = 0; i < sett_info->property_infos_len; i++) { - NMSettingDiffResult r = NM_SETTING_DIFF_RESULT_UNKNOWN; - const NMSettInfoProperty *property_info; + NMSettingDiffResult r = NM_SETTING_DIFF_RESULT_UNKNOWN; + const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; NMTernary compare_result; GParamSpec * prop_spec; - compare_result = _compare_property(sett_info, i, con_a, a, con_b, b, flags); + compare_result = _compare_property(sett_info, property_info, con_a, a, con_b, b, flags); if (compare_result == NM_TERNARY_DEFAULT) continue; @@ -2031,15 +2035,14 @@ _nm_setting_diff(NMConnection * con_a, * * We need to double-check whether the property should be ignored by * looking at @a alone. */ - if (_compare_property(sett_info, i, con_a, a, NULL, NULL, flags) + if (_compare_property(sett_info, property_info, con_a, a, NULL, NULL, flags) == NM_TERNARY_DEFAULT) continue; } compared_any = TRUE; - property_info = &sett_info->property_infos[i]; - prop_spec = property_info->param_spec; + prop_spec = property_info->param_spec; if (b) { if (compare_result == NM_TERNARY_FALSE) { @@ -2287,13 +2290,13 @@ _nm_setting_aggregate(NMSetting *setting, NMConnectionAggregateType type, gpoint static gboolean clear_secrets(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMSetting * setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data) { NMSettingSecretFlags flags = NM_SETTING_SECRET_FLAG_NONE; - GParamSpec * param_spec = sett_info->property_infos[property_idx].param_spec; + GParamSpec * param_spec = property_info->param_spec; if (!param_spec) return FALSE; @@ -2344,7 +2347,7 @@ _nm_setting_clear_secrets(NMSetting * setting, gboolean changed = FALSE; guint16 i; gboolean (*my_clear_secrets)(const struct _NMSettInfoSetting *sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMSetting * setting, NMSettingClearSecretsWithFlagsFn func, gpointer user_data); @@ -2355,7 +2358,8 @@ _nm_setting_clear_secrets(NMSetting * setting, sett_info = _nm_setting_class_get_sett_info(NM_SETTING_GET_CLASS(setting)); for (i = 0; i < sett_info->property_infos_len; i++) { - changed |= my_clear_secrets(sett_info, i, setting, func, user_data); + changed |= + my_clear_secrets(sett_info, &sett_info->property_infos[i], setting, func, user_data); } return changed; } @@ -2689,7 +2693,7 @@ nm_setting_to_string(NMSetting *setting) static GVariant * _nm_setting_get_deprecated_virtual_interface_name(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-team-utils.c b/src/libnm-core-impl/nm-team-utils.c index bd9ef510cb..c701161183 100644 --- a/src/libnm-core-impl/nm-team-utils.c +++ b/src/libnm-core-impl/nm-team-utils.c @@ -2731,7 +2731,7 @@ _nm_setting_get_team_setting(struct _NMSetting *setting) static GVariant * _nm_team_settings_property_to_dbus(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -2739,8 +2739,7 @@ _nm_team_settings_property_to_dbus(const NMSettInfoSetting * sett_ { NMTeamSetting * self = _nm_setting_get_team_setting(setting); const TeamAttrData *attr_data = - _team_attr_data_get(self->d.is_port, - sett_info->property_infos[property_idx].param_spec->param_id); + _team_attr_data_get(self->d.is_port, property_info->param_spec->param_id); if (attr_data->team_attr == NM_TEAM_ATTRIBUTE_CONFIG) { const char *config; diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 12e3bd40f4..064c29bde8 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -4004,7 +4004,7 @@ nm_utils_hwaddr_to_dbus(const char *str) static GVariant * _nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -4012,7 +4012,7 @@ _nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * sett_info, { gs_free char *addr = NULL; - nm_assert(nm_streq(sett_info->property_infos[property_idx].name, "cloned-mac-address")); + nm_assert(nm_streq(property_info->name, "cloned-mac-address")); g_object_get(setting, "cloned-mac-address", &addr, NULL); return nm_utils_hwaddr_to_dbus(addr); @@ -4069,7 +4069,7 @@ const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address = static GVariant * _nm_utils_hwaddr_cloned_data_synth(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -4080,7 +4080,7 @@ _nm_utils_hwaddr_cloned_data_synth(const NMSettInfoSetting * sett_ if (!_nm_connection_serialize_non_secret(flags)) return NULL; - nm_assert(nm_streq0(sett_info->property_infos[property_idx].name, "assigned-mac-address")); + nm_assert(nm_streq0(property_info->name, "assigned-mac-address")); g_object_get(setting, "cloned-mac-address", &addr, NULL); @@ -5447,7 +5447,7 @@ nm_utils_base64secret_normalize(const char *base64_key, static GVariant * _nm_utils_bridge_vlans_to_dbus(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, @@ -5456,7 +5456,7 @@ _nm_utils_bridge_vlans_to_dbus(const NMSettInfoSetting * sett_info gs_unref_ptrarray GPtrArray *vlans = NULL; GVariantBuilder builder; guint i; - const char * property_name = sett_info->property_infos[property_idx].name; + const char * property_name = property_info->name; nm_assert(property_name); diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 98fc0509ae..6c4ce24788 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -651,7 +651,7 @@ typedef struct _NMSettInfoSetting NMSettInfoSetting; typedef struct _NMSettInfoProperty NMSettInfoProperty; typedef GVariant *(*NMSettInfoPropToDBusFcn)(const NMSettInfoSetting * sett_info, - guint property_idx, + const NMSettInfoProperty * property_info, NMConnection * connection, NMSetting * setting, NMConnectionSerializationFlags flags, From 7e7d2d173aa2560b07c6a0eb747590964f0187a6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 14:23:16 +0200 Subject: [PATCH 02/18] libnm: add compare_fcn() to property meta data So far, we only have NMSettingClass.compare_property() hook. The ugliness is that this hook is per-setting, when basically all implementations only compare one property. It feels cleaner to have a per-property hook and call that consistently. In step one, we give all properties (the same) compare_fcn() implementation, which delegates to the existing NMSettingClass.compare_property(). In a second step, this will be untangled. There is one problem with this approach: NMSettInfoPropertType grows by one pointer size, and we have potentially many such types. That should be addressed by unifying types in the future. --- src/libnm-core-impl/nm-setting-connection.c | 2 + src/libnm-core-impl/nm-setting-dcb.c | 3 +- src/libnm-core-impl/nm-setting-ip-config.c | 2 + src/libnm-core-impl/nm-setting-ip4-config.c | 8 +- src/libnm-core-impl/nm-setting-ip6-config.c | 5 ++ src/libnm-core-impl/nm-setting-private.h | 17 ++-- src/libnm-core-impl/nm-setting-serial.c | 1 + src/libnm-core-impl/nm-setting-sriov.c | 12 +-- src/libnm-core-impl/nm-setting-tc-config.c | 13 +-- src/libnm-core-impl/nm-setting-vlan.c | 3 +- src/libnm-core-impl/nm-setting-vpn.c | 1 + src/libnm-core-impl/nm-setting-wireguard.c | 1 + src/libnm-core-impl/nm-setting-wireless.c | 6 +- src/libnm-core-impl/nm-setting.c | 91 ++++++++++++++------- src/libnm-core-impl/nm-team-utils.c | 5 ++ src/libnm-core-impl/nm-utils.c | 19 +++-- src/libnm-core-impl/tests/test-setting.c | 6 ++ src/libnm-core-intern/nm-core-internal.h | 14 ++++ 18 files changed, 154 insertions(+), 55 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 4129ed2266..5a2c12cd2a 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1996,6 +1996,7 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) NM_SETTING_PARAM_INFERRABLE, NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, .direct_type = NM_VALUE_TYPE_STRING, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .missing_from_dbus_fcn = nm_setting_connection_no_interface_name), @@ -2196,6 +2197,7 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) properties_override, obj_properties[PROP_TIMESTAMP], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_UINT64, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _to_dbus_fcn_timestamp, )); /** diff --git a/src/libnm-core-impl/nm-setting-dcb.c b/src/libnm-core-impl/nm-setting-dcb.c index fa666654c5..2fee3b9f0e 100644 --- a/src/libnm-core-impl/nm-setting-dcb.c +++ b/src/libnm-core-impl/nm-setting-dcb.c @@ -758,7 +758,8 @@ static const NMSettInfoPropertType nm_sett_info_propert_type_dcb_au = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT( NM_G_VARIANT_TYPE("au"), .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, - .gprop_from_dbus_fcn = _nm_setting_dcb_uint_array_from_dbus, ); + .gprop_from_dbus_fcn = _nm_setting_dcb_uint_array_from_dbus, + .compare_fcn = _nm_setting_property_compare_fcn_default); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 6033fc3688..4717e9f27b 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5783,6 +5783,7 @@ _nm_sett_info_property_override_create_array_ip_config(void) obj_properties[PROP_GATEWAY], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, .direct_type = NM_VALUE_TYPE_STRING, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .from_dbus_fcn = ip_gateway_set), .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, gateway), @@ -5813,6 +5814,7 @@ _nm_sett_info_property_override_create_array_ip_config(void) NM_SETTING_IP_CONFIG_ROUTING_RULES, NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), .to_dbus_fcn = _routing_rules_dbus_only_synth, + .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = _routing_rules_dbus_only_set, )); _nm_properties_override_gobj( diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index a9713221e4..20721e99ab 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -956,6 +956,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("au"), + .compare_fcn = _nm_setting_property_compare_fcn_default, .gprop_from_dbus_fcn = ip4_dns_from_dbus, ), .to_dbus_data.gprop_to_dbus_fcn = ip4_dns_to_dbus); @@ -986,12 +987,14 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ADDRESSES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aau"), .to_dbus_fcn = ip4_addresses_get, + .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = ip4_addresses_set, )); _nm_properties_override_dbus( properties_override, "address-labels", NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING_ARRAY, - .to_dbus_fcn = ip4_address_labels_get, )); + .to_dbus_fcn = ip4_address_labels_get, + .compare_fcn = _nm_setting_property_compare_fcn_default, )); /* ---dbus--- * property: address-data @@ -1007,6 +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, .from_dbus_fcn = ip4_address_data_set, )); /* ---dbus--- @@ -1040,6 +1044,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ROUTES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aau"), .to_dbus_fcn = ip4_routes_get, + .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = ip4_routes_set, )); /* ---dbus--- @@ -1060,6 +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, .from_dbus_fcn = ip4_route_data_set, )); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index e84ed2894c..2b473e61d1 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -1022,6 +1022,7 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("aay"), + .compare_fcn = _nm_setting_property_compare_fcn_default, .gprop_from_dbus_fcn = ip6_dns_from_dbus, ), .to_dbus_data.gprop_to_dbus_fcn = ip6_dns_to_dbus); @@ -1044,6 +1045,7 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ADDRESSES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a(ayuay)"), .to_dbus_fcn = ip6_addresses_get, + .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = ip6_addresses_set, )); /* ---dbus--- @@ -1060,6 +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, .from_dbus_fcn = ip6_address_data_set, )); /* ---dbus--- @@ -1081,6 +1084,7 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ROUTES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a(ayuayu)"), .to_dbus_fcn = ip6_routes_get, + .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = ip6_routes_set, )); /* ---dbus--- @@ -1101,6 +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, .from_dbus_fcn = ip6_route_data_set, )); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index f98d58ccc9..2c2e353f95 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -315,6 +315,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_default(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags); + void _nm_setting_property_get_property_direct(GObject * object, guint prop_id, GValue * value, @@ -397,11 +405,10 @@ void _nm_setting_class_commit(NMSettingClass * setting_class, .dbus_type = _dbus_type, __VA_ARGS__ \ } -#define NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(_dbus_type, ...) \ - { \ - .dbus_type = _dbus_type, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, \ - __VA_ARGS__ \ - } +#define NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(_dbus_type, ...) \ + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(_dbus_type, \ + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_gprop, \ + __VA_ARGS__) #define NM_SETT_INFO_PROPERT_TYPE(init) \ ({ \ diff --git a/src/libnm-core-impl/nm-setting-serial.c b/src/libnm-core-impl/nm-setting-serial.c index 0029551bc4..e4b5b8edcb 100644 --- a/src/libnm-core-impl/nm-setting-serial.c +++ b/src/libnm-core-impl/nm-setting-serial.c @@ -312,6 +312,7 @@ nm_setting_serial_class_init(NMSettingSerialClass *klass) properties_override, obj_properties[PROP_PARITY], NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BYTE, + .compare_fcn = _nm_setting_property_compare_fcn_default, .gprop_from_dbus_fcn = parity_from_dbus, ), .to_dbus_data.gprop_to_dbus_fcn = parity_to_dbus, ); diff --git a/src/libnm-core-impl/nm-setting-sriov.c b/src/libnm-core-impl/nm-setting-sriov.c index 8864709c3d..6f410354d7 100644 --- a/src/libnm-core-impl/nm-setting-sriov.c +++ b/src/libnm-core-impl/nm-setting-sriov.c @@ -1323,11 +1323,13 @@ nm_setting_sriov_class_init(NMSettingSriovClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_VFS], - NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), - .to_dbus_fcn = vfs_to_dbus, - .from_dbus_fcn = vfs_from_dbus, )); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_VFS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = vfs_to_dbus, + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = vfs_from_dbus, )); /** * NMSettingSriov:autoprobe-drivers diff --git a/src/libnm-core-impl/nm-setting-tc-config.c b/src/libnm-core-impl/nm-setting-tc-config.c index 873bcede89..d3d1e7c04f 100644 --- a/src/libnm-core-impl/nm-setting-tc-config.c +++ b/src/libnm-core-impl/nm-setting-tc-config.c @@ -2112,11 +2112,13 @@ nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_QDISCS], - NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), - .to_dbus_fcn = tc_qdiscs_get, - .from_dbus_fcn = tc_qdiscs_set, )); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_QDISCS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = tc_qdiscs_get, + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = tc_qdiscs_set, )); /** * NMSettingTCConfig:tfilters: (type GPtrArray(NMTCTfilter)) @@ -2254,6 +2256,7 @@ nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) obj_properties[PROP_TFILTERS], NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), .to_dbus_fcn = tc_tfilters_get, + .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = tc_tfilters_set, )); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-vlan.c b/src/libnm-core-impl/nm-setting-vlan.c index 1d2bcb93f0..13315dbc14 100644 --- a/src/libnm-core-impl/nm-setting-vlan.c +++ b/src/libnm-core-impl/nm-setting-vlan.c @@ -927,7 +927,8 @@ nm_setting_vlan_class_init(NMSettingVlanClass *klass) properties_override, obj_properties[PROP_FLAGS], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_UINT32, - .to_dbus_fcn = _override_flags_get, + .to_dbus_fcn = _override_flags_get, + .compare_fcn = _nm_setting_property_compare_fcn_default, .missing_from_dbus_fcn = _override_flags_not_set, )); /** diff --git a/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index d44aa07fa0..3ec3dc99c4 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -1231,6 +1231,7 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) obj_properties[PROP_SECRETS], NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a{ss}"), .to_dbus_fcn = vpn_secrets_to_dbus, + .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = vpn_secrets_from_dbus, )); /** diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index e913ccca77..758b8501c8 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -2597,6 +2597,7 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) NM_SETTING_WIREGUARD_PEERS, NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), .to_dbus_fcn = _peers_dbus_only_synth, + .compare_fcn = _nm_setting_property_compare_fcn_default, .from_dbus_fcn = _peers_dbus_only_set, )); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index a3a5d7f2ff..1275f3b6ac 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -1785,7 +1785,8 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) obj_properties[PROP_SEEN_BSSIDS], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING_ARRAY, .to_dbus_fcn = _to_dbus_fcn_seen_bssids, - .from_dbus_fcn = _from_dbus_fcn_seen_bssids, )); + .from_dbus_fcn = _from_dbus_fcn_seen_bssids, + .compare_fcn = _nm_setting_property_compare_fcn_default, )); /** * NMSettingWireless:mtu: @@ -1916,7 +1917,8 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) properties_override, "security", NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, - .to_dbus_fcn = nm_setting_wireless_get_security, )); + .to_dbus_fcn = nm_setting_wireless_get_security, + .compare_fcn = _nm_setting_property_compare_fcn_default, )); /** * NMSettingWireless:wake-on-wlan: diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index f5fb3c7a71..762f0f1962 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -370,35 +370,52 @@ _nm_setting_class_commit(NMSettingClass * setting_class, vtype = p->param_spec->value_type; if (vtype == G_TYPE_BOOLEAN) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BOOLEAN); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_BOOLEAN, + .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_UCHAR) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BYTE); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_BYTE, + .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_INT) p->property_type = &nm_sett_info_propert_type_plain_i; else if (vtype == G_TYPE_UINT) p->property_type = &nm_sett_info_propert_type_plain_u; else if (vtype == G_TYPE_INT64) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_INT64); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_INT64, + .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_UINT64) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_UINT64); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_UINT64, + .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_STRING) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_STRING, + .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_DOUBLE) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_DOUBLE); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_DOUBLE, + .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_STRV) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_STRING_ARRAY); + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_STRING_ARRAY, + .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_BYTES) { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_BYTESTRING, - .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES); + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES, + .compare_fcn = _nm_setting_property_compare_fcn_default); } else if (g_type_is_a(vtype, G_TYPE_ENUM)) { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_INT32, - .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM); + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM, + .compare_fcn = _nm_setting_property_compare_fcn_default); } else if (g_type_is_a(vtype, G_TYPE_FLAGS)) { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_UINT32, - .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS); + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, + .compare_fcn = _nm_setting_property_compare_fcn_default); } else nm_assert_not_reached(); @@ -1695,6 +1712,23 @@ _nm_setting_should_compare_secret_property(NMSetting * setting, return TRUE; } +/*****************************************************************************/ + +NMTernary +_nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + /* For the moment, the default implementation delegates to NMSettingClass.compare_property(). + * That will change. */ + return NM_SETTING_GET_CLASS(set_a) + ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); +} + static NMTernary compare_property(const NMSettInfoSetting * sett_info, const NMSettInfoProperty *property_info, @@ -1774,11 +1808,10 @@ _compare_property(const NMSettInfoSetting * sett_info, nm_assert(NM_SETTING_GET_CLASS(set_a) == sett_info->setting_class); nm_assert(!set_b || NM_SETTING_GET_CLASS(set_b) == sett_info->setting_class); - compare_result = - NM_SETTING_GET_CLASS(set_a) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + compare_result = property_info->property_type + ->compare_fcn(sett_info, property_info, con_a, set_a, con_b, set_b, flags); - nm_assert(NM_IN_SET(compare_result, NM_TERNARY_DEFAULT, NM_TERNARY_FALSE, NM_TERNARY_TRUE)); + nm_assert_is_ternary(compare_result); /* check that the inferable flag and the GObject property flag corresponds. */ nm_assert(!NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE) || !property_info->param_spec @@ -1786,16 +1819,12 @@ _compare_property(const NMSettInfoSetting * sett_info, || compare_result == NM_TERNARY_DEFAULT); #if NM_MORE_ASSERTS > 10 - /* assert that compare_property() is symeric. */ - nm_assert(!set_b - || compare_result - == NM_SETTING_GET_CLASS(set_a)->compare_property(sett_info, - property_info, - con_b, - set_b, - con_a, - set_a, - flags)); + /* assert that compare_fcn() is symeric. */ + nm_assert( + !set_b + || compare_result + == property_info->property_type + ->compare_fcn(sett_info, property_info, con_b, set_b, con_a, set_a, flags)); #endif return compare_result; @@ -2716,6 +2745,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, .to_dbus_fcn = _nm_setting_get_deprecated_virtual_interface_name, ); @@ -2723,33 +2753,38 @@ 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, ); 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, ); const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = - NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_INT32); + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_INT32, + .compare_fcn = _nm_setting_property_compare_fcn_default); const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = - NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_UINT32); + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_UINT32, + .compare_fcn = _nm_setting_property_compare_fcn_default); const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BOOLEAN, .direct_type = NM_VALUE_TYPE_BOOL, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32 = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT32, .direct_type = NM_VALUE_TYPE_UINT32, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); const NMSettInfoPropertType nm_sett_info_propert_type_direct_string = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, .direct_type = NM_VALUE_TYPE_STRING, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-team-utils.c b/src/libnm-core-impl/nm-team-utils.c index c701161183..a2753c1479 100644 --- a/src/libnm-core-impl/nm-team-utils.c +++ b/src/libnm-core-impl/nm-team-utils.c @@ -2787,22 +2787,27 @@ _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue const NMSettInfoPropertType nm_sett_info_propert_type_team_b = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BOOLEAN, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); const NMSettInfoPropertType nm_sett_info_propert_type_team_i = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_INT32, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); const NMSettInfoPropertType nm_sett_info_propert_type_team_s = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); const NMSettInfoPropertType nm_sett_info_propert_type_team_as = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(NM_G_VARIANT_TYPE("as"), + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(NM_G_VARIANT_TYPE("aa{sv}"), + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_team_settings_property_to_dbus, .gprop_from_dbus_fcn = _nm_team_settings_property_from_dbus_link_watchers, ); diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 064c29bde8..f0b435c667 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -777,7 +777,8 @@ const NMSettInfoPropertType nm_sett_info_propert_type_strdict = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(NM_G_VARIANT_TYPE("a{ss}"), .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, .typdata_to_dbus.gprop_type = - NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT); + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, + .compare_fcn = _nm_setting_property_compare_fcn_default); GHashTable * _nm_utils_copy_strdict(GHashTable *strdict) @@ -4063,8 +4064,9 @@ _nm_utils_hwaddr_cloned_not_set(NMSetting * setting, const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BYTESTRING, - .to_dbus_fcn = _nm_utils_hwaddr_cloned_get, - .from_dbus_fcn = _nm_utils_hwaddr_cloned_set, + .compare_fcn = _nm_setting_property_compare_fcn_default, + .to_dbus_fcn = _nm_utils_hwaddr_cloned_get, + .from_dbus_fcn = _nm_utils_hwaddr_cloned_set, .missing_from_dbus_fcn = _nm_utils_hwaddr_cloned_not_set, ); static GVariant * @@ -4126,6 +4128,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, .to_dbus_fcn = _nm_utils_hwaddr_cloned_data_synth, .from_dbus_fcn = _nm_utils_hwaddr_cloned_data_set, ); @@ -4141,10 +4144,11 @@ _nm_utils_hwaddr_from_dbus(GVariant *dbus_value, GValue *prop_value) } const NMSettInfoPropertType nm_sett_info_propert_type_mac_address = - NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT( - G_VARIANT_TYPE_BYTESTRING, - .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, - .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS); + NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_BYTESTRING, + .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, + .typdata_to_dbus.gprop_type = + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS, + .compare_fcn = _nm_setting_property_compare_fcn_default); /*****************************************************************************/ @@ -5546,6 +5550,7 @@ _nm_utils_bridge_vlans_from_dbus(NMSetting * setting, const NMSettInfoPropertType nm_sett_info_propert_type_bridge_vlans = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(NM_G_VARIANT_TYPE("aa{sv}"), + .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_utils_bridge_vlans_to_dbus, .from_dbus_fcn = _nm_utils_bridge_vlans_from_dbus, ); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 51077e2360..fd9b54084c 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4524,6 +4524,11 @@ check_done:; if (!g_hash_table_insert(h_properties, (char *) sip->name, sip->param_spec)) g_assert_not_reached(); + if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_default) { + /* for the moment, all types have this implementation. This will change. */ + } else + g_assert_not_reached(); + property_types_data = g_hash_table_lookup(h_property_types, sip->property_type); if (!property_types_data) { property_types_data = g_array_new(FALSE, FALSE, sizeof(guint)); @@ -4675,6 +4680,7 @@ check_done:; if (!g_variant_type_equal(pt->dbus_type, pt_2->dbus_type) || pt->direct_type != pt_2->direct_type || pt->to_dbus_fcn != pt_2->to_dbus_fcn || pt->from_dbus_fcn != pt_2->from_dbus_fcn + || pt->compare_fcn != pt_2->compare_fcn || pt->missing_from_dbus_fcn != pt_2->missing_from_dbus_fcn || pt->gprop_from_dbus_fcn != pt_2->gprop_from_dbus_fcn || memcmp(&pt->typdata_to_dbus, diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 6c4ce24788..a951095c6b 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -693,6 +693,20 @@ typedef struct { * to the property value. */ NMValueType direct_type; + /* compare_fcn() returns a ternary, where DEFAULT means that the property should not + * be compared due to the compare @flags. A TRUE/FALSE result means that the property is + * equal/not-equal. + * + * The "b" setting may be %NULL, in which case the function only determines whether + * the setting should be compared (TRUE) or not (DEFAULT). */ + NMTernary (*compare_fcn)(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags); + NMSettInfoPropToDBusFcn to_dbus_fcn; NMSettInfoPropFromDBusFcn from_dbus_fcn; NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn; From 243459dc3a0f26b7796667ef5708b08517501d7b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 14:37:16 +0200 Subject: [PATCH 03/18] libnm: refactor NMSettingClass.compare_property() to NMSettInfoPropertType.compare_fcn() NMSettingClass.compare_property() will be dropped. --- src/libnm-core-impl/nm-setting-bond.c | 34 ++--- src/libnm-core-impl/nm-setting-bridge-port.c | 51 +++----- src/libnm-core-impl/nm-setting-bridge.c | 51 +++----- src/libnm-core-impl/nm-setting-connection.c | 78 +++++++---- src/libnm-core-impl/nm-setting-ip-config.c | 122 ++++++++++-------- src/libnm-core-impl/nm-setting-ip4-config.c | 4 +- src/libnm-core-impl/nm-setting-ip6-config.c | 4 +- .../nm-setting-ovs-external-ids.c | 35 +++-- src/libnm-core-impl/nm-setting-private.h | 50 +++++++ src/libnm-core-impl/nm-setting-sriov.c | 51 ++++---- src/libnm-core-impl/nm-setting-tc-config.c | 80 ++++++------ src/libnm-core-impl/nm-setting-team-port.c | 93 +++++++------ src/libnm-core-impl/nm-setting-team.c | 96 ++++++++------ src/libnm-core-impl/nm-setting-user.c | 43 +++--- src/libnm-core-impl/nm-setting-vpn.c | 28 ++-- src/libnm-core-impl/nm-setting-wired.c | 39 +++--- src/libnm-core-impl/nm-setting-wireguard.c | 54 ++++---- src/libnm-core-impl/nm-setting-wireless.c | 60 +++++---- src/libnm-core-impl/nm-team-utils.c | 11 +- src/libnm-core-impl/nm-team-utils.h | 1 - src/libnm-core-impl/nm-utils-private.h | 15 ++- src/libnm-core-impl/nm-utils.c | 36 +++--- src/libnm-core-impl/tests/test-setting.c | 7 +- 23 files changed, 565 insertions(+), 478 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-bond.c b/src/libnm-core-impl/nm-setting-bond.c index b3397a47ea..bf5d88bacf 100644 --- a/src/libnm-core-impl/nm-setting-bond.c +++ b/src/libnm-core-impl/nm-setting-bond.c @@ -1090,19 +1090,15 @@ options_equal(NMSettingBond *s_bond, NMSettingBond *s_bond2, NMSettingCompareFla } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_options(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (property_info->param_spec == obj_properties[PROP_OPTIONS]) - return (!set_b || options_equal(NM_SETTING_BOND(set_a), NM_SETTING_BOND(set_b), flags)); - - return NM_SETTING_CLASS(nm_setting_bond_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return (!set_b || options_equal(NM_SETTING_BOND(set_a), NM_SETTING_BOND(set_b), flags)); } /*****************************************************************************/ @@ -1189,8 +1185,7 @@ nm_setting_bond_class_init(NMSettingBondClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->verify = verify; - setting_class->compare_property = compare_property; + setting_class->verify = verify; /** * NMSettingBond:options: (type GHashTable(utf8,utf8)): @@ -1212,9 +1207,14 @@ nm_setting_bond_class_init(NMSettingBondClass *klass) "", G_TYPE_HASH_TABLE, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_OPTIONS], - &nm_sett_info_propert_type_strdict); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_OPTIONS], + NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("a{ss}"), + .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, + .typdata_to_dbus.gprop_type = + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, + .compare_fcn = compare_fcn_options)); /* ---dbus--- * property: interface-name diff --git a/src/libnm-core-impl/nm-setting-bridge-port.c b/src/libnm-core-impl/nm-setting-bridge-port.c index 28621eee5c..6a0b6f93f1 100644 --- a/src/libnm-core-impl/nm-setting-bridge-port.c +++ b/src/libnm-core-impl/nm-setting-bridge-port.c @@ -368,35 +368,19 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_vlans(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - NMSettingBridgePortPrivate *priv_a; - NMSettingBridgePortPrivate *priv_b; - guint i; - - if (property_info->param_spec == obj_properties[PROP_VLANS]) { - if (set_b) { - priv_a = NM_SETTING_BRIDGE_PORT_GET_PRIVATE(set_a); - priv_b = NM_SETTING_BRIDGE_PORT_GET_PRIVATE(set_b); - - if (priv_a->vlans->len != priv_b->vlans->len) - return FALSE; - for (i = 0; i < priv_a->vlans->len; i++) { - if (nm_bridge_vlan_cmp(priv_a->vlans->pdata[i], priv_b->vlans->pdata[i])) - return FALSE; - } - } - return TRUE; + if (set_b) { + return _nm_utils_bridge_compare_vlans(NM_SETTING_BRIDGE_PORT_GET_PRIVATE(set_a)->vlans, + NM_SETTING_BRIDGE_PORT_GET_PRIVATE(set_b)->vlans); } - - return NM_SETTING_CLASS(nm_setting_bridge_port_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return TRUE; } /*****************************************************************************/ @@ -504,8 +488,7 @@ nm_setting_bridge_port_class_init(NMSettingBridgePortClass *klass) object_class->get_property = get_property; object_class->set_property = set_property; - setting_class->compare_property = compare_property; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingBridgePort:priority: @@ -604,9 +587,13 @@ nm_setting_bridge_port_class_init(NMSettingBridgePortClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_VLANS], - &nm_sett_info_propert_type_bridge_vlans); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_VLANS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .compare_fcn = compare_fcn_vlans, + .to_dbus_fcn = _nm_utils_bridge_vlans_to_dbus, + .from_dbus_fcn = _nm_utils_bridge_vlans_from_dbus, )); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-bridge.c b/src/libnm-core-impl/nm-setting-bridge.c index d4747af1dc..7ecd7fdbb8 100644 --- a/src/libnm-core-impl/nm-setting-bridge.c +++ b/src/libnm-core-impl/nm-setting-bridge.c @@ -1315,35 +1315,19 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_vlans(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - NMSettingBridgePrivate *priv_a; - NMSettingBridgePrivate *priv_b; - guint i; - - if (property_info->param_spec == obj_properties[PROP_VLANS]) { - if (set_b) { - priv_a = NM_SETTING_BRIDGE_GET_PRIVATE(set_a); - priv_b = NM_SETTING_BRIDGE_GET_PRIVATE(set_b); - - if (priv_a->vlans->len != priv_b->vlans->len) - return FALSE; - for (i = 0; i < priv_a->vlans->len; i++) { - if (nm_bridge_vlan_cmp(priv_a->vlans->pdata[i], priv_b->vlans->pdata[i])) - return FALSE; - } - } - return TRUE; + if (set_b) { + return _nm_utils_bridge_compare_vlans(NM_SETTING_BRIDGE_GET_PRIVATE(set_a)->vlans, + NM_SETTING_BRIDGE_GET_PRIVATE(set_b)->vlans); } - - return NM_SETTING_CLASS(nm_setting_bridge_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return TRUE; } /*****************************************************************************/ @@ -1611,8 +1595,7 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->compare_property = compare_property; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingBridge:mac-address: @@ -1914,9 +1897,13 @@ nm_setting_bridge_class_init(NMSettingBridgeClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_VLANS], - &nm_sett_info_propert_type_bridge_vlans); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_VLANS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = _nm_utils_bridge_vlans_to_dbus, + .compare_fcn = compare_fcn_vlans, + .from_dbus_fcn = _nm_utils_bridge_vlans_from_dbus, )); /* ---dbus--- * property: interface-name diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 5a2c12cd2a..f3d225c327 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1558,24 +1558,45 @@ nm_setting_connection_no_interface_name(NMSetting * setting, } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_id(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (property_info->param_spec == obj_properties[PROP_ID]) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_ID)) - return NM_TERNARY_DEFAULT; - } else if (property_info->param_spec == obj_properties[PROP_TIMESTAMP]) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP)) - return NM_TERNARY_DEFAULT; - } + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_ID)) + return NM_TERNARY_DEFAULT; - return NM_SETTING_CLASS(nm_setting_connection_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return _nm_setting_property_compare_fcn_default(sett_info, + property_info, + con_a, + set_a, + con_b, + set_b, + flags); +} + +static NMTernary +compare_fcn_timestamp(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP)) + return NM_TERNARY_DEFAULT; + + return _nm_setting_property_compare_fcn_default(sett_info, + property_info, + con_a, + set_a, + con_b, + set_b, + flags); } /*****************************************************************************/ @@ -1856,8 +1877,7 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->verify = verify; - setting_class->compare_property = compare_property; + setting_class->verify = verify; /** * NMSettingConnection:id: @@ -1871,13 +1891,19 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) * description: User friendly name for the connection profile. * ---end--- */ - _nm_setting_property_define_direct_string(properties_override, - obj_properties, - NM_SETTING_CONNECTION_ID, - PROP_ID, - NM_SETTING_PARAM_FUZZY_IGNORE, - NMSettingConnectionPrivate, - id); + _nm_setting_property_define_direct_string_full( + properties_override, + obj_properties, + NM_SETTING_CONNECTION_ID, + PROP_ID, + NM_SETTING_PARAM_FUZZY_IGNORE, + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, + .direct_type = NM_VALUE_TYPE_STRING, + .compare_fcn = compare_fcn_id, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct), + + NMSettingConnectionPrivate, + id); /** * NMSettingConnection:uuid: @@ -2197,7 +2223,7 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) properties_override, obj_properties[PROP_TIMESTAMP], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_UINT64, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = compare_fcn_timestamp, .to_dbus_fcn = _to_dbus_fcn_timestamp, )); /** diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 4717e9f27b..795451dad6 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5619,76 +5619,95 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) return TRUE; } -static NMTernary -compare_property(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_ip_config_compare_fcn_addresses(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingIPConfigPrivate *a_priv; NMSettingIPConfigPrivate *b_priv; guint i; - if (property_info->param_spec == obj_properties[PROP_ADDRESSES]) { - if (set_b) { - a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_a); - b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_b); + if (set_b) { + a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_a); + b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_b); - if (a_priv->addresses->len != b_priv->addresses->len) + if (a_priv->addresses->len != b_priv->addresses->len) + return FALSE; + for (i = 0; i < a_priv->addresses->len; i++) { + if (nm_ip_address_cmp_full(a_priv->addresses->pdata[i], + b_priv->addresses->pdata[i], + NM_IP_ADDRESS_CMP_FLAGS_WITH_ATTRS) + != 0) return FALSE; - for (i = 0; i < a_priv->addresses->len; i++) { - if (nm_ip_address_cmp_full(a_priv->addresses->pdata[i], - b_priv->addresses->pdata[i], - NM_IP_ADDRESS_CMP_FLAGS_WITH_ATTRS) - != 0) - return FALSE; - } } - return TRUE; } + return TRUE; +} - if (property_info->param_spec == obj_properties[PROP_ROUTES]) { - if (set_b) { - a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_a); - b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_b); +NMTernary +_nm_setting_ip_config_compare_fcn_routes(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + NMSettingIPConfigPrivate *a_priv; + NMSettingIPConfigPrivate *b_priv; + guint i; - if (a_priv->routes->len != b_priv->routes->len) + if (set_b) { + a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_a); + b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_b); + + if (a_priv->routes->len != b_priv->routes->len) + return FALSE; + for (i = 0; i < a_priv->routes->len; i++) { + if (!nm_ip_route_equal_full(a_priv->routes->pdata[i], + b_priv->routes->pdata[i], + NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS)) return FALSE; - for (i = 0; i < a_priv->routes->len; i++) { - if (!nm_ip_route_equal_full(a_priv->routes->pdata[i], - b_priv->routes->pdata[i], - NM_IP_ROUTE_EQUAL_CMP_FLAGS_WITH_ATTRS)) - return FALSE; - } } - return TRUE; } + return TRUE; +} - if (nm_streq(property_info->name, NM_SETTING_IP_CONFIG_ROUTING_RULES)) { - if (set_b) { - guint n; +static NMTernary +compare_fcn_routing_rules(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + NMSettingIPConfigPrivate *a_priv; + NMSettingIPConfigPrivate *b_priv; + guint i; - a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_a); - b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_b); + if (set_b) { + guint n; - n = (a_priv->routing_rules) ? a_priv->routing_rules->len : 0u; - if (n != (b_priv->routing_rules ? b_priv->routing_rules->len : 0u)) + a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_a); + b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE(set_b); + + n = (a_priv->routing_rules) ? a_priv->routing_rules->len : 0u; + if (n != (b_priv->routing_rules ? b_priv->routing_rules->len : 0u)) + return FALSE; + for (i = 0; i < n; i++) { + if (nm_ip_routing_rule_cmp(a_priv->routing_rules->pdata[i], + b_priv->routing_rules->pdata[i]) + != 0) return FALSE; - for (i = 0; i < n; i++) { - if (nm_ip_routing_rule_cmp(a_priv->routing_rules->pdata[i], - b_priv->routing_rules->pdata[i]) - != 0) - return FALSE; - } } - return TRUE; } - - return NM_SETTING_CLASS(nm_setting_ip_config_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return TRUE; } static void @@ -5814,7 +5833,7 @@ _nm_sett_info_property_override_create_array_ip_config(void) NM_SETTING_IP_CONFIG_ROUTING_RULES, NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), .to_dbus_fcn = _routing_rules_dbus_only_synth, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = compare_fcn_routing_rules, .from_dbus_fcn = _routing_rules_dbus_only_set, )); _nm_properties_override_gobj( @@ -6114,7 +6133,6 @@ nm_setting_ip_config_class_init(NMSettingIPConfigClass *klass) object_class->finalize = finalize; setting_class->verify = verify; - setting_class->compare_property = compare_property; setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->enumerate_values = enumerate_values; diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 20721e99ab..c6a8bbab0f 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -987,7 +987,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ADDRESSES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aau"), .to_dbus_fcn = ip4_addresses_get, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_ip_config_compare_fcn_addresses, .from_dbus_fcn = ip4_addresses_set, )); _nm_properties_override_dbus( properties_override, @@ -1044,7 +1044,7 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ROUTES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aau"), .to_dbus_fcn = ip4_routes_get, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_ip_config_compare_fcn_routes, .from_dbus_fcn = ip4_routes_set, )); /* ---dbus--- diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index 2b473e61d1..15b87433c4 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -1045,7 +1045,7 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ADDRESSES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a(ayuay)"), .to_dbus_fcn = ip6_addresses_get, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_ip_config_compare_fcn_addresses, .from_dbus_fcn = ip6_addresses_set, )); /* ---dbus--- @@ -1084,7 +1084,7 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_ROUTES), NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a(ayuayu)"), .to_dbus_fcn = ip6_routes_get, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_ip_config_compare_fcn_routes, .from_dbus_fcn = ip6_routes_set, )); /* ---dbus--- diff --git a/src/libnm-core-impl/nm-setting-ovs-external-ids.c b/src/libnm-core-impl/nm-setting-ovs-external-ids.c index 151ec350ec..3f0fc48c3f 100644 --- a/src/libnm-core-impl/nm-setting-ovs-external-ids.c +++ b/src/libnm-core-impl/nm-setting-ovs-external-ids.c @@ -387,7 +387,7 @@ connection_type_is_good: } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, +compare_fcn_data(const NMSettInfoSetting * sett_info, const NMSettInfoProperty *property_info, NMConnection * con_a, NMSetting * set_a, @@ -398,20 +398,15 @@ compare_property(const NMSettInfoSetting * sett_info, NMSettingOvsExternalIDsPrivate *priv; NMSettingOvsExternalIDsPrivate *pri2; - if (property_info->param_spec == obj_properties[PROP_DATA]) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) - return NM_TERNARY_DEFAULT; + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) + return NM_TERNARY_DEFAULT; - if (!set_b) - return TRUE; + if (!set_b) + return TRUE; - priv = NM_SETTING_OVS_EXTERNAL_IDS_GET_PRIVATE(NM_SETTING_OVS_EXTERNAL_IDS(set_a)); - pri2 = NM_SETTING_OVS_EXTERNAL_IDS_GET_PRIVATE(NM_SETTING_OVS_EXTERNAL_IDS(set_b)); - return nm_utils_hashtable_equal(priv->data, pri2->data, TRUE, g_str_equal); - } - - return NM_SETTING_CLASS(nm_setting_ovs_external_ids_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + priv = NM_SETTING_OVS_EXTERNAL_IDS_GET_PRIVATE(NM_SETTING_OVS_EXTERNAL_IDS(set_a)); + pri2 = NM_SETTING_OVS_EXTERNAL_IDS_GET_PRIVATE(NM_SETTING_OVS_EXTERNAL_IDS(set_b)); + return nm_utils_hashtable_equal(priv->data, pri2->data, TRUE, g_str_equal); } /*****************************************************************************/ @@ -523,8 +518,7 @@ nm_setting_ovs_external_ids_class_init(NMSettingOvsExternalIDsClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->compare_property = compare_property; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingOvsExternalIDs:data: (type GHashTable(utf8,utf8)) @@ -538,9 +532,14 @@ nm_setting_ovs_external_ids_class_init(NMSettingOvsExternalIDsClass *klass) "", G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_DATA], - &nm_sett_info_propert_type_strdict); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DATA], + NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("a{ss}"), + .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, + .typdata_to_dbus.gprop_type = + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, + .compare_fcn = compare_fcn_data)); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 2c2e353f95..0eb99c3783 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -627,6 +627,56 @@ gboolean _nm_setting_should_compare_secret_property(NMSetting * settin NMBridgeVlan *_nm_bridge_vlan_dup(const NMBridgeVlan *vlan); NMBridgeVlan *_nm_bridge_vlan_dup_and_seal(const NMBridgeVlan *vlan); +gboolean _nm_utils_bridge_vlans_from_dbus(NMSetting * setting, + GVariant * connection_dict, + const char * property, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error); + +GVariant *_nm_utils_bridge_vlans_to_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + +NMTernary _nm_setting_ip_config_compare_fcn_addresses(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_ip_config_compare_fcn_routes(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags); + +gboolean _nm_utils_hwaddr_cloned_not_set(NMSetting * setting, + GVariant * connection_dict, + const char * property, + NMSettingParseFlags parse_flags, + GError ** error); + +GVariant *_nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + +gboolean _nm_utils_hwaddr_cloned_set(NMSetting * setting, + GVariant * connection_dict, + const char * property, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error); + /*****************************************************************************/ #endif /* NM_SETTING_PRIVATE_H */ diff --git a/src/libnm-core-impl/nm-setting-sriov.c b/src/libnm-core-impl/nm-setting-sriov.c index 6f410354d7..3bddd3c2f8 100644 --- a/src/libnm-core-impl/nm-setting-sriov.c +++ b/src/libnm-core-impl/nm-setting-sriov.c @@ -1119,35 +1119,30 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_vfs(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingSriov *a; NMSettingSriov *b; guint i; - if (property_info->param_spec == obj_properties[PROP_VFS]) { - if (set_b) { - a = NM_SETTING_SRIOV(set_a); - b = NM_SETTING_SRIOV(set_b); + if (set_b) { + a = NM_SETTING_SRIOV(set_a); + b = NM_SETTING_SRIOV(set_b); - if (a->vfs->len != b->vfs->len) + if (a->vfs->len != b->vfs->len) + return FALSE; + for (i = 0; i < a->vfs->len; i++) { + if (!nm_sriov_vf_equal(a->vfs->pdata[i], b->vfs->pdata[i])) return FALSE; - for (i = 0; i < a->vfs->len; i++) { - if (!nm_sriov_vf_equal(a->vfs->pdata[i], b->vfs->pdata[i])) - return FALSE; - } } - return TRUE; } - - return NM_SETTING_CLASS(nm_setting_sriov_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return TRUE; } /*****************************************************************************/ @@ -1246,8 +1241,7 @@ nm_setting_sriov_class_init(NMSettingSriovClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->compare_property = compare_property; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingSriov:total-vfs @@ -1323,13 +1317,12 @@ nm_setting_sriov_class_init(NMSettingSriovClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj( - properties_override, - obj_properties[PROP_VFS], - NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), - .to_dbus_fcn = vfs_to_dbus, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = vfs_from_dbus, )); + _nm_properties_override_gobj(properties_override, + obj_properties[PROP_VFS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = vfs_to_dbus, + .compare_fcn = compare_fcn_vfs, + .from_dbus_fcn = vfs_from_dbus, )); /** * NMSettingSriov:autoprobe-drivers diff --git a/src/libnm-core-impl/nm-setting-tc-config.c b/src/libnm-core-impl/nm-setting-tc-config.c index d3d1e7c04f..c649a04a7a 100644 --- a/src/libnm-core-impl/nm-setting-tc-config.c +++ b/src/libnm-core-impl/nm-setting-tc-config.c @@ -1314,46 +1314,52 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_qdiscs(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingTCConfig *a_tc_config = NM_SETTING_TC_CONFIG(set_a); NMSettingTCConfig *b_tc_config = NM_SETTING_TC_CONFIG(set_b); guint i; - if (property_info->param_spec == obj_properties[PROP_QDISCS]) { - if (set_b) { - if (a_tc_config->qdiscs->len != b_tc_config->qdiscs->len) + if (set_b) { + if (a_tc_config->qdiscs->len != b_tc_config->qdiscs->len) + return FALSE; + for (i = 0; i < a_tc_config->qdiscs->len; i++) { + if (!nm_tc_qdisc_equal(a_tc_config->qdiscs->pdata[i], b_tc_config->qdiscs->pdata[i])) return FALSE; - for (i = 0; i < a_tc_config->qdiscs->len; i++) { - if (!nm_tc_qdisc_equal(a_tc_config->qdiscs->pdata[i], - b_tc_config->qdiscs->pdata[i])) - return FALSE; - } } - return TRUE; } + return TRUE; +} - if (property_info->param_spec == obj_properties[PROP_TFILTERS]) { - if (set_b) { - if (a_tc_config->tfilters->len != b_tc_config->tfilters->len) +static NMTernary +compare_fcn_tfilter(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + NMSettingTCConfig *a_tc_config = NM_SETTING_TC_CONFIG(set_a); + NMSettingTCConfig *b_tc_config = NM_SETTING_TC_CONFIG(set_b); + guint i; + + if (set_b) { + if (a_tc_config->tfilters->len != b_tc_config->tfilters->len) + return FALSE; + for (i = 0; i < a_tc_config->tfilters->len; i++) { + if (!nm_tc_tfilter_equal(a_tc_config->tfilters->pdata[i], + b_tc_config->tfilters->pdata[i])) return FALSE; - for (i = 0; i < a_tc_config->tfilters->len; i++) { - if (!nm_tc_tfilter_equal(a_tc_config->tfilters->pdata[i], - b_tc_config->tfilters->pdata[i])) - return FALSE; - } } - return TRUE; } - - return NM_SETTING_CLASS(nm_setting_tc_config_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return TRUE; } /** @@ -1803,8 +1809,7 @@ nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->compare_property = compare_property; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingTCConfig:qdiscs: (type GPtrArray(NMTCQdisc)) @@ -2112,13 +2117,12 @@ nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj( - properties_override, - obj_properties[PROP_QDISCS], - NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), - .to_dbus_fcn = tc_qdiscs_get, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .from_dbus_fcn = tc_qdiscs_set, )); + _nm_properties_override_gobj(properties_override, + obj_properties[PROP_QDISCS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .to_dbus_fcn = tc_qdiscs_get, + .compare_fcn = compare_fcn_qdiscs, + .from_dbus_fcn = tc_qdiscs_set, )); /** * NMSettingTCConfig:tfilters: (type GPtrArray(NMTCTfilter)) @@ -2256,7 +2260,7 @@ nm_setting_tc_config_class_init(NMSettingTCConfigClass *klass) obj_properties[PROP_TFILTERS], NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), .to_dbus_fcn = tc_tfilters_get, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = compare_fcn_tfilter, .from_dbus_fcn = tc_tfilters_set, )); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-team-port.c b/src/libnm-core-impl/nm-setting-team-port.c index d371cda9fe..d940200a2d 100644 --- a/src/libnm-core-impl/nm-setting-team-port.c +++ b/src/libnm-core-impl/nm-setting-team-port.c @@ -350,51 +350,57 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_link_watchers(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingTeamPortPrivate *a_priv; NMSettingTeamPortPrivate *b_priv; - if (property_info->param_spec == obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS]) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) - return NM_TERNARY_DEFAULT; - if (!set_b) - return TRUE; - a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(set_a); - b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(set_b); - return nm_team_link_watchers_equal(a_priv->team_setting->d.link_watchers, - b_priv->team_setting->d.link_watchers, - TRUE); - } + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) + return NM_TERNARY_DEFAULT; + if (!set_b) + return TRUE; + a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(set_a); + b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(set_b); + return nm_team_link_watchers_equal(a_priv->team_setting->d.link_watchers, + b_priv->team_setting->d.link_watchers, + TRUE); +} - if (property_info->param_spec == obj_properties[NM_TEAM_ATTRIBUTE_CONFIG]) { - if (set_b) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) { - /* If we are trying to match a connection in order to assume it (and thus +static NMTernary +compare_fcn_config(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + NMSettingTeamPortPrivate *a_priv; + NMSettingTeamPortPrivate *b_priv; + + if (set_b) { + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) { + /* If we are trying to match a connection in order to assume it (and thus * @flags contains INFERRABLE), use the "relaxed" matching for team * configuration. Otherwise, for all other purposes (including connection * comparison before an update), resort to the default string comparison. */ - return TRUE; - } - - a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(set_a); - b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(set_b); - - return nm_streq0(nm_team_setting_config_get(a_priv->team_setting), - nm_team_setting_config_get(b_priv->team_setting)); + return TRUE; } - return TRUE; + a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(set_a); + b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE(set_b); + + return nm_streq0(nm_team_setting_config_get(a_priv->team_setting), + nm_team_setting_config_get(b_priv->team_setting)); } - return NM_SETTING_CLASS(nm_setting_team_port_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return TRUE; } static void @@ -544,7 +550,6 @@ nm_setting_team_port_class_init(NMSettingTeamPortClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->compare_property = compare_property; setting_class->verify = verify; setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->init_from_dbus = init_from_dbus; @@ -569,9 +574,12 @@ nm_setting_team_port_class_init(NMSettingTeamPortClass *klass) "", NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], - &nm_sett_info_propert_type_team_s); + _nm_properties_override_gobj( + properties_override, + obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, + .compare_fcn = compare_fcn_config, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, )); /** * NMSettingTeamPort:queue-id: @@ -687,9 +695,14 @@ nm_setting_team_port_class_init(NMSettingTeamPortClass *klass) "", G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], - &nm_sett_info_propert_type_team_link_watchers); + _nm_properties_override_gobj( + properties_override, + obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .compare_fcn = compare_fcn_link_watchers, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .gprop_from_dbus_fcn = + _nm_team_settings_property_from_dbus_link_watchers, )); g_object_class_install_properties(object_class, G_N_ELEMENTS(obj_properties), obj_properties); diff --git a/src/libnm-core-impl/nm-setting-team.c b/src/libnm-core-impl/nm-setting-team.c index 6d4c452661..f78ce51801 100644 --- a/src/libnm-core-impl/nm-setting-team.c +++ b/src/libnm-core-impl/nm-setting-team.c @@ -1275,50 +1275,57 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_link_watchers(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - NMSettingTeamPrivate *a_priv, *b_priv; + NMSettingTeamPrivate *a_priv; + NMSettingTeamPrivate *b_priv; - if (property_info->param_spec == obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS]) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) - return NM_TERNARY_DEFAULT; - if (!set_b) - return TRUE; - a_priv = NM_SETTING_TEAM_GET_PRIVATE(set_a); - b_priv = NM_SETTING_TEAM_GET_PRIVATE(set_b); - return nm_team_link_watchers_equal(a_priv->team_setting->d.link_watchers, - b_priv->team_setting->d.link_watchers, - TRUE); - } + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) + return NM_TERNARY_DEFAULT; + if (!set_b) + return TRUE; + a_priv = NM_SETTING_TEAM_GET_PRIVATE(set_a); + b_priv = NM_SETTING_TEAM_GET_PRIVATE(set_b); + return nm_team_link_watchers_equal(a_priv->team_setting->d.link_watchers, + b_priv->team_setting->d.link_watchers, + TRUE); +} - if (property_info->param_spec == obj_properties[NM_TEAM_ATTRIBUTE_CONFIG]) { - if (set_b) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) { - /* If we are trying to match a connection in order to assume it (and thus +static NMTernary +compare_fcn_config(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + NMSettingTeamPrivate *a_priv; + NMSettingTeamPrivate *b_priv; + + if (set_b) { + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) { + /* If we are trying to match a connection in order to assume it (and thus * @flags contains INFERRABLE), use the "relaxed" matching for team * configuration. Otherwise, for all other purposes (including connection * comparison before an update), resort to the default string comparison. */ - return TRUE; - } - - a_priv = NM_SETTING_TEAM_GET_PRIVATE(set_a); - b_priv = NM_SETTING_TEAM_GET_PRIVATE(set_b); - - return nm_streq0(nm_team_setting_config_get(a_priv->team_setting), - nm_team_setting_config_get(b_priv->team_setting)); + return TRUE; } - return TRUE; + a_priv = NM_SETTING_TEAM_GET_PRIVATE(set_a); + b_priv = NM_SETTING_TEAM_GET_PRIVATE(set_b); + + return nm_streq0(nm_team_setting_config_get(a_priv->team_setting), + nm_team_setting_config_get(b_priv->team_setting)); } - return NM_SETTING_CLASS(nm_setting_team_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return TRUE; } static void @@ -1505,7 +1512,6 @@ nm_setting_team_class_init(NMSettingTeamClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->compare_property = compare_property; setting_class->verify = verify; setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->init_from_dbus = init_from_dbus; @@ -1530,9 +1536,12 @@ nm_setting_team_class_init(NMSettingTeamClass *klass) "", NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], - &nm_sett_info_propert_type_team_s); + _nm_properties_override_gobj( + properties_override, + obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, + .compare_fcn = compare_fcn_config, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, )); /** * NMSettingTeam:notify-peers-count: @@ -1809,9 +1818,14 @@ nm_setting_team_class_init(NMSettingTeamClass *klass) "", G_TYPE_PTR_ARRAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], - &nm_sett_info_propert_type_team_link_watchers); + _nm_properties_override_gobj( + properties_override, + obj_properties[NM_TEAM_ATTRIBUTE_LINK_WATCHERS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), + .compare_fcn = compare_fcn_link_watchers, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .gprop_from_dbus_fcn = + _nm_team_settings_property_from_dbus_link_watchers, )); /* ---dbus--- * property: interface-name diff --git a/src/libnm-core-impl/nm-setting-user.c b/src/libnm-core-impl/nm-setting-user.c index 861c90cd4c..b315acdc10 100644 --- a/src/libnm-core-impl/nm-setting-user.c +++ b/src/libnm-core-impl/nm-setting-user.c @@ -397,7 +397,7 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, +compare_fcn_data(const NMSettInfoSetting * sett_info, const NMSettInfoProperty *property_info, NMConnection * con_a, NMSetting * set_a, @@ -405,26 +405,19 @@ compare_property(const NMSettInfoSetting * sett_info, NMSetting * set_b, NMSettingCompareFlags flags) { - NMSettingUserPrivate *priv, *pri2; + NMSettingUserPrivate *priv; + NMSettingUserPrivate *pri2; - if (property_info->param_spec == obj_properties[PROP_DATA]) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) - return NM_TERNARY_DEFAULT; + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) + return NM_TERNARY_DEFAULT; - if (!set_b) - return TRUE; + if (!set_b) + return TRUE; - priv = NM_SETTING_USER_GET_PRIVATE(NM_SETTING_USER(set_a)); - pri2 = NM_SETTING_USER_GET_PRIVATE(NM_SETTING_USER(set_b)); - return nm_utils_hashtable_equal(priv->data, pri2->data, TRUE, g_str_equal) - && nm_utils_hashtable_equal(priv->data_invalid, - pri2->data_invalid, - TRUE, - g_str_equal); - } - - return NM_SETTING_CLASS(nm_setting_user_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + priv = NM_SETTING_USER_GET_PRIVATE(NM_SETTING_USER(set_a)); + pri2 = NM_SETTING_USER_GET_PRIVATE(NM_SETTING_USER(set_b)); + return nm_utils_hashtable_equal(priv->data, pri2->data, TRUE, g_str_equal) + && nm_utils_hashtable_equal(priv->data_invalid, pri2->data_invalid, TRUE, g_str_equal); } /*****************************************************************************/ @@ -552,8 +545,7 @@ nm_setting_user_class_init(NMSettingUserClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->compare_property = compare_property; - setting_class->verify = verify; + setting_class->verify = verify; /** * NMSettingUser:data: (type GHashTable(utf8,utf8)) @@ -581,9 +573,14 @@ nm_setting_user_class_init(NMSettingUserClass *klass) "", G_TYPE_HASH_TABLE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_DATA], - &nm_sett_info_propert_type_strdict); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_DATA], + NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("a{ss}"), + .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, + .typdata_to_dbus.gprop_type = + NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, + .compare_fcn = compare_fcn_data)); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index 3ec3dc99c4..0719c047a6 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -851,22 +851,17 @@ compare_property_secrets(NMSettingVpn *a, NMSettingVpn *b, NMSettingCompareFlags } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_secrets(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (property_info->param_spec == obj_properties[PROP_SECRETS]) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) - return NM_TERNARY_DEFAULT; - return compare_property_secrets(NM_SETTING_VPN(set_a), NM_SETTING_VPN(set_b), flags); - } - - return NM_SETTING_CLASS(nm_setting_vpn_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) + return NM_TERNARY_DEFAULT; + return compare_property_secrets(NM_SETTING_VPN(set_a), NM_SETTING_VPN(set_b), flags); } static gboolean @@ -1131,7 +1126,6 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) setting_class->get_secret_flags = get_secret_flags; setting_class->set_secret_flags = set_secret_flags; setting_class->need_secrets = need_secrets; - setting_class->compare_property = compare_property; setting_class->clear_secrets = clear_secrets; setting_class->aggregate = aggregate; @@ -1231,7 +1225,7 @@ nm_setting_vpn_class_init(NMSettingVpnClass *klass) obj_properties[PROP_SECRETS], NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("a{ss}"), .to_dbus_fcn = vpn_secrets_to_dbus, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = compare_fcn_secrets, .from_dbus_fcn = vpn_secrets_from_dbus, )); /** diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 93071e567f..312e9e41b6 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -976,22 +976,17 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_cloned_mac_address(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (property_info->param_spec == obj_properties[PROP_CLONED_MAC_ADDRESS]) { - return !set_b - || nm_streq0(NM_SETTING_WIRED_GET_PRIVATE(set_a)->cloned_mac_address, - NM_SETTING_WIRED_GET_PRIVATE(set_b)->cloned_mac_address); - } - - return NM_SETTING_CLASS(nm_setting_wired_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return !set_b + || nm_streq0(NM_SETTING_WIRED_GET_PRIVATE(set_a)->cloned_mac_address, + NM_SETTING_WIRED_GET_PRIVATE(set_b)->cloned_mac_address); } /*****************************************************************************/ @@ -1273,8 +1268,7 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) object_class->set_property = set_property; object_class->finalize = finalize; - setting_class->verify = verify; - setting_class->compare_property = compare_property; + setting_class->verify = verify; /** * NMSettingWired:port: @@ -1474,9 +1468,14 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) "", NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_CLONED_MAC_ADDRESS], - &nm_sett_info_propert_type_cloned_mac_address); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_CLONED_MAC_ADDRESS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_BYTESTRING, + .compare_fcn = compare_fcn_cloned_mac_address, + .to_dbus_fcn = _nm_utils_hwaddr_cloned_get, + .from_dbus_fcn = _nm_utils_hwaddr_cloned_set, + .missing_from_dbus_fcn = _nm_utils_hwaddr_cloned_not_set, )); /* ---dbus--- * property: assigned-mac-address diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index 758b8501c8..c7cdc78dc1 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -1997,43 +1997,38 @@ update_one_secret(NMSetting *setting, const char *key, GVariant *value, GError * } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_peers(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { NMSettingWireGuardPrivate *a_priv; NMSettingWireGuardPrivate *b_priv; guint i; - if (nm_streq(property_info->name, NM_SETTING_WIREGUARD_PEERS)) { - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) - return NM_TERNARY_DEFAULT; - - if (!set_b) - return TRUE; - - a_priv = NM_SETTING_WIREGUARD_GET_PRIVATE(set_a); - b_priv = NM_SETTING_WIREGUARD_GET_PRIVATE(set_b); - - if (a_priv->peers_arr->len != b_priv->peers_arr->len) - return FALSE; - for (i = 0; i < a_priv->peers_arr->len; i++) { - NMWireGuardPeer *a_peer = _peers_get(a_priv, i)->peer; - NMWireGuardPeer *b_peer = _peers_get(b_priv, i)->peer; - - if (nm_wireguard_peer_cmp(a_peer, b_peer, flags) != 0) - return FALSE; - } + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE)) + return NM_TERNARY_DEFAULT; + if (!set_b) return TRUE; + + a_priv = NM_SETTING_WIREGUARD_GET_PRIVATE(set_a); + b_priv = NM_SETTING_WIREGUARD_GET_PRIVATE(set_b); + + if (a_priv->peers_arr->len != b_priv->peers_arr->len) + return FALSE; + for (i = 0; i < a_priv->peers_arr->len; i++) { + NMWireGuardPeer *a_peer = _peers_get(a_priv, i)->peer; + NMWireGuardPeer *b_peer = _peers_get(b_priv, i)->peer; + + if (nm_wireguard_peer_cmp(a_peer, b_peer, flags) != 0) + return FALSE; } - return NM_SETTING_CLASS(nm_setting_wireguard_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); + return TRUE; } static void @@ -2421,7 +2416,6 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) setting_class->need_secrets = need_secrets; setting_class->clear_secrets = clear_secrets; setting_class->update_one_secret = update_one_secret; - setting_class->compare_property = compare_property; setting_class->duplicate_copy_properties = duplicate_copy_properties; setting_class->enumerate_values = enumerate_values; setting_class->aggregate = aggregate; @@ -2597,7 +2591,7 @@ nm_setting_wireguard_class_init(NMSettingWireGuardClass *klass) NM_SETTING_WIREGUARD_PEERS, NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), .to_dbus_fcn = _peers_dbus_only_synth, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = compare_fcn_peers, .from_dbus_fcn = _peers_dbus_only_set, )); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index 1275f3b6ac..ee2f1c5ed9 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -1102,28 +1102,32 @@ mac_addr_rand_ok: } static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) +compare_fcn_cloned_mac_address(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) { - if (property_info->param_spec == obj_properties[PROP_CLONED_MAC_ADDRESS]) { - return !set_b - || nm_streq0(NM_SETTING_WIRELESS_GET_PRIVATE(set_a)->cloned_mac_address, - NM_SETTING_WIRELESS_GET_PRIVATE(set_b)->cloned_mac_address); - } - if (property_info->param_spec == obj_properties[PROP_SEEN_BSSIDS]) { - return !set_b - || (nm_strv_ptrarray_cmp(NM_SETTING_WIRELESS_GET_PRIVATE(set_a)->seen_bssids, - NM_SETTING_WIRELESS_GET_PRIVATE(set_b)->seen_bssids) - == 0); - } + return !set_b + || nm_streq0(NM_SETTING_WIRELESS_GET_PRIVATE(set_a)->cloned_mac_address, + NM_SETTING_WIRELESS_GET_PRIVATE(set_b)->cloned_mac_address); +} - return NM_SETTING_CLASS(nm_setting_wireless_parent_class) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); +static NMTernary +compare_fcn_seen_bssids(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + return !set_b + || (nm_strv_ptrarray_cmp(NM_SETTING_WIRELESS_GET_PRIVATE(set_a)->seen_bssids, + NM_SETTING_WIRELESS_GET_PRIVATE(set_b)->seen_bssids) + == 0); } /*****************************************************************************/ @@ -1418,8 +1422,7 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) object_class->get_property = get_property; object_class->finalize = finalize; - setting_class->verify = verify; - setting_class->compare_property = compare_property; + setting_class->verify = verify; /** * NMSettingWireless:ssid: @@ -1665,9 +1668,14 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) "", NULL, G_PARAM_READWRITE | NM_SETTING_PARAM_INFERRABLE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_CLONED_MAC_ADDRESS], - &nm_sett_info_propert_type_cloned_mac_address); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_CLONED_MAC_ADDRESS], + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_BYTESTRING, + .compare_fcn = compare_fcn_cloned_mac_address, + .to_dbus_fcn = _nm_utils_hwaddr_cloned_get, + .from_dbus_fcn = _nm_utils_hwaddr_cloned_set, + .missing_from_dbus_fcn = _nm_utils_hwaddr_cloned_not_set, )); /* ---dbus--- * property: assigned-mac-address @@ -1786,7 +1794,7 @@ nm_setting_wireless_class_init(NMSettingWirelessClass *klass) NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING_ARRAY, .to_dbus_fcn = _to_dbus_fcn_seen_bssids, .from_dbus_fcn = _from_dbus_fcn_seen_bssids, - .compare_fcn = _nm_setting_property_compare_fcn_default, )); + .compare_fcn = compare_fcn_seen_bssids, )); /** * NMSettingWireless:mtu: diff --git a/src/libnm-core-impl/nm-team-utils.c b/src/libnm-core-impl/nm-team-utils.c index a2753c1479..fe546320c3 100644 --- a/src/libnm-core-impl/nm-team-utils.c +++ b/src/libnm-core-impl/nm-team-utils.c @@ -2729,7 +2729,7 @@ _nm_setting_get_team_setting(struct _NMSetting *setting) return _nm_setting_team_port_get_team_setting(NM_SETTING_TEAM_PORT(setting)); } -static GVariant * +GVariant * _nm_team_settings_property_to_dbus(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, NMConnection * connection, @@ -2778,7 +2778,7 @@ _nm_team_settings_property_to_dbus(const NMSettInfoSetting * sett_ return NULL; } -static void +void _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue *prop_value) { g_value_take_boxed(prop_value, @@ -2805,13 +2805,6 @@ const NMSettInfoPropertType nm_sett_info_propert_type_team_as = .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); -const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers = - NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(NM_G_VARIANT_TYPE("aa{sv}"), - .compare_fcn = _nm_setting_property_compare_fcn_default, - .to_dbus_fcn = _nm_team_settings_property_to_dbus, - .gprop_from_dbus_fcn = - _nm_team_settings_property_from_dbus_link_watchers, ); - /*****************************************************************************/ NMTeamSetting * diff --git a/src/libnm-core-impl/nm-team-utils.h b/src/libnm-core-impl/nm-team-utils.h index 41943eee8d..d888e191f8 100644 --- a/src/libnm-core-impl/nm-team-utils.h +++ b/src/libnm-core-impl/nm-team-utils.h @@ -266,6 +266,5 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_team_b; extern const NMSettInfoPropertType nm_sett_info_propert_type_team_i; extern const NMSettInfoPropertType nm_sett_info_propert_type_team_s; extern const NMSettInfoPropertType nm_sett_info_propert_type_team_as; -extern const NMSettInfoPropertType nm_sett_info_propert_type_team_link_watchers; #endif /* __NM_TEAM_UITLS_H__ */ diff --git a/src/libnm-core-impl/nm-utils-private.h b/src/libnm-core-impl/nm-utils-private.h index 5001aeb394..ee776856cb 100644 --- a/src/libnm-core-impl/nm-utils-private.h +++ b/src/libnm-core-impl/nm-utils-private.h @@ -36,12 +36,8 @@ extern const NMSettInfoPropertType nm_sett_info_propert_type_strdict; extern const NMSettInfoPropertType nm_sett_info_propert_type_mac_address; -extern const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address; - extern const NMSettInfoPropertType nm_sett_info_propert_type_assigned_mac_address; -extern const NMSettInfoPropertType nm_sett_info_propert_type_bridge_vlans; - void _nm_utils_strdict_from_dbus(GVariant *dbus_value, GValue *prop_value); void _nm_utils_bytes_from_dbus(GVariant *dbus_value, GValue *prop_value); @@ -58,4 +54,15 @@ gboolean _nm_utils_bridge_vlan_verify_list(GPtrArray * vlans, const char *setting, const char *property); +NMTernary _nm_utils_bridge_compare_vlans(GPtrArray *vlans_a, GPtrArray *vlans_b); + +GVariant *_nm_team_settings_property_to_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + +void _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue *prop_value); + #endif diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index f0b435c667..0d86e26e7a 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -4003,7 +4003,7 @@ nm_utils_hwaddr_to_dbus(const char *str) return nm_g_variant_new_ay(buf, len); } -static GVariant * +GVariant * _nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, NMConnection * connection, @@ -4019,7 +4019,7 @@ _nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * sett_info, return nm_utils_hwaddr_to_dbus(addr); } -static gboolean +gboolean _nm_utils_hwaddr_cloned_set(NMSetting * setting, GVariant * connection_dict, const char * property, @@ -4051,7 +4051,7 @@ _nm_utils_hwaddr_cloned_set(NMSetting * setting, return TRUE; } -static gboolean +gboolean _nm_utils_hwaddr_cloned_not_set(NMSetting * setting, GVariant * connection_dict, const char * property, @@ -4062,13 +4062,6 @@ _nm_utils_hwaddr_cloned_not_set(NMSetting * setting, return TRUE; } -const NMSettInfoPropertType nm_sett_info_propert_type_cloned_mac_address = - NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BYTESTRING, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .to_dbus_fcn = _nm_utils_hwaddr_cloned_get, - .from_dbus_fcn = _nm_utils_hwaddr_cloned_set, - .missing_from_dbus_fcn = _nm_utils_hwaddr_cloned_not_set, ); - static GVariant * _nm_utils_hwaddr_cloned_data_synth(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, @@ -5449,7 +5442,7 @@ nm_utils_base64secret_normalize(const char *base64_key, return TRUE; } -static GVariant * +GVariant * _nm_utils_bridge_vlans_to_dbus(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, NMConnection * connection, @@ -5496,7 +5489,7 @@ _nm_utils_bridge_vlans_to_dbus(const NMSettInfoSetting * sett_info return g_variant_builder_end(&builder); } -static gboolean +gboolean _nm_utils_bridge_vlans_from_dbus(NMSetting * setting, GVariant * connection_dict, const char * property, @@ -5548,11 +5541,20 @@ _nm_utils_bridge_vlans_from_dbus(NMSetting * setting, return TRUE; } -const NMSettInfoPropertType nm_sett_info_propert_type_bridge_vlans = - NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(NM_G_VARIANT_TYPE("aa{sv}"), - .compare_fcn = _nm_setting_property_compare_fcn_default, - .to_dbus_fcn = _nm_utils_bridge_vlans_to_dbus, - .from_dbus_fcn = _nm_utils_bridge_vlans_from_dbus, ); +NMTernary +_nm_utils_bridge_compare_vlans(GPtrArray *vlans_a, GPtrArray *vlans_b) +{ + guint l = nm_g_ptr_array_len(vlans_a); + guint i; + + if (l != nm_g_ptr_array_len(vlans_b)) + return FALSE; + for (i = 0; i < l; i++) { + if (nm_bridge_vlan_cmp(vlans_a->pdata[i], vlans_b->pdata[i])) + return FALSE; + } + return TRUE; +} gboolean _nm_utils_bridge_vlan_verify_list(GPtrArray * vlans, diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index fd9b54084c..1d6fc9ee61 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4525,9 +4525,12 @@ check_done:; g_assert_not_reached(); if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_default) { - /* for the moment, all types have this implementation. This will change. */ - } else + /* pass */ + } else if (sip->property_type->compare_fcn) { + /* pass */ + } else { g_assert_not_reached(); + } property_types_data = g_hash_table_lookup(h_property_types, sip->property_type); if (!property_types_data) { From b78fb1c6153fd5ad151d4959b3988966005079bc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 16:58:21 +0200 Subject: [PATCH 04/18] libnm: drop NMSettingClass.compare_property() --- src/libnm-core-impl/nm-setting-private.h | 14 +------------- src/libnm-core-impl/nm-setting.c | 16 ---------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 0eb99c3783..43001b8b1f 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -75,19 +75,7 @@ struct _NMSettingClass { NMSettingClearSecretsWithFlagsFn func, gpointer user_data); - /* compare_property() returns a ternary, where DEFAULT means that the property should not - * be compared due to the compare @flags. A TRUE/FALSE result means that the property is - * equal/not-equal. - * - * @other may be %NULL, in which case the function only determines whether - * the setting should be compared (TRUE) or not (DEFAULT). */ - NMTernary (*compare_property)(const struct _NMSettInfoSetting *sett_info, - const NMSettInfoProperty * property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags); + void (*padding_1)(void); void (*duplicate_copy_properties)(const struct _NMSettInfoSetting *sett_info, NMSetting * src, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 762f0f1962..a16cd9da66 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -1722,21 +1722,6 @@ _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info, NMConnection * con_b, NMSetting * set_b, NMSettingCompareFlags flags) -{ - /* For the moment, the default implementation delegates to NMSettingClass.compare_property(). - * That will change. */ - return NM_SETTING_GET_CLASS(set_a) - ->compare_property(sett_info, property_info, con_a, set_a, con_b, set_b, flags); -} - -static NMTernary -compare_property(const NMSettInfoSetting * sett_info, - const NMSettInfoProperty *property_info, - NMConnection * con_a, - NMSetting * set_a, - NMConnection * con_b, - NMSetting * set_b, - NMSettingCompareFlags flags) { const GParamSpec *param_spec = property_info->param_spec; @@ -3283,7 +3268,6 @@ nm_setting_class_init(NMSettingClass *setting_class) setting_class->update_one_secret = update_one_secret; setting_class->get_secret_flags = get_secret_flags; setting_class->set_secret_flags = set_secret_flags; - setting_class->compare_property = compare_property; setting_class->clear_secrets = clear_secrets; setting_class->for_each_secret = for_each_secret; setting_class->duplicate_copy_properties = duplicate_copy_properties; From c7262c22908065e82cf01b170af85df0e2557703 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 17:03:37 +0200 Subject: [PATCH 05/18] libnm: add special ignore function for NMSettInfoPropertType.compare_fcn() --- src/libnm-core-impl/nm-setting-ip4-config.c | 6 +++--- src/libnm-core-impl/nm-setting-ip6-config.c | 4 ++-- src/libnm-core-impl/nm-setting-private.h | 8 ++++++++ src/libnm-core-impl/nm-setting-wireless.c | 2 +- src/libnm-core-impl/nm-setting.c | 20 ++++++++++++++++---- src/libnm-core-impl/nm-utils.c | 2 +- src/libnm-core-impl/tests/test-setting.c | 14 +++++++++++++- 7 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index c6a8bbab0f..e2d6a26bbc 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -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); diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index 15b87433c4..a2cbd69e04 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -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); diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 43001b8b1f..c939111236 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -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, diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index ee2f1c5ed9..726bd19f4f 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -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: diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index a16cd9da66..a89396f66a 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -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, diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 0d86e26e7a..e5467bbad4 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -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, ); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 1d6fc9ee61..a8aeed8596 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -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 { From 33bd052a87b21edc14ac6277371744d9943b126b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 18:06:46 +0200 Subject: [PATCH 06/18] libnm: special handle "name" properties compare_fcn All settings have a "name" property. Their compare_fcn() is not interesting and was already previously ignored. But we should not special handle it via _nm_setting_property_compare_fcn_default(). --- src/libnm-core-impl/nm-setting.c | 19 +++++++++++-------- src/libnm-core-impl/tests/test-setting.c | 3 +++ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index a89396f66a..ff6e19a18f 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -389,11 +389,17 @@ _nm_setting_class_commit(NMSettingClass * setting_class, p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_UINT64, .compare_fcn = _nm_setting_property_compare_fcn_default); - else if (vtype == G_TYPE_STRING) - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( - G_VARIANT_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_default); - else if (vtype == G_TYPE_DOUBLE) + else if (vtype == G_TYPE_STRING) { + if (nm_streq(p->name, NM_SETTING_NAME)) { + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_STRING, + .compare_fcn = _nm_setting_property_compare_fcn_ignore); + } else { + p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( + G_VARIANT_TYPE_STRING, + .compare_fcn = _nm_setting_property_compare_fcn_default); + } + } else if (vtype == G_TYPE_DOUBLE) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_DOUBLE, .compare_fcn = _nm_setting_property_compare_fcn_default); @@ -1756,9 +1762,6 @@ _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info, && NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_SECRET)) return NM_TERNARY_DEFAULT; - if (nm_streq(param_spec->name, NM_SETTING_NAME)) - return NM_TERNARY_DEFAULT; - if (NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_SECRET) && !_nm_setting_should_compare_secret_property(set_a, set_b, param_spec->name, flags)) return NM_TERNARY_DEFAULT; diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index a8aeed8596..5a6d546024 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4526,6 +4526,7 @@ check_done:; if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_default) { g_assert(sip->param_spec); + g_assert_cmpstr(sip->name, !=, NM_SETTING_NAME); } 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, @@ -4534,6 +4535,8 @@ check_done:; /* pass */ } else if (!sip->param_spec) { /* pass */ + } else if (nm_streq(sip->name, NM_SETTING_NAME)) { + /* pass */ } else { /* ignoring a property for comparison make only sense in very specific cases. */ g_assert_not_reached(); From dee29e0c1c74f9e478b994fdf82bd66971e21866 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 18:12:56 +0200 Subject: [PATCH 07/18] libnm: add _nm_setting_compare_flags_check() helper --- src/libnm-core-impl/nm-setting-private.h | 5 +++ src/libnm-core-impl/nm-setting.c | 48 +++++++++++++++--------- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index c939111236..7bd3e4df99 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -303,6 +303,11 @@ gboolean _nm_setting_aggregate(NMSetting *setting, NMConnectionAggregateType typ gboolean _nm_setting_slave_type_is_valid(const char *slave_type, const char **out_port_type); +gboolean _nm_setting_compare_flags_check(const GParamSpec * param_spec, + NMSettingCompareFlags flags, + NMSetting * set_a, + NMSetting * set_b); + NMTernary _nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett_info, const NMSettInfoProperty *property_info, NMConnection * con_a, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index ff6e19a18f..c19bc02910 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -1720,6 +1720,35 @@ _nm_setting_should_compare_secret_property(NMSetting * setting, /*****************************************************************************/ +gboolean +_nm_setting_compare_flags_check(const GParamSpec * param_spec, + NMSettingCompareFlags flags, + NMSetting * set_a, + NMSetting * set_b) +{ + 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)) + return FALSE; + + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE) + && !NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_INFERRABLE)) + return FALSE; + + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY) + && NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_REAPPLY_IMMEDIATELY)) + return FALSE; + + if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS) + && NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_SECRET)) + return FALSE; + + if (NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_SECRET) + && !_nm_setting_should_compare_secret_property(set_a, set_b, param_spec->name, flags)) + return FALSE; + + return TRUE; +} + NMTernary _nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett_info, const NMSettInfoProperty *property_info, @@ -1746,24 +1775,7 @@ _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info, if (!param_spec) 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)) - return NM_TERNARY_DEFAULT; - - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_INFERRABLE) - && !NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_INFERRABLE)) - return NM_TERNARY_DEFAULT; - - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY) - && NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_REAPPLY_IMMEDIATELY)) - return NM_TERNARY_DEFAULT; - - if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS) - && NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_SECRET)) - return NM_TERNARY_DEFAULT; - - if (NM_FLAGS_HAS(param_spec->flags, NM_SETTING_PARAM_SECRET) - && !_nm_setting_should_compare_secret_property(set_a, set_b, param_spec->name, flags)) + if (!_nm_setting_compare_flags_check(param_spec, flags, set_a, set_b)) return NM_TERNARY_DEFAULT; if (set_b) { From b756e058ac0e59278be31032e581bf367a532018 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 18:18:06 +0200 Subject: [PATCH 08/18] libnm: implement "direct" properties for compare_fcn() --- src/libnm-core-impl/nm-setting-connection.c | 16 +++--- src/libnm-core-impl/nm-setting-ip-config.c | 2 +- src/libnm-core-impl/nm-setting-private.h | 8 +++ src/libnm-core-impl/nm-setting.c | 60 +++++++++++++++++---- src/libnm-core-impl/tests/test-setting.c | 7 +++ 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index f3d225c327..89afbd6a92 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1569,13 +1569,13 @@ compare_fcn_id(const NMSettInfoSetting * sett_info, if (NM_FLAGS_HAS(flags, NM_SETTING_COMPARE_FLAG_IGNORE_ID)) return NM_TERNARY_DEFAULT; - return _nm_setting_property_compare_fcn_default(sett_info, - property_info, - con_a, - set_a, - con_b, - set_b, - flags); + return _nm_setting_property_compare_fcn_direct(sett_info, + property_info, + con_a, + set_a, + con_b, + set_b, + flags); } static NMTernary @@ -2022,7 +2022,7 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) NM_SETTING_PARAM_INFERRABLE, NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, .direct_type = NM_VALUE_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_property_compare_fcn_direct, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .missing_from_dbus_fcn = nm_setting_connection_no_interface_name), diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 795451dad6..84f411e45a 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -5802,7 +5802,7 @@ _nm_sett_info_property_override_create_array_ip_config(void) obj_properties[PROP_GATEWAY], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, .direct_type = NM_VALUE_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_property_compare_fcn_direct, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .from_dbus_fcn = ip_gateway_set), .direct_offset = NM_STRUCT_OFFSET_ENSURE_TYPE(char *, NMSettingIPConfigPrivate, gateway), diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 7bd3e4df99..eb106b05ec 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -316,6 +316,14 @@ NMTernary _nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett NMSetting * set_b, NMSettingCompareFlags flags); +NMTernary _nm_setting_property_compare_fcn_direct(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, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index c19bc02910..d06ca18105 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -1761,6 +1761,44 @@ _nm_setting_property_compare_fcn_ignore(const NMSettInfoSetting * sett_info, return NM_TERNARY_DEFAULT; } +NMTernary +_nm_setting_property_compare_fcn_direct(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMConnection * con_a, + NMSetting * set_a, + NMConnection * con_b, + NMSetting * set_b, + NMSettingCompareFlags flags) +{ + gconstpointer p_a; + gconstpointer p_b; + + nm_assert(property_info->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_direct); + + if (!property_info->param_spec) + return nm_assert_unreachable_val(NM_TERNARY_DEFAULT); + + if (!_nm_setting_compare_flags_check(property_info->param_spec, flags, set_a, set_b)) + return NM_TERNARY_DEFAULT; + + if (!set_b) + return TRUE; + + p_a = _nm_setting_get_private(set_a, sett_info, property_info->direct_offset); + p_b = _nm_setting_get_private(set_b, sett_info, property_info->direct_offset); + + switch (property_info->property_type->direct_type) { + case NM_VALUE_TYPE_BOOL: + return *((const bool *) p_a) == *((const bool *) p_b); + case NM_VALUE_TYPE_UINT32: + return *((const guint32 *) p_a) == *((const guint32 *) p_b); + case NM_VALUE_TYPE_STRING: + return nm_streq0(*((const char *const *) p_a), *((const char *const *) p_b)); + default: + return nm_assert_unreachable_val(TRUE); + } +} + NMTernary _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info, const NMSettInfoProperty *property_info, @@ -1770,15 +1808,18 @@ _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info, NMSetting * set_b, NMSettingCompareFlags flags) { - const GParamSpec *param_spec = property_info->param_spec; + nm_assert(property_info->property_type->direct_type == NM_VALUE_TYPE_NONE); - if (!param_spec) + if (!property_info->param_spec) return nm_assert_unreachable_val(NM_TERNARY_DEFAULT); - if (!_nm_setting_compare_flags_check(param_spec, flags, set_a, set_b)) + if (!_nm_setting_compare_flags_check(property_info->param_spec, flags, set_a, set_b)) return NM_TERNARY_DEFAULT; - if (set_b) { + if (!set_b) + return TRUE; + + { gs_unref_variant GVariant *value1 = NULL; gs_unref_variant GVariant *value2 = NULL; @@ -1796,11 +1837,8 @@ _nm_setting_property_compare_fcn_default(const NMSettInfoSetting * sett_info, NM_CONNECTION_SERIALIZE_ALL, NULL, TRUE); - if (nm_property_compare(value1, value2) != 0) - return NM_TERNARY_FALSE; + return nm_property_compare(value1, value2) == 0; } - - return NM_TERNARY_TRUE; } static NMTernary @@ -2784,19 +2822,19 @@ const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BOOLEAN, .direct_type = NM_VALUE_TYPE_BOOL, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_property_compare_fcn_direct, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32 = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT32, .direct_type = NM_VALUE_TYPE_UINT32, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_property_compare_fcn_direct, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); const NMSettInfoPropertType nm_sett_info_propert_type_direct_string = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, .direct_type = NM_VALUE_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_default, + .compare_fcn = _nm_setting_property_compare_fcn_direct, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); /*****************************************************************************/ diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 5a6d546024..ea71e1bc92 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4527,6 +4527,11 @@ check_done:; if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_default) { g_assert(sip->param_spec); g_assert_cmpstr(sip->name, !=, NM_SETTING_NAME); + } else if (sip->property_type->compare_fcn == _nm_setting_property_compare_fcn_direct) { + g_assert(sip->param_spec); + g_assert(sip->property_type->direct_type != NM_VALUE_TYPE_NONE); + g_assert(sip->property_type->to_dbus_fcn + == _nm_setting_property_to_dbus_fcn_direct); } 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, @@ -4546,6 +4551,8 @@ check_done:; } else { g_assert_not_reached(); } + g_assert((sip->property_type->compare_fcn != _nm_setting_property_compare_fcn_direct) + || (sip->property_type->direct_type != NM_VALUE_TYPE_NONE)); property_types_data = g_hash_table_lookup(h_property_types, sip->property_type); if (!property_types_data) { From a0cf869daa32b63a09684afc745b1968fe4286d3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 20:11:34 +0200 Subject: [PATCH 09/18] libnm: refactor to_dbus_fcn() for "serial.parity" property The goal is to get rid of gprop_to_dbus_fcn() uses. --- src/libnm-core-impl/nm-setting-serial.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-serial.c b/src/libnm-core-impl/nm-setting-serial.c index e4b5b8edcb..95edf500a1 100644 --- a/src/libnm-core-impl/nm-setting-serial.c +++ b/src/libnm-core-impl/nm-setting-serial.c @@ -130,16 +130,23 @@ nm_setting_serial_get_send_delay(NMSettingSerial *setting) } static GVariant * -parity_to_dbus(const GValue *from) +parity_to_dbus_fcn(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) { - switch (g_value_get_enum(from)) { + switch (nm_setting_serial_get_parity(NM_SETTING_SERIAL(setting))) { case NM_SETTING_SERIAL_PARITY_EVEN: return g_variant_new_byte('E'); case NM_SETTING_SERIAL_PARITY_ODD: return g_variant_new_byte('o'); case NM_SETTING_SERIAL_PARITY_NONE: + /* the default, serializes to NULL. */ + return NULL; default: - return g_variant_new_byte('n'); + return NULL; } } @@ -311,10 +318,10 @@ nm_setting_serial_class_init(NMSettingSerialClass *klass) _nm_properties_override_gobj( properties_override, obj_properties[PROP_PARITY], - NM_SETT_INFO_PROPERT_TYPE_GPROP(G_VARIANT_TYPE_BYTE, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .gprop_from_dbus_fcn = parity_from_dbus, ), - .to_dbus_data.gprop_to_dbus_fcn = parity_to_dbus, ); + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_BYTE, + .compare_fcn = _nm_setting_property_compare_fcn_default, + .to_dbus_fcn = parity_to_dbus_fcn, + .gprop_from_dbus_fcn = parity_from_dbus, )); /** * NMSettingSerial:stopbits: From c07f617bff0ac759263c6639d27eac26eb5283fd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 20:11:34 +0200 Subject: [PATCH 10/18] libnm: refactor to_dbus_fcn() for "wifi-sec.wep-key-type" property The goal is to get rid of gprop_to_dbus_fcn() uses. --- .../nm-setting-wireless-security.c | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-wireless-security.c b/src/libnm-core-impl/nm-setting-wireless-security.c index ed77563295..0b806b7a0e 100644 --- a/src/libnm-core-impl/nm-setting-wireless-security.c +++ b/src/libnm-core-impl/nm-setting-wireless-security.c @@ -1290,13 +1290,24 @@ set_secret_flags(NMSetting * setting, ->set_secret_flags(setting, secret_name, flags, error); } -/* NMSettingWirelessSecurity:wep-key-type is an enum, but needs to be marshalled - * as 'u', not 'i', for backward-compatibility. - */ static GVariant * -wep_key_type_to_dbus(const GValue *from) +wep_key_type_to_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) { - return g_variant_new_uint32(g_value_get_enum(from)); + NMWepKeyType t; + + t = nm_setting_wireless_security_get_wep_key_type(NM_SETTING_WIRELESS_SECURITY(setting)); + if (t == NM_WEP_KEY_TYPE_UNKNOWN) + return NULL; + + /* NMSettingWirelessSecurity:wep-key-type is an enum, but needs to be marshalled + * as 'u', not 'i', for backward-compatibility. + */ + return g_variant_new_uint32(t); } /*****************************************************************************/ @@ -1924,10 +1935,12 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) NM_TYPE_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_UNKNOWN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); - _nm_properties_override_gobj(properties_override, - obj_properties[PROP_WEP_KEY_TYPE], - &nm_sett_info_propert_type_plain_u, - .to_dbus_data.gprop_to_dbus_fcn = wep_key_type_to_dbus, ); + _nm_properties_override_gobj( + properties_override, + obj_properties[PROP_WEP_KEY_TYPE], + NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_UINT32, + .to_dbus_fcn = wep_key_type_to_dbus, + .compare_fcn = _nm_setting_property_compare_fcn_default)); /** * NMSettingWirelessSecurity:wps-method: From bb5c89e017e18b257586c4521fba2ae845f7af7a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 21:53:55 +0200 Subject: [PATCH 11/18] libnm: refactor to_dbus_fcn() for "ipv6.dns" property The goal is to get rid of gprop_to_dbus_fcn() uses. Note that there is a change in behavior. The "dns" GPtrArray in NMSettingIPConfig is never NULL (the default of the boxed property), thus the previous code always serialized the property, even the empty list. Now, empty dns properties are omitted from D-Bus. --- src/libnm-core-impl/nm-setting-ip-config.c | 6 +++++ src/libnm-core-impl/nm-setting-ip6-config.c | 25 ++++++++++++++++----- src/libnm-core-impl/nm-utils-private.h | 2 ++ src/libnm-core-impl/nm-utils.c | 24 ++++++++++++++------ src/libnm-core-intern/nm-core-internal.h | 2 ++ 5 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index 84f411e45a..dc0624c4d2 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -4101,6 +4101,12 @@ nm_setting_ip_config_clear_dns(NMSettingIPConfig *setting) } } +GPtrArray * +_nm_setting_ip_config_get_dns_array(NMSettingIPConfig *setting) +{ + return NM_SETTING_IP_CONFIG_GET_PRIVATE(setting)->dns; +} + /** * nm_setting_ip_config_get_num_dns_searches: * @setting: the #NMSettingIPConfig diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index a2cbd69e04..abf0999961 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -10,6 +10,7 @@ #include #include "nm-setting-private.h" +#include "nm-utils-private.h" #include "nm-core-enum-types.h" #include "libnm-core-intern/nm-core-internal.h" @@ -362,9 +363,21 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static GVariant * -ip6_dns_to_dbus(const GValue *prop_value) +ip6_dns_to_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) { - return nm_utils_ip6_dns_to_variant(g_value_get_boxed(prop_value)); + GPtrArray *dns; + + dns = _nm_setting_ip_config_get_dns_array(NM_SETTING_IP_CONFIG(setting)); + + if (nm_g_ptr_array_len(dns) == 0) + return NULL; + + return _nm_utils_ip6_dns_to_variant((const char *const *) dns->pdata, dns->len); } static void @@ -1021,10 +1034,10 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) _nm_properties_override_gobj( properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), - NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("aay"), - .compare_fcn = _nm_setting_property_compare_fcn_default, - .gprop_from_dbus_fcn = ip6_dns_from_dbus, ), - .to_dbus_data.gprop_to_dbus_fcn = ip6_dns_to_dbus); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aay"), + .compare_fcn = _nm_setting_property_compare_fcn_default, + .to_dbus_fcn = ip6_dns_to_dbus, + .gprop_from_dbus_fcn = ip6_dns_from_dbus, )); /* ---dbus--- * property: addresses diff --git a/src/libnm-core-impl/nm-utils-private.h b/src/libnm-core-impl/nm-utils-private.h index ee776856cb..de4500055f 100644 --- a/src/libnm-core-impl/nm-utils-private.h +++ b/src/libnm-core-impl/nm-utils-private.h @@ -65,4 +65,6 @@ GVariant *_nm_team_settings_property_to_dbus(const NMSettInfoSetting * void _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue *prop_value); +GVariant *_nm_utils_ip6_dns_to_variant(const char *const *dns, gssize len); + #endif diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index e5467bbad4..fb97eef0d7 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -1592,19 +1592,29 @@ nm_utils_ip4_get_default_prefix(guint32 ip) **/ GVariant * nm_utils_ip6_dns_to_variant(char **dns) +{ + return _nm_utils_ip6_dns_to_variant(NM_CAST_STRV_CC(dns), -1); +} + +GVariant * +_nm_utils_ip6_dns_to_variant(const char *const *dns, gssize len) { GVariantBuilder builder; gsize i; + gsize l; + + if (len < 0) + l = NM_PTRARRAY_LEN(dns); + else + l = len; g_variant_builder_init(&builder, G_VARIANT_TYPE("aay")); - if (dns) { - for (i = 0; dns[i]; i++) { - struct in6_addr ip; + for (i = 0; i < l; i++) { + struct in6_addr ip; - if (inet_pton(AF_INET6, dns[i], &ip) != 1) - continue; - g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(&ip)); - } + if (inet_pton(AF_INET6, dns[i], &ip) != 1) + continue; + g_variant_builder_add(&builder, "@ay", nm_g_variant_new_ay_in6addr(&ip)); } return g_variant_builder_end(&builder); } diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index a951095c6b..b0d199369b 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -966,4 +966,6 @@ _nm_variant_attribute_spec_find_binary_search(const NMVariantAttributeSpec *cons gboolean _nm_ip_tunnel_mode_is_layer2(NMIPTunnelMode mode); +GPtrArray *_nm_setting_ip_config_get_dns_array(NMSettingIPConfig *setting); + #endif From d652e0f53487cf3f5b1f64038d9ff4a2f5947213 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 21:53:55 +0200 Subject: [PATCH 12/18] libnm: refactor to_dbus_fcn() for "ipv4.dns" property The goal is to get rid of gprop_to_dbus_fcn() uses. Note that there is a change in behavior. The "dns" GPtrArray in NMSettingIPConfig is never NULL (the default of the boxed property), thus the previous code always serialized the property, even the empty list. Now, empty dns properties are omitted from D-Bus. Also, there is another change in behavior: nm_utils_ip4_dns_to_variant() will now skip over strings that are not valid IPv4 addresses. Previously, it would have added 0.0.0.0 (or some undefined address). --- src/libnm-core-impl/nm-setting-ip4-config.c | 25 ++++++++++++++++----- src/libnm-core-impl/nm-utils-private.h | 1 + src/libnm-core-impl/nm-utils.c | 20 ++++++++++++----- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index e2d6a26bbc..2a10098e23 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -8,6 +8,7 @@ #include "nm-setting-ip4-config.h" #include "nm-setting-private.h" +#include "nm-utils-private.h" /** * SECTION:nm-setting-ip4-config @@ -321,9 +322,21 @@ verify(NMSetting *setting, NMConnection *connection, GError **error) } static GVariant * -ip4_dns_to_dbus(const GValue *prop_value) +ip4_dns_to_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) { - return nm_utils_ip4_dns_to_variant(g_value_get_boxed(prop_value)); + GPtrArray *dns; + + dns = _nm_setting_ip_config_get_dns_array(NM_SETTING_IP_CONFIG(setting)); + + if (nm_g_ptr_array_len(dns) == 0) + return NULL; + + return _nm_utils_ip4_dns_to_variant((const char *const *) dns->pdata, dns->len); } static void @@ -955,10 +968,10 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) _nm_properties_override_gobj( properties_override, g_object_class_find_property(G_OBJECT_CLASS(setting_class), NM_SETTING_IP_CONFIG_DNS), - NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("au"), - .compare_fcn = _nm_setting_property_compare_fcn_default, - .gprop_from_dbus_fcn = ip4_dns_from_dbus, ), - .to_dbus_data.gprop_to_dbus_fcn = ip4_dns_to_dbus); + NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("au"), + .compare_fcn = _nm_setting_property_compare_fcn_default, + .to_dbus_fcn = ip4_dns_to_dbus, + .gprop_from_dbus_fcn = ip4_dns_from_dbus, ), ); /* ---dbus--- * property: addresses diff --git a/src/libnm-core-impl/nm-utils-private.h b/src/libnm-core-impl/nm-utils-private.h index de4500055f..eec84dc637 100644 --- a/src/libnm-core-impl/nm-utils-private.h +++ b/src/libnm-core-impl/nm-utils-private.h @@ -65,6 +65,7 @@ GVariant *_nm_team_settings_property_to_dbus(const NMSettInfoSetting * void _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue *prop_value); +GVariant *_nm_utils_ip4_dns_to_variant(const char *const *dns, gssize len); GVariant *_nm_utils_ip6_dns_to_variant(const char *const *dns, gssize len); #endif diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index fb97eef0d7..ca7c820535 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -1283,19 +1283,29 @@ nm_utils_wpa_psk_valid(const char *psk) **/ GVariant * nm_utils_ip4_dns_to_variant(char **dns) +{ + return _nm_utils_ip4_dns_to_variant(NM_CAST_STRV_CC(dns), -1); +} + +GVariant * +_nm_utils_ip4_dns_to_variant(const char *const *dns, gssize len) { GVariantBuilder builder; + gsize l; gsize i; + if (len < 0) + l = NM_PTRARRAY_LEN(dns); + else + l = len; + g_variant_builder_init(&builder, G_VARIANT_TYPE("au")); - if (dns) { - for (i = 0; dns[i]; i++) { - guint32 ip = 0; + for (i = 0; i < l; i++) { + in_addr_t ip; - inet_pton(AF_INET, dns[i], &ip); + if (inet_pton(AF_INET, dns[i], &ip) == 1) g_variant_builder_add(&builder, "u", ip); - } } return g_variant_builder_end(&builder); From 9a05db61d621e1c91ca56b6bac8a626a31b57b9a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 22:06:37 +0200 Subject: [PATCH 13/18] libnm: drop unused NMSettInfoProperty.gprop_to_dbus_fcn() hook --- src/libnm-core-impl/nm-setting.c | 7 ------- src/libnm-core-impl/tests/test-setting.c | 6 +----- src/libnm-core-intern/nm-core-internal.h | 6 ------ 3 files changed, 1 insertion(+), 18 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index d06ca18105..6c37134eec 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -943,9 +943,6 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s nm_assert(property_info->param_spec); nm_assert(property_info->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop); - nm_assert(property_info->property_type->typdata_to_dbus.gprop_type - == NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT - || !property_info->to_dbus_data.gprop_to_dbus_fcn); g_value_init(&prop_value, property_info->param_spec->value_type); @@ -957,9 +954,6 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s switch (property_info->property_type->typdata_to_dbus.gprop_type) { case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT: - if (property_info->to_dbus_data.gprop_to_dbus_fcn) - return property_info->to_dbus_data.gprop_to_dbus_fcn(&prop_value); - return g_dbus_gvalue_to_gvariant(&prop_value, property_info->property_type->dbus_type); case NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES: nm_assert(G_VALUE_HOLDS(&prop_value, G_TYPE_BYTES)); @@ -999,7 +993,6 @@ property_to_dbus(const NMSettInfoSetting * sett_info, if (!property_info->property_type->to_dbus_fcn) { nm_assert(!property_info->param_spec); - nm_assert(!property_info->to_dbus_data.none); return NULL; } diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index ea71e1bc92..9446db8608 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4480,9 +4480,8 @@ test_setting_metadata(void) if (!sip->property_type->to_dbus_fcn) { /* it's allowed to have no to_dbus_fcn(), to ignore a property. But such - * properties must not have a param_spec and no gprop_to_dbus_fcn. */ + * properties must not have a param_spec. */ g_assert(!sip->param_spec); - g_assert(!sip->to_dbus_data.none); } else if (sip->property_type->to_dbus_fcn == _nm_setting_property_to_dbus_fcn_gprop) { g_assert(sip->param_spec); switch (sip->property_type->typdata_to_dbus.gprop_type) { @@ -4509,9 +4508,6 @@ test_setting_metadata(void) } g_assert_not_reached(); check_done:; - if (sip->property_type->typdata_to_dbus.gprop_type - != NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_DEFAULT) - g_assert(!sip->to_dbus_data.gprop_to_dbus_fcn); can_set_including_default = TRUE; } diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index b0d199369b..6035b9f55b 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -667,7 +667,6 @@ typedef gboolean (*NMSettInfoPropMissingFromDBusFcn)(NMSetting * setting const char * property, NMSettingParseFlags parse_flags, GError ** error); -typedef GVariant *(*NMSettInfoPropGPropToDBusFcn)(const GValue *from); typedef void (*NMSettInfoPropGPropFromDBusFcn)(GVariant *from, GValue *to); const NMSettInfoSetting *nmtst_sett_info_settings(void); @@ -746,11 +745,6 @@ struct _NMSettInfoProperty { bool direct_has_special_setter : 1; struct { - union { - gpointer none; - NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn; - }; - /* Usually, properties that are set to the default value for the GParamSpec * are not serialized to GVariant (and NULL is returned by to_dbus_data(). * Set this flag to force always converting the property even if the value From 36f552c5ca525cd2a8600cebbba337cd0be61f6d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 22:11:08 +0200 Subject: [PATCH 14/18] libnm: move NMSettInfoProperty.to_dbus_including_default flag The "to_dbus_data" existed for namespacing the properties inside it. However, such a struct adds overhead due to the alignment that it enforces. We can share the memory needed for the bitfield by having them beside each other. --- src/libnm-core-impl/nm-setting-wired.c | 2 +- src/libnm-core-impl/nm-setting.c | 8 ++++---- src/libnm-core-impl/tests/test-setting.c | 2 +- src/libnm-core-intern/nm-core-internal.h | 12 +++++------- 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-wired.c b/src/libnm-core-impl/nm-setting-wired.c index 312e9e41b6..4c35545ce2 100644 --- a/src/libnm-core-impl/nm-setting-wired.c +++ b/src/libnm-core-impl/nm-setting-wired.c @@ -1383,7 +1383,7 @@ nm_setting_wired_class_init(NMSettingWiredClass *klass) NM_SETTING_PARAM_NONE, NMSettingWiredPrivate, auto_negotiate, - .to_dbus_data.including_default = TRUE); + .to_dbus_including_default = TRUE); /** * NMSettingWired:mac-address: diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 6c37134eec..f14e29563a 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -886,7 +886,7 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * gboolean val; val = *((bool *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); - if (!property_info->to_dbus_data.including_default + if (!property_info->to_dbus_including_default && val == NM_G_PARAM_SPEC_GET_DEFAULT_BOOLEAN(property_info->param_spec)) return NULL; return g_variant_ref(nm_g_variant_singleton_b(val)); @@ -897,7 +897,7 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * val = *( (guint32 *) _nm_setting_get_private(setting, sett_info, property_info->direct_offset)); - if (!property_info->to_dbus_data.including_default + if (!property_info->to_dbus_including_default && val == NM_G_PARAM_SPEC_GET_DEFAULT_UINT(property_info->param_spec)) return NULL; return g_variant_new_uint32(val); @@ -912,7 +912,7 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * * Setting "including_default" for a string makes no sense because a * GVariant of type "s" cannot express NULL. */ nm_assert(!NM_G_PARAM_SPEC_GET_DEFAULT_STRING(property_info->param_spec)); - nm_assert(!property_info->to_dbus_data.including_default); + nm_assert(!property_info->to_dbus_including_default); val = *((const char *const *) _nm_setting_get_private(setting, sett_info, @@ -948,7 +948,7 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s g_object_get_property(G_OBJECT(setting), property_info->param_spec->name, &prop_value); - if (!property_info->to_dbus_data.including_default + if (!property_info->to_dbus_including_default && g_param_value_defaults(property_info->param_spec, &prop_value)) return NULL; diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 9446db8608..3823922f94 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4512,7 +4512,7 @@ check_done:; } if (!can_set_including_default) - g_assert(!sip->to_dbus_data.including_default); + g_assert(!sip->to_dbus_including_default); g_assert(!sip->property_type->from_dbus_fcn || !sip->property_type->gprop_from_dbus_fcn); diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 6035b9f55b..59fb7853e7 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -744,13 +744,11 @@ struct _NMSettInfoProperty { * except of marking those properties and serve as a reminder that special care needs to be taken. */ bool direct_has_special_setter : 1; - struct { - /* Usually, properties that are set to the default value for the GParamSpec - * are not serialized to GVariant (and NULL is returned by to_dbus_data(). - * Set this flag to force always converting the property even if the value - * is the default. */ - bool including_default : 1; - } to_dbus_data; + /* Usually, properties that are set to the default value for the GParamSpec + * are not serialized to GVariant (and NULL is returned by to_dbus_data(). + * Set this flag to force always converting the property even if the value + * is the default. */ + bool to_dbus_including_default : 1; }; typedef struct { From 1d9baa65d8cc2d6f0709431662c5b319ff01fa33 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 22:19:52 +0200 Subject: [PATCH 15/18] libnm: reorder code in init_from_dbus() No functional change, just untangle the if-else-if blocks. --- src/libnm-core-impl/nm-setting.c | 45 ++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index f14e29563a..69cef95229 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -1291,10 +1291,30 @@ init_from_dbus(NMSetting * setting, value = g_variant_lookup_value(setting_dict, property_info->name, NULL); - if (value && keys) + if (!value) { + if (property_info->property_type->missing_from_dbus_fcn + && !property_info->property_type->missing_from_dbus_fcn(setting, + connection_dict, + property_info->name, + parse_flags, + &local)) { + if (!NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) + continue; + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("failed to set property: %s"), + local->message); + g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name); + return FALSE; + } + continue; + } + + if (keys) g_hash_table_remove(keys, property_info->name); - if (value && property_info->property_type->from_dbus_fcn) { + if (property_info->property_type->from_dbus_fcn) { if (!g_variant_type_equal(g_variant_get_type(value), property_info->property_type->dbus_type)) { /* for backward behavior, fail unless best-effort is chosen. */ @@ -1330,23 +1350,10 @@ init_from_dbus(NMSetting * setting, g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name); return FALSE; } - } else if (!value && property_info->property_type->missing_from_dbus_fcn) { - if (!property_info->property_type->missing_from_dbus_fcn(setting, - connection_dict, - property_info->name, - parse_flags, - &local)) { - if (!NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) - continue; - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("failed to set property: %s"), - local->message); - g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name); - return FALSE; - } - } else if (value && property_info->param_spec) { + continue; + } + + if (property_info->param_spec) { nm_auto_unset_gvalue GValue object_value = G_VALUE_INIT; g_value_init(&object_value, property_info->param_spec->value_type); From b34220a0844b02ff4efeee635e496e7d7f2ed4a2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 22:28:07 +0200 Subject: [PATCH 16/18] libnm: explicitly ignore to-dbus for "name" property NM_SETTING_NAME is also a GObject property, but it's not supposed to be serialized to/from D-Bus. It also is irrelevant for comparison. Hence, it's operations are all NOPs. Make an explicit property type for that case instead of checking the GParamSpec flags. --- src/libnm-core-impl/nm-setting-private.h | 8 +++ src/libnm-core-impl/nm-setting.c | 70 +++++++++++++++--------- src/libnm-core-impl/tests/test-setting.c | 5 ++ 3 files changed, 58 insertions(+), 25 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index eb106b05ec..dd47e32158 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -280,6 +280,7 @@ gboolean _nm_setting_clear_secrets(NMSetting * setting, */ #define NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS (1 << (7 + G_PARAM_USER_SHIFT)) +extern const NMSettInfoPropertType nm_sett_info_propert_type_setting_name; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i; extern const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u; @@ -342,6 +343,13 @@ void _nm_setting_property_set_property_direct(GObject * object, const GValue *value, GParamSpec * pspec); +GVariant *_nm_setting_property_to_dbus_fcn_ignore(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options); + GVariant *_nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, NMConnection * connection, diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 69cef95229..ee55e1249f 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -390,11 +390,11 @@ _nm_setting_class_commit(NMSettingClass * setting_class, G_VARIANT_TYPE_UINT64, .compare_fcn = _nm_setting_property_compare_fcn_default); else if (vtype == G_TYPE_STRING) { - if (nm_streq(p->name, NM_SETTING_NAME)) { - p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( - G_VARIANT_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_ignore); - } else { + nm_assert(nm_streq(p->name, NM_SETTING_NAME) + == (!NM_FLAGS_HAS(p->param_spec->flags, G_PARAM_WRITABLE))); + if (!NM_FLAGS_HAS(p->param_spec->flags, G_PARAM_WRITABLE)) + p->property_type = &nm_sett_info_propert_type_setting_name; + else { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_STRING, .compare_fcn = _nm_setting_property_compare_fcn_default); @@ -928,6 +928,17 @@ _nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * } } +GVariant * +_nm_setting_property_to_dbus_fcn_ignore(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty * property_info, + NMConnection * connection, + NMSetting * setting, + NMConnectionSerializationFlags flags, + const NMConnectionSerializationOptions *options) +{ + return NULL; +} + GVariant * _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, @@ -996,13 +1007,12 @@ property_to_dbus(const NMSettInfoSetting * sett_info, return NULL; } - if (property_info->param_spec - && (!ignore_flags - && !NM_FLAGS_HAS(property_info->param_spec->flags, - NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS))) { - if (!NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE)) - return NULL; + nm_assert(!property_info->param_spec + || NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE) + || property_info->property_type == &nm_sett_info_propert_type_setting_name); + if (property_info->param_spec && !ignore_flags + && !NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_TO_DBUS_IGNORE_FLAGS)) { if (NM_FLAGS_HAS(property_info->param_spec->flags, NM_SETTING_PARAM_LEGACY) && !_nm_utils_is_manager_process) return NULL; @@ -1286,9 +1296,12 @@ init_from_dbus(NMSetting * setting, gs_unref_variant GVariant *value = NULL; gs_free_error GError *local = NULL; - if (property_info->param_spec && !(property_info->param_spec->flags & G_PARAM_WRITABLE)) + if (property_info->property_type == &nm_sett_info_propert_type_setting_name) continue; + nm_assert(!property_info->param_spec + || NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE)); + value = g_variant_lookup_value(setting_dict, property_info->name, NULL); if (!value) { @@ -1505,21 +1518,23 @@ duplicate_copy_properties(const NMSettInfoSetting *sett_info, NMSetting *src, NM for (i = 0; i < sett_info->property_infos_len; i++) { const NMSettInfoProperty *property_info = &sett_info->property_infos[i]; - if (property_info->param_spec) { - if ((property_info->param_spec->flags & (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)) - != G_PARAM_WRITABLE) - continue; - - if (!frozen) { - g_object_freeze_notify(G_OBJECT(dst)); - frozen = TRUE; - } - _gobject_copy_property(G_OBJECT(src), - G_OBJECT(dst), - property_info->param_spec->name, - G_PARAM_SPEC_VALUE_TYPE(property_info->param_spec)); + if (!property_info->param_spec) continue; + + nm_assert(!NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_CONSTRUCT_ONLY)); + if (property_info->property_type == &nm_sett_info_propert_type_setting_name) + continue; + + nm_assert(NM_FLAGS_HAS(property_info->param_spec->flags, G_PARAM_WRITABLE)); + + if (!frozen) { + g_object_freeze_notify(G_OBJECT(dst)); + frozen = TRUE; } + _gobject_copy_property(G_OBJECT(src), + G_OBJECT(dst), + property_info->param_spec->name, + G_PARAM_SPEC_VALUE_TYPE(property_info->param_spec)); } if (frozen) @@ -2799,6 +2814,11 @@ const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name .to_dbus_fcn = _nm_setting_get_deprecated_virtual_interface_name, ); +const NMSettInfoPropertType nm_sett_info_propert_type_setting_name = + NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_ignore, + .compare_fcn = _nm_setting_property_compare_fcn_ignore); + const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT( G_VARIANT_TYPE_INT32, diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 3823922f94..4af74d0037 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4566,6 +4566,11 @@ check_done:; g_assert_cmpstr(sip->name, ==, sip->param_spec->name); + g_assert(NM_FLAGS_HAS(sip->param_spec->flags, G_PARAM_WRITABLE) + != nm_streq(sip->name, NM_SETTING_NAME)); + g_assert((sip->property_type == &nm_sett_info_propert_type_setting_name) + == nm_streq(sip->name, NM_SETTING_NAME)); + g_value_init(&val, sip->param_spec->value_type); g_object_get_property(G_OBJECT(setting), sip->name, &val); From a9ef71eb4aab3c3728400c47dfbc61241d1b20da Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 29 Jun 2021 23:51:46 +0200 Subject: [PATCH 17/18] libnm: pass full property meta data to from_dbus_fcn() hook --- src/libnm-core-impl/nm-setting-ip-config.c | 28 ++++++----- src/libnm-core-impl/nm-setting-ip4-config.c | 54 +++++++++++---------- src/libnm-core-impl/nm-setting-ip6-config.c | 54 +++++++++++---------- src/libnm-core-impl/nm-setting-private.h | 26 +++++----- src/libnm-core-impl/nm-setting-sriov.c | 13 ++--- src/libnm-core-impl/nm-setting-tc-config.c | 26 +++++----- src/libnm-core-impl/nm-setting-vpn.c | 13 ++--- src/libnm-core-impl/nm-setting-wireguard.c | 13 ++--- src/libnm-core-impl/nm-setting-wireless.c | 13 ++--- src/libnm-core-impl/nm-setting.c | 5 +- src/libnm-core-impl/nm-utils.c | 45 +++++++++-------- src/libnm-core-intern/nm-core-internal.h | 13 ++--- 12 files changed, 163 insertions(+), 140 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-ip-config.c b/src/libnm-core-impl/nm-setting-ip-config.c index dc0624c4d2..7f524a24f7 100644 --- a/src/libnm-core-impl/nm-setting-ip-config.c +++ b/src/libnm-core-impl/nm-setting-ip-config.c @@ -4985,12 +4985,13 @@ _routing_rules_dbus_only_synth(const NMSettInfoSetting * sett_info } static gboolean -_routing_rules_dbus_only_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +_routing_rules_dbus_only_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GVariantIter iter_rules; GVariant * rule_var; @@ -5775,12 +5776,13 @@ enumerate_values(const NMSettInfoProperty *property_info, /*****************************************************************************/ static gboolean -ip_gateway_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip_gateway_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { /* FIXME: properly handle errors */ @@ -5788,7 +5790,7 @@ ip_gateway_set(NMSetting * setting, if (_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "gateway")) return TRUE; - g_object_set(setting, property, g_variant_get_string(value, NULL), NULL); + g_object_set(setting, property_info->name, g_variant_get_string(value, NULL), NULL); return TRUE; } diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 2a10098e23..46263fb332 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -362,12 +362,13 @@ ip4_addresses_get(const NMSettInfoSetting * sett_info, } static gboolean -ip4_addresses_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip4_addresses_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *addrs; GVariant * s_ip4; @@ -467,12 +468,13 @@ ip4_address_data_get(const NMSettInfoSetting * sett_info, } static gboolean -ip4_address_data_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip4_address_data_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *addrs; @@ -503,12 +505,13 @@ ip4_routes_get(const NMSettInfoSetting * sett_info, } static gboolean -ip4_routes_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip4_routes_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *routes; @@ -518,7 +521,7 @@ ip4_routes_set(NMSetting * setting, return TRUE; routes = nm_utils_ip4_routes_from_variant(value); - g_object_set(setting, property, routes, NULL); + g_object_set(setting, property_info->name, routes, NULL); g_ptr_array_unref(routes); return TRUE; } @@ -541,12 +544,13 @@ ip4_route_data_get(const NMSettInfoSetting * sett_info, } static gboolean -ip4_route_data_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip4_route_data_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *routes; diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index abf0999961..1d29141eea 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -403,12 +403,13 @@ ip6_addresses_get(const NMSettInfoSetting * sett_info, } static gboolean -ip6_addresses_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip6_addresses_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *addrs; char * gateway = NULL; @@ -449,12 +450,13 @@ ip6_address_data_get(const NMSettInfoSetting * sett_info, } static gboolean -ip6_address_data_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip6_address_data_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *addrs; @@ -485,12 +487,13 @@ ip6_routes_get(const NMSettInfoSetting * sett_info, } static gboolean -ip6_routes_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip6_routes_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *routes; @@ -500,7 +503,7 @@ ip6_routes_set(NMSetting * setting, return TRUE; routes = nm_utils_ip6_routes_from_variant(value); - g_object_set(setting, property, routes, NULL); + g_object_set(setting, property_info->name, routes, NULL); g_ptr_array_unref(routes); return TRUE; } @@ -523,12 +526,13 @@ ip6_route_data_get(const NMSettInfoSetting * sett_info, } static gboolean -ip6_route_data_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +ip6_route_data_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *routes; diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index dd47e32158..6a19e0ec24 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -644,12 +644,13 @@ gboolean _nm_setting_should_compare_secret_property(NMSetting * settin NMBridgeVlan *_nm_bridge_vlan_dup(const NMBridgeVlan *vlan); NMBridgeVlan *_nm_bridge_vlan_dup_and_seal(const NMBridgeVlan *vlan); -gboolean _nm_utils_bridge_vlans_from_dbus(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error); +gboolean _nm_utils_bridge_vlans_from_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error); GVariant *_nm_utils_bridge_vlans_to_dbus(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, @@ -687,12 +688,13 @@ GVariant *_nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * se NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); -gboolean _nm_utils_hwaddr_cloned_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error); +gboolean _nm_utils_hwaddr_cloned_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-sriov.c b/src/libnm-core-impl/nm-setting-sriov.c index 3bddd3c2f8..adf43ceccd 100644 --- a/src/libnm-core-impl/nm-setting-sriov.c +++ b/src/libnm-core-impl/nm-setting-sriov.c @@ -956,12 +956,13 @@ vfs_to_dbus(const NMSettInfoSetting * sett_info, } static gboolean -vfs_from_dbus(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +vfs_from_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray * vfs; GVariantIter vf_iter; diff --git a/src/libnm-core-impl/nm-setting-tc-config.c b/src/libnm-core-impl/nm-setting-tc-config.c index c649a04a7a..2260678d02 100644 --- a/src/libnm-core-impl/nm-setting-tc-config.c +++ b/src/libnm-core-impl/nm-setting-tc-config.c @@ -1501,12 +1501,13 @@ tc_qdiscs_get(const NMSettInfoSetting * sett_info, } static gboolean -tc_qdiscs_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +tc_qdiscs_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GPtrArray *qdiscs; @@ -1699,12 +1700,13 @@ tc_tfilters_get(const NMSettInfoSetting * sett_info, } static gboolean -tc_tfilters_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +tc_tfilters_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { gs_unref_ptrarray GPtrArray *tfilters = NULL; diff --git a/src/libnm-core-impl/nm-setting-vpn.c b/src/libnm-core-impl/nm-setting-vpn.c index 0719c047a6..4faff54ad2 100644 --- a/src/libnm-core-impl/nm-setting-vpn.c +++ b/src/libnm-core-impl/nm-setting-vpn.c @@ -909,12 +909,13 @@ clear_secrets(const NMSettInfoSetting * sett_info, } static gboolean -vpn_secrets_from_dbus(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +vpn_secrets_from_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { NMSettingVpn * self = NM_SETTING_VPN(setting); NMSettingVpnPrivate *priv = NM_SETTING_VPN_GET_PRIVATE(self); diff --git a/src/libnm-core-impl/nm-setting-wireguard.c b/src/libnm-core-impl/nm-setting-wireguard.c index c7cdc78dc1..e8eeabb317 100644 --- a/src/libnm-core-impl/nm-setting-wireguard.c +++ b/src/libnm-core-impl/nm-setting-wireguard.c @@ -1563,12 +1563,13 @@ _peers_dbus_only_synth(const NMSettInfoSetting * sett_info, } static gboolean -_peers_dbus_only_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +_peers_dbus_only_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { GVariantIter iter_peers; GVariant * peer_var; diff --git a/src/libnm-core-impl/nm-setting-wireless.c b/src/libnm-core-impl/nm-setting-wireless.c index 726bd19f4f..4b7ec8fa1e 100644 --- a/src/libnm-core-impl/nm-setting-wireless.c +++ b/src/libnm-core-impl/nm-setting-wireless.c @@ -769,12 +769,13 @@ _to_dbus_fcn_seen_bssids(const NMSettInfoSetting * sett_info, } static gboolean -_from_dbus_fcn_seen_bssids(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +_from_dbus_fcn_seen_bssids(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { NMSettingWirelessPrivate *priv; gs_free const char ** s = NULL; diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index ee55e1249f..5ba37e0fce 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -1347,9 +1347,10 @@ init_from_dbus(NMSetting * setting, return FALSE; } - if (!property_info->property_type->from_dbus_fcn(setting, + if (!property_info->property_type->from_dbus_fcn(sett_info, + property_info, + setting, connection_dict, - property_info->name, value, parse_flags, &local)) { diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index ca7c820535..499fab3430 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -4040,18 +4040,19 @@ _nm_utils_hwaddr_cloned_get(const NMSettInfoSetting * sett_info, } gboolean -_nm_utils_hwaddr_cloned_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +_nm_utils_hwaddr_cloned_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { gsize length; const guint8 *array; char * str; - nm_assert(nm_streq0(property, "cloned-mac-address")); + nm_assert(nm_streq0(property_info->name, "cloned-mac-address")); if (!_nm_setting_use_legacy_property(setting, connection_dict, @@ -4117,14 +4118,15 @@ _nm_utils_hwaddr_cloned_data_synth(const NMSettInfoSetting * sett_ } static gboolean -_nm_utils_hwaddr_cloned_data_set(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +_nm_utils_hwaddr_cloned_data_set(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { - nm_assert(nm_streq0(property, "assigned-mac-address")); + nm_assert(nm_streq0(property_info->name, "assigned-mac-address")); if (_nm_setting_use_legacy_property(setting, connection_dict, @@ -5510,12 +5512,13 @@ _nm_utils_bridge_vlans_to_dbus(const NMSettInfoSetting * sett_info } gboolean -_nm_utils_bridge_vlans_from_dbus(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error) +_nm_utils_bridge_vlans_from_dbus(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) { gs_unref_ptrarray GPtrArray *vlans = NULL; GVariantIter vlan_iter; @@ -5556,7 +5559,7 @@ _nm_utils_bridge_vlans_from_dbus(NMSetting * setting, g_ptr_array_add(vlans, vlan); } - g_object_set(setting, property, vlans, NULL); + g_object_set(setting, property_info->name, vlans, NULL); return TRUE; } diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 59fb7853e7..89d86d0ee3 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -656,12 +656,13 @@ typedef GVariant *(*NMSettInfoPropToDBusFcn)(const NMSettInfoSetting * NMSetting * setting, NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); -typedef gboolean (*NMSettInfoPropFromDBusFcn)(NMSetting * setting, - GVariant * connection_dict, - const char * property, - GVariant * value, - NMSettingParseFlags parse_flags, - GError ** error); +typedef gboolean (*NMSettInfoPropFromDBusFcn)(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error); typedef gboolean (*NMSettInfoPropMissingFromDBusFcn)(NMSetting * setting, GVariant * connection_dict, const char * property, From 77d2c13e21c5153db71e033fe665b311f0a68e7a Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 30 Jun 2021 00:05:49 +0200 Subject: [PATCH 18/18] libnm: always set from_dbus_fcn() property hook When looking at a property, it should always be clear how it is handled. Also the "default" action should be an explicit hook. Add _nm_setting_property_from_dbus_fcn_gprop() and set that as from_dbus_fcn() callback to handle the "default" case which us build around g_object_set_property(). While this adds lines of code, I think it makes the code easier to understand. Basically, to convert a GVariant to a property, now all properties call their from_dbus_fcn() handler, there is no special casing. And the gprop-hook is only called for properties that are using _nm_setting_property_from_dbus_fcn_gprop(). So, you can reason about these two functions at separate layers. --- src/libnm-core-impl/nm-setting-bond.c | 6 +- src/libnm-core-impl/nm-setting-connection.c | 18 +- src/libnm-core-impl/nm-setting-dcb.c | 8 +- src/libnm-core-impl/nm-setting-ip4-config.c | 4 +- src/libnm-core-impl/nm-setting-ip6-config.c | 4 +- .../nm-setting-ovs-external-ids.c | 6 +- src/libnm-core-impl/nm-setting-private.h | 16 ++ src/libnm-core-impl/nm-setting-serial.c | 4 +- src/libnm-core-impl/nm-setting-team-port.c | 12 +- src/libnm-core-impl/nm-setting-team.c | 12 +- src/libnm-core-impl/nm-setting-user.c | 6 +- src/libnm-core-impl/nm-setting-vlan.c | 4 +- .../nm-setting-wireless-security.c | 6 +- src/libnm-core-impl/nm-setting.c | 208 ++++++++++++------ src/libnm-core-impl/nm-team-utils.c | 24 +- src/libnm-core-impl/nm-utils.c | 12 +- src/libnm-core-impl/tests/test-general.c | 3 +- src/libnm-core-impl/tests/test-setting.c | 19 +- src/libnm-core-intern/nm-core-internal.h | 20 +- 19 files changed, 274 insertions(+), 118 deletions(-) diff --git a/src/libnm-core-impl/nm-setting-bond.c b/src/libnm-core-impl/nm-setting-bond.c index bf5d88bacf..49e292a30f 100644 --- a/src/libnm-core-impl/nm-setting-bond.c +++ b/src/libnm-core-impl/nm-setting-bond.c @@ -1211,10 +1211,12 @@ nm_setting_bond_class_init(NMSettingBondClass *klass) properties_override, obj_properties[PROP_OPTIONS], NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("a{ss}"), - .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, + .typdata_from_dbus.gprop_fcn = _nm_utils_strdict_from_dbus, .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, - .compare_fcn = compare_fcn_options)); + .compare_fcn = compare_fcn_options, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /* ---dbus--- * property: interface-name diff --git a/src/libnm-core-impl/nm-setting-connection.c b/src/libnm-core-impl/nm-setting-connection.c index 89afbd6a92..a9a6fd9f1f 100644 --- a/src/libnm-core-impl/nm-setting-connection.c +++ b/src/libnm-core-impl/nm-setting-connection.c @@ -1898,9 +1898,11 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) PROP_ID, NM_SETTING_PARAM_FUZZY_IGNORE, NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, - .direct_type = NM_VALUE_TYPE_STRING, - .compare_fcn = compare_fcn_id, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct), + .direct_type = NM_VALUE_TYPE_STRING, + .compare_fcn = compare_fcn_id, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE), NMSettingConnectionPrivate, id); @@ -2025,7 +2027,9 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) .compare_fcn = _nm_setting_property_compare_fcn_direct, .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, .missing_from_dbus_fcn = - nm_setting_connection_no_interface_name), + nm_setting_connection_no_interface_name, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE), NMSettingConnectionPrivate, interface_name); @@ -2223,8 +2227,10 @@ nm_setting_connection_class_init(NMSettingConnectionClass *klass) properties_override, obj_properties[PROP_TIMESTAMP], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_UINT64, - .compare_fcn = compare_fcn_timestamp, - .to_dbus_fcn = _to_dbus_fcn_timestamp, )); + .compare_fcn = compare_fcn_timestamp, + .to_dbus_fcn = _to_dbus_fcn_timestamp, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /** * NMSettingConnection:read-only: diff --git a/src/libnm-core-impl/nm-setting-dcb.c b/src/libnm-core-impl/nm-setting-dcb.c index 2fee3b9f0e..47528b5186 100644 --- a/src/libnm-core-impl/nm-setting-dcb.c +++ b/src/libnm-core-impl/nm-setting-dcb.c @@ -757,9 +757,11 @@ _nm_setting_dcb_uint_array_from_dbus(GVariant *dbus_value, GValue *prop_value) static const NMSettInfoPropertType nm_sett_info_propert_type_dcb_au = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT( NM_G_VARIANT_TYPE("au"), - .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, - .gprop_from_dbus_fcn = _nm_setting_dcb_uint_array_from_dbus, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_GARRAY_UINT, + .typdata_from_dbus.gprop_fcn = _nm_setting_dcb_uint_array_from_dbus, + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-setting-ip4-config.c b/src/libnm-core-impl/nm-setting-ip4-config.c index 46263fb332..5995a582b7 100644 --- a/src/libnm-core-impl/nm-setting-ip4-config.c +++ b/src/libnm-core-impl/nm-setting-ip4-config.c @@ -975,7 +975,9 @@ nm_setting_ip4_config_class_init(NMSettingIP4ConfigClass *klass) NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("au"), .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = ip4_dns_to_dbus, - .gprop_from_dbus_fcn = ip4_dns_from_dbus, ), ); + .typdata_from_dbus.gprop_fcn = ip4_dns_from_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE), ); /* ---dbus--- * property: addresses diff --git a/src/libnm-core-impl/nm-setting-ip6-config.c b/src/libnm-core-impl/nm-setting-ip6-config.c index 1d29141eea..3c2dfc8595 100644 --- a/src/libnm-core-impl/nm-setting-ip6-config.c +++ b/src/libnm-core-impl/nm-setting-ip6-config.c @@ -1041,7 +1041,9 @@ nm_setting_ip6_config_class_init(NMSettingIP6ConfigClass *klass) NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aay"), .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = ip6_dns_to_dbus, - .gprop_from_dbus_fcn = ip6_dns_from_dbus, )); + .typdata_from_dbus.gprop_fcn = ip6_dns_from_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /* ---dbus--- * property: addresses diff --git a/src/libnm-core-impl/nm-setting-ovs-external-ids.c b/src/libnm-core-impl/nm-setting-ovs-external-ids.c index 3f0fc48c3f..d044aaf202 100644 --- a/src/libnm-core-impl/nm-setting-ovs-external-ids.c +++ b/src/libnm-core-impl/nm-setting-ovs-external-ids.c @@ -536,10 +536,12 @@ nm_setting_ovs_external_ids_class_init(NMSettingOvsExternalIDsClass *klass) properties_override, obj_properties[PROP_DATA], NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("a{ss}"), - .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, + .typdata_from_dbus.gprop_fcn = _nm_utils_strdict_from_dbus, .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, - .compare_fcn = compare_fcn_data)); + .compare_fcn = compare_fcn_data, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-private.h b/src/libnm-core-impl/nm-setting-private.h index 6a19e0ec24..dc0654ce83 100644 --- a/src/libnm-core-impl/nm-setting-private.h +++ b/src/libnm-core-impl/nm-setting-private.h @@ -364,6 +364,22 @@ GVariant *_nm_setting_property_to_dbus_fcn_direct(const NMSettInfoSetting * NMConnectionSerializationFlags flags, const NMConnectionSerializationOptions *options); +gboolean _nm_setting_property_from_dbus_fcn_ignore(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error); + +gboolean _nm_setting_property_from_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error); + GVariant *_nm_setting_to_dbus(NMSetting * setting, NMConnection * connection, NMConnectionSerializationFlags flags, diff --git a/src/libnm-core-impl/nm-setting-serial.c b/src/libnm-core-impl/nm-setting-serial.c index 95edf500a1..fe59ac3da0 100644 --- a/src/libnm-core-impl/nm-setting-serial.c +++ b/src/libnm-core-impl/nm-setting-serial.c @@ -321,7 +321,9 @@ nm_setting_serial_class_init(NMSettingSerialClass *klass) NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_BYTE, .compare_fcn = _nm_setting_property_compare_fcn_default, .to_dbus_fcn = parity_to_dbus_fcn, - .gprop_from_dbus_fcn = parity_from_dbus, )); + .typdata_from_dbus.gprop_fcn = parity_from_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /** * NMSettingSerial:stopbits: diff --git a/src/libnm-core-impl/nm-setting-team-port.c b/src/libnm-core-impl/nm-setting-team-port.c index d940200a2d..bed56656cf 100644 --- a/src/libnm-core-impl/nm-setting-team-port.c +++ b/src/libnm-core-impl/nm-setting-team-port.c @@ -578,8 +578,10 @@ nm_setting_team_port_class_init(NMSettingTeamPortClass *klass) properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, - .compare_fcn = compare_fcn_config, - .to_dbus_fcn = _nm_team_settings_property_to_dbus, )); + .compare_fcn = compare_fcn_config, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /** * NMSettingTeamPort:queue-id: @@ -701,8 +703,10 @@ nm_setting_team_port_class_init(NMSettingTeamPortClass *klass) NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), .compare_fcn = compare_fcn_link_watchers, .to_dbus_fcn = _nm_team_settings_property_to_dbus, - .gprop_from_dbus_fcn = - _nm_team_settings_property_from_dbus_link_watchers, )); + .typdata_from_dbus.gprop_fcn = + _nm_team_settings_property_from_dbus_link_watchers, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); g_object_class_install_properties(object_class, G_N_ELEMENTS(obj_properties), obj_properties); diff --git a/src/libnm-core-impl/nm-setting-team.c b/src/libnm-core-impl/nm-setting-team.c index f78ce51801..881bb81974 100644 --- a/src/libnm-core-impl/nm-setting-team.c +++ b/src/libnm-core-impl/nm-setting-team.c @@ -1540,8 +1540,10 @@ nm_setting_team_class_init(NMSettingTeamClass *klass) properties_override, obj_properties[NM_TEAM_ATTRIBUTE_CONFIG], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_STRING, - .compare_fcn = compare_fcn_config, - .to_dbus_fcn = _nm_team_settings_property_to_dbus, )); + .compare_fcn = compare_fcn_config, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /** * NMSettingTeam:notify-peers-count: @@ -1824,8 +1826,10 @@ nm_setting_team_class_init(NMSettingTeamClass *klass) NM_SETT_INFO_PROPERT_TYPE_DBUS(NM_G_VARIANT_TYPE("aa{sv}"), .compare_fcn = compare_fcn_link_watchers, .to_dbus_fcn = _nm_team_settings_property_to_dbus, - .gprop_from_dbus_fcn = - _nm_team_settings_property_from_dbus_link_watchers, )); + .typdata_from_dbus.gprop_fcn = + _nm_team_settings_property_from_dbus_link_watchers, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /* ---dbus--- * property: interface-name diff --git a/src/libnm-core-impl/nm-setting-user.c b/src/libnm-core-impl/nm-setting-user.c index b315acdc10..f597a0201d 100644 --- a/src/libnm-core-impl/nm-setting-user.c +++ b/src/libnm-core-impl/nm-setting-user.c @@ -577,10 +577,12 @@ nm_setting_user_class_init(NMSettingUserClass *klass) properties_override, obj_properties[PROP_DATA], NM_SETT_INFO_PROPERT_TYPE_GPROP(NM_G_VARIANT_TYPE("a{ss}"), - .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, + .typdata_from_dbus.gprop_fcn = _nm_utils_strdict_from_dbus, .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, - .compare_fcn = compare_fcn_data)); + .compare_fcn = compare_fcn_data, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties); diff --git a/src/libnm-core-impl/nm-setting-vlan.c b/src/libnm-core-impl/nm-setting-vlan.c index 13315dbc14..783b539c1f 100644 --- a/src/libnm-core-impl/nm-setting-vlan.c +++ b/src/libnm-core-impl/nm-setting-vlan.c @@ -929,7 +929,9 @@ nm_setting_vlan_class_init(NMSettingVlanClass *klass) NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_UINT32, .to_dbus_fcn = _override_flags_get, .compare_fcn = _nm_setting_property_compare_fcn_default, - .missing_from_dbus_fcn = _override_flags_not_set, )); + .missing_from_dbus_fcn = _override_flags_not_set, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /** * NMSettingVlan:ingress-priority-map: diff --git a/src/libnm-core-impl/nm-setting-wireless-security.c b/src/libnm-core-impl/nm-setting-wireless-security.c index 0b806b7a0e..3c4993d79d 100644 --- a/src/libnm-core-impl/nm-setting-wireless-security.c +++ b/src/libnm-core-impl/nm-setting-wireless-security.c @@ -1939,8 +1939,10 @@ nm_setting_wireless_security_class_init(NMSettingWirelessSecurityClass *klass) properties_override, obj_properties[PROP_WEP_KEY_TYPE], NM_SETT_INFO_PROPERT_TYPE_DBUS(G_VARIANT_TYPE_UINT32, - .to_dbus_fcn = wep_key_type_to_dbus, - .compare_fcn = _nm_setting_property_compare_fcn_default)); + .to_dbus_fcn = wep_key_type_to_dbus, + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE)); /** * NMSettingWirelessSecurity:wps-method: diff --git a/src/libnm-core-impl/nm-setting.c b/src/libnm-core-impl/nm-setting.c index 5ba37e0fce..342f9e0fa5 100644 --- a/src/libnm-core-impl/nm-setting.c +++ b/src/libnm-core-impl/nm-setting.c @@ -54,6 +54,9 @@ G_DEFINE_ABSTRACT_TYPE(NMSetting, nm_setting, G_TYPE_OBJECT) /*****************************************************************************/ static GenData *_gendata_hash(NMSetting *setting, gboolean create_if_necessary); +static gboolean set_property_from_dbus(const NMSettInfoProperty *property_info, + GVariant * src_value, + GValue * dst_value); /*****************************************************************************/ @@ -171,12 +174,15 @@ _nm_properties_override_assert(const NMSettInfoProperty *prop_info) /* we always require a dbus_type. */ nm_assert(property_type->dbus_type); - /* from_dbus_fcn and gprop_from_dbus_fcn cannot both be set. */ - nm_assert(!property_type->from_dbus_fcn || !property_type->gprop_from_dbus_fcn); + if (property_type->typdata_from_dbus.gprop_fcn) + nm_assert(property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_gprop); + + if (property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_gprop) + nm_assert(prop_info->param_spec); if (!prop_info->param_spec) { - /* if we don't have a param_spec, we cannot have gprop_from_dbus_fcn. */ - nm_assert(property_type->from_dbus_fcn || !property_type->gprop_from_dbus_fcn); + /* if we don't have a param_spec, we cannot have typdata_from_dbus.gprop_fcn. */ + nm_assert(property_type->from_dbus_fcn || !property_type->typdata_from_dbus.gprop_fcn); } } #endif @@ -372,11 +378,15 @@ _nm_setting_class_commit(NMSettingClass * setting_class, if (vtype == G_TYPE_BOOLEAN) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_BOOLEAN, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); else if (vtype == G_TYPE_UCHAR) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_BYTE, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); else if (vtype == G_TYPE_INT) p->property_type = &nm_sett_info_propert_type_plain_i; else if (vtype == G_TYPE_UINT) @@ -384,11 +394,15 @@ _nm_setting_class_commit(NMSettingClass * setting_class, else if (vtype == G_TYPE_INT64) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_INT64, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); else if (vtype == G_TYPE_UINT64) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_UINT64, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); else if (vtype == G_TYPE_STRING) { nm_assert(nm_streq(p->name, NM_SETTING_NAME) == (!NM_FLAGS_HAS(p->param_spec->flags, G_PARAM_WRITABLE))); @@ -397,31 +411,43 @@ _nm_setting_class_commit(NMSettingClass * setting_class, else { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); } } else if (vtype == G_TYPE_DOUBLE) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_DOUBLE, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); else if (vtype == G_TYPE_STRV) p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_STRING_ARRAY, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); else if (vtype == G_TYPE_BYTES) { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_BYTESTRING, .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_BYTES, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); } else if (g_type_is_a(vtype, G_TYPE_ENUM)) { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_INT32, .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_ENUM, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); } else if (g_type_is_a(vtype, G_TYPE_FLAGS)) { p->property_type = NM_SETT_INFO_PROPERT_TYPE_GPROP( G_VARIANT_TYPE_UINT32, .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_FLAGS, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); } else nm_assert_not_reached(); @@ -989,6 +1015,69 @@ _nm_setting_property_to_dbus_fcn_gprop(const NMSettInfoSetting * s return nm_assert_unreachable_val(NULL); } +gboolean +_nm_setting_property_from_dbus_fcn_ignore(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) +{ + return TRUE; +} + +gboolean +_nm_setting_property_from_dbus_fcn_gprop(const NMSettInfoSetting * sett_info, + const NMSettInfoProperty *property_info, + NMSetting * setting, + GVariant * connection_dict, + GVariant * value, + NMSettingParseFlags parse_flags, + GError ** error) +{ + nm_auto_unset_gvalue GValue object_value = G_VALUE_INIT; + gs_free_error GError *local = NULL; + + nm_assert(property_info->param_spec); + + g_value_init(&object_value, property_info->param_spec->value_type); + if (!set_property_from_dbus(property_info, value, &object_value)) { + /* for backward behavior, fail unless best-effort is chosen. */ + if (NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT)) + return TRUE; + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("can't set property of type '%s' from value of type '%s'"), + property_info->property_type->dbus_type + ? g_variant_type_peek_string(property_info->property_type->dbus_type) + : (property_info->param_spec + ? g_type_name(property_info->param_spec->value_type) + : "(unknown)"), + g_variant_get_type_string(value)); + g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name); + return FALSE; + } + + if (!nm_g_object_set_property(G_OBJECT(setting), + property_info->param_spec->name, + &object_value, + &local)) { + if (!NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) + return TRUE; + g_set_error(error, + NM_CONNECTION_ERROR, + NM_CONNECTION_ERROR_INVALID_PROPERTY, + _("can not set property: %s"), + local->message); + g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name); + return FALSE; + } + + return TRUE; +} + static GVariant * property_to_dbus(const NMSettInfoSetting * sett_info, const NMSettInfoProperty * property_info, @@ -1056,11 +1145,11 @@ set_property_from_dbus(const NMSettInfoProperty *property_info, nm_assert(property_info->param_spec); nm_assert(property_info->property_type->dbus_type); - if (property_info->property_type->gprop_from_dbus_fcn) { + if (property_info->property_type->typdata_from_dbus.gprop_fcn) { if (!g_variant_type_equal(g_variant_get_type(src_value), property_info->property_type->dbus_type)) return FALSE; - property_info->property_type->gprop_from_dbus_fcn(src_value, dst_value); + property_info->property_type->typdata_from_dbus.gprop_fcn(src_value, dst_value); } else if (dst_value->g_type == G_TYPE_BYTES) { if (!g_variant_is_of_type(src_value, G_VARIANT_TYPE_BYTESTRING)) return FALSE; @@ -1328,8 +1417,11 @@ init_from_dbus(NMSetting * setting, g_hash_table_remove(keys, property_info->name); if (property_info->property_type->from_dbus_fcn) { - if (!g_variant_type_equal(g_variant_get_type(value), - property_info->property_type->dbus_type)) { + if (property_info->property_type->from_dbus_is_full) { + /* These hooks perform their own type checking, and can coerce/ignore + * a value regardless of the D-Bus type. */ + } else if (!g_variant_type_equal(g_variant_get_type(value), + property_info->property_type->dbus_type)) { /* for backward behavior, fail unless best-effort is chosen. */ if (NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT)) continue; @@ -1354,7 +1446,10 @@ init_from_dbus(NMSetting * setting, value, parse_flags, &local)) { - if (!NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) + if (property_info->property_type->from_dbus_is_full) { + /* the error we received from from_dbus_fcn() should be propagated, even + * in non-strict mode. */ + } else if (!NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) continue; g_set_error(error, NM_CONNECTION_ERROR, @@ -1367,44 +1462,7 @@ init_from_dbus(NMSetting * setting, continue; } - if (property_info->param_spec) { - nm_auto_unset_gvalue GValue object_value = G_VALUE_INIT; - - g_value_init(&object_value, property_info->param_spec->value_type); - if (!set_property_from_dbus(property_info, value, &object_value)) { - /* for backward behavior, fail unless best-effort is chosen. */ - if (NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT)) - continue; - g_set_error( - error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("can't set property of type '%s' from value of type '%s'"), - property_info->property_type->dbus_type - ? g_variant_type_peek_string(property_info->property_type->dbus_type) - : (property_info->param_spec - ? g_type_name(property_info->param_spec->value_type) - : "(unknown)"), - g_variant_get_type_string(value)); - g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name); - return FALSE; - } - - if (!nm_g_object_set_property(G_OBJECT(setting), - property_info->param_spec->name, - &object_value, - &local)) { - if (!NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT)) - continue; - g_set_error(error, - NM_CONNECTION_ERROR, - NM_CONNECTION_ERROR_INVALID_PROPERTY, - _("can not set property: %s"), - local->message); - g_prefix_error(error, "%s.%s: ", nm_setting_get_name(setting), property_info->name); - return FALSE; - } - } + nm_assert(!property_info->param_spec); } return TRUE; @@ -2817,7 +2875,9 @@ const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_interface_name const NMSettInfoPropertType nm_sett_info_propert_type_setting_name = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_ignore, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_ignore, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_ignore, + .from_dbus_is_full = TRUE, .compare_fcn = _nm_setting_property_compare_fcn_ignore); const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_i = @@ -2834,29 +2894,39 @@ const NMSettInfoPropertType nm_sett_info_propert_type_deprecated_ignore_u = const NMSettInfoPropertType nm_sett_info_propert_type_plain_i = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_INT32, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); const NMSettInfoPropertType nm_sett_info_propert_type_plain_u = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_UINT32, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); const NMSettInfoPropertType nm_sett_info_propert_type_direct_boolean = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BOOLEAN, - .direct_type = NM_VALUE_TYPE_BOOL, - .compare_fcn = _nm_setting_property_compare_fcn_direct, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); + .direct_type = NM_VALUE_TYPE_BOOL, + .compare_fcn = _nm_setting_property_compare_fcn_direct, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); const NMSettInfoPropertType nm_sett_info_propert_type_direct_uint32 = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_UINT32, - .direct_type = NM_VALUE_TYPE_UINT32, - .compare_fcn = _nm_setting_property_compare_fcn_direct, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); + .direct_type = NM_VALUE_TYPE_UINT32, + .compare_fcn = _nm_setting_property_compare_fcn_direct, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); const NMSettInfoPropertType nm_sett_info_propert_type_direct_string = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, - .direct_type = NM_VALUE_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_direct, - .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct); + .direct_type = NM_VALUE_TYPE_STRING, + .compare_fcn = _nm_setting_property_compare_fcn_direct, + .to_dbus_fcn = _nm_setting_property_to_dbus_fcn_direct, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-team-utils.c b/src/libnm-core-impl/nm-team-utils.c index fe546320c3..a632b08e43 100644 --- a/src/libnm-core-impl/nm-team-utils.c +++ b/src/libnm-core-impl/nm-team-utils.c @@ -2787,23 +2787,31 @@ _nm_team_settings_property_from_dbus_link_watchers(GVariant *dbus_value, GValue const NMSettInfoPropertType nm_sett_info_propert_type_team_b = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_BOOLEAN, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); const NMSettInfoPropertType nm_sett_info_propert_type_team_i = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_INT32, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); const NMSettInfoPropertType nm_sett_info_propert_type_team_s = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(G_VARIANT_TYPE_STRING, - .compare_fcn = _nm_setting_property_compare_fcn_default, - .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); const NMSettInfoPropertType nm_sett_info_propert_type_team_as = NM_SETT_INFO_PROPERT_TYPE_DBUS_INIT(NM_G_VARIANT_TYPE("as"), - .compare_fcn = _nm_setting_property_compare_fcn_default, - .to_dbus_fcn = _nm_team_settings_property_to_dbus, ); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .to_dbus_fcn = _nm_team_settings_property_to_dbus, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); /*****************************************************************************/ diff --git a/src/libnm-core-impl/nm-utils.c b/src/libnm-core-impl/nm-utils.c index 499fab3430..5b1f85ccb5 100644 --- a/src/libnm-core-impl/nm-utils.c +++ b/src/libnm-core-impl/nm-utils.c @@ -775,10 +775,12 @@ _nm_utils_strdict_from_dbus(GVariant *dbus_value, GValue *prop_value) const NMSettInfoPropertType nm_sett_info_propert_type_strdict = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(NM_G_VARIANT_TYPE("a{ss}"), - .gprop_from_dbus_fcn = _nm_utils_strdict_from_dbus, + .typdata_from_dbus.gprop_fcn = _nm_utils_strdict_from_dbus, .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_STRDICT, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); GHashTable * _nm_utils_copy_strdict(GHashTable *strdict) @@ -4160,10 +4162,12 @@ _nm_utils_hwaddr_from_dbus(GVariant *dbus_value, GValue *prop_value) const NMSettInfoPropertType nm_sett_info_propert_type_mac_address = NM_SETT_INFO_PROPERT_TYPE_GPROP_INIT(G_VARIANT_TYPE_BYTESTRING, - .gprop_from_dbus_fcn = _nm_utils_hwaddr_from_dbus, + .typdata_from_dbus.gprop_fcn = _nm_utils_hwaddr_from_dbus, .typdata_to_dbus.gprop_type = NM_SETTING_PROPERTY_TO_DBUS_FCN_GPROP_TYPE_MAC_ADDRESS, - .compare_fcn = _nm_setting_property_compare_fcn_default); + .compare_fcn = _nm_setting_property_compare_fcn_default, + .from_dbus_fcn = _nm_setting_property_from_dbus_fcn_gprop, + .from_dbus_is_full = TRUE); /*****************************************************************************/ diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c index a7e741ea24..503613160c 100644 --- a/src/libnm-core-impl/tests/test-general.c +++ b/src/libnm-core-impl/tests/test-general.c @@ -3094,8 +3094,7 @@ test_setting_new_from_dbus_bad(void) "i", 10);); conn = _connection_new_from_dbus(dict, &error); - g_assert(conn); - g_assert_no_error(error); + nmtst_assert_success(conn, error); setting = nm_connection_get_setting(conn, NM_TYPE_SETTING_WIRELESS); g_assert(setting); g_assert_cmpint(nm_setting_wireless_get_rate(NM_SETTING_WIRELESS(setting)), ==, 10); diff --git a/src/libnm-core-impl/tests/test-setting.c b/src/libnm-core-impl/tests/test-setting.c index 4af74d0037..1c081b55db 100644 --- a/src/libnm-core-impl/tests/test-setting.c +++ b/src/libnm-core-impl/tests/test-setting.c @@ -4514,8 +4514,18 @@ check_done:; if (!can_set_including_default) g_assert(!sip->to_dbus_including_default); - g_assert(!sip->property_type->from_dbus_fcn - || !sip->property_type->gprop_from_dbus_fcn); + g_assert(sip->property_type->from_dbus_fcn || !sip->param_spec); + if (sip->property_type->typdata_from_dbus.gprop_fcn) { + g_assert(sip->property_type->from_dbus_fcn + == _nm_setting_property_from_dbus_fcn_gprop); + } + if (sip->property_type->from_dbus_fcn == _nm_setting_property_from_dbus_fcn_gprop) + g_assert(sip->param_spec); + + g_assert(sip->property_type->from_dbus_is_full + == NM_IN_SET(sip->property_type->from_dbus_fcn, + _nm_setting_property_from_dbus_fcn_gprop, + _nm_setting_property_from_dbus_fcn_ignore)); if (!g_hash_table_insert(h_properties, (char *) sip->name, sip->param_spec)) g_assert_not_reached(); @@ -4708,7 +4718,10 @@ check_done:; || pt->from_dbus_fcn != pt_2->from_dbus_fcn || pt->compare_fcn != pt_2->compare_fcn || pt->missing_from_dbus_fcn != pt_2->missing_from_dbus_fcn - || pt->gprop_from_dbus_fcn != pt_2->gprop_from_dbus_fcn + || memcmp(&pt->typdata_from_dbus, + &pt_2->typdata_from_dbus, + sizeof(pt->typdata_from_dbus)) + != 0 || memcmp(&pt->typdata_to_dbus, &pt_2->typdata_to_dbus, sizeof(pt->typdata_to_dbus)) diff --git a/src/libnm-core-intern/nm-core-internal.h b/src/libnm-core-intern/nm-core-internal.h index 89d86d0ee3..26f69d3e65 100644 --- a/src/libnm-core-intern/nm-core-internal.h +++ b/src/libnm-core-intern/nm-core-internal.h @@ -693,6 +693,15 @@ typedef struct { * to the property value. */ NMValueType direct_type; + /* Whether from_dbus_fcn() has special capabilities + * + * - whether the from_dbus_fcn expects to handle differences between + * the D-Bus types and can convert between them. Otherwise, the caller + * will already pre-validate that the D-Bus types match. + * - by default, with NM_SETTING_PARSE_FLAGS_BEST_EFFORT all errors from + * from_dbus_fcn() are ignored. If true, then error are propagated. */ + bool from_dbus_is_full : 1; + /* compare_fcn() returns a ternary, where DEFAULT means that the property should not * be compared due to the compare @flags. A TRUE/FALSE result means that the property is * equal/not-equal. @@ -711,9 +720,14 @@ typedef struct { NMSettInfoPropFromDBusFcn from_dbus_fcn; NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn; - /* Simpler variants of @from_dbus_fcn that operate solely - * on the GValue value of the GObject property. */ - NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn; + struct { + union { + /* If from_dbus_fcn is set to _nm_setting_property_from_dbus_fcn_gprop, + * then this is an optional handler for converting between GVariant and + * GValue. */ + NMSettInfoPropGPropFromDBusFcn gprop_fcn; + }; + } typdata_from_dbus; struct { union {