blob: 4f0851f7bb91f49fbafc9112d96dc984ec22231e [file] [log] [blame]
mukesh agrawal8a3188d2011-12-01 20:56:44 +00001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Chris Masone2b105542011-06-22 10:58:09 -07005#include "shill/device.h"
6
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -07007#include <netinet/in.h>
8#include <linux/if.h> // Needs definitions from netinet/in.h
Paul Stewart75897df2011-04-27 09:05:53 -07009#include <stdio.h>
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -070010#include <time.h>
Chris Masoneee929b72011-05-10 10:02:18 -070011
Paul Stewart75897df2011-04-27 09:05:53 -070012#include <string>
Chris Masone8fe2c7e2011-06-09 15:51:19 -070013#include <vector>
Paul Stewart75897df2011-04-27 09:05:53 -070014
Eric Shienbrood3e20a232012-02-16 11:35:56 -050015#include <base/bind.h>
Paul Stewart2bf1d352011-12-06 15:02:55 -080016#include <base/file_util.h>
Chris Masoneee929b72011-05-10 10:02:18 -070017#include <base/logging.h>
Chris Masone487b8bf2011-05-13 16:27:57 -070018#include <base/memory/ref_counted.h>
Chris Masone5dec5f42011-07-22 14:07:55 -070019#include <base/stringprintf.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070020#include <chromeos/dbus/service_constants.h>
Chris Masoneee929b72011-05-10 10:02:18 -070021
Paul Stewarte6132022011-08-16 09:11:02 -070022#include "shill/connection.h"
Paul Stewart75897df2011-04-27 09:05:53 -070023#include "shill/control_interface.h"
Chris Masoned7732e42011-05-20 11:08:56 -070024#include "shill/device_dbus_adaptor.h"
Chris Masone2b105542011-06-22 10:58:09 -070025#include "shill/dhcp_config.h"
Darin Petkovafa6fc42011-06-21 16:21:08 -070026#include "shill/dhcp_provider.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070027#include "shill/error.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070028#include "shill/event_dispatcher.h"
Paul Stewartf65320c2011-10-13 14:34:52 -070029#include "shill/http_proxy.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070030#include "shill/manager.h"
Thieu Le85e050b2012-03-13 15:04:38 -070031#include "shill/metrics.h"
Chris Masone95207da2011-06-29 16:50:49 -070032#include "shill/property_accessor.h"
Chris Masone2b105542011-06-22 10:58:09 -070033#include "shill/refptr_types.h"
Paul Stewartc39f1132011-06-22 12:02:28 -070034#include "shill/rtnl_handler.h"
Ben Chanfad4a0b2012-04-18 15:49:59 -070035#include "shill/scope_logger.h"
Chris Masone2b105542011-06-22 10:58:09 -070036#include "shill/service.h"
Chris Masone5dec5f42011-07-22 14:07:55 -070037#include "shill/store_interface.h"
Gaurav Shah435de2c2011-11-17 19:01:07 -080038#include "shill/technology.h"
Paul Stewart75897df2011-04-27 09:05:53 -070039
Eric Shienbrood3e20a232012-02-16 11:35:56 -050040using base::Bind;
Chris Masone5dec5f42011-07-22 14:07:55 -070041using base::StringPrintf;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070042using std::string;
43using std::vector;
44
Paul Stewart75897df2011-04-27 09:05:53 -070045namespace shill {
Chris Masone5dec5f42011-07-22 14:07:55 -070046
47// static
Paul Stewart2bf1d352011-12-06 15:02:55 -080048const char Device::kIPFlagTemplate[] = "/proc/sys/net/%s/conf/%s/%s";
49// static
50const char Device::kIPFlagVersion4[] = "ipv4";
51// static
52const char Device::kIPFlagVersion6[] = "ipv6";
53// static
54const char Device::kIPFlagDisableIPv6[] = "disable_ipv6";
55// static
56const char Device::kIPFlagUseTempAddr[] = "use_tempaddr";
57// static
58const char Device::kIPFlagUseTempAddrUsedAndDefault[] = "2";
Paul Stewartc8f4bef2011-12-13 09:45:51 -080059// static
60const char Device::kIPFlagReversePathFilter[] = "rp_filter";
61// static
62const char Device::kIPFlagReversePathFilterEnabled[] = "1";
63// static
64const char Device::kIPFlagReversePathFilterLooseMode[] = "2";
Paul Stewart2bf1d352011-12-06 15:02:55 -080065// static
Chris Masone5dec5f42011-07-22 14:07:55 -070066const char Device::kStoragePowered[] = "Powered";
Chris Masone5dec5f42011-07-22 14:07:55 -070067// static
68const char Device::kStorageIPConfigs[] = "IPConfigs";
Paul Stewart6ff27f52012-07-11 06:51:41 -070069// static
70const char Device::kStorageReceiveByteCount[] = "ReceiveByteCount";
71// static
72const char Device::kStorageTransmitByteCount[] = "TransmitByteCount";
Chris Masone5dec5f42011-07-22 14:07:55 -070073
Paul Stewart75897df2011-04-27 09:05:53 -070074Device::Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070075 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080076 Metrics *metrics,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070077 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070078 const string &link_name,
Chris Masone626719f2011-08-18 16:58:48 -070079 const string &address,
Gaurav Shah435de2c2011-11-17 19:01:07 -080080 int interface_index,
81 Technology::Identifier technology)
Eric Shienbrood9a245532012-03-07 14:20:39 -050082 : enabled_(false),
83 enabled_persistent_(true),
84 enabled_pending_(enabled_),
Chris Masoneb925cc82011-06-22 15:39:57 -070085 reconnect_(true),
Chris Masone626719f2011-08-18 16:58:48 -070086 hardware_address_(address),
mukesh agrawalf60e4062011-05-27 13:13:41 -070087 interface_index_(interface_index),
88 running_(false),
Darin Petkovafa6fc42011-06-21 16:21:08 -070089 link_name_(link_name),
Chris Masone19e30402011-07-19 15:48:47 -070090 unique_id_(link_name),
Darin Petkovd9661952011-08-03 16:25:42 -070091 control_interface_(control_interface),
92 dispatcher_(dispatcher),
Thieu Le3426c8f2012-01-11 17:35:11 -080093 metrics_(metrics),
Chris Masone7df0c672011-07-15 10:24:54 -070094 manager_(manager),
Eric Shienbrood9a245532012-03-07 14:20:39 -050095 weak_ptr_factory_(this),
Darin Petkov77cb6812011-08-15 16:19:41 -070096 adaptor_(control_interface->CreateDeviceAdaptor(this)),
Eric Shienbrood9a245532012-03-07 14:20:39 -050097 portal_detector_callback_(Bind(&Device::PortalDetectorCallback,
98 weak_ptr_factory_.GetWeakPtr())),
Gaurav Shah435de2c2011-11-17 19:01:07 -080099 technology_(technology),
Thieu Le85e050b2012-03-13 15:04:38 -0700100 portal_attempts_to_online_(0),
Paul Stewart6ff27f52012-07-11 06:51:41 -0700101 receive_byte_offset_(0),
102 transmit_byte_offset_(0),
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700103 dhcp_provider_(DHCPProvider::GetInstance()),
104 rtnl_handler_(RTNLHandler::GetInstance()) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700105 store_.RegisterConstString(flimflam::kAddressProperty, &hardware_address_);
Chris Masone4d42df82011-07-02 17:09:39 -0700106
107 // flimflam::kBgscanMethodProperty: Registered in WiFi
108 // flimflam::kBgscanShortIntervalProperty: Registered in WiFi
109 // flimflam::kBgscanSignalThresholdProperty: Registered in WiFi
110
111 // flimflam::kCellularAllowRoamingProperty: Registered in Cellular
112 // flimflam::kCarrierProperty: Registered in Cellular
113 // flimflam::kEsnProperty: Registered in Cellular
Darin Petkov3335b372011-08-22 11:05:32 -0700114 // flimflam::kHomeProviderProperty: Registered in Cellular
Chris Masone4d42df82011-07-02 17:09:39 -0700115 // flimflam::kImeiProperty: Registered in Cellular
Ben Chana5e27082012-07-31 14:30:28 -0700116 // flimflam::kIccidProperty: Registered in Cellular
Chris Masone4d42df82011-07-02 17:09:39 -0700117 // flimflam::kImsiProperty: Registered in Cellular
118 // flimflam::kManufacturerProperty: Registered in Cellular
119 // flimflam::kMdnProperty: Registered in Cellular
120 // flimflam::kMeidProperty: Registered in Cellular
121 // flimflam::kMinProperty: Registered in Cellular
122 // flimflam::kModelIDProperty: Registered in Cellular
123 // flimflam::kFirmwareRevisionProperty: Registered in Cellular
124 // flimflam::kHardwareRevisionProperty: Registered in Cellular
125 // flimflam::kPRLVersionProperty: Registered in Cellular
126 // flimflam::kSIMLockStatusProperty: Registered in Cellular
127 // flimflam::kFoundNetworksProperty: Registered in Cellular
Darin Petkove9d12e02011-07-27 15:09:37 -0700128 // flimflam::kDBusConnectionProperty: Registered in Cellular
129 // flimflam::kDBusObjectProperty: Register in Cellular
Chris Masone4d42df82011-07-02 17:09:39 -0700130
Jason Glasgowe8334fd2012-03-30 16:02:37 -0400131 store_.RegisterConstString(flimflam::kInterfaceProperty, &link_name_);
Jason Glasgow08afdff2012-04-03 10:22:26 -0400132 HelpRegisterConstDerivedRpcIdentifiers(flimflam::kIPConfigsProperty,
133 &Device::AvailableIPConfigs);
Chris Masone27c4aa52011-07-02 13:10:14 -0700134 store_.RegisterConstString(flimflam::kNameProperty, &link_name_);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500135 store_.RegisterConstBool(flimflam::kPoweredProperty, &enabled_);
Jason Glasgowb5790052012-01-27 01:03:52 -0500136 HelpRegisterDerivedString(flimflam::kTypeProperty,
137 &Device::GetTechnologyString,
138 NULL);
139
Chris Masoneb925cc82011-06-22 15:39:57 -0700140 // TODO(cmasone): Chrome doesn't use this...does anyone?
Chris Masone27c4aa52011-07-02 13:10:14 -0700141 // store_.RegisterConstBool(flimflam::kReconnectProperty, &reconnect_);
Chris Masoneb925cc82011-06-22 15:39:57 -0700142
Chris Masone4e851612011-07-01 10:46:53 -0700143 // TODO(cmasone): Figure out what shill concept maps to flimflam's "Network".
Chris Masoneb925cc82011-06-22 15:39:57 -0700144 // known_properties_.push_back(flimflam::kNetworksProperty);
145
Chris Masone4d42df82011-07-02 17:09:39 -0700146 // flimflam::kScanningProperty: Registered in WiFi, Cellular
147 // flimflam::kScanIntervalProperty: Registered in WiFi, Cellular
Paul Stewart6ff27f52012-07-11 06:51:41 -0700148
149 if (manager_ && manager_->device_info()) { // Unit tests may not have these.
150 manager_->device_info()->GetByteCounts(
151 interface_index_, &receive_byte_offset_, &transmit_byte_offset_);
152 HelpRegisterConstDerivedUint64(shill::kReceiveByteCountProperty,
153 &Device::GetReceiveByteCount);
154 HelpRegisterConstDerivedUint64(shill::kTransmitByteCountProperty,
155 &Device::GetTransmitByteCount);
156 }
157
Darin Petkova0a0efe2012-06-27 12:50:01 +0200158 LOG(INFO) << "Device created: " << link_name_
159 << " index " << interface_index_;
Paul Stewart75897df2011-04-27 09:05:53 -0700160}
161
162Device::~Device() {
Darin Petkova0a0efe2012-06-27 12:50:01 +0200163 LOG(INFO) << "Device destructed: " << link_name_
164 << " index " << interface_index_;
Paul Stewart75897df2011-04-27 09:05:53 -0700165}
166
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700167void Device::LinkEvent(unsigned flags, unsigned change) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700168 SLOG(Device, 2) << "Device " << link_name_
169 << std::showbase << std::hex
170 << " flags " << flags << " changed " << change
171 << std::dec << std::noshowbase;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700172}
173
Darin Petkovc0865312011-09-16 15:31:20 -0700174void Device::Scan(Error *error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700175 SLOG(Device, 2) << "Device " << link_name_ << " scan requested.";
Paul Stewartbe005172011-11-02 18:10:29 -0700176 Error::PopulateAndLog(error, Error::kNotSupported,
177 "Device doesn't support scan.");
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700178}
179
Eric Shienbrood9a245532012-03-07 14:20:39 -0500180void Device::RegisterOnNetwork(const std::string &/*network_id*/, Error *error,
181 const ResultCallback &/*callback*/) {
182 Error::PopulateAndLog(error, Error::kNotSupported,
Paul Stewartbe005172011-11-02 18:10:29 -0700183 "Device doesn't support network registration.");
Darin Petkov9ae310f2011-08-30 15:41:13 -0700184}
185
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100186void Device::RequirePIN(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500187 const string &/*pin*/, bool /*require*/,
188 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700189 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500190 Error::PopulateAndLog(error, Error::kNotSupported,
191 "Device doesn't support RequirePIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700192}
193
Eric Shienbrood9a245532012-03-07 14:20:39 -0500194void Device::EnterPIN(const string &/*pin*/,
195 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700196 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500197 Error::PopulateAndLog(error, Error::kNotSupported,
198 "Device doesn't support EnterPIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700199}
200
mukesh agrawal1830fa12011-09-26 14:31:40 -0700201void Device::UnblockPIN(const string &/*unblock_code*/,
202 const string &/*pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500203 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700204 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500205 Error::PopulateAndLog(error, Error::kNotSupported,
206 "Device doesn't support UnblockPIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700207}
208
mukesh agrawal1830fa12011-09-26 14:31:40 -0700209void Device::ChangePIN(const string &/*old_pin*/,
210 const string &/*new_pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500211 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700212 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500213 Error::PopulateAndLog(error, Error::kNotSupported,
214 "Device doesn't support ChangePIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700215}
216
Paul Stewart2bf1d352011-12-06 15:02:55 -0800217void Device::DisableIPv6() {
218 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagDisableIPv6, "1");
219}
220
221void Device::EnableIPv6() {
222 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagDisableIPv6, "0");
223}
224
225void Device::EnableIPv6Privacy() {
226 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagUseTempAddr,
227 kIPFlagUseTempAddrUsedAndDefault);
228}
229
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800230void Device::DisableReversePathFilter() {
231 // TODO(pstew): Current kernel doesn't offer reverse-path filtering flag
232 // for IPv6. crosbug.com/24228
233 SetIPFlag(IPAddress::kFamilyIPv4, kIPFlagReversePathFilter,
234 kIPFlagReversePathFilterLooseMode);
235}
236
237void Device::EnableReversePathFilter() {
238 SetIPFlag(IPAddress::kFamilyIPv4, kIPFlagReversePathFilter,
239 kIPFlagReversePathFilterEnabled);
240}
241
Gaurav Shah435de2c2011-11-17 19:01:07 -0800242bool Device::IsConnected() const {
243 if (selected_service_)
244 return selected_service_->IsConnected();
245 return false;
246}
247
Paul Stewartd215af62012-04-24 23:25:50 -0700248bool Device::IsConnectedToService(const ServiceRefPtr &service) const {
249 return service == selected_service_ && IsConnected();
250}
251
Chris Masone27c4aa52011-07-02 13:10:14 -0700252string Device::GetRpcIdentifier() {
253 return adaptor_->GetRpcIdentifier();
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700254}
255
Chris Masone5dec5f42011-07-22 14:07:55 -0700256string Device::GetStorageIdentifier() {
257 string id = GetRpcIdentifier();
258 ControlInterface::RpcIdToStorageId(&id);
Chris Masone626719f2011-08-18 16:58:48 -0700259 size_t needle = id.find('_');
Chris Masone34af2182011-08-22 11:59:36 -0700260 DLOG_IF(ERROR, needle == string::npos) << "No _ in storage id?!?!";
Chris Masone626719f2011-08-18 16:58:48 -0700261 id.replace(id.begin() + needle + 1, id.end(), hardware_address_);
Chris Masone5dec5f42011-07-22 14:07:55 -0700262 return id;
263}
264
Jason Glasgowb5790052012-01-27 01:03:52 -0500265string Device::GetTechnologyString(Error */*error*/) {
266 return Technology::NameFromIdentifier(technology());
267}
268
Chris Masone19e30402011-07-19 15:48:47 -0700269const string& Device::FriendlyName() const {
Chris Masone7df0c672011-07-15 10:24:54 -0700270 return link_name_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700271}
272
Chris Masone19e30402011-07-19 15:48:47 -0700273const string& Device::UniqueName() const {
274 return unique_id_;
275}
276
Chris Masone5dec5f42011-07-22 14:07:55 -0700277bool Device::Load(StoreInterface *storage) {
278 const string id = GetStorageIdentifier();
279 if (!storage->ContainsGroup(id)) {
280 LOG(WARNING) << "Device is not available in the persistent store: " << id;
281 return false;
282 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500283 enabled_persistent_ = true;
284 storage->GetBool(id, kStoragePowered, &enabled_persistent_);
Paul Stewart6ff27f52012-07-11 06:51:41 -0700285 uint64 rx_byte_count = 0, tx_byte_count = 0;
286
287 manager_->device_info()->GetByteCounts(
288 interface_index_, &rx_byte_count, &tx_byte_count);
289 // If there is a byte-count present in the profile, the return value
290 // of Device::Get*ByteCount() should be the this stored value plus
291 // whatever additional bytes we receive since time-of-load. We
292 // accomplish this by the subtractions below, which can validly
293 // roll over "negative" in the subtractions below and in Get*ByteCount.
294 uint64 profile_byte_count;
295 if (storage->GetUint64(id, kStorageReceiveByteCount, &profile_byte_count)) {
296 receive_byte_offset_ = rx_byte_count - profile_byte_count;
297 }
298 if (storage->GetUint64(id, kStorageTransmitByteCount, &profile_byte_count)) {
299 transmit_byte_offset_ = tx_byte_count - profile_byte_count;
300 }
301
Chris Masone5dec5f42011-07-22 14:07:55 -0700302 return true;
303}
304
305bool Device::Save(StoreInterface *storage) {
306 const string id = GetStorageIdentifier();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500307 storage->SetBool(id, kStoragePowered, enabled_persistent_);
Chris Masone34af2182011-08-22 11:59:36 -0700308 if (ipconfig_.get()) {
309 // The _0 is an index into the list of IPConfigs that this device might
310 // have. We only have one IPConfig right now, and I hope to never have
311 // to support more, as sleffler indicates that associating IPConfigs
312 // with devices is wrong and due to be changed in flimflam anyhow.
313 string suffix = hardware_address_ + "_0";
314 ipconfig_->Save(storage, suffix);
315 storage->SetString(id, kStorageIPConfigs, SerializeIPConfigs(suffix));
316 }
Paul Stewart6ff27f52012-07-11 06:51:41 -0700317 storage->SetUint64(id, kStorageReceiveByteCount, GetReceiveByteCount(NULL));
318 storage->SetUint64(id, kStorageTransmitByteCount, GetTransmitByteCount(NULL));
Chris Masone5dec5f42011-07-22 14:07:55 -0700319 return true;
320}
321
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200322void Device::DropConnection() {
323 SLOG(Device, 2) << __func__;
324 DestroyIPConfig();
325 SelectService(NULL);
326}
327
Darin Petkovafa6fc42011-06-21 16:21:08 -0700328void Device::DestroyIPConfig() {
Paul Stewart2bf1d352011-12-06 15:02:55 -0800329 DisableIPv6();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700330 if (ipconfig_.get()) {
331 ipconfig_->ReleaseIP();
332 ipconfig_ = NULL;
333 }
Paul Stewarte6132022011-08-16 09:11:02 -0700334 DestroyConnection();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700335}
336
Paul Stewart2bf1d352011-12-06 15:02:55 -0800337bool Device::AcquireIPConfig() {
Paul Stewartd408fdf2012-05-07 17:15:57 -0700338 return AcquireIPConfigWithLeaseName(string());
339}
340
341bool Device::AcquireIPConfigWithLeaseName(const string &lease_name) {
Darin Petkovafa6fc42011-06-21 16:21:08 -0700342 DestroyIPConfig();
Paul Stewart2bf1d352011-12-06 15:02:55 -0800343 EnableIPv6();
Paul Stewartd408fdf2012-05-07 17:15:57 -0700344 ipconfig_ = dhcp_provider_->CreateConfig(link_name_,
345 manager_->GetHostName(),
346 lease_name,
347 manager_->GetArpGateway());
Eric Shienbrood9a245532012-03-07 14:20:39 -0500348 ipconfig_->RegisterUpdateCallback(Bind(&Device::OnIPConfigUpdated,
349 weak_ptr_factory_.GetWeakPtr()));
Paul Stewart1062d9d2012-04-27 10:42:27 -0700350 dispatcher_->PostTask(Bind(&Device::ConfigureStaticIPTask,
351 weak_ptr_factory_.GetWeakPtr()));
Darin Petkovafa6fc42011-06-21 16:21:08 -0700352 return ipconfig_->RequestIP();
353}
354
Jason Glasgowb5790052012-01-27 01:03:52 -0500355void Device::HelpRegisterDerivedString(
356 const string &name,
357 string(Device::*get)(Error *error),
358 void(Device::*set)(const string &value, Error *error)) {
359 store_.RegisterDerivedString(
360 name,
361 StringAccessor(new CustomAccessor<Device, string>(this, get, set)));
362}
363
mukesh agrawalffa3d042011-10-06 15:26:10 -0700364void Device::HelpRegisterDerivedStrings(
365 const string &name,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500366 Strings(Device::*get)(Error *error),
367 void(Device::*set)(const Strings &value, Error *error)) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700368 store_.RegisterDerivedStrings(
369 name,
370 StringsAccessor(new CustomAccessor<Device, Strings>(this, get, set)));
Chris Masone4e851612011-07-01 10:46:53 -0700371}
372
Jason Glasgow08afdff2012-04-03 10:22:26 -0400373void Device::HelpRegisterConstDerivedRpcIdentifiers(
374 const string &name,
375 RpcIdentifiers(Device::*get)(Error *)) {
376 store_.RegisterDerivedRpcIdentifiers(
377 name,
378 RpcIdentifiersAccessor(
379 new CustomAccessor<Device, RpcIdentifiers>(this, get, NULL)));
380}
381
Paul Stewart6ff27f52012-07-11 06:51:41 -0700382void Device::HelpRegisterConstDerivedUint64(
383 const string &name,
384 uint64(Device::*get)(Error *)) {
385 store_.RegisterDerivedUint64(
386 name,
387 Uint64Accessor(
388 new CustomAccessor<Device, uint64>(this, get, NULL)));
389}
390
Paul Stewart1062d9d2012-04-27 10:42:27 -0700391void Device::ConfigureStaticIPTask() {
392 SLOG(Device, 2) << __func__ << " selected_service " << selected_service_.get()
393 << " ipconfig " << ipconfig_.get();
394
395 if (!selected_service_ || !ipconfig_) {
396 return;
397 }
398
399 const StaticIPParameters &static_ip_parameters =
400 selected_service_->static_ip_parameters();
401 if (static_ip_parameters.ContainsAddress()) {
402 SLOG(Device, 2) << __func__ << " " << " configuring static IP parameters.";
403 // If the parameters contain an IP address, apply them now and bring
404 // the interface up. When DHCP information arrives, it will supplement
405 // the static information.
406 OnIPConfigUpdated(ipconfig_, true);
407 } else {
408 SLOG(Device, 2) << __func__ << " " << " no static IP address.";
409 }
410}
411
Darin Petkov79d74c92012-03-07 17:20:32 +0100412void Device::OnIPConfigUpdated(const IPConfigRefPtr &ipconfig, bool success) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700413 SLOG(Device, 2) << __func__ << " " << " success: " << success;
Paul Stewartc39f1132011-06-22 12:02:28 -0700414 if (success) {
Paul Stewarte6132022011-08-16 09:11:02 -0700415 CreateConnection();
Paul Stewart1062d9d2012-04-27 10:42:27 -0700416 if (selected_service_) {
417 ipconfig->ApplyStaticIPParameters(
418 selected_service_->static_ip_parameters());
419 }
Paul Stewarte6132022011-08-16 09:11:02 -0700420 connection_->UpdateFromIPConfig(ipconfig);
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800421 // SetConnection must occur after the UpdateFromIPConfig so the
422 // service can use the values derived from the connection.
Paul Stewart1062d9d2012-04-27 10:42:27 -0700423 if (selected_service_) {
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800424 selected_service_->SetConnection(connection_);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800425 }
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800426 // The service state change needs to happen last, so that at the
427 // time we report the state change to the manager, the service
428 // has its connection.
429 SetServiceState(Service::kStateConnected);
Thieu Le85e050b2012-03-13 15:04:38 -0700430 portal_attempts_to_online_ = 0;
Paul Stewart20088d82012-02-16 06:58:55 -0800431 // Subtle: Start portal detection after transitioning the service
432 // to the Connected state because this call may immediately transition
433 // to the Online state.
434 StartPortalDetection();
Paul Stewarte6132022011-08-16 09:11:02 -0700435 } else {
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700436 // TODO(pstew): This logic gets yet more complex when multiple
437 // IPConfig types are run in parallel (e.g. DHCP and DHCP6)
438 if (selected_service_ &&
439 selected_service_->static_ip_parameters().ContainsAddress()) {
440 // Consider three cases:
441 //
442 // 1. We're here because DHCP failed while starting up. There
443 // are two subcases:
444 // a. DHCP has failed, and Static IP config has _not yet_
445 // completed. It's fine to do nothing, because we'll
446 // apply the static config shortly.
447 // b. DHCP has failed, and Static IP config has _already_
448 // completed. It's fine to do nothing, because we can
449 // continue to use the static config that's already
450 // been applied.
451 //
452 // 2. We're here because a previously valid DHCP configuration
453 // is no longer valid. There's still a static IP config,
454 // because the condition in the if clause evaluated to true.
455 // Furthermore, the static config includes an IP address for
456 // us to use.
457 //
458 // The current configuration may include some DHCP
459 // parameters, overriden by any static parameters
460 // provided. We continue to use this configuration, because
461 // the only configuration element that is leased to us (IP
462 // address) will be overriden by a static parameter.
463 return;
464 }
465
Paul Stewart03dba0b2011-08-22 16:32:45 -0700466 SetServiceState(Service::kStateDisconnected);
Paul Stewarte6132022011-08-16 09:11:02 -0700467 DestroyConnection();
Paul Stewartc39f1132011-06-22 12:02:28 -0700468 }
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700469}
470
Paul Stewarte6132022011-08-16 09:11:02 -0700471void Device::CreateConnection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700472 SLOG(Device, 2) << __func__;
Paul Stewarte6132022011-08-16 09:11:02 -0700473 if (!connection_.get()) {
Paul Stewartbf667612012-06-29 14:49:54 -0700474 connection_ = new Connection(
475 interface_index_,
476 link_name_,
477 technology_,
478 manager_->device_info(),
479 manager_->IsTechnologyShortDNSTimeoutEnabled(technology_));
Paul Stewarte6132022011-08-16 09:11:02 -0700480 }
481}
482
483void Device::DestroyConnection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700484 SLOG(Device, 2) << __func__;
Paul Stewart20088d82012-02-16 06:58:55 -0800485 StopPortalDetection();
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800486 if (selected_service_.get()) {
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800487 selected_service_->SetConnection(NULL);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800488 }
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800489 connection_ = NULL;
Paul Stewarte6132022011-08-16 09:11:02 -0700490}
491
Paul Stewart03dba0b2011-08-22 16:32:45 -0700492void Device::SelectService(const ServiceRefPtr &service) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700493 SLOG(Device, 2) << __func__ << ": "
494 << (service.get() ?
495 StringPrintf("%s (%s)",
496 service->UniqueName().c_str(),
497 service->friendly_name().c_str()) :
498 "*reset*");
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000499
500 if (selected_service_.get() == service.get()) {
501 // No change to |selected_service_|. Return early to avoid
502 // changing its state.
503 return;
504 }
505
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800506 if (selected_service_.get()) {
507 if (selected_service_->state() != Service::kStateFailure) {
508 selected_service_->SetState(Service::kStateIdle);
509 }
Paul Stewart20b0a092012-05-22 20:39:57 -0700510 // Just in case the Device subclass has not already done so, make
511 // sure the previously selected service has its connection removed.
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800512 selected_service_->SetConnection(NULL);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700513 }
514 selected_service_ = service;
515}
516
517void Device::SetServiceState(Service::ConnectState state) {
518 if (selected_service_.get()) {
519 selected_service_->SetState(state);
520 }
521}
522
523void Device::SetServiceFailure(Service::ConnectFailure failure_state) {
524 if (selected_service_.get()) {
525 selected_service_->SetFailure(failure_state);
526 }
527}
528
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400529void Device::SetServiceFailureSilent(Service::ConnectFailure failure_state) {
530 if (selected_service_.get()) {
531 selected_service_->SetFailureSilent(failure_state);
532 }
533}
534
Chris Masone34af2182011-08-22 11:59:36 -0700535string Device::SerializeIPConfigs(const string &suffix) {
536 return StringPrintf("%s:%s", suffix.c_str(), ipconfig_->type().c_str());
Chris Masone5dec5f42011-07-22 14:07:55 -0700537}
538
Paul Stewart2bf1d352011-12-06 15:02:55 -0800539bool Device::SetIPFlag(IPAddress::Family family, const string &flag,
540 const string &value) {
541 string ip_version;
542 if (family == IPAddress::kFamilyIPv4) {
543 ip_version = kIPFlagVersion4;
544 } else if (family == IPAddress::kFamilyIPv6) {
545 ip_version = kIPFlagVersion6;
546 } else {
547 NOTIMPLEMENTED();
548 }
549 FilePath flag_file(StringPrintf(kIPFlagTemplate, ip_version.c_str(),
550 link_name_.c_str(), flag.c_str()));
Ben Chanfad4a0b2012-04-18 15:49:59 -0700551 SLOG(Device, 2) << "Writing " << value << " to flag file "
552 << flag_file.value();
Paul Stewart2bf1d352011-12-06 15:02:55 -0800553 if (file_util::WriteFile(flag_file, value.c_str(), value.length()) != 1) {
554 LOG(ERROR) << StringPrintf("IP flag write failed: %s to %s",
555 value.c_str(), flag_file.value().c_str());
556 return false;
557 }
558 return true;
559}
560
Paul Stewart6ff27f52012-07-11 06:51:41 -0700561void Device::ResetByteCounters() {
562 manager_->device_info()->GetByteCounts(
563 interface_index_, &receive_byte_offset_, &transmit_byte_offset_);
564 manager_->UpdateDevice(this);
565}
566
Paul Stewartd215af62012-04-24 23:25:50 -0700567bool Device::RestartPortalDetection() {
568 StopPortalDetection();
569 return StartPortalDetection();
570}
571
Paul Stewartc681fa02012-03-02 19:40:04 -0800572bool Device::RequestPortalDetection() {
573 if (!selected_service_) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700574 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800575 << ": No selected service, so no need for portal check.";
576 return false;
577 }
578
579 if (!connection_.get()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700580 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800581 << ": No connection, so no need for portal check.";
582 return false;
583 }
584
585 if (selected_service_->state() != Service::kStatePortal) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700586 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800587 << ": Service is not in portal state. No need to start check.";
588 return false;
589 }
590
591 if (!connection_->is_default()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700592 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800593 << ": Service is not the default connection. Don't start check.";
594 return false;
595 }
596
597 if (portal_detector_.get() && portal_detector_->IsInProgress()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700598 SLOG(Device, 2) << FriendlyName()
599 << ": Portal detection is already running.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800600 return true;
601 }
602
603 return StartPortalDetection();
604}
605
Paul Stewart20088d82012-02-16 06:58:55 -0800606bool Device::StartPortalDetection() {
Paul Stewartd215af62012-04-24 23:25:50 -0700607 DCHECK(selected_service_.get());
608 if (selected_service_->IsPortalDetectionDisabled()) {
609 SLOG(Device, 2) << "Service " << selected_service_->friendly_name()
610 << ": Portal detection is disabled; "
611 << "marking service online.";
612 SetServiceConnectedState(Service::kStateOnline);
613 return false;
614 }
615
616 if (selected_service_->IsPortalDetectionAuto() &&
617 !manager_->IsPortalDetectionEnabled(technology())) {
Paul Stewart20088d82012-02-16 06:58:55 -0800618 // If portal detection is disabled for this technology, immediately set
619 // the service state to "Online".
Ben Chanfad4a0b2012-04-18 15:49:59 -0700620 SLOG(Device, 2) << "Device " << FriendlyName()
621 << ": Portal detection is disabled; "
622 << "marking service online.";
Paul Stewart20088d82012-02-16 06:58:55 -0800623 SetServiceConnectedState(Service::kStateOnline);
624 return false;
625 }
626
Paul Stewart20088d82012-02-16 06:58:55 -0800627 if (selected_service_->HasProxyConfig()) {
628 // Services with HTTP proxy configurations should not be checked by the
629 // connection manager, since we don't have the ability to evaluate
630 // arbitrary proxy configs and their possible credentials.
Ben Chanfad4a0b2012-04-18 15:49:59 -0700631 SLOG(Device, 2) << "Device " << FriendlyName()
632 << ": Service has proxy config; marking it online.";
Paul Stewart20088d82012-02-16 06:58:55 -0800633 SetServiceConnectedState(Service::kStateOnline);
634 return false;
635 }
636
637 portal_detector_.reset(new PortalDetector(connection_,
638 dispatcher_,
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500639 portal_detector_callback_));
Paul Stewart20088d82012-02-16 06:58:55 -0800640 if (!portal_detector_->Start(manager_->GetPortalCheckURL())) {
641 LOG(ERROR) << "Device " << FriendlyName()
642 << ": Portal detection failed to start: likely bad URL: "
643 << manager_->GetPortalCheckURL();
644 SetServiceConnectedState(Service::kStateOnline);
645 return false;
646 }
647
Ben Chanfad4a0b2012-04-18 15:49:59 -0700648 SLOG(Device, 2) << "Device " << FriendlyName()
649 << ": Portal detection has started.";
Paul Stewart20088d82012-02-16 06:58:55 -0800650 return true;
651}
652
653void Device::StopPortalDetection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700654 SLOG(Device, 2) << "Device " << FriendlyName()
655 << ": Portal detection has stopped.";
Paul Stewart20088d82012-02-16 06:58:55 -0800656 portal_detector_.reset();
657}
658
659void Device::SetServiceConnectedState(Service::ConnectState state) {
660 DCHECK(selected_service_.get());
661
662 if (!selected_service_.get()) {
663 LOG(ERROR) << FriendlyName() << ": "
664 << "Portal detection completed but no selected service exists!";
665 return;
666 }
667
668 if (!selected_service_->IsConnected()) {
669 LOG(ERROR) << FriendlyName() << ": "
670 << "Portal detection completed but selected service "
671 << selected_service_->UniqueName()
672 << " is in non-connected state.";
673 return;
674 }
675
Paul Stewartc681fa02012-03-02 19:40:04 -0800676 if (state == Service::kStatePortal && connection_->is_default() &&
677 manager_->GetPortalCheckInterval() != 0) {
678 CHECK(portal_detector_.get());
679 if (!portal_detector_->StartAfterDelay(
680 manager_->GetPortalCheckURL(),
681 manager_->GetPortalCheckInterval())) {
682 LOG(ERROR) << "Device " << FriendlyName()
683 << ": Portal detection failed to restart: likely bad URL: "
684 << manager_->GetPortalCheckURL();
685 SetServiceState(Service::kStateOnline);
686 portal_detector_.reset();
687 return;
688 }
Ben Chanfad4a0b2012-04-18 15:49:59 -0700689 SLOG(Device, 2) << "Device " << FriendlyName()
690 << ": Portal detection retrying.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800691 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700692 SLOG(Device, 2) << "Device " << FriendlyName()
693 << ": Portal will not retry.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800694 portal_detector_.reset();
695 }
696
Paul Stewart20088d82012-02-16 06:58:55 -0800697 SetServiceState(state);
698}
699
700void Device::PortalDetectorCallback(const PortalDetector::Result &result) {
701 if (!result.final) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700702 SLOG(Device, 2) << "Device " << FriendlyName()
703 << ": Received non-final status: "
704 << PortalDetector::StatusToString(result.status);
Paul Stewart20088d82012-02-16 06:58:55 -0800705 return;
706 }
707
Ben Chanfad4a0b2012-04-18 15:49:59 -0700708 SLOG(Device, 2) << "Device " << FriendlyName()
709 << ": Received final status: "
710 << PortalDetector::StatusToString(result.status);
Paul Stewart20088d82012-02-16 06:58:55 -0800711
Thieu Le85e050b2012-03-13 15:04:38 -0700712 portal_attempts_to_online_ += result.num_attempts;
713
714 metrics()->SendEnumToUMA(
715 metrics()->GetFullMetricName(Metrics::kMetricPortalResult, technology()),
716 Metrics::PortalDetectionResultToEnum(result),
717 Metrics::kPortalResultMax);
718
Paul Stewart20088d82012-02-16 06:58:55 -0800719 if (result.status == PortalDetector::kStatusSuccess) {
720 SetServiceConnectedState(Service::kStateOnline);
Thieu Le85e050b2012-03-13 15:04:38 -0700721
722 metrics()->SendToUMA(
723 metrics()->GetFullMetricName(
724 Metrics::kMetricPortalAttemptsToOnline, technology()),
725 portal_attempts_to_online_,
726 Metrics::kMetricPortalAttemptsToOnlineMin,
727 Metrics::kMetricPortalAttemptsToOnlineMax,
728 Metrics::kMetricPortalAttemptsToOnlineNumBuckets);
Paul Stewart20088d82012-02-16 06:58:55 -0800729 } else {
730 SetServiceConnectedState(Service::kStatePortal);
Thieu Le85e050b2012-03-13 15:04:38 -0700731
732 metrics()->SendToUMA(
733 metrics()->GetFullMetricName(
734 Metrics::kMetricPortalAttempts, technology()),
735 result.num_attempts,
736 Metrics::kMetricPortalAttemptsMin,
737 Metrics::kMetricPortalAttemptsMax,
738 Metrics::kMetricPortalAttemptsNumBuckets);
Paul Stewart20088d82012-02-16 06:58:55 -0800739 }
740}
741
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800742vector<string> Device::AvailableIPConfigs(Error */*error*/) {
Jason Glasgow08afdff2012-04-03 10:22:26 -0400743 if (ipconfig_.get()) {
744 string id = ipconfig_->GetRpcIdentifier();
745 return vector<string>(1, id);
746 }
747 return vector<string>();
Chris Masone4e851612011-07-01 10:46:53 -0700748}
749
750string Device::GetRpcConnectionIdentifier() {
751 return adaptor_->GetRpcConnectionIdentifier();
752}
753
Paul Stewart6ff27f52012-07-11 06:51:41 -0700754uint64 Device::GetReceiveByteCount(Error */*error*/) {
755 uint64 rx_byte_count = 0, tx_byte_count = 0;
756 manager_->device_info()->GetByteCounts(
757 interface_index_, &rx_byte_count, &tx_byte_count);
758 return rx_byte_count - receive_byte_offset_;
759}
760
761uint64 Device::GetTransmitByteCount(Error */*error*/) {
762 uint64 rx_byte_count = 0, tx_byte_count = 0;
763 manager_->device_info()->GetByteCounts(
764 interface_index_, &rx_byte_count, &tx_byte_count);
765 return tx_byte_count - transmit_byte_offset_;
766}
767
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400768bool Device::IsUnderlyingDeviceEnabled() const {
769 return false;
770}
771
Eric Shienbrood9a245532012-03-07 14:20:39 -0500772// callback
773void Device::OnEnabledStateChanged(const ResultCallback &callback,
774 const Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700775 SLOG(Device, 2) << __func__ << "(" << enabled_pending_ << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500776 if (error.IsSuccess()) {
777 enabled_ = enabled_pending_;
778 manager_->UpdateEnabledTechnologies();
779 adaptor_->EmitBoolChanged(flimflam::kPoweredProperty, enabled_);
780 adaptor_->UpdateEnabled();
781 }
Gary Morainbaeefdf2012-04-30 14:53:35 -0700782 enabled_pending_ = enabled_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500783 if (!callback.is_null())
784 callback.Run(error);
785}
786
787void Device::SetEnabled(bool enable) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700788 SLOG(Device, 2) << __func__ << "(" << enable << ")";
Jason Glasgow4a490792012-04-10 15:02:05 -0400789 Error error;
790 SetEnabledInternal(enable, false, &error, ResultCallback());
Jason Glasgow7234ec32012-05-23 16:01:21 -0400791 LOG_IF(ERROR, error.IsFailure() && !error.IsOngoing())
Jason Glasgow4a490792012-04-10 15:02:05 -0400792 << "Enabled failed, but no way to report the failure.";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500793}
794
795void Device::SetEnabledPersistent(bool enable,
796 Error *error,
797 const ResultCallback &callback) {
798 SetEnabledInternal(enable, true, error, callback);
799}
800
801void Device::SetEnabledInternal(bool enable,
802 bool persist,
803 Error *error,
804 const ResultCallback &callback) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400805 DCHECK(error);
Ben Chanfad4a0b2012-04-18 15:49:59 -0700806 SLOG(Device, 2) << "Device " << link_name_ << " "
807 << (enable ? "starting" : "stopping");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500808 if (enable == enabled_) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400809 error->Reset();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500810 return;
811 }
812
813 if (enabled_pending_ == enable) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400814 Error::PopulateAndLog(error, Error::kInProgress,
815 "Enable operation already in progress");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500816 return;
817 }
818
819 if (persist) {
820 enabled_persistent_ = enable;
Darin Petkove7c6ad32012-06-29 10:22:09 +0200821 manager_->UpdateDevice(this);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500822 }
823
824 enabled_pending_ = enable;
825 EnabledStateChangedCallback enabled_callback =
826 Bind(&Device::OnEnabledStateChanged,
827 weak_ptr_factory_.GetWeakPtr(), callback);
828 if (enable) {
829 running_ = true;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500830 Start(error, enabled_callback);
831 } else {
832 running_ = false;
833 DestroyIPConfig(); // breaks a reference cycle
834 SelectService(NULL); // breaks a reference cycle
835 rtnl_handler_->SetInterfaceFlags(interface_index(), 0, IFF_UP);
Ben Chanfad4a0b2012-04-18 15:49:59 -0700836 SLOG(Device, 3) << "Device " << link_name_ << " ipconfig_ "
837 << (ipconfig_ ? "is set." : "is not set.");
838 SLOG(Device, 3) << "Device " << link_name_ << " connection_ "
839 << (connection_ ? "is set." : "is not set.");
840 SLOG(Device, 3) << "Device " << link_name_ << " selected_service_ "
841 << (selected_service_ ? "is set." : "is not set.");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500842 Stop(error, enabled_callback);
843 }
844}
845
Paul Stewart75897df2011-04-27 09:05:53 -0700846} // namespace shill