blob: 0924ea2410a3c1036e409fc429eb9ca755999fc9 [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 Petkov92c43902011-06-09 20:46:06 -070011#include <base/stringprintf.h>
Chris Masone43b48a12011-07-01 13:37:07 -070012#include <chromeos/dbus/service_constants.h>
Darin Petkovd1b715b2011-06-02 21:21:22 -070013
14#include "shill/dhcpcd_proxy.h"
15#include "shill/dhcp_provider.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070016#include "shill/event_dispatcher.h"
Darin Petkov3258a812011-06-23 11:28:45 -070017#include "shill/glib.h"
Paul Stewart1d18e8c2011-07-15 11:00:31 -070018#include "shill/ip_address.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070019#include "shill/logging.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"
Darin Petkov50308cd2011-06-01 18:25:07 -070022
Darin Petkove7cb7f82011-06-03 13:21:51 -070023using std::string;
24using std::vector;
25
Darin Petkov50308cd2011-06-01 18:25:07 -070026namespace shill {
27
Chris Masone0756f232011-07-21 17:24:00 -070028// static
Darin Petkove7cb7f82011-06-03 13:21:51 -070029const char DHCPConfig::kConfigurationKeyBroadcastAddress[] = "BroadcastAddress";
30const char DHCPConfig::kConfigurationKeyDNS[] = "DomainNameServers";
31const char DHCPConfig::kConfigurationKeyDomainName[] = "DomainName";
32const char DHCPConfig::kConfigurationKeyDomainSearch[] = "DomainSearch";
33const char DHCPConfig::kConfigurationKeyIPAddress[] = "IPAddress";
34const char DHCPConfig::kConfigurationKeyMTU[] = "InterfaceMTU";
35const char DHCPConfig::kConfigurationKeyRouters[] = "Routers";
36const char DHCPConfig::kConfigurationKeySubnetCIDR[] = "SubnetCIDR";
Thieu Le94eed562012-02-21 15:57:29 -080037const int DHCPConfig::kDHCPCDExitPollMilliseconds = 50;
38const int DHCPConfig::kDHCPCDExitWaitMilliseconds = 3000;
Darin Petkovd1b715b2011-06-02 21:21:22 -070039const char DHCPConfig::kDHCPCDPath[] = "/sbin/dhcpcd";
Paul Stewartd408fdf2012-05-07 17:15:57 -070040const char DHCPConfig::kDHCPCDPathFormatLease[] =
41 "var/lib/dhcpcd/dhcpcd-%s.lease";
Jorge Lucangeli Obes2f3169d2012-04-25 11:38:25 -070042const char DHCPConfig::kDHCPCDPathFormatPID[] =
43 "var/run/dhcpcd/dhcpcd-%s.pid";
mukesh agrawalcc0fded2012-05-09 13:40:58 -070044const int DHCPConfig::kDHCPTimeoutSeconds = 30;
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -070045const char DHCPConfig::kDHCPCDUser[] = "dhcp";
Darin Petkov14c29ec2012-03-02 11:34:19 +010046const int DHCPConfig::kMinMTU = 576;
Darin Petkovf9b0ca82011-06-20 12:10:23 -070047const char DHCPConfig::kReasonBound[] = "BOUND";
48const char DHCPConfig::kReasonFail[] = "FAIL";
Paul Stewarta02ee492012-05-16 10:04:53 -070049const char DHCPConfig::kReasonGatewayArp[] = "GATEWAY-ARP";
Darin Petkovf9b0ca82011-06-20 12:10:23 -070050const char DHCPConfig::kReasonRebind[] = "REBIND";
51const char DHCPConfig::kReasonReboot[] = "REBOOT";
52const char DHCPConfig::kReasonRenew[] = "RENEW";
Chris Masone0756f232011-07-21 17:24:00 -070053// static
54const char DHCPConfig::kType[] = "dhcp";
Darin Petkovf9b0ca82011-06-20 12:10:23 -070055
Darin Petkove7cb7f82011-06-03 13:21:51 -070056
Chris Masone19e30402011-07-19 15:48:47 -070057DHCPConfig::DHCPConfig(ControlInterface *control_interface,
Darin Petkova7b89492011-07-27 12:48:17 -070058 EventDispatcher *dispatcher,
Chris Masone19e30402011-07-19 15:48:47 -070059 DHCPProvider *provider,
Darin Petkovf65e9282011-06-21 14:29:56 -070060 const string &device_name,
Paul Stewartd32f4842012-01-11 16:08:13 -080061 const string &request_hostname,
Paul Stewartd408fdf2012-05-07 17:15:57 -070062 const string &lease_file_suffix,
63 bool arp_gateway,
Darin Petkov3258a812011-06-23 11:28:45 -070064 GLib *glib)
Chris Masone0756f232011-07-21 17:24:00 -070065 : IPConfig(control_interface, device_name, kType),
Darin Petkovab565bb2011-10-06 02:55:51 -070066 proxy_factory_(ProxyFactory::GetInstance()),
Darin Petkovd1b715b2011-06-02 21:21:22 -070067 provider_(provider),
Paul Stewartd32f4842012-01-11 16:08:13 -080068 request_hostname_(request_hostname),
Paul Stewartd408fdf2012-05-07 17:15:57 -070069 lease_file_suffix_(lease_file_suffix),
70 arp_gateway_(arp_gateway),
Darin Petkovf7897bc2011-06-08 17:13:36 -070071 pid_(0),
Darin Petkov92c43902011-06-09 20:46:06 -070072 child_watch_tag_(0),
mukesh agrawalcc0fded2012-05-09 13:40:58 -070073 lease_acquisition_timeout_seconds_(kDHCPTimeoutSeconds),
Darin Petkov92c43902011-06-09 20:46:06 -070074 root_("/"),
mukesh agrawalcc0fded2012-05-09 13:40:58 -070075 weak_ptr_factory_(this),
Darin Petkova7b89492011-07-27 12:48:17 -070076 dispatcher_(dispatcher),
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -070077 glib_(glib),
78 minijail_(Minijail::GetInstance()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070079 SLOG(DHCP, 2) << __func__ << ": " << device_name;
Paul Stewartd408fdf2012-05-07 17:15:57 -070080 if (lease_file_suffix_.empty()) {
81 lease_file_suffix_ = device_name;
82 }
Darin Petkov50308cd2011-06-01 18:25:07 -070083}
84
85DHCPConfig::~DHCPConfig() {
Ben Chanfad4a0b2012-04-18 15:49:59 -070086 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkov92c43902011-06-09 20:46:06 -070087
88 // Don't leave behind dhcpcd running.
89 Stop();
90
Darin Petkov98dd6a02011-06-10 15:12:57 -070091 // Make sure we don't get any callbacks to the destroyed instance.
Darin Petkov92c43902011-06-09 20:46:06 -070092 CleanupClientState();
Darin Petkovd1b715b2011-06-02 21:21:22 -070093}
94
Darin Petkov92c43902011-06-09 20:46:06 -070095bool DHCPConfig::RequestIP() {
Ben Chanfad4a0b2012-04-18 15:49:59 -070096 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkovd1b715b2011-06-02 21:21:22 -070097 if (!pid_) {
98 return Start();
99 }
100 if (!proxy_.get()) {
Darin Petkov98dd6a02011-06-10 15:12:57 -0700101 LOG(ERROR) << "Unable to request IP before acquiring destination.";
102 return Restart();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700103 }
Darin Petkov92c43902011-06-09 20:46:06 -0700104 return RenewIP();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700105}
106
Darin Petkov92c43902011-06-09 20:46:06 -0700107bool DHCPConfig::RenewIP() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700108 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkov98dd6a02011-06-10 15:12:57 -0700109 if (!pid_) {
110 return false;
111 }
Darin Petkovaceede32011-07-18 15:32:38 -0700112 proxy_->Rebind(device_name());
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700113 StartDHCPTimeout();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700114 return true;
115}
116
Darin Petkov92c43902011-06-09 20:46:06 -0700117bool DHCPConfig::ReleaseIP() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700118 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkov98dd6a02011-06-10 15:12:57 -0700119 if (!pid_) {
120 return true;
121 }
Paul Stewarta02ee492012-05-16 10:04:53 -0700122 // If we are using gateway unicast ARP to speed up re-connect, don't
123 // give up our leases when we disconnect.
124 if (!arp_gateway_ && proxy_.get()) {
Darin Petkova7b89492011-07-27 12:48:17 -0700125 proxy_->Release(device_name());
Darin Petkov98dd6a02011-06-10 15:12:57 -0700126 }
Darin Petkov98dd6a02011-06-10 15:12:57 -0700127 Stop();
128 return true;
Darin Petkov92c43902011-06-09 20:46:06 -0700129}
130
Darin Petkova7b89492011-07-27 12:48:17 -0700131void DHCPConfig::InitProxy(const string &service) {
Darin Petkova7b89492011-07-27 12:48:17 -0700132 if (!proxy_.get()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700133 SLOG(DHCP, 2) << "Init DHCP Proxy: " << device_name() << " at " << service;
Darin Petkovab565bb2011-10-06 02:55:51 -0700134 proxy_.reset(proxy_factory_->CreateDHCPProxy(service));
Darin Petkovd1b715b2011-06-02 21:21:22 -0700135 }
136}
137
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700138void DHCPConfig::ProcessEventSignal(const string &reason,
Darin Petkove7cb7f82011-06-03 13:21:51 -0700139 const Configuration &configuration) {
140 LOG(INFO) << "Event reason: " << reason;
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700141 if (reason == kReasonFail) {
142 LOG(ERROR) << "Received failure event from DHCP client.";
143 UpdateProperties(IPConfig::Properties(), false);
Darin Petkove7cb7f82011-06-03 13:21:51 -0700144 return;
145 }
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700146 if (reason != kReasonBound &&
147 reason != kReasonRebind &&
148 reason != kReasonReboot &&
Paul Stewarta02ee492012-05-16 10:04:53 -0700149 reason != kReasonRenew &&
150 reason != kReasonGatewayArp) {
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700151 LOG(WARNING) << "Event ignored.";
152 return;
153 }
154 IPConfig::Properties properties;
155 CHECK(ParseConfiguration(configuration, &properties));
Paul Stewarta02ee492012-05-16 10:04:53 -0700156 if (reason == kReasonGatewayArp) {
157 // This is a non-authoritative confirmation that we or on the same
158 // network as the one we received a lease on previously. The DHCP
159 // client is still running, so we should not cancel the timeout
160 // until that completes. In the meantime, however, we can tentatively
161 // configure our network in anticipation of successful completion.
162 IPConfig::UpdateProperties(properties, true);
163 } else {
164 UpdateProperties(properties, true);
165 }
Darin Petkove7cb7f82011-06-03 13:21:51 -0700166}
167
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700168void DHCPConfig::UpdateProperties(const Properties &properties, bool success) {
169 StopDHCPTimeout();
170 IPConfig::UpdateProperties(properties, success);
171}
172
Darin Petkovd1b715b2011-06-02 21:21:22 -0700173bool DHCPConfig::Start() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700174 SLOG(DHCP, 2) << __func__ << ": " << device_name();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700175
Paul Stewartd32f4842012-01-11 16:08:13 -0800176 vector<char *> args;
177 args.push_back(const_cast<char *>(kDHCPCDPath));
Paul Stewartd408fdf2012-05-07 17:15:57 -0700178 args.push_back(const_cast<char *>("-B")); // Run in foreground.
mukesh agrawal7eb02892012-05-29 11:22:37 -0700179 args.push_back(const_cast<char *>("-q")); // Only warnings+errors to stderr.
Paul Stewartd32f4842012-01-11 16:08:13 -0800180 if (!request_hostname_.empty()) {
Paul Stewartd408fdf2012-05-07 17:15:57 -0700181 args.push_back(const_cast<char *>("-h")); // Request hostname from server.
Paul Stewartd32f4842012-01-11 16:08:13 -0800182 args.push_back(const_cast<char *>(request_hostname_.c_str()));
183 }
Paul Stewartd408fdf2012-05-07 17:15:57 -0700184 if (arp_gateway_) {
185 args.push_back(const_cast<char *>("-R")); // ARP for default gateway.
Paul Stewarta02ee492012-05-16 10:04:53 -0700186 args.push_back(const_cast<char *>("-U")); // Enable unicast ARP on renew.
Paul Stewartd408fdf2012-05-07 17:15:57 -0700187 }
188 string interface_arg(device_name());
189 if (lease_file_suffix_ != device_name()) {
190 interface_arg = base::StringPrintf("%s=%s", device_name().c_str(),
191 lease_file_suffix_.c_str());
192 }
193 args.push_back(const_cast<char *>(interface_arg.c_str()));
Paul Stewartd32f4842012-01-11 16:08:13 -0800194 args.push_back(NULL);
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -0700195
196 struct minijail *jail = minijail_->New();
197 minijail_->DropRoot(jail, kDHCPCDUser);
198 minijail_->UseCapabilities(jail,
199 CAP_TO_MASK(CAP_NET_BIND_SERVICE) |
200 CAP_TO_MASK(CAP_NET_BROADCAST) |
201 CAP_TO_MASK(CAP_NET_ADMIN) |
202 CAP_TO_MASK(CAP_NET_RAW));
Darin Petkovd1b715b2011-06-02 21:21:22 -0700203
Darin Petkov98dd6a02011-06-10 15:12:57 -0700204 CHECK(!pid_);
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -0700205 if (!minijail_->RunAndDestroy(jail, args, &pid_)) {
206 LOG(ERROR) << "Unable to spawn " << kDHCPCDPath << " in a jail.";
Darin Petkovd1b715b2011-06-02 21:21:22 -0700207 return false;
208 }
Darin Petkovd1b715b2011-06-02 21:21:22 -0700209 LOG(INFO) << "Spawned " << kDHCPCDPath << " with pid: " << pid_;
Darin Petkovf7897bc2011-06-08 17:13:36 -0700210 provider_->BindPID(pid_, this);
Darin Petkov98dd6a02011-06-10 15:12:57 -0700211 CHECK(!child_watch_tag_);
212 child_watch_tag_ = glib_->ChildWatchAdd(pid_, ChildWatchCallback, this);
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700213 StartDHCPTimeout();
Darin Petkovd1b715b2011-06-02 21:21:22 -0700214 return true;
Darin Petkov50308cd2011-06-01 18:25:07 -0700215}
216
Darin Petkov92c43902011-06-09 20:46:06 -0700217void DHCPConfig::Stop() {
218 if (pid_) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700219 SLOG(DHCP, 2) << "Terminating " << pid_;
Thieu Le94eed562012-02-21 15:57:29 -0800220 if (kill(pid_, SIGTERM) < 0) {
221 PLOG(ERROR);
222 return;
223 }
224 pid_t ret;
225 int num_iterations =
226 kDHCPCDExitWaitMilliseconds / kDHCPCDExitPollMilliseconds;
227 for (int count = 0; count < num_iterations; ++count) {
228 ret = waitpid(pid_, NULL, WNOHANG);
229 if (ret == pid_ || ret == -1)
230 break;
231 usleep(kDHCPCDExitPollMilliseconds * 1000);
232 if (count == num_iterations / 2) // Make one last attempt to kill dhcpcd.
233 kill(pid_, SIGKILL);
234 }
235 if (ret != pid_)
236 PLOG(ERROR);
Darin Petkov92c43902011-06-09 20:46:06 -0700237 }
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700238 StopDHCPTimeout();
Darin Petkov92c43902011-06-09 20:46:06 -0700239}
240
Darin Petkov98dd6a02011-06-10 15:12:57 -0700241bool DHCPConfig::Restart() {
242 // Check to ensure that this instance doesn't get destroyed in the middle of
243 // this call. If stopping a running client while there's only one reference to
244 // this instance, we will end up destroying it when the PID is unbound from
245 // the Provider. Since the Provider doesn't invoke Restart, this would mean
246 // that Restart was erroneously executed through a bare reference.
247 CHECK(!pid_ || !HasOneRef());
248 Stop();
249 if (pid_) {
250 provider_->UnbindPID(pid_);
251 }
252 CleanupClientState();
253 return Start();
254}
255
Darin Petkove7cb7f82011-06-03 13:21:51 -0700256string DHCPConfig::GetIPv4AddressString(unsigned int address) {
257 char str[INET_ADDRSTRLEN];
258 if (inet_ntop(AF_INET, &address, str, arraysize(str))) {
259 return str;
260 }
261 LOG(ERROR) << "Unable to convert IPv4 address to string: " << address;
262 return "";
263}
264
265bool DHCPConfig::ParseConfiguration(const Configuration& configuration,
266 IPConfig::Properties *properties) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700267 SLOG(DHCP, 2) << __func__;
Chris Masone43b48a12011-07-01 13:37:07 -0700268 properties->method = flimflam::kTypeDHCP;
Paul Stewart7355ce12011-09-02 10:47:01 -0700269 properties->address_family = IPAddress::kFamilyIPv4;
Darin Petkove7cb7f82011-06-03 13:21:51 -0700270 for (Configuration::const_iterator it = configuration.begin();
271 it != configuration.end(); ++it) {
272 const string &key = it->first;
273 const DBus::Variant &value = it->second;
Ben Chanfad4a0b2012-04-18 15:49:59 -0700274 SLOG(DHCP, 2) << "Processing key: " << key;
Darin Petkove7cb7f82011-06-03 13:21:51 -0700275 if (key == kConfigurationKeyIPAddress) {
276 properties->address = GetIPv4AddressString(value.reader().get_uint32());
277 if (properties->address.empty()) {
278 return false;
279 }
280 } else if (key == kConfigurationKeySubnetCIDR) {
Paul Stewart48100b02012-03-19 07:53:52 -0700281 properties->subnet_prefix = value.reader().get_byte();
Darin Petkove7cb7f82011-06-03 13:21:51 -0700282 } else if (key == kConfigurationKeyBroadcastAddress) {
283 properties->broadcast_address =
284 GetIPv4AddressString(value.reader().get_uint32());
285 if (properties->broadcast_address.empty()) {
286 return false;
287 }
288 } else if (key == kConfigurationKeyRouters) {
Darin Petkovf7897bc2011-06-08 17:13:36 -0700289 vector<unsigned int> routers = value.operator vector<unsigned int>();
Darin Petkove7cb7f82011-06-03 13:21:51 -0700290 if (routers.empty()) {
291 LOG(ERROR) << "No routers provided.";
292 return false;
293 }
294 properties->gateway = GetIPv4AddressString(routers[0]);
295 if (properties->gateway.empty()) {
296 return false;
297 }
298 } else if (key == kConfigurationKeyDNS) {
Darin Petkovf7897bc2011-06-08 17:13:36 -0700299 vector<unsigned int> servers = value.operator vector<unsigned int>();
Darin Petkove7cb7f82011-06-03 13:21:51 -0700300 for (vector<unsigned int>::const_iterator it = servers.begin();
301 it != servers.end(); ++it) {
302 string server = GetIPv4AddressString(*it);
303 if (server.empty()) {
304 return false;
305 }
306 properties->dns_servers.push_back(server);
307 }
308 } else if (key == kConfigurationKeyDomainName) {
309 properties->domain_name = value.reader().get_string();
310 } else if (key == kConfigurationKeyDomainSearch) {
Darin Petkovf7897bc2011-06-08 17:13:36 -0700311 properties->domain_search = value.operator vector<string>();
Darin Petkove7cb7f82011-06-03 13:21:51 -0700312 } else if (key == kConfigurationKeyMTU) {
313 int mtu = value.reader().get_uint16();
Darin Petkov14c29ec2012-03-02 11:34:19 +0100314 if (mtu >= kMinMTU) {
Darin Petkove7cb7f82011-06-03 13:21:51 -0700315 properties->mtu = mtu;
316 }
317 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700318 SLOG(DHCP, 2) << "Key ignored.";
Darin Petkove7cb7f82011-06-03 13:21:51 -0700319 }
320 }
321 return true;
322}
323
Darin Petkov92c43902011-06-09 20:46:06 -0700324void DHCPConfig::ChildWatchCallback(GPid pid, gint status, gpointer data) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700325 SLOG(DHCP, 2) << "pid " << pid << " exit status " << status;
Darin Petkov92c43902011-06-09 20:46:06 -0700326 DHCPConfig *config = reinterpret_cast<DHCPConfig *>(data);
327 config->child_watch_tag_ = 0;
Darin Petkov92c43902011-06-09 20:46:06 -0700328 CHECK_EQ(pid, config->pid_);
Darin Petkov92c43902011-06-09 20:46:06 -0700329 config->CleanupClientState();
330
331 // |config| instance may be destroyed after this call.
332 config->provider_->UnbindPID(pid);
333}
334
335void DHCPConfig::CleanupClientState() {
Darin Petkov98dd6a02011-06-10 15:12:57 -0700336 if (child_watch_tag_) {
337 glib_->SourceRemove(child_watch_tag_);
338 child_watch_tag_ = 0;
339 }
Jorge Lucangeli Obesad43cc62012-04-11 16:25:43 -0700340 pid_ = 0;
Darin Petkovf9b0ca82011-06-20 12:10:23 -0700341 proxy_.reset();
Paul Stewartd408fdf2012-05-07 17:15:57 -0700342 if (lease_file_suffix_ == device_name()) {
343 // If the lease file suffix was left as default, clean it up at exit.
344 file_util::Delete(root_.Append(
345 base::StringPrintf(kDHCPCDPathFormatLease,
346 device_name().c_str())), false);
347 }
348 file_util::Delete(root_.Append(
349 base::StringPrintf(kDHCPCDPathFormatPID, device_name().c_str())), false);
Darin Petkov92c43902011-06-09 20:46:06 -0700350}
351
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700352void DHCPConfig::StartDHCPTimeout() {
353 lease_acquisition_timeout_callback_.Reset(
354 Bind(&DHCPConfig::ProcessDHCPTimeout, weak_ptr_factory_.GetWeakPtr()));
355 dispatcher_->PostDelayedTask(
356 lease_acquisition_timeout_callback_.callback(),
357 lease_acquisition_timeout_seconds_ * 1000);
358}
359
360void DHCPConfig::StopDHCPTimeout() {
361 lease_acquisition_timeout_callback_.Cancel();
362}
363
364void DHCPConfig::ProcessDHCPTimeout() {
365 LOG(ERROR) << "Timed out waiting for DHCP lease on " << device_name() << " "
366 << "(after " << lease_acquisition_timeout_seconds_ << " seconds).";
367 UpdateProperties(IPConfig::Properties(), false);
368}
369
Darin Petkov50308cd2011-06-01 18:25:07 -0700370} // namespace shill