[network-manager-applet] editor: make algorithm for choosing num for bond and bridge deterministic
- From: Thomas Haller <thaller src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] editor: make algorithm for choosing num for bond and bridge deterministic
- Date: Wed, 18 Sep 2013 11:06:00 +0000 (UTC)
commit 008cbcd8c8bf18153618c6b4b67ab99e2a781acf
Author: Thomas Haller <thaller redhat com>
Date: Wed Sep 18 10:16:51 2013 +0200
editor: make algorithm for choosing num for bond and bridge deterministic
The previous algorithm for choosing bond_num/bridge_num is not deterministic.
It does neither choose one of
(a) MAX(existing nums) + 1
(b) MIN(unused nums)
What it actually chooses depends on the order how the existing
connections are returned. For example:
[0 2] => 1
[2 0] => 3
This commit changes the algorithm to use (a).
Signed-off-by: Thomas Haller <thaller redhat com>
src/connection-editor/page-bond.c | 9 +++------
src/connection-editor/page-bridge.c | 9 +++------
2 files changed, 6 insertions(+), 12 deletions(-)
---
diff --git a/src/connection-editor/page-bond.c b/src/connection-editor/page-bond.c
index 0db3fca..5f09896 100644
--- a/src/connection-editor/page-bond.c
+++ b/src/connection-editor/page-bond.c
@@ -547,7 +547,7 @@ bond_connection_new (GtkWindow *parent,
gpointer user_data)
{
NMConnection *connection;
- int bond_num, max_bond_num, num;
+ int bond_num = 0, num;
GSList *connections, *iter;
NMConnection *conn2;
NMSettingBond *s_bond;
@@ -562,7 +562,6 @@ bond_connection_new (GtkWindow *parent,
nm_connection_add_setting (connection, nm_setting_bond_new ());
/* Find an available interface name */
- bond_num = max_bond_num = 0;
connections = nm_remote_settings_list_connections (settings);
for (iter = connections; iter; iter = iter->next) {
conn2 = iter->data;
@@ -577,10 +576,8 @@ bond_connection_new (GtkWindow *parent,
continue;
num = atoi (iface + 4);
- if (num > max_bond_num)
- max_bond_num = num;
- if (num == bond_num)
- bond_num = max_bond_num + 1;
+ if (bond_num <= num)
+ bond_num = num + 1;
}
g_slist_free (connections);
diff --git a/src/connection-editor/page-bridge.c b/src/connection-editor/page-bridge.c
index 649d2cd..2f119de 100644
--- a/src/connection-editor/page-bridge.c
+++ b/src/connection-editor/page-bridge.c
@@ -300,7 +300,7 @@ bridge_connection_new (GtkWindow *parent,
gpointer user_data)
{
NMConnection *connection;
- int bridge_num, max_bridge_num, num;
+ int bridge_num = 0, num;
GSList *connections, *iter;
NMConnection *conn2;
NMSettingBridge *s_bridge;
@@ -315,7 +315,6 @@ bridge_connection_new (GtkWindow *parent,
nm_connection_add_setting (connection, nm_setting_bridge_new ());
/* Find an available interface name */
- bridge_num = max_bridge_num = 0;
connections = nm_remote_settings_list_connections (settings);
for (iter = connections; iter; iter = iter->next) {
conn2 = iter->data;
@@ -330,10 +329,8 @@ bridge_connection_new (GtkWindow *parent,
continue;
num = atoi (iface + 4);
- if (num > max_bridge_num)
- max_bridge_num = num;
- if (num == bridge_num)
- bridge_num = max_bridge_num + 1;
+ if (bridge_num <= num)
+ bridge_num = num + 1;
}
g_slist_free (connections);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]