diff options
author | Thomas Haller <thaller@redhat.com> | 2013-09-18 10:16:51 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2013-09-18 13:05:31 +0200 |
commit | 008cbcd8c8bf18153618c6b4b67ab99e2a781acf (patch) | |
tree | 536df192aea9bb078b237b370707025ff62a3f5d | |
parent | 94c820dec35e5432bbaf61b451ad465df73c4814 (diff) | |
download | network-manager-applet-008cbcd8c8bf18153618c6b4b67ab99e2a781acf.tar.gz |
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>
-rw-r--r-- | src/connection-editor/page-bond.c | 9 | ||||
-rw-r--r-- | 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 0db3fca0..5f09896d 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 649d2cd7..2f119def 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); |