shill: renew DHCP on resume
When the system resumes, we should renew our DHCP lease. This is
because the alarm that dhcpcd uses for DHCP renewals doesn't
advance to reflect time spent suspended.
We could modify dhcpcd to use alarms that do include time spent
suspended, but that's a bigger change than I'd really like to make.
(We'd need to use create_timerfd/set_timerfd, and modify the kernel
to allow a timerfd to be bound to CLOCK_BOOTTIME.)
Renew-on-resume is implemented by having Manager call an event handler
on each Device, as the system resumes. The Device is responsible for
poking its IPConfig object to actually renew the DHCP lease.
While there, I added a call from Manager to Devices for suspend events
as well.
BUG=chromium-os:33219
TEST=new autotests, manual (see below)
Manual testing:
- Connect WiFi to GoogleGuest.
- "echo > /var/log/messages"
- Suspend the device.
- Resume the device 60 seconds later.
- Check that /var/log/messages includes "dhcpcd[<pid>]: wlan0:
rebinding lease", and that WiFi did not disconnect before that
message showed up.
- NB: Testing on Ethernet did not work, because the link went down
during suspend. (Thus, on resume, there was no ipconfig set, and
Device could not renew.)
Change-Id: I76e29c68882415ebb34759aba98a40ecb5e1694b
Reviewed-on: https://gerrit.chromium.org/gerrit/29766
Reviewed-by: Paul Stewart <pstew@chromium.org>
Tested-by: mukesh agrawal <quiche@chromium.org>
Reviewed-by: mukesh agrawal <quiche@chromium.org>
Commit-Ready: mukesh agrawal <quiche@chromium.org>
diff --git a/device_unittest.cc b/device_unittest.cc
index 244c7cc..86ac95d 100644
--- a/device_unittest.cc
+++ b/device_unittest.cc
@@ -382,6 +382,20 @@
EXPECT_FALSE(device_->selected_service_.get());
}
+TEST_F(DeviceTest, ResumeWithIPConfig) {
+ scoped_refptr<MockIPConfig> ipconfig =
+ new MockIPConfig(control_interface(), kDeviceName);
+ device_->set_ipconfig(ipconfig);
+ EXPECT_CALL(*ipconfig, RenewIP());
+ device_->OnAfterResume();
+}
+
+TEST_F(DeviceTest, ResumeWithoutIPConfig) {
+ // Just test that we don't crash in this case.
+ ASSERT_EQ(NULL, device_->ipconfig().get());
+ device_->OnAfterResume();
+}
+
class DevicePortalDetectionTest : public DeviceTest {
public:
DevicePortalDetectionTest()