blob: a654811a7d64b5ca0f8c5678d3d0effa625d3356 [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 Stewart9a908082011-08-31 12:18:48 -0700474 connection_ = new Connection(interface_index_,
475 link_name_,
Paul Stewarte00600e2012-03-16 07:08:00 -0700476 technology_,
Paul Stewart9a908082011-08-31 12:18:48 -0700477 manager_->device_info());
Paul Stewarte6132022011-08-16 09:11:02 -0700478 }
479}
480
481void Device::DestroyConnection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700482 SLOG(Device, 2) << __func__;
Paul Stewart20088d82012-02-16 06:58:55 -0800483 StopPortalDetection();
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800484 if (selected_service_.get()) {
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800485 selected_service_->SetConnection(NULL);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800486 }
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800487 connection_ = NULL;
Paul Stewarte6132022011-08-16 09:11:02 -0700488}
489
Paul Stewart03dba0b2011-08-22 16:32:45 -0700490void Device::SelectService(const ServiceRefPtr &service) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700491 SLOG(Device, 2) << __func__ << ": "
492 << (service.get() ?
493 StringPrintf("%s (%s)",
494 service->UniqueName().c_str(),
495 service->friendly_name().c_str()) :
496 "*reset*");
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000497
498 if (selected_service_.get() == service.get()) {
499 // No change to |selected_service_|. Return early to avoid
500 // changing its state.
501 return;
502 }
503
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800504 if (selected_service_.get()) {
505 if (selected_service_->state() != Service::kStateFailure) {
506 selected_service_->SetState(Service::kStateIdle);
507 }
Paul Stewart20b0a092012-05-22 20:39:57 -0700508 // Just in case the Device subclass has not already done so, make
509 // sure the previously selected service has its connection removed.
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800510 selected_service_->SetConnection(NULL);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700511 }
512 selected_service_ = service;
513}
514
515void Device::SetServiceState(Service::ConnectState state) {
516 if (selected_service_.get()) {
517 selected_service_->SetState(state);
518 }
519}
520
521void Device::SetServiceFailure(Service::ConnectFailure failure_state) {
522 if (selected_service_.get()) {
523 selected_service_->SetFailure(failure_state);
524 }
525}
526
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400527void Device::SetServiceFailureSilent(Service::ConnectFailure failure_state) {
528 if (selected_service_.get()) {
529 selected_service_->SetFailureSilent(failure_state);
530 }
531}
532
Chris Masone34af2182011-08-22 11:59:36 -0700533string Device::SerializeIPConfigs(const string &suffix) {
534 return StringPrintf("%s:%s", suffix.c_str(), ipconfig_->type().c_str());
Chris Masone5dec5f42011-07-22 14:07:55 -0700535}
536
Paul Stewart2bf1d352011-12-06 15:02:55 -0800537bool Device::SetIPFlag(IPAddress::Family family, const string &flag,
538 const string &value) {
539 string ip_version;
540 if (family == IPAddress::kFamilyIPv4) {
541 ip_version = kIPFlagVersion4;
542 } else if (family == IPAddress::kFamilyIPv6) {
543 ip_version = kIPFlagVersion6;
544 } else {
545 NOTIMPLEMENTED();
546 }
547 FilePath flag_file(StringPrintf(kIPFlagTemplate, ip_version.c_str(),
548 link_name_.c_str(), flag.c_str()));
Ben Chanfad4a0b2012-04-18 15:49:59 -0700549 SLOG(Device, 2) << "Writing " << value << " to flag file "
550 << flag_file.value();
Paul Stewart2bf1d352011-12-06 15:02:55 -0800551 if (file_util::WriteFile(flag_file, value.c_str(), value.length()) != 1) {
552 LOG(ERROR) << StringPrintf("IP flag write failed: %s to %s",
553 value.c_str(), flag_file.value().c_str());
554 return false;
555 }
556 return true;
557}
558
Paul Stewart6ff27f52012-07-11 06:51:41 -0700559void Device::ResetByteCounters() {
560 manager_->device_info()->GetByteCounts(
561 interface_index_, &receive_byte_offset_, &transmit_byte_offset_);
562 manager_->UpdateDevice(this);
563}
564
Paul Stewartd215af62012-04-24 23:25:50 -0700565bool Device::RestartPortalDetection() {
566 StopPortalDetection();
567 return StartPortalDetection();
568}
569
Paul Stewartc681fa02012-03-02 19:40:04 -0800570bool Device::RequestPortalDetection() {
571 if (!selected_service_) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700572 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800573 << ": No selected service, so no need for portal check.";
574 return false;
575 }
576
577 if (!connection_.get()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700578 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800579 << ": No connection, so no need for portal check.";
580 return false;
581 }
582
583 if (selected_service_->state() != Service::kStatePortal) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700584 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800585 << ": Service is not in portal state. No need to start check.";
586 return false;
587 }
588
589 if (!connection_->is_default()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700590 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800591 << ": Service is not the default connection. Don't start check.";
592 return false;
593 }
594
595 if (portal_detector_.get() && portal_detector_->IsInProgress()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700596 SLOG(Device, 2) << FriendlyName()
597 << ": Portal detection is already running.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800598 return true;
599 }
600
601 return StartPortalDetection();
602}
603
Paul Stewart20088d82012-02-16 06:58:55 -0800604bool Device::StartPortalDetection() {
Paul Stewartd215af62012-04-24 23:25:50 -0700605 DCHECK(selected_service_.get());
606 if (selected_service_->IsPortalDetectionDisabled()) {
607 SLOG(Device, 2) << "Service " << selected_service_->friendly_name()
608 << ": Portal detection is disabled; "
609 << "marking service online.";
610 SetServiceConnectedState(Service::kStateOnline);
611 return false;
612 }
613
614 if (selected_service_->IsPortalDetectionAuto() &&
615 !manager_->IsPortalDetectionEnabled(technology())) {
Paul Stewart20088d82012-02-16 06:58:55 -0800616 // If portal detection is disabled for this technology, immediately set
617 // the service state to "Online".
Ben Chanfad4a0b2012-04-18 15:49:59 -0700618 SLOG(Device, 2) << "Device " << FriendlyName()
619 << ": Portal detection is disabled; "
620 << "marking service online.";
Paul Stewart20088d82012-02-16 06:58:55 -0800621 SetServiceConnectedState(Service::kStateOnline);
622 return false;
623 }
624
Paul Stewart20088d82012-02-16 06:58:55 -0800625 if (selected_service_->HasProxyConfig()) {
626 // Services with HTTP proxy configurations should not be checked by the
627 // connection manager, since we don't have the ability to evaluate
628 // arbitrary proxy configs and their possible credentials.
Ben Chanfad4a0b2012-04-18 15:49:59 -0700629 SLOG(Device, 2) << "Device " << FriendlyName()
630 << ": Service has proxy config; marking it online.";
Paul Stewart20088d82012-02-16 06:58:55 -0800631 SetServiceConnectedState(Service::kStateOnline);
632 return false;
633 }
634
635 portal_detector_.reset(new PortalDetector(connection_,
636 dispatcher_,
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500637 portal_detector_callback_));
Paul Stewart20088d82012-02-16 06:58:55 -0800638 if (!portal_detector_->Start(manager_->GetPortalCheckURL())) {
639 LOG(ERROR) << "Device " << FriendlyName()
640 << ": Portal detection failed to start: likely bad URL: "
641 << manager_->GetPortalCheckURL();
642 SetServiceConnectedState(Service::kStateOnline);
643 return false;
644 }
645
Ben Chanfad4a0b2012-04-18 15:49:59 -0700646 SLOG(Device, 2) << "Device " << FriendlyName()
647 << ": Portal detection has started.";
Paul Stewart20088d82012-02-16 06:58:55 -0800648 return true;
649}
650
651void Device::StopPortalDetection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700652 SLOG(Device, 2) << "Device " << FriendlyName()
653 << ": Portal detection has stopped.";
Paul Stewart20088d82012-02-16 06:58:55 -0800654 portal_detector_.reset();
655}
656
657void Device::SetServiceConnectedState(Service::ConnectState state) {
658 DCHECK(selected_service_.get());
659
660 if (!selected_service_.get()) {
661 LOG(ERROR) << FriendlyName() << ": "
662 << "Portal detection completed but no selected service exists!";
663 return;
664 }
665
666 if (!selected_service_->IsConnected()) {
667 LOG(ERROR) << FriendlyName() << ": "
668 << "Portal detection completed but selected service "
669 << selected_service_->UniqueName()
670 << " is in non-connected state.";
671 return;
672 }
673
Paul Stewartc681fa02012-03-02 19:40:04 -0800674 if (state == Service::kStatePortal && connection_->is_default() &&
675 manager_->GetPortalCheckInterval() != 0) {
676 CHECK(portal_detector_.get());
677 if (!portal_detector_->StartAfterDelay(
678 manager_->GetPortalCheckURL(),
679 manager_->GetPortalCheckInterval())) {
680 LOG(ERROR) << "Device " << FriendlyName()
681 << ": Portal detection failed to restart: likely bad URL: "
682 << manager_->GetPortalCheckURL();
683 SetServiceState(Service::kStateOnline);
684 portal_detector_.reset();
685 return;
686 }
Ben Chanfad4a0b2012-04-18 15:49:59 -0700687 SLOG(Device, 2) << "Device " << FriendlyName()
688 << ": Portal detection retrying.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800689 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700690 SLOG(Device, 2) << "Device " << FriendlyName()
691 << ": Portal will not retry.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800692 portal_detector_.reset();
693 }
694
Paul Stewart20088d82012-02-16 06:58:55 -0800695 SetServiceState(state);
696}
697
698void Device::PortalDetectorCallback(const PortalDetector::Result &result) {
699 if (!result.final) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700700 SLOG(Device, 2) << "Device " << FriendlyName()
701 << ": Received non-final status: "
702 << PortalDetector::StatusToString(result.status);
Paul Stewart20088d82012-02-16 06:58:55 -0800703 return;
704 }
705
Ben Chanfad4a0b2012-04-18 15:49:59 -0700706 SLOG(Device, 2) << "Device " << FriendlyName()
707 << ": Received final status: "
708 << PortalDetector::StatusToString(result.status);
Paul Stewart20088d82012-02-16 06:58:55 -0800709
Thieu Le85e050b2012-03-13 15:04:38 -0700710 portal_attempts_to_online_ += result.num_attempts;
711
712 metrics()->SendEnumToUMA(
713 metrics()->GetFullMetricName(Metrics::kMetricPortalResult, technology()),
714 Metrics::PortalDetectionResultToEnum(result),
715 Metrics::kPortalResultMax);
716
Paul Stewart20088d82012-02-16 06:58:55 -0800717 if (result.status == PortalDetector::kStatusSuccess) {
718 SetServiceConnectedState(Service::kStateOnline);
Thieu Le85e050b2012-03-13 15:04:38 -0700719
720 metrics()->SendToUMA(
721 metrics()->GetFullMetricName(
722 Metrics::kMetricPortalAttemptsToOnline, technology()),
723 portal_attempts_to_online_,
724 Metrics::kMetricPortalAttemptsToOnlineMin,
725 Metrics::kMetricPortalAttemptsToOnlineMax,
726 Metrics::kMetricPortalAttemptsToOnlineNumBuckets);
Paul Stewart20088d82012-02-16 06:58:55 -0800727 } else {
728 SetServiceConnectedState(Service::kStatePortal);
Thieu Le85e050b2012-03-13 15:04:38 -0700729
730 metrics()->SendToUMA(
731 metrics()->GetFullMetricName(
732 Metrics::kMetricPortalAttempts, technology()),
733 result.num_attempts,
734 Metrics::kMetricPortalAttemptsMin,
735 Metrics::kMetricPortalAttemptsMax,
736 Metrics::kMetricPortalAttemptsNumBuckets);
Paul Stewart20088d82012-02-16 06:58:55 -0800737 }
738}
739
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800740vector<string> Device::AvailableIPConfigs(Error */*error*/) {
Jason Glasgow08afdff2012-04-03 10:22:26 -0400741 if (ipconfig_.get()) {
742 string id = ipconfig_->GetRpcIdentifier();
743 return vector<string>(1, id);
744 }
745 return vector<string>();
Chris Masone4e851612011-07-01 10:46:53 -0700746}
747
748string Device::GetRpcConnectionIdentifier() {
749 return adaptor_->GetRpcConnectionIdentifier();
750}
751
Paul Stewart6ff27f52012-07-11 06:51:41 -0700752uint64 Device::GetReceiveByteCount(Error */*error*/) {
753 uint64 rx_byte_count = 0, tx_byte_count = 0;
754 manager_->device_info()->GetByteCounts(
755 interface_index_, &rx_byte_count, &tx_byte_count);
756 return rx_byte_count - receive_byte_offset_;
757}
758
759uint64 Device::GetTransmitByteCount(Error */*error*/) {
760 uint64 rx_byte_count = 0, tx_byte_count = 0;
761 manager_->device_info()->GetByteCounts(
762 interface_index_, &rx_byte_count, &tx_byte_count);
763 return tx_byte_count - transmit_byte_offset_;
764}
765
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400766bool Device::IsUnderlyingDeviceEnabled() const {
767 return false;
768}
769
Eric Shienbrood9a245532012-03-07 14:20:39 -0500770// callback
771void Device::OnEnabledStateChanged(const ResultCallback &callback,
772 const Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700773 SLOG(Device, 2) << __func__ << "(" << enabled_pending_ << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500774 if (error.IsSuccess()) {
775 enabled_ = enabled_pending_;
776 manager_->UpdateEnabledTechnologies();
777 adaptor_->EmitBoolChanged(flimflam::kPoweredProperty, enabled_);
778 adaptor_->UpdateEnabled();
779 }
Gary Morainbaeefdf2012-04-30 14:53:35 -0700780 enabled_pending_ = enabled_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500781 if (!callback.is_null())
782 callback.Run(error);
783}
784
785void Device::SetEnabled(bool enable) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700786 SLOG(Device, 2) << __func__ << "(" << enable << ")";
Jason Glasgow4a490792012-04-10 15:02:05 -0400787 Error error;
788 SetEnabledInternal(enable, false, &error, ResultCallback());
Jason Glasgow7234ec32012-05-23 16:01:21 -0400789 LOG_IF(ERROR, error.IsFailure() && !error.IsOngoing())
Jason Glasgow4a490792012-04-10 15:02:05 -0400790 << "Enabled failed, but no way to report the failure.";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500791}
792
793void Device::SetEnabledPersistent(bool enable,
794 Error *error,
795 const ResultCallback &callback) {
796 SetEnabledInternal(enable, true, error, callback);
797}
798
799void Device::SetEnabledInternal(bool enable,
800 bool persist,
801 Error *error,
802 const ResultCallback &callback) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400803 DCHECK(error);
Ben Chanfad4a0b2012-04-18 15:49:59 -0700804 SLOG(Device, 2) << "Device " << link_name_ << " "
805 << (enable ? "starting" : "stopping");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500806 if (enable == enabled_) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400807 error->Reset();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500808 return;
809 }
810
811 if (enabled_pending_ == enable) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400812 Error::PopulateAndLog(error, Error::kInProgress,
813 "Enable operation already in progress");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500814 return;
815 }
816
817 if (persist) {
818 enabled_persistent_ = enable;
Darin Petkove7c6ad32012-06-29 10:22:09 +0200819 manager_->UpdateDevice(this);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500820 }
821
822 enabled_pending_ = enable;
823 EnabledStateChangedCallback enabled_callback =
824 Bind(&Device::OnEnabledStateChanged,
825 weak_ptr_factory_.GetWeakPtr(), callback);
826 if (enable) {
827 running_ = true;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500828 Start(error, enabled_callback);
829 } else {
830 running_ = false;
831 DestroyIPConfig(); // breaks a reference cycle
832 SelectService(NULL); // breaks a reference cycle
833 rtnl_handler_->SetInterfaceFlags(interface_index(), 0, IFF_UP);
Ben Chanfad4a0b2012-04-18 15:49:59 -0700834 SLOG(Device, 3) << "Device " << link_name_ << " ipconfig_ "
835 << (ipconfig_ ? "is set." : "is not set.");
836 SLOG(Device, 3) << "Device " << link_name_ << " connection_ "
837 << (connection_ ? "is set." : "is not set.");
838 SLOG(Device, 3) << "Device " << link_name_ << " selected_service_ "
839 << (selected_service_ ? "is set." : "is not set.");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500840 Stop(error, enabled_callback);
841 }
842}
843
Paul Stewart75897df2011-04-27 09:05:53 -0700844} // namespace shill