After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 513488 - Option to disable wifi when wired network is detected
Option to disable wifi when wired network is detected
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: Wi-Fi
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: Dan Williams
NetworkManager maintainer(s)
: 679275 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2008-01-31 17:25 UTC by nicolas_bonifas
Modified: 2014-04-28 22:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch for disabling wifi connection(s) when wired connection is available (4.69 KB, patch)
2012-09-05 17:39 UTC, Johannes Buchner
none Details | Review
Patch that disables wifi when wired connection is available (1.94 KB, patch)
2012-09-05 18:03 UTC, Johannes Buchner
none Details | Review
0001-examples-update-70-wifi-wired-exclusive.sh-bgo-51348.patch (1.78 KB, patch)
2014-04-25 14:54 UTC, Dan Williams
accepted-commit_now Details | Review

Description nicolas_bonifas 2008-01-31 17:25:31 UTC
Hello,
Having an option to disable wifi when a wired network is detected and reactivating it after unplugging would be useful, in order to save battery on laptops.
Moreover, this is probably a really easy to implement feature, for someone who knows NM code.
Regards,
Nicolas
Comment 1 Wouter Bolsterlee (uws) 2008-05-06 15:03:05 UTC
Sounds pretty sane, confirming.
Comment 2 Pavel Simerda 2012-07-27 00:56:36 UTC
Still valid in 9.x.
Comment 3 Pavel Simerda 2012-07-27 00:59:49 UTC
Still valid in 9.x.

From bug 679275:

Roan Kattouw [reporter] 2012-07-27 00:23:09 UTC

Is this a new feature? I can see how trying to autoconnect to wifi even when
eth is already up would be consistent with supporting multiple connections, so
if those two things were introduced at the same time, that makes sense. It
would still be nice to have a config option to limit autoconnect to 1 interface
though (with eth preferred over wifi, as in previous versions of NM).
Comment 4 Pavel Simerda 2012-07-27 01:01:42 UTC
*** Bug 679275 has been marked as a duplicate of this bug. ***
Comment 5 Roan Kattouw 2012-07-27 01:41:29 UTC
(In reply to comment #4)
> *** Bug 679275 has been marked as a duplicate of this bug. ***
What I raised on that bug is subtly different: instead of disabling the wifi hardware to save power (which would also be nice), I want NetworkManager to stop trying to autoconnect to wifi networks (and prompting me for their passwords) when I have a live connection on a wired network. Obviously disabling the wifi hardware entirely would also accomplish that :)
Comment 6 Pavel Simerda 2012-07-27 01:45:11 UTC
It seems so related to me that I'll keep it in one bug report, if you don't object.
Comment 7 Roan Kattouw 2012-07-27 02:00:17 UTC
(In reply to comment #6)
> It seems so related to me that I'll keep it in one bug report, if you don't
> object.

Sure, no problem. Just pointing out that my request is a subset of the original reporter's request.
Comment 8 Johannes Buchner 2012-09-05 15:53:31 UTC
How do I vote +1? +1 anyways, I'd like to see this feature implemented.
Comment 9 Johannes Buchner 2012-09-05 17:39:48 UTC
Created attachment 223570 [details] [review]
Patch for disabling wifi connection(s) when wired connection is available

This is not meant to compile. Just for feedback on the approach. Don't laugh.

Still missing is a (global) config option that enables this "powersave"/single-connection mode.
Comment 10 Dan Williams 2012-09-05 17:58:47 UTC
A counter-proposal here would involve using dispatcher scripts to do this.  Thus, when an ethernet connection was up, the dispatcher script would call 'nmcli nm wifi off' or such, and when all ethernet connections went down, it could call 'nmcli nm wifi on'.

We'd need to:

1) enhance the dispatcher to put the device type into the script environment, which currently is not the case.  That would involve passing the value of the hash key NMD_DEVICE_PROPS_TYPE into construct_basic_items() in callouts/nm-dispatcher-utils.c and putting that into the script environment.

2) create a dispatcher script that checks the device type and rfkills wifi when any ethernet connection starts; if the device type isn't present, the script can call 'nmcli -t --fields type,state dev' which returns output liek this:

802-11-wireless:connected
802-3-ethernet:unavailable

and if any 802-3-ethernet device is "connected" then rfkill wifi using 'nmcli nm wifi off'.

3) when any interface gets disconnected, run the same 'nmcli -t --fields type,state dev' and if all 802-3-ethernet devices are unmanaged, unavailable, or disconnected, then unkill wifi using 'nmcli nm wifi on"
Comment 11 Johannes Buchner 2012-09-05 18:03:12 UTC
Created attachment 223572 [details] [review]
Patch that disables wifi when wired connection is available

Second one, which just disables/enables wifi completely by recommendation from dcbw on irc. 

Will follow Comment 10 now.
Comment 12 Dan Williams 2012-09-05 18:04:08 UTC
For 3, really, we just want to grep the nmcli output and look for "802-3-ethernet:connected" || "802-3-ethernet:connecting" and if neither of those are found, unkill wifi.
Comment 13 Johannes Buchner 2012-09-05 18:28:03 UTC
Here it is, the dispatcher script you need in all its glory

/etc/NetworkManager/dispatcher.d/wifi-xor-wired

#!/bin/bash
# Author: Johannes Buchner (C) 2012
# Disables wifi when wired connection is available
# Enables wifi when wired connection is lost

if   nmcli -t --fields type,state dev |
        grep -E "802-3-ethernet:connected" -q
then
        # ethernet is available, so we can drop the wifi
        nmcli nm wifi off && echo "disabled wifi"
elif nmcli -t --fields type,state dev |
        # no ethernet, wifi please help us
        grep -E "802-3-ethernet:(disconnected|unavailable)" -q
then
        nmcli nm wifi on && echo "enabled wifi"
fi
Comment 14 Dan Williams 2014-04-25 14:54:55 UTC
Created attachment 275137 [details] [review]
0001-examples-update-70-wifi-wired-exclusive.sh-bgo-51348.patch

Updated 0001-examples-update-70-wifi-wired-exclusive.sh-bgo-51348.patch following Johannes' suggestions.
Comment 15 Dan Winship 2014-04-25 19:32:20 UTC
Comment on attachment 275137 [details] [review]
0001-examples-update-70-wifi-wired-exclusive.sh-bgo-51348.patch

>+# (C) 2012 Johannes Buchner <buchner.johannes@gmx.at>
>+# (C) 2012 - 2014 Red Hat, Inc.

IANAL, but I was told at one point that "(C)" is technically legally meaningless, because it is not literally a circled C. So, "Copyright" is preferred.

>+	#with older nmcli, use nmcli nm wifi off

This will only be shipping with newer nmcli, so I don't think we need those comments.
Comment 16 Dan Williams 2014-04-28 22:06:41 UTC
Fixed up for your comments and pushed to git master.