libnm: add out_is_modified argument to from_dbus_fcn() to detect modification

Note that most implementations use g_object_set(), and it's not
easy to detect modification. In those cases, we assume that modification
happened -- just like also the GObject setter will emit a notification
(as none of our properties use G_PARAM_EXPLICIT_NOTIFY).
This commit is contained in:
Thomas Haller
2021-07-27 10:27:44 +02:00
parent c593980b2d
commit f1fee9fe27
9 changed files with 71 additions and 33 deletions

View File

@@ -5024,6 +5024,7 @@ _routing_rules_dbus_only_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
success = TRUE;
out:
*out_is_modified = rules_changed;
if (rules_changed)
_routing_rules_notify(NM_SETTING_IP_CONFIG(setting));
return success;
@@ -5760,6 +5761,7 @@ _nm_setting_property_from_dbus_fcn_direct_ip_config_gateway(
connection_dict,
value,
parse_flags,
out_is_modified,
error);
}

View File

@@ -361,8 +361,10 @@ ip4_addresses_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
/* FIXME: properly handle errors */
if (!_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data"))
if (!_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data")) {
*out_is_modified = FALSE;
return TRUE;
}
addrs = nm_utils_ip4_addresses_from_variant(value, &gateway);
@@ -449,8 +451,10 @@ ip4_address_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
/* FIXME: properly handle errors */
/* Ignore 'address-data' if we're going to process 'addresses' */
if (_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data"))
if (_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data")) {
*out_is_modified = FALSE;
return TRUE;
}
addrs = nm_utils_ip_addresses_from_variant(value, AF_INET);
g_object_set(setting, NM_SETTING_IP_CONFIG_ADDRESSES, addrs, NULL);
@@ -474,8 +478,10 @@ ip4_routes_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
/* FIXME: properly handle errors */
if (!_nm_setting_use_legacy_property(setting, connection_dict, "routes", "route-data"))
if (!_nm_setting_use_legacy_property(setting, connection_dict, "routes", "route-data")) {
*out_is_modified = FALSE;
return TRUE;
}
routes = nm_utils_ip4_routes_from_variant(value);
g_object_set(setting, property_info->name, routes, NULL);
@@ -503,8 +509,10 @@ ip4_route_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
/* FIXME: properly handle errors */
/* Ignore 'route-data' if we're going to process 'routes' */
if (_nm_setting_use_legacy_property(setting, connection_dict, "routes", "route-data"))
if (_nm_setting_use_legacy_property(setting, connection_dict, "routes", "route-data")) {
*out_is_modified = FALSE;
return TRUE;
}
routes = nm_utils_ip_routes_from_variant(value, AF_INET);
g_object_set(setting, NM_SETTING_IP_CONFIG_ROUTES, routes, NULL);

View File

@@ -398,10 +398,10 @@ ip6_addresses_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
GPtrArray *addrs;
char * gateway = NULL;
/* FIXME: properly handle errors */
if (!_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data"))
if (!_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data")) {
*out_is_modified = FALSE;
return TRUE;
}
addrs = nm_utils_ip6_addresses_from_variant(value, &gateway);
@@ -433,11 +433,11 @@ ip6_address_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
{
GPtrArray *addrs;
/* FIXME: properly handle errors */
/* Ignore 'address-data' if we're going to process 'addresses' */
if (_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data"))
if (_nm_setting_use_legacy_property(setting, connection_dict, "addresses", "address-data")) {
*out_is_modified = FALSE;
return TRUE;
}
addrs = nm_utils_ip_addresses_from_variant(value, AF_INET6);
g_object_set(setting, NM_SETTING_IP_CONFIG_ADDRESSES, addrs, NULL);
@@ -459,10 +459,10 @@ ip6_routes_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
{
GPtrArray *routes;
/* FIXME: properly handle errors */
if (!_nm_setting_use_legacy_property(setting, connection_dict, "routes", "route-data"))
if (!_nm_setting_use_legacy_property(setting, connection_dict, "routes", "route-data")) {
*out_is_modified = FALSE;
return TRUE;
}
routes = nm_utils_ip6_routes_from_variant(value);
g_object_set(setting, property_info->name, routes, NULL);
@@ -487,11 +487,11 @@ ip6_route_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
{
GPtrArray *routes;
/* FIXME: properly handle errors */
/* Ignore 'route-data' if we're going to process 'routes' */
if (_nm_setting_use_legacy_property(setting, connection_dict, "routes", "route-data"))
if (_nm_setting_use_legacy_property(setting, connection_dict, "routes", "route-data")) {
*out_is_modified = FALSE;
return TRUE;
}
routes = nm_utils_ip_routes_from_variant(value, AF_INET6);
g_object_set(setting, NM_SETTING_IP_CONFIG_ROUTES, routes, NULL);

View File

@@ -1486,12 +1486,10 @@ tc_qdiscs_get(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_nil)
static gboolean
tc_qdiscs_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
{
GPtrArray *qdiscs;
gs_unref_ptrarray GPtrArray *qdiscs = NULL;
qdiscs = _qdiscs_from_variant(value);
g_object_set(setting, NM_SETTING_TC_CONFIG_QDISCS, qdiscs, NULL);
g_ptr_array_unref(qdiscs);
return TRUE;
}

View File

@@ -1677,6 +1677,7 @@ _peers_dbus_only_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
success = TRUE;
out:
*out_is_modified = peers_changed;
if (peers_changed)
_peers_notify(setting);
return success;

View File

@@ -771,6 +771,7 @@ _from_dbus_fcn_seen_bssids(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
if (_nm_utils_is_manager_process) {
/* in the manager process, we don't accept seen-bssid from the client.
* Do nothing. */
*out_is_modified = FALSE;
return TRUE;
}

View File

@@ -1071,6 +1071,7 @@ _nm_setting_property_to_dbus_fcn_gprop(_NM_SETT_INFO_PROP_TO_DBUS_FCN_ARGS _nm_n
gboolean
_nm_setting_property_from_dbus_fcn_ignore(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
{
*out_is_modified = FALSE;
return TRUE;
}
@@ -1091,8 +1092,10 @@ _nm_setting_property_from_dbus_fcn_direct_mac_address(_NM_SETT_INFO_PROP_FROM_DB
if (nm_strdup_reset_take(
_nm_setting_get_private(setting, sett_info, property_info->direct_offset),
length > 0 ? nm_utils_hwaddr_ntoa(array, length) : NULL))
length > 0 ? nm_utils_hwaddr_ntoa(array, length) : NULL)) {
g_object_notify_by_pspec(G_OBJECT(setting), property_info->param_spec);
} else
*out_is_modified = FALSE;
return TRUE;
}
@@ -1125,6 +1128,8 @@ _nm_setting_property_from_dbus_fcn_direct(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS
_success; \
})
*out_is_modified = FALSE;
switch (property_info->property_type->direct_type) {
case NM_VALUE_TYPE_BOOL:
{
@@ -1239,6 +1244,7 @@ out_unchanged:
return TRUE;
out_notify:
*out_is_modified = TRUE;
g_object_notify_by_pspec(G_OBJECT(setting), property_info->param_spec);
return TRUE;
@@ -1282,6 +1288,7 @@ _nm_setting_property_from_dbus_fcn_gprop(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _
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. */
*out_is_modified = FALSE;
if (NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_BEST_EFFORT))
return TRUE;
g_set_error(error,
@@ -1302,6 +1309,7 @@ _nm_setting_property_from_dbus_fcn_gprop(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _
property_info->param_spec->name,
&object_value,
&local)) {
*out_is_modified = FALSE;
if (!NM_FLAGS_HAS(parse_flags, NM_SETTING_PARSE_FLAGS_STRICT))
return TRUE;
g_set_error(error,
@@ -1567,9 +1575,14 @@ _property_set_from_dbus(const NMSettInfoSetting * sett_info,
GVariant * connection_dict,
GVariant * value,
NMSettingParseFlags parse_flags,
gboolean * out_is_modified,
GError ** error)
{
gs_free_error GError *local = NULL;
NMTernary is_modified = NM_TERNARY_DEFAULT;
gboolean success;
NM_SET_OUT(out_is_modified, FALSE);
if (!property_info->property_type->from_dbus_fcn) {
nm_assert(!property_info->param_spec);
@@ -1597,13 +1610,21 @@ _property_set_from_dbus(const NMSettInfoSetting * sett_info,
return FALSE;
}
if (!property_info->property_type->from_dbus_fcn(sett_info,
success = property_info->property_type->from_dbus_fcn(sett_info,
property_info,
setting,
connection_dict,
value,
parse_flags,
&local)) {
&is_modified,
&local);
/* We allow the from_dbus_fcn() to leave is_modified at NM_TERNARY_DEFAULT,
* which we assume to also mean that it was modified. That is, we err on the
* side of assuming modification happened. */
NM_SET_OUT(out_is_modified, is_modified != FALSE);
if (!success) {
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. */
@@ -1711,6 +1732,7 @@ init_from_dbus(NMSetting * setting,
connection_dict,
value,
parse_flags,
NULL,
error))
return FALSE;
}

View File

@@ -4084,14 +4084,18 @@ _nm_utils_hwaddr_cloned_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
if (!_nm_setting_use_legacy_property(setting,
connection_dict,
"cloned-mac-address",
"assigned-mac-address"))
"assigned-mac-address")) {
*out_is_modified = FALSE;
return TRUE;
}
length = 0;
array = g_variant_get_fixed_array(value, &length, 1);
if (!length)
if (!length) {
*out_is_modified = FALSE;
return TRUE;
}
str = nm_utils_hwaddr_ntoa(array, length);
g_object_set(setting, "cloned-mac-address", str, NULL);
@@ -4143,8 +4147,10 @@ _nm_utils_hwaddr_cloned_data_set(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil)
if (_nm_setting_use_legacy_property(setting,
connection_dict,
"cloned-mac-address",
"assigned-mac-address"))
"assigned-mac-address")) {
*out_is_modified = FALSE;
return TRUE;
}
g_object_set(setting,
"cloned-mac-address",

View File

@@ -716,7 +716,7 @@ typedef struct {
#define _NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS \
const NMSettInfoSetting *sett_info, const NMSettInfoProperty *property_info, \
NMSetting *setting, GVariant *connection_dict, GVariant *value, \
NMSettingParseFlags parse_flags, GError **error
NMSettingParseFlags parse_flags, NMTernary *out_is_modified, GError **error
gboolean (*from_dbus_fcn)(_NM_SETT_INFO_PROP_FROM_DBUS_FCN_ARGS _nm_nil);