blob: 7e879e4ebd53d895e1d71f7ecc3fd958493a9dc5 [file] [log] [blame]
Thieu Le94eed562012-02-21 15:57:29 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Darin Petkov50308cd2011-06-01 18:25:07 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/dhcp_config.h"
6
Darin Petkove7cb7f82011-06-03 13:21:51 -07007#include <arpa/inet.h>
Thieu Le94eed562012-02-21 15:57:29 -08008#include <sys/wait.h>
Darin Petkove7cb7f82011-06-03 13:21:51 -07009
Darin Petkov92c43902011-06-09 20:46:06 -070010#include <base/file_util.h>
Darin Petkov50308cd2011-06-01 18:25:07 -070011#include <base/logging.h>
Darin Petkov92c43902011-06-09 20:46:06 -070012#include <base/stringprintf.h>
Chris Masone43b48a12011-07-01 13:37:07 -070013#include <chromeos/dbus/service_constants.h>
Darin Petkovd1b715b2011-06-02 21:21:22 -070014
15#include "shill/dhcpcd_proxy.h"
16#include "shill/dhcp_provider.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070017#include "shill/event_dispatcher.h"
Darin Petkov3258a812011-06-23 11:28:45 -070018#include "shill/glib.h"
Paul Stewart1d18e8c2011-07-15 11:00:31 -070019#include "shill/ip_address.h"
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -070020#include "shill/minijail.h"
Darin Petkovaceede32011-07-18 15:32:38 -070021#include "shill/proxy_factory.h"
Ben Chanfad4a0b2012-04-18 15:49:59 -070022#include "shill/scope_logger.h"
Darin Petkov50308cd2011-06-01 18:25:07 -070023
Darin Petkove7cb7f82011-06-03 13:21:51 -070024using std::string;
25using std::vector;
26
Darin Petkov50308cd2011-06-01 18:25:07 -070027namespace shill {
28
Chris Masone0756f232011-07-21 17:24:00 -070029// static
Darin Petkove7cb7f82011-06-03 13:21:51 -070030const char DHCPConfig::kConfigurationKeyBroadcastAddress[] = "BroadcastAddress";
31const char DHCPConfig::kConfigurationKeyDNS[] = "DomainNameServers";
32const char DHCPConfig::kConfigurationKeyDomainName[] = "DomainName";
33const char DHCPConfig::kConfigurationKeyDomainSearch[] = "DomainSearch";
34const char DHCPConfig::kConfigurationKeyIPAddress[] = "IPAddress";
35const char DHCPConfig::kConfigurationKeyMTU[] = "InterfaceMTU";
36const char DHCPConfig::kConfigurationKeyRouters[] = "Routers";
37const char DHCPConfig::kConfigurationKeySubnetCIDR[] = "SubnetCIDR";
Thieu Le94eed562012-02-21 15:57:29 -080038const int DHCPConfig::kDHCPCDExitPollMilliseconds = 50;
39const int DHCPConfig::kDHCPCDExitWaitMilliseconds = 3000;
Darin Petkovd1b715b2011-06-02 21:21:22 -070040const char DHCPConfig::kDHCPCDPath[] = "/sbin/dhcpcd";
Paul Stewartd408fdf2012-05-07 17:15:57 -070041const char DHCPConfig::kDHCPCDPathFormatLease[] =
42 "var/lib/dhcpcd/dhcpcd-%s.lease";
Jorge Lucangeli Obes2f3169d2012-04-25 11:38:25 -070043const char DHCPConfig::kDHCPCDPathFormatPID[] =
44 "var/run/dhcpcd/dhcpcd-%s.pid";
mukesh agrawalcc0fded2012-05-09 13:40:58 -070045const int DHCPConfig::kDHCPTimeoutSeconds = 30;
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -070046const char DHCPConfig::kDHCPCDUser[] = "dhcp";
Darin Petkov14c29ec2012-03-02 11:34:19 +010047const int DHCPConfig::kMinMTU = 576;
Darin Petkovf9b0ca82011-06-20 12:10:23 -070048const char DHCPConfig::kReasonBound[] = "BOUND";
49const char DHCPConfig::kReasonFail[] = "FAIL";
Paul Stewarta02ee492012-05-16 10:04:53 -070050const char DHCPConfig::kReasonGatewayArp[] = "GATEWAY-ARP";
Darin Petkovf9b0ca82011-06-20 12:10:23 -070051const char DHCPConfig::kReasonRebind[] = "REBIND";
52const char DHCPConfig::kReasonReboot[] = "REBOOT";
53const char DHCPConfig::kReasonRenew[] = "RENEW";
Chris Masone0756f232011-07-21 17:24:00 -070054// static
55const char DHCPConfig::kType[] = "dhcp";
Darin Petkovf9b0ca82011-06-20 12:10:23 -070056
Darin Petkove7cb7f82011-06-03 13:21:51 -070057
Chris Masone19e30402011-07-19 15:48:47 -070058DHCPConfig::DHCPConfig(ControlInterface *control_interface,
Darin Petkova7b89492011-07-27 12:48:17 -070059 EventDispatcher *dispatcher,
Chris Masone19e30402011-07-19 15:48:47 -070060 DHCPProvider *provider,
Darin Petkovf65e9282011-06-21 14:29:56 -070061 const string &device_name,
Paul Stewartd32f4842012-01-11 16:08:13 -080062 const string &request_hostname,
Paul Stewartd408fdf2012-05-07 17:15:57 -070063 const string &lease_file_suffix,
64 bool arp_gateway,
Darin Petkov3258a812011-06-23 11:28:45 -070065 GLib *glib)
Chris Masone0756f232011-07-21 17:24:00 -070066 : IPConfig(control_interface, device_name, kType),
Darin Petkovab565bb2011-10-06 02:55:51 -070067 proxy_factory_(ProxyFactory::GetInstance()),
Darin Petkovd1b715b2011-06-02 21:21:22 -070068 provider_(provider),
Paul Stewartd32f4842012-01-11 16:08:13 -080069 request_hostname_(request_hostname),
Paul Stewartd408fdf2012-05-07 17:15:57 -070070 lease_file_suffix_(lease_file_suffix),
71 arp_gateway_(arp_gateway),
Darin Petkovf7897bc2011-06-08 17:13:36 -070072 pid_(0),
Darin Petkov92c43902011-06-09 20:46:06 -070073 child_watch_tag_(0),
mukesh agrawalcc0fded2012-05-09 13:40:58 -070074 lease_acquisition_timeout_seconds_(kDHCPTimeoutSeconds),
Darin Petkov92c43902011-06-09 20:46:06 -070075 root_("/"),
mukesh agrawalcc0fded2012-05-09 13:40:58 -070076 weak_ptr_factory_(this),
Darin Petkova7b89492011-07-27 12:48:17 -070077 dispatcher_(dispatcher),
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -070078 glib_(glib),
79 minijail_(Minijail::GetInstance()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070080 SLOG(DHCP, 2) << __func__ << ": " << device_name;
Paul Stewartd408fdf2012-05-07 17:15:57 -070081 if (lease_file_suffix_.empty()) {
82 lease_file_suffix_ = device_name;
83 }
Darin Petkov50308cd2011-06-01 18:25:07 -070084}
85
86DHCPConfig::~DHCPConfig() {
Ben Chanfad4a0b2012-04-18 15:49:59 -070087 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkov92c43902011-06-09 20:46:06 -070088
89 // Don't leave behind dhcpcd running.
90 Stop();
91
Darin Petkov98dd6a02011-06-10 15:12:57 -070092 // Make sure we don't get any callbacks to the destroyed instance.
Darin Petkov92c43902011-06-09 20:46:06 -070093 CleanupClientState();
Darin Petkovd1b715b2011-06-02 21:21:22 -070094}
95
Darin Petkov92c43902011-06-09 20:46:06 -070096bool DHCPConfig::RequestIP() {
Ben Chanfad4a0b2012-04-18 15:49:59 -070097 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkovd1b715b2011-06-02 21:21:22 -070098 if (!pid_) {
99 return Start();
100 }
101 if (!proxy_.get()) {
Darin Petkov98dd6a02011-06-10 15:12:57 -0700102 LOG(ERROR) << "Unable to request IP before acquiring destination.";
103 return Restart();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700104 }
Darin Petkov92c43902011-06-09 20:46:06 -0700105 return RenewIP();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700106}
107
Darin Petkov92c43902011-06-09 20:46:06 -0700108bool DHCPConfig::RenewIP() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700109 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkov98dd6a02011-06-10 15:12:57 -0700110 if (!pid_) {
111 return false;
112 }
Darin Petkovaceede32011-07-18 15:32:38 -0700113 proxy_->Rebind(device_name());
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700114 StartDHCPTimeout();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700115 return true;
116}
117
Darin Petkov92c43902011-06-09 20:46:06 -0700118bool DHCPConfig::ReleaseIP() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700119 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkov98dd6a02011-06-10 15:12:57 -0700120 if (!pid_) {
121 return true;
122 }
Paul Stewarta02ee492012-05-16 10:04:53 -0700123 // If we are using gateway unicast ARP to speed up re-connect, don't
124 // give up our leases when we disconnect.
125 if (!arp_gateway_ && proxy_.get()) {
Darin Petkova7b89492011-07-27 12:48:17 -0700126 proxy_->Release(device_name());
Darin Petkov98dd6a02011-06-10 15:12:57 -0700127 }
Darin Petkov98dd6a02011-06-10 15:12:57 -0700128 Stop();
129 return true;
Darin Petkov92c43902011-06-09 20:46:06 -0700130}
131
Darin Petkova7b89492011-07-27 12:48:17 -0700132void DHCPConfig::InitProxy(const string &service) {
Darin Petkova7b89492011-07-27 12:48:17 -0700133 if (!proxy_.get()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700134 SLOG(DHCP, 2) << "Init DHCP Proxy: " << device_name() << " at " << service;
Darin Petkovab565bb2011-10-06 02:55:51 -0700135 proxy_.reset(proxy_factory_->CreateDHCPProxy(service));
Darin Petkovd1b715b2011-06-02 21:21:22 -0700136 }
137}
138
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700139void DHCPConfig::ProcessEventSignal(const string &reason,
Darin Petkove7cb7f82011-06-03 13:21:51 -0700140 const Configuration &configuration) {
141 LOG(INFO) << "Event reason: " << reason;
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700142 if (reason == kReasonFail) {
143 LOG(ERROR) << "Received failure event from DHCP client.";
144 UpdateProperties(IPConfig::Properties(), false);
Darin Petkove7cb7f82011-06-03 13:21:51 -0700145 return;
146 }
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700147 if (reason != kReasonBound &&
148 reason != kReasonRebind &&
149 reason != kReasonReboot &&
Paul Stewarta02ee492012-05-16 10:04:53 -0700150 reason != kReasonRenew &&
151 reason != kReasonGatewayArp) {
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700152 LOG(WARNING) << "Event ignored.";
153 return;
154 }
155 IPConfig::Properties properties;
156 CHECK(ParseConfiguration(configuration, &properties));
Paul Stewarta02ee492012-05-16 10:04:53 -0700157 if (reason == kReasonGatewayArp) {
158 // This is a non-authoritative confirmation that we or on the same
159 // network as the one we received a lease on previously. The DHCP
160 // client is still running, so we should not cancel the timeout
161 // until that completes. In the meantime, however, we can tentatively
162 // configure our network in anticipation of successful completion.
163 IPConfig::UpdateProperties(properties, true);
164 } else {
165 UpdateProperties(properties, true);
166 }
Darin Petkove7cb7f82011-06-03 13:21:51 -0700167}
168
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700169void DHCPConfig::UpdateProperties(const Properties &properties, bool success) {
170 StopDHCPTimeout();
171 IPConfig::UpdateProperties(properties, success);
172}
173
Darin Petkovd1b715b2011-06-02 21:21:22 -0700174bool DHCPConfig::Start() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700175 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700176
Paul Stewartd32f4842012-01-11 16:08:13 -0800177 vector<char *> args;
178 args.push_back(const_cast<char *>(kDHCPCDPath));
Paul Stewartd408fdf2012-05-07 17:15:57 -0700179 args.push_back(const_cast<char *>("-B")); // Run in foreground.
mukesh agrawal7eb02892012-05-29 11:22:37 -0700180 args.push_back(const_cast<char *>("-q")); // Only warnings+errors to stderr.
Paul Stewartd32f4842012-01-11 16:08:13 -0800181 if (!request_hostname_.empty()) {
Paul Stewartd408fdf2012-05-07 17:15:57 -0700182 args.push_back(const_cast<char *>("-h")); // Request hostname from server.
Paul Stewartd32f4842012-01-11 16:08:13 -0800183 args.push_back(const_cast<char *>(request_hostname_.c_str()));
184 }
Paul Stewartd408fdf2012-05-07 17:15:57 -0700185 if (arp_gateway_) {
186 args.push_back(const_cast<char *>("-R")); // ARP for default gateway.
Paul Stewarta02ee492012-05-16 10:04:53 -0700187 args.push_back(const_cast<char *>("-U")); // Enable unicast ARP on renew.
Paul Stewartd408fdf2012-05-07 17:15:57 -0700188 }
189 string interface_arg(device_name());
190 if (lease_file_suffix_ != device_name()) {
191 interface_arg = base::StringPrintf("%s=%s", device_name().c_str(),
192 lease_file_suffix_.c_str());
193 }
194 args.push_back(const_cast<char *>(interface_arg.c_str()));
Paul Stewartd32f4842012-01-11 16:08:13 -0800195 args.push_back(NULL);
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -0700196
197 struct minijail *jail = minijail_->New();
198 minijail_->DropRoot(jail, kDHCPCDUser);
199 minijail_->UseCapabilities(jail,
200 CAP_TO_MASK(CAP_NET_BIND_SERVICE) |
201 CAP_TO_MASK(CAP_NET_BROADCAST) |
202 CAP_TO_MASK(CAP_NET_ADMIN) |
203 CAP_TO_MASK(CAP_NET_RAW));
Darin Petkovd1b715b2011-06-02 21:21:22 -0700204
Darin Petkov98dd6a02011-06-10 15:12:57 -0700205 CHECK(!pid_);
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -0700206 if (!minijail_->RunAndDestroy(jail, args, &pid_)) {
207 LOG(ERROR) << "Unable to spawn " << kDHCPCDPath << " in a jail.";
Darin Petkovd1b715b2011-06-02 21:21:22 -0700208 return false;
209 }
Darin Petkovd1b715b2011-06-02 21:21:22 -0700210 LOG(INFO) << "Spawned " << kDHCPCDPath << " with pid: " << pid_;
Darin Petkovf7897bc2011-06-08 17:13:36 -0700211 provider_->BindPID(pid_, this);
Darin Petkov98dd6a02011-06-10 15:12:57 -0700212 CHECK(!child_watch_tag_);
213 child_watch_tag_ = glib_->ChildWatchAdd(pid_, ChildWatchCallback, this);
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700214 StartDHCPTimeout();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700215 return true;
Darin Petkov50308cd2011-06-01 18:25:07 -0700216}
217
Darin Petkov92c43902011-06-09 20:46:06 -0700218void DHCPConfig::Stop() {
219 if (pid_) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700220 SLOG(DHCP, 2) << "Terminating " << pid_;
Thieu Le94eed562012-02-21 15:57:29 -0800221 if (kill(pid_, SIGTERM) < 0) {
222 PLOG(ERROR);
223 return;
224 }
225 pid_t ret;
226 int num_iterations =
227 kDHCPCDExitWaitMilliseconds / kDHCPCDExitPollMilliseconds;
228 for (int count = 0; count < num_iterations; ++count) {
229 ret = waitpid(pid_, NULL, WNOHANG);
230 if (ret == pid_ || ret == -1)
231 break;
232 usleep(kDHCPCDExitPollMilliseconds * 1000);
233 if (count == num_iterations / 2) // Make one last attempt to kill dhcpcd.
234 kill(pid_, SIGKILL);
235 }
236 if (ret != pid_)
237 PLOG(ERROR);
Darin Petkov92c43902011-06-09 20:46:06 -0700238 }
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700239 StopDHCPTimeout();
Darin Petkov92c43902011-06-09 20:46:06 -0700240}
241
Darin Petkov98dd6a02011-06-10 15:12:57 -0700242bool DHCPConfig::Restart() {
243 // Check to ensure that this instance doesn't get destroyed in the middle of
244 // this call. If stopping a running client while there's only one reference to
245 // this instance, we will end up destroying it when the PID is unbound from
246 // the Provider. Since the Provider doesn't invoke Restart, this would mean
247 // that Restart was erroneously executed through a bare reference.
248 CHECK(!pid_ || !HasOneRef());
249 Stop();
250 if (pid_) {
251 provider_->UnbindPID(pid_);
252 }
253 CleanupClientState();
254 return Start();
255}
256
Darin Petkove7cb7f82011-06-03 13:21:51 -0700257string DHCPConfig::GetIPv4AddressString(unsigned int address) {
258 char str[INET_ADDRSTRLEN];
259 if (inet_ntop(AF_INET, &address, str, arraysize(str))) {
260 return str;
261 }
262 LOG(ERROR) << "Unable to convert IPv4 address to string: " << address;
263 return "";
264}
265
266bool DHCPConfig::ParseConfiguration(const Configuration& configuration,
267 IPConfig::Properties *properties) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700268 SLOG(DHCP, 2) << __func__;
Chris Masone43b48a12011-07-01 13:37:07 -0700269 properties->method = flimflam::kTypeDHCP;
Paul Stewart7355ce12011-09-02 10:47:01 -0700270 properties->address_family = IPAddress::kFamilyIPv4;
Darin Petkove7cb7f82011-06-03 13:21:51 -0700271 for (Configuration::const_iterator it = configuration.begin();
272 it != configuration.end(); ++it) {
273 const string &key = it->first;
274 const DBus::Variant &value = it->second;
Ben Chanfad4a0b2012-04-18 15:49:59 -0700275 SLOG(DHCP, 2) << "Processing key: " << key;
Darin Petkove7cb7f82011-06-03 13:21:51 -0700276 if (key == kConfigurationKeyIPAddress) {
277 properties->address = GetIPv4AddressString(value.reader().get_uint32());
278 if (properties->address.empty()) {
279 return false;
280 }
281 } else if (key == kConfigurationKeySubnetCIDR) {
Paul Stewart48100b02012-03-19 07:53:52 -0700282 properties->subnet_prefix = value.reader().get_byte();
Darin Petkove7cb7f82011-06-03 13:21:51 -0700283 } else if (key == kConfigurationKeyBroadcastAddress) {
284 properties->broadcast_address =
285 GetIPv4AddressString(value.reader().get_uint32());
286 if (properties->broadcast_address.empty()) {
287 return false;
288 }
289 } else if (key == kConfigurationKeyRouters) {
Darin Petkovf7897bc2011-06-08 17:13:36 -0700290 vector<unsigned int> routers = value.operator vector<unsigned int>();
Darin Petkove7cb7f82011-06-03 13:21:51 -0700291 if (routers.empty()) {
292 LOG(ERROR) << "No routers provided.";
293 return false;
294 }
295 properties->gateway = GetIPv4AddressString(routers[0]);
296 if (properties->gateway.empty()) {
297 return false;
298 }
299 } else if (key == kConfigurationKeyDNS) {
Darin Petkovf7897bc2011-06-08 17:13:36 -0700300 vector<unsigned int> servers = value.operator vector<unsigned int>();
Darin Petkove7cb7f82011-06-03 13:21:51 -0700301 for (vector<unsigned int>::const_iterator it = servers.begin();
302 it != servers.end(); ++it) {
303 string server = GetIPv4AddressString(*it);
304 if (server.empty()) {
305 return false;
306 }
307 properties->dns_servers.push_back(server);
308 }
309 } else if (key == kConfigurationKeyDomainName) {
310 properties->domain_name = value.reader().get_string();
311 } else if (key == kConfigurationKeyDomainSearch) {
Darin Petkovf7897bc2011-06-08 17:13:36 -0700312 properties->domain_search = value.operator vector<string>();
Darin Petkove7cb7f82011-06-03 13:21:51 -0700313 } else if (key == kConfigurationKeyMTU) {
314 int mtu = value.reader().get_uint16();
Darin Petkov14c29ec2012-03-02 11:34:19 +0100315 if (mtu >= kMinMTU) {
Darin Petkove7cb7f82011-06-03 13:21:51 -0700316 properties->mtu = mtu;
317 }
318 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700319 SLOG(DHCP, 2) << "Key ignored.";
Darin Petkove7cb7f82011-06-03 13:21:51 -0700320 }
321 }
322 return true;
323}
324
Darin Petkov92c43902011-06-09 20:46:06 -0700325void DHCPConfig::ChildWatchCallback(GPid pid, gint status, gpointer data) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700326 SLOG(DHCP, 2) << "pid " << pid << " exit status " << status;
Darin Petkov92c43902011-06-09 20:46:06 -0700327 DHCPConfig *config = reinterpret_cast<DHCPConfig *>(data);
328 config->child_watch_tag_ = 0;
Darin Petkov92c43902011-06-09 20:46:06 -0700329 CHECK_EQ(pid, config->pid_);
Darin Petkov92c43902011-06-09 20:46:06 -0700330 config->CleanupClientState();
331
332 // |config| instance may be destroyed after this call.
333 config->provider_->UnbindPID(pid);
334}
335
336void DHCPConfig::CleanupClientState() {
Darin Petkov98dd6a02011-06-10 15:12:57 -0700337 if (child_watch_tag_) {
338 glib_->SourceRemove(child_watch_tag_);
339 child_watch_tag_ = 0;
340 }
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -0700341 pid_ = 0;
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700342 proxy_.reset();
Paul Stewartd408fdf2012-05-07 17:15:57 -0700343 if (lease_file_suffix_ == device_name()) {
344 // If the lease file suffix was left as default, clean it up at exit.
345 file_util::Delete(root_.Append(
346 base::StringPrintf(kDHCPCDPathFormatLease,
347 device_name().c_str())), false);
348 }
349 file_util::Delete(root_.Append(
350 base::StringPrintf(kDHCPCDPathFormatPID, device_name().c_str())), false);
Darin Petkov92c43902011-06-09 20:46:06 -0700351}
352
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700353void DHCPConfig::StartDHCPTimeout() {
354 lease_acquisition_timeout_callback_.Reset(
355 Bind(&DHCPConfig::ProcessDHCPTimeout, weak_ptr_factory_.GetWeakPtr()));
356 dispatcher_->PostDelayedTask(
357 lease_acquisition_timeout_callback_.callback(),
358 lease_acquisition_timeout_seconds_ * 1000);
359}
360
361void DHCPConfig::StopDHCPTimeout() {
362 lease_acquisition_timeout_callback_.Cancel();
363}
364
365void DHCPConfig::ProcessDHCPTimeout() {
366 LOG(ERROR) << "Timed out waiting for DHCP lease on " << device_name() << " "
367 << "(after " << lease_acquisition_timeout_seconds_ << " seconds).";
368 UpdateProperties(IPConfig::Properties(), false);
369}
370
Darin Petkov50308cd2011-06-01 18:25:07 -0700371} // namespace shill