mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 07:10:12 +01:00
libnm/team: add function to compare list of link-watchers
This commit is contained in:
parent
265864952d
commit
9d2a15514a
3 changed files with 44 additions and 41 deletions
|
|
@ -537,6 +537,8 @@ gboolean _nm_utils_inet6_is_token (const struct in6_addr *in6addr);
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
gboolean _nm_team_link_watchers_equal (GPtrArray *a, GPtrArray *b, gboolean ignore_order);
|
||||
|
||||
gboolean _nm_utils_team_config_equal (const char *conf1, const char *conf2, gboolean port);
|
||||
GValue *_nm_utils_team_config_get (const char *conf,
|
||||
const char *key,
|
||||
|
|
|
|||
|
|
@ -396,31 +396,18 @@ compare_property (const NMSettInfoSetting *sett_info,
|
|||
{
|
||||
NMSettingTeamPortPrivate *a_priv;
|
||||
NMSettingTeamPortPrivate *b_priv;
|
||||
guint i, j;
|
||||
|
||||
if (nm_streq (sett_info->property_infos[property_idx].name, NM_SETTING_TEAM_PORT_LINK_WATCHERS)) {
|
||||
|
||||
if (NM_FLAGS_HAS (flags, NM_SETTING_COMPARE_FLAG_INFERRABLE))
|
||||
return NM_TERNARY_DEFAULT;
|
||||
|
||||
if (other) {
|
||||
a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (setting);
|
||||
b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (other);
|
||||
|
||||
if (a_priv->link_watchers->len != b_priv->link_watchers->len)
|
||||
return FALSE;
|
||||
for (i = 0; i < a_priv->link_watchers->len; i++) {
|
||||
for (j = 0; j < b_priv->link_watchers->len; j++) {
|
||||
if (nm_team_link_watcher_equal (a_priv->link_watchers->pdata[i],
|
||||
b_priv->link_watchers->pdata[j])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == b_priv->link_watchers->len)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
if (!other)
|
||||
return TRUE;
|
||||
a_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (setting);
|
||||
b_priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (other);
|
||||
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)) {
|
||||
|
|
|
|||
|
|
@ -396,6 +396,34 @@ nm_team_link_watcher_equal (NMTeamLinkWatcher *watcher, NMTeamLinkWatcher *other
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_nm_team_link_watchers_equal (GPtrArray *a, GPtrArray *b, gboolean ignore_order)
|
||||
{
|
||||
guint i, j;
|
||||
|
||||
if (a->len != b->len)
|
||||
return FALSE;
|
||||
if (ignore_order) {
|
||||
/* FIXME: comparing this way is O(n^2). Don't do that, instead
|
||||
* add nm_team_link_watcher_cmp(), sort both lists, and
|
||||
* compare step by step. */
|
||||
for (i = 0; i < a->len; i++) {
|
||||
for (j = 0; j < b->len; j++) {
|
||||
if (nm_team_link_watcher_equal (a->pdata[i], b->pdata[j]))
|
||||
break;
|
||||
}
|
||||
if (j == b->len)
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < a->len; i++) {
|
||||
if (!nm_team_link_watcher_equal (a->pdata[i], b->pdata[i]))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_team_link_watcher_dup:
|
||||
* @watcher: the #NMTeamLinkWatcher
|
||||
|
|
@ -1289,31 +1317,17 @@ compare_property (const NMSettInfoSetting *sett_info,
|
|||
NMSettingCompareFlags flags)
|
||||
{
|
||||
NMSettingTeamPrivate *a_priv, *b_priv;
|
||||
guint i, j;
|
||||
|
||||
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) {
|
||||
a_priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
|
||||
b_priv = NM_SETTING_TEAM_GET_PRIVATE (other);
|
||||
|
||||
if (a_priv->link_watchers->len != b_priv->link_watchers->len)
|
||||
return FALSE;
|
||||
for (i = 0; i < a_priv->link_watchers->len; i++) {
|
||||
for (j = 0; j < b_priv->link_watchers->len; j++) {
|
||||
if (nm_team_link_watcher_equal (a_priv->link_watchers->pdata[i],
|
||||
b_priv->link_watchers->pdata[j])) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == b_priv->link_watchers->len)
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
if (!other)
|
||||
return TRUE;
|
||||
a_priv = NM_SETTING_TEAM_GET_PRIVATE (setting);
|
||||
b_priv = NM_SETTING_TEAM_GET_PRIVATE (other);
|
||||
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)) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue