summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2012-09-12 22:54:44 -0500
committerDan Williams <dcbw@redhat.com>2012-09-20 10:11:36 -0500
commitccfe5fec8d1c1038467e4a56656d8f90bc94d2ed (patch)
tree6944e03af67a77fd6c635b2466892ac404929b8f
parent1966aba8e9a4a438da347c96d4ebd02449914e5e (diff)
wifi: don't autoconnect to networks that have never been successful
If you accidentally click on an wifi network in the menu, and you don't know the password, and cancel, the connection always stuck around and was available for autoconnection. That's annoying, and it's a few clicks to go delete them. But better yet, we can slightly repurpose the 'timestamp' property of connections to determine whether or not they've been successfully connected in the past; NM stores timestamps for all connections as of version 0.9. So if a wifi connection hasn't ever been successful (which means it has a timestamp in the timestamp cache, but that timestamp is zero), don't try to autoconnect it. Preloaded connections without a timestamp will still be autoconnected at least once (as they always have) because they won't yet have a timestamp in the timestamp cache.
-rw-r--r--TODO32
-rw-r--r--src/nm-device-wifi.c10
2 files changed, 10 insertions, 32 deletions
diff --git a/TODO b/TODO
index a2f7ee99f2..cdea070d00 100644
--- a/TODO
+++ b/TODO
@@ -53,38 +53,6 @@ provide Ad-Hoc connection sharing support for those devices and switch between
Ad-Hoc and AP mode depending on device capabilities.
-* Reconnect to WiFi Networks Only If They Succeeded Once
-
-Currently, NetworkManager will attempt to connect to a previously attempted
-WiFi network even if that network was never successfully connected to. This
-causes confusion because sometimes users will randomly try various WiFi networks
-hoping to find an open AP, and then wonder why NM tries to reconnect to any of
-those APs later when none of them worked originally due to AP-side MAC filtering
-or other failures. What should happen is that NetworkManager should set a flag
-on a connection when that connection is successfully connected at least once,
-and only autoconnect the wifi network if that flag is present *and* the
-NMSettingConnection's 'autoconnect' property is TRUE.
-
-This is a bit tricky because we want to consider all connections that don't have
-this flag as having succeeded so that we don't break users' existing connections,
-while holding all newly created connections to this policy. This flag should
-be determined and set for all connections, even if we only use it to determine
-WiFi behavior for now.
-
-This flag should be a new gboolean property on the NMSettingConnection object
-called "connect-success", with a default value of TRUE. It should default to
-TRUE to ensure that existing connections are assumed to have connected
-successfully in the past. New connections created via the AddConnection and
-AddAndActivateConnection D-Bus method calls should have the 'connect-success'
-property explicitly set to FALSE. Then, in nm-device.c's device_state_changed()
-function where the NM_DEVICE_STATE_ACTIVATED state is handled, the
-'connect-success' property should be set to TRUE.
-
-For WiFi then, in nm-device-wifi.c's get_best_auto_connection() method, the
-'connect-success' property should be checked and if it is FALSE, the connection
-is not considered for auto-activation.
-
-
* Implement NM_DEVICE_STATE_DISCONNECTING
To allow for "pre-down" scenarios, this state should be implemented before a
diff --git a/src/nm-device-wifi.c b/src/nm-device-wifi.c
index 6f0cf57c48..6119c9dbf4 100644
--- a/src/nm-device-wifi.c
+++ b/src/nm-device-wifi.c
@@ -1357,6 +1357,7 @@ real_get_best_auto_connection (NMDevice *dev,
gboolean mac_blacklist_found = FALSE;
NMSettingIP4Config *s_ip4;
const char *method = NULL;
+ guint64 timestamp = 0;
s_con = nm_connection_get_setting_connection (connection);
if (s_con == NULL)
@@ -1366,6 +1367,15 @@ real_get_best_auto_connection (NMDevice *dev,
if (!nm_setting_connection_get_autoconnect (s_con))
continue;
+ /* Don't autoconnect to networks that have been tried at least once
+ * but haven't been successful, since these are often accidental choices
+ * from the menu and the user may not know the password.
+ */
+ if (nm_settings_connection_get_timestamp (NM_SETTINGS_CONNECTION (connection), &timestamp)) {
+ if (timestamp == 0)
+ continue;
+ }
+
s_wireless = nm_connection_get_setting_wireless (connection);
if (!s_wireless)
continue;