Skip to content

Commit ccfe5fe

Browse files
committed
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.
1 parent 1966aba commit ccfe5fe

File tree

2 files changed

+10
-32
lines changed

2 files changed

+10
-32
lines changed

TODO

-32
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,6 @@ provide Ad-Hoc connection sharing support for those devices and switch between
5353
Ad-Hoc and AP mode depending on device capabilities.
5454

5555

56-
* Reconnect to WiFi Networks Only If They Succeeded Once
57-
58-
Currently, NetworkManager will attempt to connect to a previously attempted
59-
WiFi network even if that network was never successfully connected to. This
60-
causes confusion because sometimes users will randomly try various WiFi networks
61-
hoping to find an open AP, and then wonder why NM tries to reconnect to any of
62-
those APs later when none of them worked originally due to AP-side MAC filtering
63-
or other failures. What should happen is that NetworkManager should set a flag
64-
on a connection when that connection is successfully connected at least once,
65-
and only autoconnect the wifi network if that flag is present *and* the
66-
NMSettingConnection's 'autoconnect' property is TRUE.
67-
68-
This is a bit tricky because we want to consider all connections that don't have
69-
this flag as having succeeded so that we don't break users' existing connections,
70-
while holding all newly created connections to this policy. This flag should
71-
be determined and set for all connections, even if we only use it to determine
72-
WiFi behavior for now.
73-
74-
This flag should be a new gboolean property on the NMSettingConnection object
75-
called "connect-success", with a default value of TRUE. It should default to
76-
TRUE to ensure that existing connections are assumed to have connected
77-
successfully in the past. New connections created via the AddConnection and
78-
AddAndActivateConnection D-Bus method calls should have the 'connect-success'
79-
property explicitly set to FALSE. Then, in nm-device.c's device_state_changed()
80-
function where the NM_DEVICE_STATE_ACTIVATED state is handled, the
81-
'connect-success' property should be set to TRUE.
82-
83-
For WiFi then, in nm-device-wifi.c's get_best_auto_connection() method, the
84-
'connect-success' property should be checked and if it is FALSE, the connection
85-
is not considered for auto-activation.
86-
87-
8856
* Implement NM_DEVICE_STATE_DISCONNECTING
8957

9058
To allow for "pre-down" scenarios, this state should be implemented before a

src/nm-device-wifi.c

+10
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,7 @@ real_get_best_auto_connection (NMDevice *dev,
13571357
gboolean mac_blacklist_found = FALSE;
13581358
NMSettingIP4Config *s_ip4;
13591359
const char *method = NULL;
1360+
guint64 timestamp = 0;
13601361

13611362
s_con = nm_connection_get_setting_connection (connection);
13621363
if (s_con == NULL)
@@ -1366,6 +1367,15 @@ real_get_best_auto_connection (NMDevice *dev,
13661367
if (!nm_setting_connection_get_autoconnect (s_con))
13671368
continue;
13681369

1370+
/* Don't autoconnect to networks that have been tried at least once
1371+
* but haven't been successful, since these are often accidental choices
1372+
* from the menu and the user may not know the password.
1373+
*/
1374+
if (nm_settings_connection_get_timestamp (NM_SETTINGS_CONNECTION (connection), &timestamp)) {
1375+
if (timestamp == 0)
1376+
continue;
1377+
}
1378+
13691379
s_wireless = nm_connection_get_setting_wireless (connection);
13701380
if (!s_wireless)
13711381
continue;

0 commit comments

Comments
 (0)