diff options
author | Thomas Haller <thaller@redhat.com> | 2019-04-25 10:17:47 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-05-01 13:46:32 +0200 |
commit | b1344b6b94645296e658c8cba383acec7e4dd778 (patch) | |
tree | 3a94b92a87e2b8118b2901787687ca9d2325853a | |
parent | 3c810a84456368c2e3a1c79a5bd80d792f739119 (diff) | |
download | NetworkManager-b1344b6b94645296e658c8cba383acec7e4dd778.tar.gz |
libnm: pass connection to compare_property() function
We have certain artificial properties that not only depend on one
property alone or that depend on a property in another(!) setting.
For that, we have synth_func.
Other than that, synth_func and get_func are really fundamentally
similar and should be merged. That is because the distinction whether a
property value is "synthetized" or just based on a plain property is
minor. It's better to have the general concept of "convert property to
GVariant" in one form only.
Note that compare_property() is by default implemented based
on get_func. Hence, if get_func and synth_func get merged,
compare_property() will also require access to the NMConnection.
Also it makes some sense: some properties are artificial and actually
stored in "another" setting of the connection. But still, the property
descriptor for the property is in this setting. The example is the
"bond.interface-name" which only exists on D-Bus. It's stored as
"connection.interface-name".
I don't really like to say "exists on D-Bus only". It's still a valid
property, despite in NMSetting it's stored somehow differently (or not
at all). So, this is also just a regular property for which we have a
property-info vtable.
Does it make sense to compare such properties? Maybe. But the point is that
compare_property() function needs sometimes access to the entire
connection. So add the argument.
-rw-r--r-- | libnm-core/nm-connection.c | 5 | ||||
-rw-r--r-- | libnm-core/nm-core-internal.h | 14 | ||||
-rw-r--r-- | libnm-core/nm-setting-bond.c | 18 | ||||
-rw-r--r-- | libnm-core/nm-setting-bridge-port.c | 18 | ||||
-rw-r--r-- | libnm-core/nm-setting-bridge.c | 18 | ||||
-rw-r--r-- | libnm-core/nm-setting-connection.c | 12 | ||||
-rw-r--r-- | libnm-core/nm-setting-ip-config.c | 30 | ||||
-rw-r--r-- | libnm-core/nm-setting-sriov.c | 18 | ||||
-rw-r--r-- | libnm-core/nm-setting-tc-config.c | 20 | ||||
-rw-r--r-- | libnm-core/nm-setting-team-port.c | 24 | ||||
-rw-r--r-- | libnm-core/nm-setting-team.c | 24 | ||||
-rw-r--r-- | libnm-core/nm-setting-user.c | 18 | ||||
-rw-r--r-- | libnm-core/nm-setting-vpn.c | 14 | ||||
-rw-r--r-- | libnm-core/nm-setting-wired.c | 18 | ||||
-rw-r--r-- | libnm-core/nm-setting-wireguard.c | 18 | ||||
-rw-r--r-- | libnm-core/nm-setting-wireless.c | 18 | ||||
-rw-r--r-- | libnm-core/nm-setting.c | 72 | ||||
-rw-r--r-- | libnm-core/nm-setting.h | 6 |
18 files changed, 236 insertions, 129 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c index 3182e3460f..cf06f1b0fc 100644 --- a/libnm-core/nm-connection.c +++ b/libnm-core/nm-connection.c @@ -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) diff --git a/libnm-core/nm-core-internal.h b/libnm-core/nm-core-internal.h index 6d11a999fa..2aaa9f57de 100644 --- a/libnm-core/nm-core-internal.h +++ b/libnm-core/nm-core-internal.h @@ -770,6 +770,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, diff --git a/libnm-core/nm-setting-bond.c b/libnm-core/nm-setting-bond.c index 51ce2debbc..2cc01bca1e 100644 --- a/libnm-core/nm-setting-bond.c +++ b/libnm-core/nm-setting-bond.c @@ -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); } diff --git a/libnm-core/nm-setting-bridge-port.c b/libnm-core/nm-setting-bridge-port.c index 7a8b345f01..12a7b1a726 100644 --- a/libnm-core/nm-setting-bridge-port.c +++ b/libnm-core/nm-setting-bridge-port.c @@ -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); } diff --git a/libnm-core/nm-setting-bridge.c b/libnm-core/nm-setting-bridge.c index c6aca0211a..0175fca834 100644 --- a/libnm-core/nm-setting-bridge.c +++ b/libnm-core/nm-setting-bridge.c @@ -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); } diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c index e4fb70c247..282bff1e06 100644 --- a/libnm-core/nm-setting-connection.c +++ b/libnm-core/nm-setting-connection.c @@ -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); } diff --git a/libnm-core/nm-setting-ip-config.c b/libnm-core/nm-setting-ip-config.c index f362945f41..1003994f10 100644 --- a/libnm-core/nm-setting-ip-config.c +++ b/libnm-core/nm-setting-ip-config.c @@ -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); } diff --git a/libnm-core/nm-setting-sriov.c b/libnm-core/nm-setting-sriov.c index b662ca2cf6..b63a2a9924 100644 --- a/libnm-core/nm-setting-sriov.c +++ b/libnm-core/nm-setting-sriov.c @@ -1129,8 +1129,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 +1140,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 +1156,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); } diff --git a/libnm-core/nm-setting-tc-config.c b/libnm-core/nm-setting-tc-config.c index dc2f4f6498..f677f69727 100644 --- a/libnm-core/nm-setting-tc-config.c +++ b/libnm-core/nm-setting-tc-config.c @@ -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); } diff --git a/libnm-core/nm-setting-team-port.c b/libnm-core/nm-setting-team-port.c index b2c57ffa94..e17cd026e2 100644 --- a/libnm-core/nm-setting-team-port.c +++ b/libnm-core/nm-setting-team-port.c @@ -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); } diff --git a/libnm-core/nm-setting-team.c b/libnm-core/nm-setting-team.c index 9fd070c1fe..e865f2ad9c 100644 --- a/libnm-core/nm-setting-team.c +++ b/libnm-core/nm-setting-team.c @@ -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); } diff --git a/libnm-core/nm-setting-user.c b/libnm-core/nm-setting-user.c index 01ac671b14..7d8bd5615a 100644 --- a/libnm-core/nm-setting-user.c +++ b/libnm-core/nm-setting-user.c @@ -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); } diff --git a/libnm-core/nm-setting-vpn.c b/libnm-core/nm-setting-vpn.c index 606b9d7f77..2591b8b435 100644 --- a/libnm-core/nm-setting-vpn.c +++ b/libnm-core/nm-setting-vpn.c @@ -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); } diff --git a/libnm-core/nm-setting-wired.c b/libnm-core/nm-setting-wired.c index b37acda4ca..6a8c5b2a05 100644 --- a/libnm-core/nm-setting-wired.c +++ b/libnm-core/nm-setting-wired.c @@ -905,21 +905,25 @@ 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); } diff --git a/libnm-core/nm-setting-wireguard.c b/libnm-core/nm-setting-wireguard.c index 861b2abd3a..7105d4779f 100644 --- a/libnm-core/nm-setting-wireguard.c +++ b/libnm-core/nm-setting-wireguard.c @@ -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); } diff --git a/libnm-core/nm-setting-wireless.c b/libnm-core/nm-setting-wireless.c index d8056c6c59..e03fbefd6c 100644 --- a/libnm-core/nm-setting-wireless.c +++ b/libnm-core/nm-setting-wireless.c @@ -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); } diff --git a/libnm-core/nm-setting.c b/libnm-core/nm-setting.c index 783a0c456f..6888759c01 100644 --- a/libnm-core/nm-setting.c +++ b/libnm-core/nm-setting.c @@ -1385,8 +1385,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]; @@ -1415,18 +1417,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 = get_property_for_dbus (set_a, property_info, TRUE); + value2 = get_property_for_dbus (set_b, property_info, TRUE); if (nm_property_compare (value1, value2) != 0) return NM_TERNARY_FALSE; @@ -1438,8 +1440,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; @@ -1447,14 +1451,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, @@ -1486,12 +1492,25 @@ 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; 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; @@ -1509,7 +1528,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; } @@ -1559,6 +1578,18 @@ nm_setting_diff (NMSetting *a, 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; NMSettingDiffResult a_result = NM_SETTING_DIFF_RESULT_IN_A; @@ -1576,6 +1607,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). */ @@ -1652,7 +1686,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; @@ -1673,7 +1707,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; } diff --git a/libnm-core/nm-setting.h b/libnm-core/nm-setting.h index fdf4a4c516..b91baf3d7a 100644 --- a/libnm-core/nm-setting.h +++ b/libnm-core/nm-setting.h @@ -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 >*/ |