LWN.net Logo

Making NetworkManager work with suspend/resume

Anybody who travels with a suspended laptop has likely run into the irritating problem of NetworkManager trying to reconnect to the old network - the one which was left behind before getting onto the airplane. It seems that Dan Williams has figured out the problem and queued a set of patches to fix it. "See, drivers timestamp wifi networks they know about. That way you can figure out if the network was last seen a second ago, 7 seconds ago, or so long ago that it’s dead to me. But they all use an kernel counter called ‘jiffies’ to do that. And ‘jiffies’ doesn’t increment across suspend/resume. See where I’m going with this?" Your editor plans to buy Dan a beer at the next opportunity.
(Log in to post comments)

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 16:01 UTC (Fri) by louie (subscriber, #3285) [Link]

I plan to buy two beers, one for Dan and one to pour on the next kernel guy who tells me that network manager sucks. :)

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 16:03 UTC (Fri) by stumbles (guest, #8796) [Link]

Since I am not a kernel developer, I have no fear of a brewski bath by saying.... NetWorkManger sucks!

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 16:22 UTC (Fri) by JoeBuck (subscriber, #2330) [Link]

But if you follow and read the link, you'll see that this particular problem wasn't NetworkManager's fault. It is the drivers, not NetworkManager, that think the networks they say a day ago were seen a few seconds ago.

So the article really should have been called "making wireless networking work with suspend/resume".

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 17:02 UTC (Fri) by drag (subscriber, #31333) [Link]

Ya.

The driver can't scan for networks continuously and networks don't transmit continuously. So the driver depends on timeouts and such to help it understand the topography of the area and when to look for networks and such.

When you suspend and then wake up then those timestamps and such are never updated. Thus the driver will tell userspace that networks are there when they are not really there. Thus when you wake your laptop up from suspend Network-Manager still thinks that your network exists and tries to connect to it wasting your time.

Making NetworkManager work with suspend/resume

Posted Mar 5, 2009 18:40 UTC (Thu) by rfunk (subscriber, #4054) [Link]

I'm no kernel developer, but I'll stop saying NetworkManager sucks when I
can use it to make a wifi connection from a command-line no-GUI
environment.

Making NetworkManager work with suspend/resume

Posted Mar 5, 2009 21:27 UTC (Thu) by mvidner (subscriber, #40070) [Link]

Yeah, that's why I wrote cnetworkmanager: http://vidner.net/martin/software/cnetworkmanager/
It is far from perfect, but it does connect to WEP and WPA-PSK.

Making NetworkManager work with the console

Posted Mar 5, 2009 21:57 UTC (Thu) by rfunk (subscriber, #4054) [Link]

That's awesome!

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 16:23 UTC (Fri) by clugstj (subscriber, #4020) [Link]

I can't figure out why this is so hard. Here's my "NetworkManager", it works great. I run it every 5 minutes as a cron job. Granted, the default router is hardcoded, but it would only take one more line of shell script to fix that!

#!/bin/sh

ping -c 2 -W 10 192.168.1.1 >/dev/null 2>&1
if [ $? -gt 0 ] ; then
/etc/init.d/net.wlan0 restart >/dev/null 2>&1
if [ $? -eq 0 ] ; then
echo "Restarted wlan0 at `date`"
fi
fi

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 16:52 UTC (Fri) by drag (subscriber, #31333) [Link]

Network Manager depends on the driver to tell it what networks were in range and their relative strengths. It can't determine it on itself, it needs to be told what networks are available and using the network card to scan for networks is the only way to do it.

The problem with that is if you suspend your laptop, move it to another area and time, and then wake it up the Linux kernel will tell you that networks exist that are not really there any more. The driver has no notion of time when it's put to sleep and thus it tells userspace bad information.

So Bad Information in = Bad results out.

So in order to make Network Manager perform it's function correctly (which is track networks, connect to networks, manage passwords, run appropriate if-up/if-down scripts, manage VPN, etc etc in a mobile environment with continuously changing topography without user intervention if possible) then it needs to have reliable information from the kernel.

This blog entry is just a overview of the developer figuring out that it wasn't Network-Manager's fault for behaving badly when it was simply reacting appropriately to a flaw in driver design. Which he then fixed.

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 19:25 UTC (Fri) by jengelh (subscriber, #33263) [Link]

Simple as it seems, there are post-suspend shell scripts that can get run, and which could be used to kick NM to issue a rescan.

# opensuse
grep RESTART_SERVICES /etc/sysconfig/powersave/sleep

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 21:53 UTC (Fri) by drag (subscriber, #31333) [Link]

Well ya....

But that is not what the blog post was about. Instead of mucking around with shell scripts to make NM work and being lazy, he was much more proud of actually fixing the buggy behavior in the drivers.

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 20:01 UTC (Fri) by dlang (✭ supporter ✭, #313) [Link]

since mobile IP has not been solved, it's not possible to transparently move from one network to another.

some things can recover from doing so, but many things cannot.

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 23:07 UTC (Fri) by zlynx (subscriber, #2285) [Link]

Actually it pretty much has been solved. It's just inefficient and inconvenient.

Use your home system as the target for OpenVPN and use only your OpenVPN network for connections. It will keep the same addresses and reconnect your OpenVPN sessions transparently.

If you shift networks before your TCP sessions time out, they will still be running when your laptop comes up on the new network.

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 23:51 UTC (Fri) by tialaramex (subscriber, #21167) [Link]

... and TCP connections don't actually timeout unless they've got outstanding data. So its possible for a connection to live indefinitely in your absence if its idle. A SSH session with no "keep-alive" flag can survive you moving to a new house, setting up DSL and IP at the new house, and then reconnecting the intervening architecture. Tap enter a couple of times and it all wakes back up and continues...

But anyway, Mobile IP exists, I've taken part in live demos of it over continental distances, moving a device from a local network to a wireless relay and seeing a streaming video briefly stumble and then continue. But it /is/ a little bit inefficient, and more importantly it relies on you not having a network made of string and parcel tape (NATs and private IP) and thus it's not an option in the real world where expediency has long ago triumphed over good engineering.

Making NetworkManager work with suspend/resume

Posted Mar 16, 2009 14:02 UTC (Mon) by robbe (guest, #16131) [Link]

> So its possible for a connection to live indefinitely in your absence
> if its idle.

In the 80's Internet, yeah. Today most interesting connections pass a
stateful firewall (or NAT device) -- and this state will not be kept
indefinitely.

Making NetworkManager work with suspend/resume

Posted Mar 30, 2009 16:29 UTC (Mon) by Lennie (subscriber, #49641) [Link]

Which would be a really good reason to start using IPv6. ;-)

Making NetworkManager work with suspend/resume

Posted Mar 1, 2009 14:35 UTC (Sun) by renox (subscriber, #23785) [Link]

[[since mobile IP has not been solved, it's not possible to transparently move from one network to another.]]

I think that there were some 'loss of context' for this sentence, given that many phone users use mobile IP to transfer data..
You're probably thinking only about WiFi users.

Making NetworkManager work with suspend/resume

Posted Mar 1, 2009 15:45 UTC (Sun) by dlang (✭ supporter ✭, #313) [Link]

by mobile IP I am not referring to the problem of moving from one wireless link to another within one network (either a cell network moving between towers, or a wifi network moving between access points), that's an easy thing to do.

I'm referring to the concept that your machine (phone or laptop) can get one IP address and have that address work as it shifts from one network to another. In a 'working' mobile IP environment, you could move from wired to wifi to cell (including bouncing between different providers) and have your connections remain.

the example above of using a VPN to a home network are close, but not quite the same.

Making NetworkManager work with suspend/resume

Posted Mar 2, 2009 11:59 UTC (Mon) by whitemice (guest, #3748) [Link]

> since mobile IP has not been solved

What?? Linux Journal as even had an article about the solutions - and it works great! IPv6 contains a solid solution for mobile IP among numerous other issues (like router performance, fragmentation, link-local addressing, etc...) Once you've been on an IPv6 network with WAN Bonjour/Zeroconf configured.... everything else looks so bronze age.

Making NetworkManager work with suspend/resume

Posted Mar 3, 2009 2:21 UTC (Tue) by dlang (✭ supporter ✭, #313) [Link]

the folks at OLPC would be interested to learn that 'it works great', it is something that they would love to do with their deployments, but the experts in the field say that it's not yet usable in the real world.

it sounds good in theory, but in practice it requires so much cooperation between everything that it doesn't work. I believe (but could be mistaken) that it also requires an IPv6-only Internet, which doesn't exist

Making NetworkManager work with suspend/resume

Posted Feb 28, 2009 3:36 UTC (Sat) by tialaramex (subscriber, #21167) [Link]

Your "NetworkManager" seems to be missing quite a few features that are found in the current NetworkManager, I hope you won't mind if I stick to the real thing until you add at least:

• Automatically flipping from wireless to wired or vice versa as they become available. This was essential to me for several months, doing it manually is a big pain

• Picking a Wireless network from a friendly list and then remembering my preferences so that there's no need to prompt me if a preferred Wireless network is visible.

• Integrating with my existing secure password storage to remember passwords for various corporate Wireless networks

Now, NetworkManager isn't perfect. Things it doesn't do (or doesn't do well enough in the version I have)

• Migration, leaving my slow-but-mobile SSH connection over the Wireless network still working while allowing my nice fast Cat5e I just plugged in to be used for new connections.

• DHCP retry. After it fails to find a DHCP server and chooses LLv4 NetworkManager doesn't learn about DHCP servers, even when they send broadcasts. So if your DHCP server happens to be offline when you boot up, you currently must manually re-connect, NetworkManager should retry at intervals and obtain a DHCP address within say 3-5 minutes of the server becoming available.

• LLv4 routing. When LLv4 isn't selected, NetworkManager seems to actively remove the LLv4 route - this means that LLv4 autoconfigured devices (like say a cheap networked printer) are needlessly difficult to use. Instead the LLv4 route should always be added to the active link, in addition to any unicast routes towards the Internet or a private network.

Making NetworkManager work with suspend/resume

Posted Mar 1, 2009 21:39 UTC (Sun) by ballombe (subscriber, #9523) [Link]

> LLv4 routing. When LLv4 isn't selected, NetworkManager seems to actively remove the LLv4 route - this means that LLv4 autoconfigured devices (like say a cheap networked printer) are needlessly difficult to use. Instead the LLv4 route should always be added to the active link, in addition to any unicast routes towards the Internet or a private network.


NetworkManager behaviour is in accordance with RFC 3927:
" This document does not recommend that IPv4 Link-Local addresses and
routable addresses be configured simultaneously on the same
interface. "

Making NetworkManager work with suspend/resume

Posted Mar 2, 2009 11:26 UTC (Mon) by nye (guest, #51576) [Link]

But the GP didn't say 'LLv4 *address*'. You can perfectly easily have the LLv4 route remain while having the interface configured only with a routable address.
Of course for this to be useful, the device you're trying to talk to would need to have its routes properly configured as well, and not just rely on being used only by machines with link-local adresses.

Making NetworkManager work with suspend/resume

Posted Mar 5, 2009 3:32 UTC (Thu) by jwb (guest, #15467) [Link]

"• Migration, leaving my slow-but-mobile SSH connection over the Wireless network still working while allowing my nice fast Cat5e I just plugged in to be used for new connections."

I think it =does= do this, and I was pleasantly surprised to find that recently. I had an IRC session open on my wireless network, but I plugged my laptop into a gigabit port to transfer some files. My IRC continued to work, and my files were transfer over the faster wired connection.

Perhaps this is a very new feature? I'm using Ubuntu Jaunty.

Making NetworkManager work with suspend/resume

Posted Mar 5, 2009 15:00 UTC (Thu) by clugstj (subscriber, #4020) [Link]

Yours is the perfect example of how NOT to design an application.

wpa_supplicant already does the "picking a wireless network from a friendly list" thing, why does some other app do it to? Flipping from wireless to wired? Doesn't the kernel networking subsystem do that when interfaces are brought up/down?

But, the article was about making wireless survive hibernation. My painfully simple solution does this reliably.

Nokia's internet tablets do it right

Posted Feb 27, 2009 16:34 UTC (Fri) by havoc (guest, #2261) [Link]

I've been pleased with my little Nokia n810 and it's networking. If I save an access point, the Nokia Internet Tablets (NIT) will automatically connect to the strongest available "authorized" signal, and stay attached until it is no longer reliable (rather than switch back and forth between available signals).

It's a just-works solution. Of course, the solution that Nokia is using may well be in the wireless driver, since they have complete control over all of the hardware, but the NIT solution may be worth having a look at.

Nokia's internet tablets do it right

Posted Feb 27, 2009 19:52 UTC (Fri) by dcbw (guest, #50562) [Link]

The one problem with "continuous scan" like the tablets do is that since not every network shows up every scan, the tablets just don't get the list right when you're in the Connection dialog. Sometimes your network will be in the list, other times it wont. You really do have to build up a list of scan results, just because wireless is by definition unreliable. This is precisely the reason why having a "Rescan" button doesn't work; just hitting the button won't necessarily show your AP.

You could walk through your saved list and probe-scan each AP in the list, but that actually takes a while, especially if you have 5GHz support (lots of channels) or a long list of known APs. So that doesn't work well either. Yeah, there are tricks you can do like probe-scanning the 5 most-used APs, etc. But in the end you have to find the balance between getting it right most of the time, and not getting it right the rest of the time, and somehow making the user not angry.

The user isn't going to blame the air, they are going to blame your device when they can't find their AP... even if the AP itself is a PoS, which is often the case. *That's* what makes wifi hard.

Nokia's internet tablets do it right

Posted Feb 27, 2009 21:58 UTC (Fri) by drag (subscriber, #31333) [Link]

Plus it gets worse with other types of wireless networks.

A wireless scan only takes a few moments to do on 802.11, but if your doing other types it can take anywhere from 5 minutes to half a hour to do a full scan.

Nokia's internet tablets do it right

Posted Feb 28, 2009 0:00 UTC (Sat) by leromarinvit (guest, #56850) [Link]

Still, I would find a "Scan now" button in NM very useful. Of course it shouldn't replace the whole list - just add to it incrementally. Very often it happens that I can see the AP I want to connect to with iwlist scan, but NM takes about half a minute or so to take note of it. Together with these patches it would be perfect, since the no-longer-present APs will be removed immediately.

Making NetworkManager work with suspend/resume

Posted Feb 27, 2009 16:54 UTC (Fri) by doogie (subscriber, #2445) [Link]

And the link to the patch(s) is ...

Making NetworkManager work with suspend/resume

Making NetworkManager work with suspend/resume

Posted Feb 28, 2009 16:40 UTC (Sat) by lacostej (guest, #2760) [Link]

I wonder how this impacts Android. It suspends often, right ? It's not using NetworkManager, but could perhaps benefit from the same kernel changes ?

Making NetworkManager work with suspend/resume

Posted Feb 28, 2009 21:51 UTC (Sat) by fredex (subscriber, #11727) [Link]

After reading this article, I tested it with my eeepc (running Fedora 10). While at work I connected to the office wireless. put it to sleep. carried it home, told it to "wake up" and it came right up and connected to my home lan. no muss, no fuss. So apparently it is either fixed (or hacked around) in F10.

Making NetworkManager work with suspend/resume

Posted Mar 5, 2009 7:02 UTC (Thu) by jgsack@san.rr.com (guest, #33287) [Link]

I didn't notice anyone saying that this bug points out a need to properly define the right "time" to use. Jiffies no, realtime-clock yes.

~jim

Suprised no one pointed this out

Posted Mar 6, 2009 2:27 UTC (Fri) by landman (subscriber, #2901) [Link]

NetworkManager is ... well ... to be blunt ... hopelessly broken. Has never worked correctly on any laptop I have tried it on. That it doesn't suspend/resume properly is not surprising in the least to me.

I make it a point these days, when I see NetworkManager installed on one of our systems, to immediately download and install wicd (http://wicd.sourceforge.net/) . Usually this involves removing NetworkManager.

What happens next is wireless and networking in general ... works, correctly. No fuss. With WPA2-PSK and other things that give NetworkManager fits.

Suprised no one pointed this out

Posted Mar 6, 2009 19:34 UTC (Fri) by jimparis (subscriber, #38647) [Link]

I've had the opposite experience -- NetworkManager works incredibly well on every laptop and desktop system I've set up in the past two years. But certainly experiences differ, and a lot of it depends on the hardware driver support, as demonstrated by this article.

Copyright © 2009, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds