libnm: merge branch 'th/libnm-setting-cleanup'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/126
This commit is contained in:
Thomas Haller 2019-05-01 13:46:50 +02:00
commit da3750d758
25 changed files with 555 additions and 385 deletions

View file

@ -581,7 +581,8 @@ nm_connection_compare (NMConnection *a,
while (g_hash_table_iter_next (&iter, NULL, (gpointer) &src)) {
NMSetting *cmp = nm_connection_get_setting (b, G_OBJECT_TYPE (src));
if (!cmp || !nm_setting_compare (src, cmp, flags))
if ( !cmp
|| !_nm_setting_compare (a, src, b, cmp, flags))
return FALSE;
}
@ -614,7 +615,7 @@ diff_one_connection (NMConnection *a,
if (results)
new_results = FALSE;
if (!nm_setting_diff (a_setting, b_setting, flags, invert_results, &results))
if (!_nm_setting_diff (a, a_setting, b, b_setting, flags, invert_results, &results))
diff_found = TRUE;
if (new_results && results)

View file

@ -662,40 +662,40 @@ GVariant *nm_ip_routing_rule_to_dbus (const NMIPRoutingRule *self);
typedef struct _NMSettInfoSetting NMSettInfoSetting;
typedef struct _NMSettInfoProperty NMSettInfoProperty;
typedef GVariant *(*NMSettingPropertyGetFunc) (NMSetting *setting,
const char *property);
typedef GVariant *(*NMSettingPropertySynthFunc) (const NMSettInfoSetting *sett_info,
typedef GVariant *(*NMSettInfoPropToDBusFcn) (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags);
typedef gboolean (*NMSettingPropertySetFunc) (NMSetting *setting,
typedef gboolean (*NMSettInfoPropFromDBusFcn) (NMSetting *setting,
GVariant *connection_dict,
const char *property,
GVariant *value,
NMSettingParseFlags parse_flags,
GError **error);
typedef gboolean (*NMSettingPropertyNotSetFunc) (NMSetting *setting,
typedef gboolean (*NMSettInfoPropMissingFromDBusFcn) (NMSetting *setting,
GVariant *connection_dict,
const char *property,
NMSettingParseFlags parse_flags,
GError **error);
typedef GVariant *(*NMSettingPropertyTransformToFunc) (const GValue *from);
typedef void (*NMSettingPropertyTransformFromFunc) (GVariant *from,
GValue *to);
typedef GVariant *(*NMSettInfoPropGPropToDBusFcn) (const GValue *from);
typedef void (*NMSettInfoPropGPropFromDBusFcn) (GVariant *from,
GValue *to);
struct _NMSettInfoProperty {
const char *name;
GParamSpec *param_spec;
const GVariantType *dbus_type;
NMSettingPropertyGetFunc get_func;
NMSettingPropertySynthFunc synth_func;
NMSettingPropertySetFunc set_func;
NMSettingPropertyNotSetFunc not_set_func;
NMSettInfoPropToDBusFcn to_dbus_fcn;
NMSettInfoPropFromDBusFcn from_dbus_fcn;
NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn;
NMSettingPropertyTransformToFunc to_dbus;
NMSettingPropertyTransformFromFunc from_dbus;
/* Simpler variants of @to_dbus_fcn/@from_dbus_fcn that operate solely
* on the GValue value of the GObject property. */
NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn;
NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn;
};
typedef struct {
@ -769,6 +769,20 @@ _nm_setting_class_get_property_info (NMSettingClass *setting_class,
/*****************************************************************************/
gboolean _nm_setting_compare (NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags);
gboolean _nm_setting_diff (NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags,
gboolean invert_results,
GHashTable **results);
NMSetting8021xCKScheme _nm_setting_802_1x_cert_get_scheme (GBytes *bytes, GError **error);
GBytes *_nm_setting_802_1x_cert_value_to_bytes (NMSetting8021xCKScheme scheme,

View file

@ -854,21 +854,25 @@ options_equal (NMSettingBond *s_bond,
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
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)) {
return ( !other
|| options_equal (NM_SETTING_BOND (setting),
NM_SETTING_BOND (other),
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,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -356,8 +356,10 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingBridgePortPrivate *priv_a;
@ -365,9 +367,9 @@ compare_property (const NMSettInfoSetting *sett_info,
guint i;
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_BRIDGE_PORT_VLANS)) {
if (other) {
priv_a = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (setting);
priv_b = NM_SETTING_BRIDGE_PORT_GET_PRIVATE (other);
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;
@ -381,8 +383,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_bridge_port_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -997,8 +997,10 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingBridgePrivate *priv_a;
@ -1006,9 +1008,9 @@ compare_property (const NMSettInfoSetting *sett_info,
guint i;
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_BRIDGE_VLANS)) {
if (other) {
priv_a = NM_SETTING_BRIDGE_GET_PRIVATE (setting);
priv_b = NM_SETTING_BRIDGE_GET_PRIVATE (other);
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;
@ -1022,8 +1024,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_bridge_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -1268,8 +1268,10 @@ nm_setting_connection_no_interface_name (NMSetting *setting,
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
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)
@ -1282,8 +1284,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_connection_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -4969,8 +4969,10 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingIPConfigPrivate *a_priv;
@ -4978,9 +4980,9 @@ compare_property (const NMSettInfoSetting *sett_info,
guint i;
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_IP_CONFIG_ADDRESSES)) {
if (other) {
a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (other);
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)
return FALSE;
@ -4993,9 +4995,9 @@ compare_property (const NMSettInfoSetting *sett_info,
}
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_IP_CONFIG_ROUTES)) {
if (other) {
a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (other);
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;
@ -5008,11 +5010,11 @@ compare_property (const NMSettInfoSetting *sett_info,
}
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_IP_CONFIG_ROUTING_RULES)) {
if (other) {
if (set_b) {
guint n;
a_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (setting);
b_priv = NM_SETTING_IP_CONFIG_GET_PRIVATE (other);
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))
@ -5027,8 +5029,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_ip_config_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -253,19 +253,18 @@ ip4_dns_from_dbus (GVariant *dbus_value,
}
static GVariant *
ip4_addresses_get (NMSetting *setting,
const char *property)
ip4_addresses_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
GPtrArray *addrs;
gs_unref_ptrarray GPtrArray *addrs = NULL;
const char *gateway;
GVariant *ret;
g_object_get (setting, property, &addrs, NULL);
g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting));
ret = nm_utils_ip4_addresses_to_variant (addrs, gateway);
g_ptr_array_unref (addrs);
return ret;
return nm_utils_ip4_addresses_to_variant (addrs, gateway);
}
static gboolean
@ -388,17 +387,16 @@ ip4_address_data_set (NMSetting *setting,
}
static GVariant *
ip4_routes_get (NMSetting *setting,
const char *property)
ip4_routes_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
GPtrArray *routes;
GVariant *ret;
gs_unref_ptrarray GPtrArray *routes = NULL;
g_object_get (setting, property, &routes, NULL);
ret = nm_utils_ip4_routes_to_variant (routes);
g_ptr_array_unref (routes);
return ret;
g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
return nm_utils_ip4_routes_to_variant (routes);
}
static gboolean

View file

@ -313,19 +313,18 @@ ip6_dns_from_dbus (GVariant *dbus_value,
}
static GVariant *
ip6_addresses_get (NMSetting *setting,
const char *property)
ip6_addresses_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
GPtrArray *addrs;
gs_unref_ptrarray GPtrArray *addrs = NULL;
const char *gateway;
GVariant *ret;
g_object_get (setting, property, &addrs, NULL);
g_object_get (setting, NM_SETTING_IP_CONFIG_ADDRESSES, &addrs, NULL);
gateway = nm_setting_ip_config_get_gateway (NM_SETTING_IP_CONFIG (setting));
ret = nm_utils_ip6_addresses_to_variant (addrs, gateway);
g_ptr_array_unref (addrs);
return ret;
return nm_utils_ip6_addresses_to_variant (addrs, gateway);
}
static gboolean
@ -394,17 +393,16 @@ ip6_address_data_set (NMSetting *setting,
}
static GVariant *
ip6_routes_get (NMSetting *setting,
const char *property)
ip6_routes_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
GPtrArray *routes;
GVariant *ret;
gs_unref_ptrarray GPtrArray *routes = NULL;
g_object_get (setting, property, &routes, NULL);
ret = nm_utils_ip6_routes_to_variant (routes);
g_ptr_array_unref (routes);
return ret;
g_object_get (setting, NM_SETTING_IP_CONFIG_ROUTES, &routes, NULL);
return nm_utils_ip6_routes_to_variant (routes);
}
static gboolean

View file

@ -175,21 +175,21 @@ void _properties_override_add__helper (GArray *properties_override,
void _properties_override_add_dbus_only (GArray *properties_override,
const char *property_name,
const GVariantType *dbus_type,
NMSettingPropertySynthFunc synth_func,
NMSettingPropertySetFunc set_func);
NMSettInfoPropToDBusFcn to_dbus_fcn,
NMSettInfoPropFromDBusFcn from_dbus_fcn);
void _properties_override_add_override (GArray *properties_override,
GParamSpec *param_spec,
const GVariantType *dbus_type,
NMSettingPropertyGetFunc get_func,
NMSettingPropertySetFunc set_func,
NMSettingPropertyNotSetFunc not_set_func);
NMSettInfoPropToDBusFcn to_dbus_fcn,
NMSettInfoPropFromDBusFcn from_dbus_fcn,
NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn);
void _properties_override_add_transform (GArray *properties_override,
GParamSpec *param_spec,
const GVariantType *dbus_type,
NMSettingPropertyTransformToFunc to_dbus,
NMSettingPropertyTransformFromFunc from_dbus);
NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn,
NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn);
/*****************************************************************************/

View file

@ -905,7 +905,11 @@ _nm_setting_sriov_sort_vfs (NMSettingSriov *setting)
/*****************************************************************************/
static GVariant *
vfs_to_dbus (NMSetting *setting, const char *property)
vfs_to_dbus (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
gs_unref_ptrarray GPtrArray *vfs = NULL;
GVariantBuilder builder;
@ -1129,8 +1133,10 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingSriov *a;
@ -1138,9 +1144,9 @@ compare_property (const NMSettInfoSetting *sett_info,
guint i;
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_SRIOV_VFS)) {
if (other) {
a = NM_SETTING_SRIOV (setting);
b = NM_SETTING_SRIOV (other);
if (set_b) {
a = NM_SETTING_SRIOV (set_a);
b = NM_SETTING_SRIOV (set_b);
if (a->vfs->len != b->vfs->len)
return FALSE;
@ -1154,8 +1160,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_sriov_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -1325,16 +1325,18 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingTCConfig *a_tc_config = NM_SETTING_TC_CONFIG (setting);
NMSettingTCConfig *b_tc_config = NM_SETTING_TC_CONFIG (other);
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 (other) {
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++) {
@ -1346,7 +1348,7 @@ compare_property (const NMSettInfoSetting *sett_info,
}
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_TC_CONFIG_TFILTERS)) {
if (other) {
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++) {
@ -1359,8 +1361,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_tc_config_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}
@ -1479,17 +1483,16 @@ next:
}
static GVariant *
tc_qdiscs_get (NMSetting *setting,
const char *property)
tc_qdiscs_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
GPtrArray *qdiscs;
GVariant *ret;
gs_unref_ptrarray GPtrArray *qdiscs = NULL;
g_object_get (setting, NM_SETTING_TC_CONFIG_QDISCS, &qdiscs, NULL);
ret = _qdiscs_to_variant (qdiscs);
g_ptr_array_unref (qdiscs);
return ret;
return _qdiscs_to_variant (qdiscs);
}
static gboolean
@ -1665,17 +1668,16 @@ next:
}
static GVariant *
tc_tfilters_get (NMSetting *setting,
const char *property)
tc_tfilters_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
GPtrArray *tfilters;
GVariant *ret;
gs_unref_ptrarray GPtrArray *tfilters = NULL;
g_object_get (setting, NM_SETTING_TC_CONFIG_TFILTERS, &tfilters, NULL);
ret = _tfilters_to_variant (tfilters);
g_ptr_array_unref (tfilters);
return ret;
return _tfilters_to_variant (tfilters);
}
static gboolean
@ -1686,12 +1688,10 @@ tc_tfilters_set (NMSetting *setting,
NMSettingParseFlags parse_flags,
GError **error)
{
GPtrArray *tfilters;
gs_unref_ptrarray GPtrArray *tfilters = NULL;
tfilters = _tfilters_from_variant (value);
g_object_set (setting, NM_SETTING_TC_CONFIG_TFILTERS, tfilters, NULL);
g_ptr_array_unref (tfilters);
return TRUE;
}

View file

@ -390,8 +390,10 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingTeamPortPrivate *a_priv;
@ -401,19 +403,19 @@ compare_property (const NMSettInfoSetting *sett_info,
if (NM_FLAGS_HAS (flags, NM_SETTING_COMPARE_FLAG_INFERRABLE))
return NM_TERNARY_DEFAULT;
if (!other)
if (!set_b)
return TRUE;
a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (setting);
b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (other);
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->link_watchers,
b_priv->link_watchers,
TRUE);
}
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_TEAM_PORT_CONFIG)) {
if (other) {
a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (setting);
b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (other);
if (set_b) {
a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (set_a);
b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (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
@ -433,8 +435,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_team_port_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -1314,8 +1314,10 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingTeamPrivate *a_priv, *b_priv;
@ -1323,19 +1325,19 @@ compare_property (const NMSettInfoSetting *sett_info,
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_TEAM_LINK_WATCHERS)) {
if (NM_FLAGS_HAS (flags, NM_SETTING_COMPARE_FLAG_INFERRABLE))
return NM_TERNARY_DEFAULT;
if (!other)
if (!set_b)
return TRUE;
a_priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
b_priv = NM_SETTING_TEAM_GET_PRIVATE (other);
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->link_watchers,
b_priv->link_watchers,
TRUE);
}
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_TEAM_CONFIG)) {
if (other) {
a_priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
b_priv = NM_SETTING_TEAM_GET_PRIVATE (other);
if (set_b) {
a_priv = NM_SETTING_TEAM_GET_PRIVATE (set_a);
b_priv = NM_SETTING_TEAM_GET_PRIVATE (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
@ -1355,8 +1357,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_team_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -398,8 +398,10 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingUserPrivate *priv, *pri2;
@ -409,19 +411,21 @@ compare_property (const NMSettInfoSetting *sett_info,
if (NM_FLAGS_HAS (flags, NM_SETTING_COMPARE_FLAG_INFERRABLE))
return NM_TERNARY_DEFAULT;
if (!other)
if (!set_b)
return TRUE;
priv = NM_SETTING_USER_GET_PRIVATE (NM_SETTING_USER (setting));
pri2 = NM_SETTING_USER_GET_PRIVATE (NM_SETTING_USER (other));
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_hash_table_equal (priv->data, pri2->data, TRUE, g_str_equal)
&& nm_utils_hash_table_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_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -679,7 +679,11 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
}
static GVariant *
_override_flags_get (NMSetting *setting, const char *property)
_override_flags_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
return g_variant_new_uint32 (nm_setting_vlan_get_flags ((NMSettingVlan *) setting));
}
@ -921,7 +925,7 @@ nm_setting_vlan_class_init (NMSettingVlanClass *klass)
_properties_override_add_override (properties_override,
obj_properties[PROP_FLAGS],
NULL,
G_VARIANT_TYPE_UINT32,
_override_flags_get,
NULL,
_override_flags_not_set);

View file

@ -839,20 +839,24 @@ compare_property_secrets (NMSettingVpn *a,
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
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 (NM_FLAGS_HAS (flags, NM_SETTING_COMPARE_FLAG_INFERRABLE))
return NM_TERNARY_DEFAULT;
return compare_property_secrets (NM_SETTING_VPN (setting), NM_SETTING_VPN (other), flags);
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,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -905,26 +905,34 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
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)) {
return !other
|| nm_streq0 (NM_SETTING_WIRED_GET_PRIVATE (setting)->cloned_mac_address,
NM_SETTING_WIRED_GET_PRIVATE (other)->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,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}
static GVariant *
_override_autoneg_get (NMSetting *setting, const char *property)
_override_autoneg_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
return g_variant_new_boolean (nm_setting_wired_get_auto_negotiate ((NMSettingWired *) setting));
}
@ -1406,11 +1414,11 @@ nm_setting_wired_class_init (NMSettingWiredClass *klass)
G_PARAM_STATIC_STRINGS);
_properties_override_add_override (properties_override,
obj_properties[PROP_CLONED_MAC_ADDRESS],
G_VARIANT_TYPE_BYTESTRING,
_nm_utils_hwaddr_cloned_get,
_nm_utils_hwaddr_cloned_set,
_nm_utils_hwaddr_cloned_not_set);
obj_properties[PROP_CLONED_MAC_ADDRESS],
G_VARIANT_TYPE_BYTESTRING,
_nm_utils_hwaddr_cloned_get,
_nm_utils_hwaddr_cloned_set,
_nm_utils_hwaddr_cloned_not_set);
/* ---dbus---
* property: assigned-mac-address

View file

@ -1945,8 +1945,10 @@ update_one_secret (NMSetting *setting,
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMSettingWireGuardPrivate *a_priv;
@ -1958,11 +1960,11 @@ compare_property (const NMSettInfoSetting *sett_info,
if (NM_FLAGS_HAS (flags, NM_SETTING_COMPARE_FLAG_INFERRABLE))
return NM_TERNARY_DEFAULT;
if (!other)
if (!set_b)
return TRUE;
a_priv = NM_SETTING_WIREGUARD_GET_PRIVATE (setting);
b_priv = NM_SETTING_WIREGUARD_GET_PRIVATE (other);
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;
@ -1981,8 +1983,10 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_SETTING_CLASS (nm_setting_wireguard_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -919,20 +919,24 @@ mac_addr_rand_ok:
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
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_WIRELESS_CLONED_MAC_ADDRESS)) {
return !other
|| nm_streq0 (NM_SETTING_WIRELESS_GET_PRIVATE (setting)->cloned_mac_address,
NM_SETTING_WIRELESS_GET_PRIVATE (other)->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);
}
return NM_SETTING_CLASS (nm_setting_wireless_parent_class)->compare_property (sett_info,
property_idx,
setting,
other,
con_a,
set_a,
con_b,
set_b,
flags);
}

View file

@ -199,10 +199,31 @@ _nm_sett_info_property_find_in_array (const NMSettInfoProperty *properties, guin
return NULL;
}
static GVariant *
_gprop_to_dbus_fcn_bytes (const GValue *val)
{
nm_assert (G_VALUE_HOLDS (val, G_TYPE_BYTES));
return nm_utils_gbytes_to_variant_ay (g_value_get_boxed (val));
}
static GVariant *
_gprop_to_dbus_fcn_enum (const GValue *val)
{
return g_variant_new_int32 (g_value_get_enum (val));
}
static GVariant *
_gprop_to_dbus_fcn_flags (const GValue *val)
{
return g_variant_new_uint32 (g_value_get_flags (val));
}
void
_properties_override_add_struct (GArray *properties_override,
const NMSettInfoProperty *prop_info)
{
NMSettInfoProperty *p;
nm_assert (properties_override);
nm_assert (prop_info);
nm_assert (prop_info->name || prop_info->param_spec);
@ -211,16 +232,25 @@ _properties_override_add_struct (GArray *properties_override,
properties_override->len,
prop_info->name ?: prop_info->param_spec->name));
nm_assert (!prop_info->from_dbus || prop_info->dbus_type);
nm_assert (!prop_info->set_func || prop_info->dbus_type);
nm_assert (!prop_info->gprop_from_dbus_fcn || prop_info->dbus_type);
nm_assert (!prop_info->from_dbus_fcn || prop_info->dbus_type);
nm_assert (!prop_info->to_dbus_fcn || prop_info->dbus_type);
nm_assert (!prop_info->to_dbus_fcn || !prop_info->gprop_to_dbus_fcn);
nm_assert (!prop_info->from_dbus_fcn || !prop_info->gprop_from_dbus_fcn);
nm_assert (!prop_info->gprop_to_dbus_fcn || prop_info->param_spec);
nm_assert (!prop_info->gprop_from_dbus_fcn || prop_info->param_spec);
g_array_append_vals (properties_override, prop_info, 1);
if (!prop_info->name) {
/* for convenience, allow omitting "name" if "param_spec" is given. */
g_array_index (properties_override,
NMSettInfoProperty,
properties_override->len - 1).name = prop_info->param_spec->name;
p = &g_array_index (properties_override,
NMSettInfoProperty,
properties_override->len - 1);
nm_assert (p->param_spec);
p->name = p->param_spec->name;
}
}
@ -229,34 +259,34 @@ _properties_override_add_struct (GArray *properties_override,
* @properties_override: an array collecting the overrides
* @property_name: the name of the property to override
* @dbus_type: the type of the property (in its D-Bus representation)
* @synth_func: (allow-none): function to call to synthesize a value for the property
* @set_func: (allow-none): function to call to set the value of the property
* @to_dbus_fcn: (allow-none): function to call to synthesize a value for the property
* @from_dbus_fcn: (allow-none): function to call to set the value of the property
*
* Registers a property named @property_name, which will be used in the D-Bus
* serialization of objects of this setting type, but which does not correspond to
* a #GObject property.
*
* When serializing a setting to D-Bus, @synth_func will be called to synthesize
* When serializing a setting to D-Bus, @to_dbus_fcn will be called to synthesize
* a value for the property. (If it returns %NULL, no value will be added to the
* serialization. If @synth_func is %NULL, the property will always be omitted
* serialization. If @to_dbus_fcn is %NULL, the property will always be omitted
* in the serialization.)
*
* When deserializing a D-Bus representation into a setting, if @property_name
* is present, then @set_func will be called to set it. (If @set_func is %NULL
* is present, then @from_dbus_fcn will be called to set it. (If @from_dbus_fcn is %NULL
* then the property will be ignored when deserializing.)
*/
void
_properties_override_add_dbus_only (GArray *properties_override,
const char *property_name,
const GVariantType *dbus_type,
NMSettingPropertySynthFunc synth_func,
NMSettingPropertySetFunc set_func)
NMSettInfoPropToDBusFcn to_dbus_fcn,
NMSettInfoPropFromDBusFcn from_dbus_fcn)
{
_properties_override_add (properties_override,
.name = property_name,
.dbus_type = dbus_type,
.synth_func = synth_func,
.set_func = set_func);
.name = property_name,
.dbus_type = dbus_type,
.to_dbus_fcn = to_dbus_fcn,
.from_dbus_fcn = from_dbus_fcn);
}
/**
@ -264,26 +294,26 @@ _properties_override_add_dbus_only (GArray *properties_override,
* @properties_override: an array collecting the overrides
* @param_spec: the name of the property to override
* @dbus_type: the type of the property (in its D-Bus representation)
* @get_func: (allow-none): function to call to get the value of the property
* @set_func: (allow-none): function to call to set the value of the property
* @not_set_func: (allow-none): function to call to indicate the property was not set
* @to_dbus_fcn: (allow-none): function to call to get the value of the property
* @from_dbus_fcn: (allow-none): function to call to set the value of the property
* @missing_from_dbus_fcn: (allow-none): function to call to indicate the property was not set
*
* Overrides the D-Bus representation of the #GObject property that shares the
* same name as @param_spec.
*
* When serializing a setting to D-Bus, if @get_func is non-%NULL, then it will
* When serializing a setting to D-Bus, if @to_dbus_fcn is non-%NULL, then it will
* be called to get the property's value. If it returns a #GVariant, the
* property will be added to the hash, and if it returns %NULL, the property
* will be omitted. (If @get_func is %NULL, the property will be read normally
* will be omitted. (If @to_dbus_fcn is %NULL, the property will be read normally
* with g_object_get_property(), and added to the hash if it is not the default
* value.)
*
* When deserializing a D-Bus representation into a setting, if a value with
* the name of @param_spec is present, then @set_func will be called to set it.
* (If @set_func is %NULL then the property will be set normally with
* the name of @param_spec is present, then @from_dbus_fcn will be called to set it.
* (If @from_dbus_fcn is %NULL then the property will be set normally with
* g_object_set_property().)
*
* If @not_set_func is non-%NULL, then it will be called when deserializing a
* If @missing_from_dbus_fcn is non-%NULL, then it will be called when deserializing a
* representation that does NOT contain a value for the property. This can be used,
* eg, if a new property needs to be initialized from some older deprecated property
* when it is not present.
@ -292,18 +322,18 @@ void
_properties_override_add_override (GArray *properties_override,
GParamSpec *param_spec,
const GVariantType *dbus_type,
NMSettingPropertyGetFunc get_func,
NMSettingPropertySetFunc set_func,
NMSettingPropertyNotSetFunc not_set_func)
NMSettInfoPropToDBusFcn to_dbus_fcn,
NMSettInfoPropFromDBusFcn from_dbus_fcn,
NMSettInfoPropMissingFromDBusFcn missing_from_dbus_fcn)
{
nm_assert (param_spec);
_properties_override_add (properties_override,
.param_spec = param_spec,
.dbus_type = dbus_type,
.get_func = get_func,
.set_func = set_func,
.not_set_func = not_set_func);
.param_spec = param_spec,
.dbus_type = dbus_type,
.to_dbus_fcn = to_dbus_fcn,
.from_dbus_fcn = from_dbus_fcn,
.missing_from_dbus_fcn = missing_from_dbus_fcn);
}
/**
@ -311,8 +341,8 @@ _properties_override_add_override (GArray *properties_override,
* @properties_override: an array collecting the overrides
* @param_spec: the param spec of the property to transform.
* @dbus_type: the type of the property (in its D-Bus representation)
* @to_dbus: function to convert from object to D-Bus format
* @from_dbus: function to convert from D-Bus to object format
* @gprop_to_dbus_fcn: function to convert from object to D-Bus format
* @gprop_from_dbus_fcn: function to convert from D-Bus to object format
*
* Indicates that @property on @setting_class does not have the same format as
* its corresponding D-Bus representation, and so must be transformed when
@ -326,16 +356,16 @@ void
_properties_override_add_transform (GArray *properties_override,
GParamSpec *param_spec,
const GVariantType *dbus_type,
NMSettingPropertyTransformToFunc to_dbus,
NMSettingPropertyTransformFromFunc from_dbus)
NMSettInfoPropGPropToDBusFcn gprop_to_dbus_fcn,
NMSettInfoPropGPropFromDBusFcn gprop_from_dbus_fcn)
{
nm_assert (param_spec);
_properties_override_add (properties_override,
.param_spec = param_spec,
.dbus_type = dbus_type,
.to_dbus = to_dbus,
.from_dbus = from_dbus);
.param_spec = param_spec,
.dbus_type = dbus_type,
.gprop_to_dbus_fcn = gprop_to_dbus_fcn,
.gprop_from_dbus_fcn = gprop_from_dbus_fcn);
}
static NMSettInfoSetting _sett_info_settings[_NM_META_SETTING_TYPE_NUM];
@ -478,6 +508,49 @@ _nm_setting_class_commit_full (NMSettingClass *setting_class,
p->param_spec = property_specs[i];
}
for (i = 0; i < properties_override->len; i++) {
NMSettInfoProperty *p = &g_array_index (properties_override, NMSettInfoProperty, i);
GType vtype;
if (p->dbus_type)
continue;
nm_assert (p->param_spec);
nm_assert (!p->gprop_to_dbus_fcn);
vtype = p->param_spec->value_type;
if (vtype == G_TYPE_BOOLEAN)
p->dbus_type = G_VARIANT_TYPE_BOOLEAN;
else if (vtype == G_TYPE_UCHAR)
p->dbus_type = G_VARIANT_TYPE_BYTE;
else if (vtype == G_TYPE_INT)
p->dbus_type = G_VARIANT_TYPE_INT32;
else if (vtype == G_TYPE_UINT)
p->dbus_type = G_VARIANT_TYPE_UINT32;
else if (vtype == G_TYPE_INT64)
p->dbus_type = G_VARIANT_TYPE_INT64;
else if (vtype == G_TYPE_UINT64)
p->dbus_type = G_VARIANT_TYPE_UINT64;
else if (vtype == G_TYPE_STRING)
p->dbus_type = G_VARIANT_TYPE_STRING;
else if (vtype == G_TYPE_DOUBLE)
p->dbus_type = G_VARIANT_TYPE_DOUBLE;
else if (vtype == G_TYPE_STRV)
p->dbus_type = G_VARIANT_TYPE_STRING_ARRAY;
else if (vtype == G_TYPE_BYTES) {
p->dbus_type = G_VARIANT_TYPE_BYTESTRING;
p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_bytes;
} else if (g_type_is_a (vtype, G_TYPE_ENUM)) {
p->dbus_type = G_VARIANT_TYPE_INT32;
p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_enum;
} else if (g_type_is_a (vtype, G_TYPE_FLAGS)) {
p->dbus_type = G_VARIANT_TYPE_UINT32;
p->gprop_to_dbus_fcn = _gprop_to_dbus_fcn_flags;
}
nm_assert (p->dbus_type);
}
G_STATIC_ASSERT_EXPR (G_STRUCT_OFFSET (NMSettInfoProperty, name) == 0);
g_array_sort (properties_override, nm_strcmp_p);
@ -609,73 +682,70 @@ _nm_setting_use_legacy_property (NMSetting *setting,
/*****************************************************************************/
static const GVariantType *
variant_type_for_gtype (GType type)
{
if (type == G_TYPE_BOOLEAN)
return G_VARIANT_TYPE_BOOLEAN;
else if (type == G_TYPE_UCHAR)
return G_VARIANT_TYPE_BYTE;
else if (type == G_TYPE_INT)
return G_VARIANT_TYPE_INT32;
else if (type == G_TYPE_UINT)
return G_VARIANT_TYPE_UINT32;
else if (type == G_TYPE_INT64)
return G_VARIANT_TYPE_INT64;
else if (type == G_TYPE_UINT64)
return G_VARIANT_TYPE_UINT64;
else if (type == G_TYPE_STRING)
return G_VARIANT_TYPE_STRING;
else if (type == G_TYPE_DOUBLE)
return G_VARIANT_TYPE_DOUBLE;
else if (type == G_TYPE_STRV)
return G_VARIANT_TYPE_STRING_ARRAY;
else if (type == G_TYPE_BYTES)
return G_VARIANT_TYPE_BYTESTRING;
else if (g_type_is_a (type, G_TYPE_ENUM))
return G_VARIANT_TYPE_INT32;
else if (g_type_is_a (type, G_TYPE_FLAGS))
return G_VARIANT_TYPE_UINT32;
else
g_assert_not_reached ();
}
static GVariant *
get_property_for_dbus (NMSetting *setting,
const NMSettInfoProperty *property,
gboolean ignore_default)
property_to_dbus (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags,
gboolean ignore_flags,
gboolean ignore_default)
{
GValue prop_value = { 0, };
GVariant *dbus_value;
const NMSettInfoProperty *property = &sett_info->property_infos[property_idx];
GVariant *variant;
if (property->get_func)
return property->get_func (setting, property->name);
else
g_return_val_if_fail (property->param_spec != NULL, NULL);
nm_assert (property->dbus_type);
g_value_init (&prop_value, property->param_spec->value_type);
g_object_get_property (G_OBJECT (setting), property->param_spec->name, &prop_value);
if (!property->param_spec) {
if (!property->to_dbus_fcn)
return NULL;
} else if (!ignore_flags) {
if (!NM_FLAGS_HAS (property->param_spec->flags, G_PARAM_WRITABLE))
return NULL;
if (ignore_default && g_param_value_defaults (property->param_spec, &prop_value)) {
g_value_unset (&prop_value);
return NULL;
if (NM_FLAGS_ANY (property->param_spec->flags, NM_SETTING_PARAM_GENDATA_BACKED))
return NULL;
if ( NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_LEGACY)
&& !_nm_utils_is_manager_process)
return NULL;
if ( NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_NO_SECRETS)
&& NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_SECRET))
return NULL;
if ( NM_FLAGS_HAS (flags, NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
&& !NM_FLAGS_HAS (property->param_spec->flags, NM_SETTING_PARAM_SECRET))
return NULL;
}
if (property->to_dbus)
dbus_value = property->to_dbus (&prop_value);
else if (property->dbus_type)
dbus_value = g_dbus_gvalue_to_gvariant (&prop_value, property->dbus_type);
else if (g_type_is_a (prop_value.g_type, G_TYPE_ENUM))
dbus_value = g_variant_new_int32 (g_value_get_enum (&prop_value));
else if (g_type_is_a (prop_value.g_type, G_TYPE_FLAGS))
dbus_value = g_variant_new_uint32 (g_value_get_flags (&prop_value));
else if (prop_value.g_type == G_TYPE_BYTES)
dbus_value = nm_utils_gbytes_to_variant_ay (g_value_get_boxed (&prop_value));
else
dbus_value = g_dbus_gvalue_to_gvariant (&prop_value, variant_type_for_gtype (prop_value.g_type));
g_value_unset (&prop_value);
if (property->to_dbus_fcn) {
variant = property->to_dbus_fcn (sett_info, property_idx, connection, setting, flags);
nm_g_variant_take_ref (variant);
} else {
nm_auto_unset_gvalue GValue prop_value = { 0, };
return dbus_value;
nm_assert (property->param_spec);
g_value_init (&prop_value, property->param_spec->value_type);
g_object_get_property (G_OBJECT (setting), property->param_spec->name, &prop_value);
if ( ignore_default
&& g_param_value_defaults (property->param_spec, &prop_value))
return NULL;
if (property->gprop_to_dbus_fcn) {
variant = property->gprop_to_dbus_fcn (&prop_value);
nm_g_variant_take_ref (variant);
} else
variant = g_dbus_gvalue_to_gvariant (&prop_value, property->dbus_type);
}
nm_assert (!variant || !g_variant_is_floating (variant));
nm_assert (!variant || g_variant_is_of_type (variant, property->dbus_type));
return variant;
}
static gboolean
@ -683,13 +753,13 @@ set_property_from_dbus (const NMSettInfoProperty *property,
GVariant *src_value,
GValue *dst_value)
{
g_return_val_if_fail (property->param_spec != NULL, FALSE);
nm_assert (property->param_spec);
nm_assert (property->dbus_type);
if (property->from_dbus) {
if (property->gprop_from_dbus_fcn) {
if (!g_variant_type_equal (g_variant_get_type (src_value), property->dbus_type))
return FALSE;
property->from_dbus (src_value, dst_value);
property->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;
@ -732,7 +802,6 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
{
NMSettingPrivate *priv;
GVariantBuilder builder;
GVariant *dbus_value;
const NMSettInfoSetting *sett_info;
guint n_properties, i;
const char *const*gendata_keys;
@ -753,49 +822,14 @@ _nm_setting_to_dbus (NMSetting *setting, NMConnection *connection, NMConnectionS
sett_info = _nm_setting_class_get_sett_info (NM_SETTING_GET_CLASS (setting));
for (i = 0; i < sett_info->property_infos_len; i++) {
const NMSettInfoProperty *property = &sett_info->property_infos[i];
GParamSpec *prop_spec = property->param_spec;
if (!prop_spec) {
if (!property->synth_func)
continue;
} else {
/* For the moment, properties backed by a GObject property don't
* define a synth function. There is no problem supporting that,
* however, for now just disallow it. */
nm_assert (!property->synth_func);
if (!(prop_spec->flags & G_PARAM_WRITABLE))
continue;
if (NM_FLAGS_ANY (prop_spec->flags, NM_SETTING_PARAM_GENDATA_BACKED))
continue;
if ( (prop_spec->flags & NM_SETTING_PARAM_LEGACY)
&& !_nm_utils_is_manager_process)
continue;
if ( (flags & NM_CONNECTION_SERIALIZE_NO_SECRETS)
&& (prop_spec->flags & NM_SETTING_PARAM_SECRET))
continue;
if ( (flags & NM_CONNECTION_SERIALIZE_ONLY_SECRETS)
&& !(prop_spec->flags & NM_SETTING_PARAM_SECRET))
continue;
}
if (property->synth_func)
dbus_value = property->synth_func (sett_info, i, connection, setting, flags);
else
dbus_value = get_property_for_dbus (setting, property, TRUE);
gs_unref_variant GVariant *dbus_value = NULL;
dbus_value = property_to_dbus (sett_info, i, connection, setting, flags, FALSE, TRUE);
if (dbus_value) {
/* Allow dbus_value to be either floating or not. */
g_variant_take_ref (dbus_value);
g_variant_builder_add (&builder, "{sv}", property->name, dbus_value);
g_variant_unref (dbus_value);
g_variant_builder_add (&builder,
"{sv}",
sett_info->property_infos[i].name,
dbus_value);
}
}
@ -912,7 +946,7 @@ _nm_setting_new_from_dbus (GType setting_type,
g_hash_table_remove (keys, property_info->name);
if ( value
&& property_info->set_func) {
&& property_info->from_dbus_fcn) {
if (!g_variant_type_equal (g_variant_get_type (value), property_info->dbus_type)) {
/* for backward behavior, fail unless best-effort is chosen. */
@ -929,12 +963,12 @@ _nm_setting_new_from_dbus (GType setting_type,
return NULL;
}
if (!property_info->set_func (setting,
connection_dict,
property_info->name,
value,
parse_flags,
&local)) {
if (!property_info->from_dbus_fcn (setting,
connection_dict,
property_info->name,
value,
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,
@ -944,12 +978,12 @@ _nm_setting_new_from_dbus (GType setting_type,
return NULL;
}
} else if ( !value
&& property_info->not_set_func) {
if (!property_info->not_set_func (setting,
connection_dict,
property_info->name,
parse_flags,
&local)) {
&& property_info->missing_from_dbus_fcn) {
if (!property_info->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,
@ -1028,12 +1062,12 @@ nm_setting_get_dbus_property_type (NMSetting *setting,
g_return_val_if_fail (property_name != NULL, NULL);
property = _nm_setting_class_get_property_info (NM_SETTING_GET_CLASS (setting), property_name);
g_return_val_if_fail (property != NULL, NULL);
if (property->dbus_type)
return property->dbus_type;
else
return variant_type_for_gtype (property->param_spec->value_type);
nm_assert (property->dbus_type);
return property->dbus_type;
}
gboolean
@ -1342,8 +1376,10 @@ _nm_setting_should_compare_secret_property (NMSetting *setting,
static NMTernary
compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
const NMSettInfoProperty *property_info = &sett_info->property_infos[property_idx];
@ -1372,19 +1408,18 @@ compare_property (const NMSettInfoSetting *sett_info,
return NM_TERNARY_DEFAULT;
if ( NM_FLAGS_HAS (param_spec->flags, NM_SETTING_PARAM_SECRET)
&& !_nm_setting_should_compare_secret_property (setting,
other,
&& !_nm_setting_should_compare_secret_property (set_a,
set_b,
param_spec->name,
flags))
return NM_TERNARY_DEFAULT;
if (other) {
if (set_b) {
gs_unref_variant GVariant *value1 = NULL;
gs_unref_variant GVariant *value2 = NULL;
value1 = get_property_for_dbus (setting, property_info, TRUE);
value2 = get_property_for_dbus (other, property_info, TRUE);
value1 = property_to_dbus (sett_info, property_idx, con_a, set_a, NM_CONNECTION_SERIALIZE_ALL, TRUE, TRUE);
value2 = property_to_dbus (sett_info, property_idx, con_b, set_b, NM_CONNECTION_SERIALIZE_ALL, TRUE, TRUE);
if (nm_property_compare (value1, value2) != 0)
return NM_TERNARY_FALSE;
}
@ -1395,8 +1430,10 @@ compare_property (const NMSettInfoSetting *sett_info,
static NMTernary
_compare_property (const NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags)
{
NMTernary compare_result;
@ -1404,14 +1441,16 @@ _compare_property (const NMSettInfoSetting *sett_info,
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 (NM_SETTING_GET_CLASS (setting) == sett_info->setting_class);
nm_assert (!other || NM_SETTING_GET_CLASS (other) == sett_info->setting_class);
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 (setting)->compare_property (sett_info,
property_idx,
setting,
other,
flags);
compare_result = NM_SETTING_GET_CLASS (set_a)->compare_property (sett_info,
property_idx,
con_a,
set_a,
con_b,
set_b,
flags);
nm_assert (NM_IN_SET (compare_result, NM_TERNARY_DEFAULT,
NM_TERNARY_FALSE,
@ -1442,6 +1481,16 @@ gboolean
nm_setting_compare (NMSetting *a,
NMSetting *b,
NMSettingCompareFlags flags)
{
return _nm_setting_compare (NULL, a, NULL, b, flags);
}
gboolean
_nm_setting_compare (NMConnection *con_a,
NMSetting *a,
NMConnection *con_b,
NMSetting *b,
NMSettingCompareFlags flags)
{
const NMSettInfoSetting *sett_info;
guint i;
@ -1449,6 +1498,9 @@ nm_setting_compare (NMSetting *a,
g_return_val_if_fail (NM_IS_SETTING (a), FALSE);
g_return_val_if_fail (NM_IS_SETTING (b), FALSE);
nm_assert (!con_a || NM_IS_CONNECTION (con_a));
nm_assert (!con_b || NM_IS_CONNECTION (con_b));
/* First check that both have the same type */
if (G_OBJECT_TYPE (a) != G_OBJECT_TYPE (b))
return FALSE;
@ -1466,7 +1518,7 @@ nm_setting_compare (NMSetting *a,
}
for (i = 0; i < sett_info->property_infos_len; i++) {
if (_compare_property (sett_info, i, a, b, flags) == NM_TERNARY_FALSE)
if (_compare_property (sett_info, i, con_a, a, con_b, b, flags) == NM_TERNARY_FALSE)
return FALSE;
}
@ -1515,6 +1567,18 @@ nm_setting_diff (NMSetting *a,
NMSettingCompareFlags flags,
gboolean invert_results,
GHashTable **results)
{
return _nm_setting_diff (NULL, a, NULL, b, flags, invert_results, results);
}
gboolean
_nm_setting_diff (NMConnection *con_a,
NMSetting *a,
NMConnection *con_b,
NMSetting *b,
NMSettingCompareFlags flags,
gboolean invert_results,
GHashTable **results)
{
const NMSettInfoSetting *sett_info;
guint i;
@ -1533,6 +1597,9 @@ nm_setting_diff (NMSetting *a,
g_return_val_if_fail (G_OBJECT_TYPE (a) == G_OBJECT_TYPE (b), FALSE);
}
nm_assert (!con_a || NM_IS_CONNECTION (con_a));
nm_assert (!con_b || NM_IS_CONNECTION (con_b));
if ((flags & (NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT | NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT)) ==
(NM_SETTING_COMPARE_FLAG_DIFF_RESULT_WITH_DEFAULT | NM_SETTING_COMPARE_FLAG_DIFF_RESULT_NO_DEFAULT)) {
/* conflicting flags: default to WITH_DEFAULT (clearing NO_DEFAULT). */
@ -1609,7 +1676,7 @@ nm_setting_diff (NMSetting *a,
NMTernary compare_result;
GParamSpec *prop_spec;
compare_result = _compare_property (sett_info, i, a, b, flags);
compare_result = _compare_property (sett_info, i, con_a, a, con_b, b, flags);
if (compare_result == NM_TERNARY_DEFAULT)
continue;
@ -1630,7 +1697,7 @@ nm_setting_diff (NMSetting *a,
*
* We need to double-check whether the property should be ignored by
* looking at @a alone. */
if (_compare_property (sett_info, i, a, NULL, flags) == NM_TERNARY_DEFAULT)
if (_compare_property (sett_info, i, con_a, a, NULL, NULL, flags) == NM_TERNARY_DEFAULT)
continue;
}

View file

@ -236,8 +236,10 @@ typedef struct {
/*< private >*/
NMTernary (*compare_property) (const struct _NMSettInfoSetting *sett_info,
guint property_idx,
NMSetting *setting,
NMSetting *other,
NMConnection *con_a,
NMSetting *set_a,
NMConnection *con_b,
NMSetting *set_b,
NMSettingCompareFlags flags);
/*< private >*/

View file

@ -55,8 +55,11 @@ gboolean _nm_utils_wps_method_validate (NMSettingWirelessSecurityWpsMethod wps_m
/* D-Bus transform funcs */
GVariant *_nm_utils_hwaddr_cloned_get (NMSetting *setting,
const char *property);
GVariant *_nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags);
gboolean _nm_utils_hwaddr_cloned_set (NMSetting *setting,
GVariant *connection_dict,
const char *property,
@ -103,7 +106,12 @@ void _nm_utils_format_variant_attributes_full (GString *str,
char key_value_separator);
gboolean _nm_sriov_vf_parse_vlans (NMSriovVF *vf, const char *str, GError **error);
GVariant * _nm_utils_bridge_vlans_to_dbus (NMSetting *setting, const char *property);
GVariant * _nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags);
gboolean _nm_utils_bridge_vlans_from_dbus (NMSetting *setting,
GVariant *connection_dict,
const char *property,

View file

@ -4280,12 +4280,15 @@ _nm_utils_hwaddr_to_dbus_impl (const char *str)
}
GVariant *
_nm_utils_hwaddr_cloned_get (NMSetting *setting,
const char *property)
_nm_utils_hwaddr_cloned_get (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
gs_free char *addr = NULL;
nm_assert (nm_streq0 (property, "cloned-mac-address"));
nm_assert (nm_streq (sett_info->property_infos[property_idx].name, "cloned-mac-address"));
g_object_get (setting, "cloned-mac-address", &addr, NULL);
return _nm_utils_hwaddr_to_dbus_impl (addr);
@ -6790,13 +6793,20 @@ nm_utils_base64secret_normalize (const char *base64_key,
}
GVariant *
_nm_utils_bridge_vlans_to_dbus (NMSetting *setting, const char *property)
_nm_utils_bridge_vlans_to_dbus (const NMSettInfoSetting *sett_info,
guint property_idx,
NMConnection *connection,
NMSetting *setting,
NMConnectionSerializationFlags flags)
{
gs_unref_ptrarray GPtrArray *vlans = NULL;
GVariantBuilder builder;
guint i;
const char *property_name = sett_info->property_infos[property_idx].name;
g_object_get (setting, property, &vlans, NULL);
nm_assert (property_name);
g_object_get (setting, property_name, &vlans, NULL);
g_variant_builder_init (&builder, G_VARIANT_TYPE ("aa{sv}"));
if (vlans) {

View file

@ -1226,6 +1226,14 @@ nm_g_variant_unref (GVariant *v)
g_variant_unref (v);
}
static inline GVariant *
nm_g_variant_take_ref (GVariant *v)
{
if (v)
g_variant_take_ref (v);
return v;
}
/*****************************************************************************/
/* Determine whether @x is a power of two (@x being an integer type).