blob: db0616f9e6c17d19435bbfd50327b0fc9342091d [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
116 // flimflam::kImsiProperty: Registered in Cellular
117 // flimflam::kManufacturerProperty: Registered in Cellular
118 // flimflam::kMdnProperty: Registered in Cellular
119 // flimflam::kMeidProperty: Registered in Cellular
120 // flimflam::kMinProperty: Registered in Cellular
121 // flimflam::kModelIDProperty: Registered in Cellular
122 // flimflam::kFirmwareRevisionProperty: Registered in Cellular
123 // flimflam::kHardwareRevisionProperty: Registered in Cellular
124 // flimflam::kPRLVersionProperty: Registered in Cellular
125 // flimflam::kSIMLockStatusProperty: Registered in Cellular
126 // flimflam::kFoundNetworksProperty: Registered in Cellular
Darin Petkove9d12e02011-07-27 15:09:37 -0700127 // flimflam::kDBusConnectionProperty: Registered in Cellular
128 // flimflam::kDBusObjectProperty: Register in Cellular
Chris Masone4d42df82011-07-02 17:09:39 -0700129
Jason Glasgowe8334fd2012-03-30 16:02:37 -0400130 store_.RegisterConstString(flimflam::kInterfaceProperty, &link_name_);
Jason Glasgow08afdff2012-04-03 10:22:26 -0400131 HelpRegisterConstDerivedRpcIdentifiers(flimflam::kIPConfigsProperty,
132 &Device::AvailableIPConfigs);
Chris Masone27c4aa52011-07-02 13:10:14 -0700133 store_.RegisterConstString(flimflam::kNameProperty, &link_name_);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500134 store_.RegisterConstBool(flimflam::kPoweredProperty, &enabled_);
Jason Glasgowb5790052012-01-27 01:03:52 -0500135 HelpRegisterDerivedString(flimflam::kTypeProperty,
136 &Device::GetTechnologyString,
137 NULL);
138
Chris Masoneb925cc82011-06-22 15:39:57 -0700139 // TODO(cmasone): Chrome doesn't use this...does anyone?
Chris Masone27c4aa52011-07-02 13:10:14 -0700140 // store_.RegisterConstBool(flimflam::kReconnectProperty, &reconnect_);
Chris Masoneb925cc82011-06-22 15:39:57 -0700141
Chris Masone4e851612011-07-01 10:46:53 -0700142 // TODO(cmasone): Figure out what shill concept maps to flimflam's "Network".
Chris Masoneb925cc82011-06-22 15:39:57 -0700143 // known_properties_.push_back(flimflam::kNetworksProperty);
144
Chris Masone4d42df82011-07-02 17:09:39 -0700145 // flimflam::kScanningProperty: Registered in WiFi, Cellular
146 // flimflam::kScanIntervalProperty: Registered in WiFi, Cellular
Paul Stewart6ff27f52012-07-11 06:51:41 -0700147
148 if (manager_ && manager_->device_info()) { // Unit tests may not have these.
149 manager_->device_info()->GetByteCounts(
150 interface_index_, &receive_byte_offset_, &transmit_byte_offset_);
151 HelpRegisterConstDerivedUint64(shill::kReceiveByteCountProperty,
152 &Device::GetReceiveByteCount);
153 HelpRegisterConstDerivedUint64(shill::kTransmitByteCountProperty,
154 &Device::GetTransmitByteCount);
155 }
156
Darin Petkova0a0efe2012-06-27 12:50:01 +0200157 LOG(INFO) << "Device created: " << link_name_
158 << " index " << interface_index_;
Paul Stewart75897df2011-04-27 09:05:53 -0700159}
160
161Device::~Device() {
Darin Petkova0a0efe2012-06-27 12:50:01 +0200162 LOG(INFO) << "Device destructed: " << link_name_
163 << " index " << interface_index_;
Paul Stewart75897df2011-04-27 09:05:53 -0700164}
165
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700166void Device::LinkEvent(unsigned flags, unsigned change) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700167 SLOG(Device, 2) << "Device " << link_name_
168 << std::showbase << std::hex
169 << " flags " << flags << " changed " << change
170 << std::dec << std::noshowbase;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700171}
172
Darin Petkovc0865312011-09-16 15:31:20 -0700173void Device::Scan(Error *error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700174 SLOG(Device, 2) << "Device " << link_name_ << " scan requested.";
Paul Stewartbe005172011-11-02 18:10:29 -0700175 Error::PopulateAndLog(error, Error::kNotSupported,
176 "Device doesn't support scan.");
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700177}
178
Eric Shienbrood9a245532012-03-07 14:20:39 -0500179void Device::RegisterOnNetwork(const std::string &/*network_id*/, Error *error,
180 const ResultCallback &/*callback*/) {
181 Error::PopulateAndLog(error, Error::kNotSupported,
Paul Stewartbe005172011-11-02 18:10:29 -0700182 "Device doesn't support network registration.");
Darin Petkov9ae310f2011-08-30 15:41:13 -0700183}
184
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100185void Device::RequirePIN(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500186 const string &/*pin*/, bool /*require*/,
187 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700188 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500189 Error::PopulateAndLog(error, Error::kNotSupported,
190 "Device doesn't support RequirePIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700191}
192
Eric Shienbrood9a245532012-03-07 14:20:39 -0500193void Device::EnterPIN(const string &/*pin*/,
194 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700195 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500196 Error::PopulateAndLog(error, Error::kNotSupported,
197 "Device doesn't support EnterPIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700198}
199
mukesh agrawal1830fa12011-09-26 14:31:40 -0700200void Device::UnblockPIN(const string &/*unblock_code*/,
201 const string &/*pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500202 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700203 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500204 Error::PopulateAndLog(error, Error::kNotSupported,
205 "Device doesn't support UnblockPIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700206}
207
mukesh agrawal1830fa12011-09-26 14:31:40 -0700208void Device::ChangePIN(const string &/*old_pin*/,
209 const string &/*new_pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500210 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700211 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500212 Error::PopulateAndLog(error, Error::kNotSupported,
213 "Device doesn't support ChangePIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700214}
215
Paul Stewart2bf1d352011-12-06 15:02:55 -0800216void Device::DisableIPv6() {
217 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagDisableIPv6, "1");
218}
219
220void Device::EnableIPv6() {
221 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagDisableIPv6, "0");
222}
223
224void Device::EnableIPv6Privacy() {
225 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagUseTempAddr,
226 kIPFlagUseTempAddrUsedAndDefault);
227}
228
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800229void Device::DisableReversePathFilter() {
230 // TODO(pstew): Current kernel doesn't offer reverse-path filtering flag
231 // for IPv6. crosbug.com/24228
232 SetIPFlag(IPAddress::kFamilyIPv4, kIPFlagReversePathFilter,
233 kIPFlagReversePathFilterLooseMode);
234}
235
236void Device::EnableReversePathFilter() {
237 SetIPFlag(IPAddress::kFamilyIPv4, kIPFlagReversePathFilter,
238 kIPFlagReversePathFilterEnabled);
239}
240
Gaurav Shah435de2c2011-11-17 19:01:07 -0800241bool Device::IsConnected() const {
242 if (selected_service_)
243 return selected_service_->IsConnected();
244 return false;
245}
246
Paul Stewartd215af62012-04-24 23:25:50 -0700247bool Device::IsConnectedToService(const ServiceRefPtr &service) const {
248 return service == selected_service_ && IsConnected();
249}
250
Chris Masone27c4aa52011-07-02 13:10:14 -0700251string Device::GetRpcIdentifier() {
252 return adaptor_->GetRpcIdentifier();
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700253}
254
Chris Masone5dec5f42011-07-22 14:07:55 -0700255string Device::GetStorageIdentifier() {
256 string id = GetRpcIdentifier();
257 ControlInterface::RpcIdToStorageId(&id);
Chris Masone626719f2011-08-18 16:58:48 -0700258 size_t needle = id.find('_');
Chris Masone34af2182011-08-22 11:59:36 -0700259 DLOG_IF(ERROR, needle == string::npos) << "No _ in storage id?!?!";
Chris Masone626719f2011-08-18 16:58:48 -0700260 id.replace(id.begin() + needle + 1, id.end(), hardware_address_);
Chris Masone5dec5f42011-07-22 14:07:55 -0700261 return id;
262}
263
Jason Glasgowb5790052012-01-27 01:03:52 -0500264string Device::GetTechnologyString(Error */*error*/) {
265 return Technology::NameFromIdentifier(technology());
266}
267
Chris Masone19e30402011-07-19 15:48:47 -0700268const string& Device::FriendlyName() const {
Chris Masone7df0c672011-07-15 10:24:54 -0700269 return link_name_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700270}
271
Chris Masone19e30402011-07-19 15:48:47 -0700272const string& Device::UniqueName() const {
273 return unique_id_;
274}
275
Chris Masone5dec5f42011-07-22 14:07:55 -0700276bool Device::Load(StoreInterface *storage) {
277 const string id = GetStorageIdentifier();
278 if (!storage->ContainsGroup(id)) {
279 LOG(WARNING) << "Device is not available in the persistent store: " << id;
280 return false;
281 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500282 enabled_persistent_ = true;
283 storage->GetBool(id, kStoragePowered, &enabled_persistent_);
Paul Stewart6ff27f52012-07-11 06:51:41 -0700284 uint64 rx_byte_count = 0, tx_byte_count = 0;
285
286 manager_->device_info()->GetByteCounts(
287 interface_index_, &rx_byte_count, &tx_byte_count);
288 // If there is a byte-count present in the profile, the return value
289 // of Device::Get*ByteCount() should be the this stored value plus
290 // whatever additional bytes we receive since time-of-load. We
291 // accomplish this by the subtractions below, which can validly
292 // roll over "negative" in the subtractions below and in Get*ByteCount.
293 uint64 profile_byte_count;
294 if (storage->GetUint64(id, kStorageReceiveByteCount, &profile_byte_count)) {
295 receive_byte_offset_ = rx_byte_count - profile_byte_count;
296 }
297 if (storage->GetUint64(id, kStorageTransmitByteCount, &profile_byte_count)) {
298 transmit_byte_offset_ = tx_byte_count - profile_byte_count;
299 }
300
Chris Masone5dec5f42011-07-22 14:07:55 -0700301 return true;
302}
303
304bool Device::Save(StoreInterface *storage) {
305 const string id = GetStorageIdentifier();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500306 storage->SetBool(id, kStoragePowered, enabled_persistent_);
Chris Masone34af2182011-08-22 11:59:36 -0700307 if (ipconfig_.get()) {
308 // The _0 is an index into the list of IPConfigs that this device might
309 // have. We only have one IPConfig right now, and I hope to never have
310 // to support more, as sleffler indicates that associating IPConfigs
311 // with devices is wrong and due to be changed in flimflam anyhow.
312 string suffix = hardware_address_ + "_0";
313 ipconfig_->Save(storage, suffix);
314 storage->SetString(id, kStorageIPConfigs, SerializeIPConfigs(suffix));
315 }
Paul Stewart6ff27f52012-07-11 06:51:41 -0700316 storage->SetUint64(id, kStorageReceiveByteCount, GetReceiveByteCount(NULL));
317 storage->SetUint64(id, kStorageTransmitByteCount, GetTransmitByteCount(NULL));
Chris Masone5dec5f42011-07-22 14:07:55 -0700318 return true;
319}
320
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200321void Device::DropConnection() {
322 SLOG(Device, 2) << __func__;
323 DestroyIPConfig();
324 SelectService(NULL);
325}
326
Darin Petkovafa6fc42011-06-21 16:21:08 -0700327void Device::DestroyIPConfig() {
Paul Stewart2bf1d352011-12-06 15:02:55 -0800328 DisableIPv6();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700329 if (ipconfig_.get()) {
330 ipconfig_->ReleaseIP();
331 ipconfig_ = NULL;
332 }
Paul Stewarte6132022011-08-16 09:11:02 -0700333 DestroyConnection();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700334}
335
Paul Stewart2bf1d352011-12-06 15:02:55 -0800336bool Device::AcquireIPConfig() {
Paul Stewartd408fdf2012-05-07 17:15:57 -0700337 return AcquireIPConfigWithLeaseName(string());
338}
339
340bool Device::AcquireIPConfigWithLeaseName(const string &lease_name) {
Darin Petkovafa6fc42011-06-21 16:21:08 -0700341 DestroyIPConfig();
Paul Stewart2bf1d352011-12-06 15:02:55 -0800342 EnableIPv6();
Paul Stewartd408fdf2012-05-07 17:15:57 -0700343 ipconfig_ = dhcp_provider_->CreateConfig(link_name_,
344 manager_->GetHostName(),
345 lease_name,
346 manager_->GetArpGateway());
Eric Shienbrood9a245532012-03-07 14:20:39 -0500347 ipconfig_->RegisterUpdateCallback(Bind(&Device::OnIPConfigUpdated,
348 weak_ptr_factory_.GetWeakPtr()));
Paul Stewart1062d9d2012-04-27 10:42:27 -0700349 dispatcher_->PostTask(Bind(&Device::ConfigureStaticIPTask,
350 weak_ptr_factory_.GetWeakPtr()));
Darin Petkovafa6fc42011-06-21 16:21:08 -0700351 return ipconfig_->RequestIP();
352}
353
Jason Glasgowb5790052012-01-27 01:03:52 -0500354void Device::HelpRegisterDerivedString(
355 const string &name,
356 string(Device::*get)(Error *error),
357 void(Device::*set)(const string &value, Error *error)) {
358 store_.RegisterDerivedString(
359 name,
360 StringAccessor(new CustomAccessor<Device, string>(this, get, set)));
361}
362
mukesh agrawalffa3d042011-10-06 15:26:10 -0700363void Device::HelpRegisterDerivedStrings(
364 const string &name,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500365 Strings(Device::*get)(Error *error),
366 void(Device::*set)(const Strings &value, Error *error)) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700367 store_.RegisterDerivedStrings(
368 name,
369 StringsAccessor(new CustomAccessor<Device, Strings>(this, get, set)));
Chris Masone4e851612011-07-01 10:46:53 -0700370}
371
Jason Glasgow08afdff2012-04-03 10:22:26 -0400372void Device::HelpRegisterConstDerivedRpcIdentifiers(
373 const string &name,
374 RpcIdentifiers(Device::*get)(Error *)) {
375 store_.RegisterDerivedRpcIdentifiers(
376 name,
377 RpcIdentifiersAccessor(
378 new CustomAccessor<Device, RpcIdentifiers>(this, get, NULL)));
379}
380
Paul Stewart6ff27f52012-07-11 06:51:41 -0700381void Device::HelpRegisterConstDerivedUint64(
382 const string &name,
383 uint64(Device::*get)(Error *)) {
384 store_.RegisterDerivedUint64(
385 name,
386 Uint64Accessor(
387 new CustomAccessor<Device, uint64>(this, get, NULL)));
388}
389
Paul Stewart1062d9d2012-04-27 10:42:27 -0700390void Device::ConfigureStaticIPTask() {
391 SLOG(Device, 2) << __func__ << " selected_service " << selected_service_.get()
392 << " ipconfig " << ipconfig_.get();
393
394 if (!selected_service_ || !ipconfig_) {
395 return;
396 }
397
398 const StaticIPParameters &static_ip_parameters =
399 selected_service_->static_ip_parameters();
400 if (static_ip_parameters.ContainsAddress()) {
401 SLOG(Device, 2) << __func__ << " " << " configuring static IP parameters.";
402 // If the parameters contain an IP address, apply them now and bring
403 // the interface up. When DHCP information arrives, it will supplement
404 // the static information.
405 OnIPConfigUpdated(ipconfig_, true);
406 } else {
407 SLOG(Device, 2) << __func__ << " " << " no static IP address.";
408 }
409}
410
Darin Petkov79d74c92012-03-07 17:20:32 +0100411void Device::OnIPConfigUpdated(const IPConfigRefPtr &ipconfig, bool success) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700412 SLOG(Device, 2) << __func__ << " " << " success: " << success;
Paul Stewartc39f1132011-06-22 12:02:28 -0700413 if (success) {
Paul Stewarte6132022011-08-16 09:11:02 -0700414 CreateConnection();
Paul Stewart1062d9d2012-04-27 10:42:27 -0700415 if (selected_service_) {
416 ipconfig->ApplyStaticIPParameters(
417 selected_service_->static_ip_parameters());
418 }
Paul Stewarte6132022011-08-16 09:11:02 -0700419 connection_->UpdateFromIPConfig(ipconfig);
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800420 // SetConnection must occur after the UpdateFromIPConfig so the
421 // service can use the values derived from the connection.
Paul Stewart1062d9d2012-04-27 10:42:27 -0700422 if (selected_service_) {
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800423 selected_service_->SetConnection(connection_);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800424 }
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800425 // The service state change needs to happen last, so that at the
426 // time we report the state change to the manager, the service
427 // has its connection.
428 SetServiceState(Service::kStateConnected);
Thieu Le85e050b2012-03-13 15:04:38 -0700429 portal_attempts_to_online_ = 0;
Paul Stewart20088d82012-02-16 06:58:55 -0800430 // Subtle: Start portal detection after transitioning the service
431 // to the Connected state because this call may immediately transition
432 // to the Online state.
433 StartPortalDetection();
Paul Stewarte6132022011-08-16 09:11:02 -0700434 } else {
mukesh agrawalcc0fded2012-05-09 13:40:58 -0700435 // TODO(pstew): This logic gets yet more complex when multiple
436 // IPConfig types are run in parallel (e.g. DHCP and DHCP6)
437 if (selected_service_ &&
438 selected_service_->static_ip_parameters().ContainsAddress()) {
439 // Consider three cases:
440 //
441 // 1. We're here because DHCP failed while starting up. There
442 // are two subcases:
443 // a. DHCP has failed, and Static IP config has _not yet_
444 // completed. It's fine to do nothing, because we'll
445 // apply the static config shortly.
446 // b. DHCP has failed, and Static IP config has _already_
447 // completed. It's fine to do nothing, because we can
448 // continue to use the static config that's already
449 // been applied.
450 //
451 // 2. We're here because a previously valid DHCP configuration
452 // is no longer valid. There's still a static IP config,
453 // because the condition in the if clause evaluated to true.
454 // Furthermore, the static config includes an IP address for
455 // us to use.
456 //
457 // The current configuration may include some DHCP
458 // parameters, overriden by any static parameters
459 // provided. We continue to use this configuration, because
460 // the only configuration element that is leased to us (IP
461 // address) will be overriden by a static parameter.
462 return;
463 }
464
Paul Stewart03dba0b2011-08-22 16:32:45 -0700465 SetServiceState(Service::kStateDisconnected);
Paul Stewarte6132022011-08-16 09:11:02 -0700466 DestroyConnection();
Paul Stewartc39f1132011-06-22 12:02:28 -0700467 }
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700468}
469
Paul Stewarte6132022011-08-16 09:11:02 -0700470void Device::CreateConnection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700471 SLOG(Device, 2) << __func__;
Paul Stewarte6132022011-08-16 09:11:02 -0700472 if (!connection_.get()) {
Paul Stewart9a908082011-08-31 12:18:48 -0700473 connection_ = new Connection(interface_index_,
474 link_name_,
Paul Stewarte00600e2012-03-16 07:08:00 -0700475 technology_,
Paul Stewart9a908082011-08-31 12:18:48 -0700476 manager_->device_info());
Paul Stewarte6132022011-08-16 09:11:02 -0700477 }
478}
479
480void Device::DestroyConnection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700481 SLOG(Device, 2) << __func__;
Paul Stewart20088d82012-02-16 06:58:55 -0800482 StopPortalDetection();
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800483 if (selected_service_.get()) {
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800484 selected_service_->SetConnection(NULL);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800485 }
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800486 connection_ = NULL;
Paul Stewarte6132022011-08-16 09:11:02 -0700487}
488
Paul Stewart03dba0b2011-08-22 16:32:45 -0700489void Device::SelectService(const ServiceRefPtr &service) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700490 SLOG(Device, 2) << __func__ << ": "
491 << (service.get() ?
492 StringPrintf("%s (%s)",
493 service->UniqueName().c_str(),
494 service->friendly_name().c_str()) :
495 "*reset*");
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000496
497 if (selected_service_.get() == service.get()) {
498 // No change to |selected_service_|. Return early to avoid
499 // changing its state.
500 return;
501 }
502
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800503 if (selected_service_.get()) {
504 if (selected_service_->state() != Service::kStateFailure) {
505 selected_service_->SetState(Service::kStateIdle);
506 }
Paul Stewart20b0a092012-05-22 20:39:57 -0700507 // Just in case the Device subclass has not already done so, make
508 // sure the previously selected service has its connection removed.
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800509 selected_service_->SetConnection(NULL);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700510 }
511 selected_service_ = service;
512}
513
514void Device::SetServiceState(Service::ConnectState state) {
515 if (selected_service_.get()) {
516 selected_service_->SetState(state);
517 }
518}
519
520void Device::SetServiceFailure(Service::ConnectFailure failure_state) {
521 if (selected_service_.get()) {
522 selected_service_->SetFailure(failure_state);
523 }
524}
525
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400526void Device::SetServiceFailureSilent(Service::ConnectFailure failure_state) {
527 if (selected_service_.get()) {
528 selected_service_->SetFailureSilent(failure_state);
529 }
530}
531
Chris Masone34af2182011-08-22 11:59:36 -0700532string Device::SerializeIPConfigs(const string &suffix) {
533 return StringPrintf("%s:%s", suffix.c_str(), ipconfig_->type().c_str());
Chris Masone5dec5f42011-07-22 14:07:55 -0700534}
535
Paul Stewart2bf1d352011-12-06 15:02:55 -0800536bool Device::SetIPFlag(IPAddress::Family family, const string &flag,
537 const string &value) {
538 string ip_version;
539 if (family == IPAddress::kFamilyIPv4) {
540 ip_version = kIPFlagVersion4;
541 } else if (family == IPAddress::kFamilyIPv6) {
542 ip_version = kIPFlagVersion6;
543 } else {
544 NOTIMPLEMENTED();
545 }
546 FilePath flag_file(StringPrintf(kIPFlagTemplate, ip_version.c_str(),
547 link_name_.c_str(), flag.c_str()));
Ben Chanfad4a0b2012-04-18 15:49:59 -0700548 SLOG(Device, 2) << "Writing " << value << " to flag file "
549 << flag_file.value();
Paul Stewart2bf1d352011-12-06 15:02:55 -0800550 if (file_util::WriteFile(flag_file, value.c_str(), value.length()) != 1) {
551 LOG(ERROR) << StringPrintf("IP flag write failed: %s to %s",
552 value.c_str(), flag_file.value().c_str());
553 return false;
554 }
555 return true;
556}
557
Paul Stewart6ff27f52012-07-11 06:51:41 -0700558void Device::ResetByteCounters() {
559 manager_->device_info()->GetByteCounts(
560 interface_index_, &receive_byte_offset_, &transmit_byte_offset_);
561 manager_->UpdateDevice(this);
562}
563
Paul Stewartd215af62012-04-24 23:25:50 -0700564bool Device::RestartPortalDetection() {
565 StopPortalDetection();
566 return StartPortalDetection();
567}
568
Paul Stewartc681fa02012-03-02 19:40:04 -0800569bool Device::RequestPortalDetection() {
570 if (!selected_service_) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700571 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800572 << ": No selected service, so no need for portal check.";
573 return false;
574 }
575
576 if (!connection_.get()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700577 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800578 << ": No connection, so no need for portal check.";
579 return false;
580 }
581
582 if (selected_service_->state() != Service::kStatePortal) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700583 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800584 << ": Service is not in portal state. No need to start check.";
585 return false;
586 }
587
588 if (!connection_->is_default()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700589 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800590 << ": Service is not the default connection. Don't start check.";
591 return false;
592 }
593
594 if (portal_detector_.get() && portal_detector_->IsInProgress()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700595 SLOG(Device, 2) << FriendlyName()
596 << ": Portal detection is already running.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800597 return true;
598 }
599
600 return StartPortalDetection();
601}
602
Paul Stewart20088d82012-02-16 06:58:55 -0800603bool Device::StartPortalDetection() {
Paul Stewartd215af62012-04-24 23:25:50 -0700604 DCHECK(selected_service_.get());
605 if (selected_service_->IsPortalDetectionDisabled()) {
606 SLOG(Device, 2) << "Service " << selected_service_->friendly_name()
607 << ": Portal detection is disabled; "
608 << "marking service online.";
609 SetServiceConnectedState(Service::kStateOnline);
610 return false;
611 }
612
613 if (selected_service_->IsPortalDetectionAuto() &&
614 !manager_->IsPortalDetectionEnabled(technology())) {
Paul Stewart20088d82012-02-16 06:58:55 -0800615 // If portal detection is disabled for this technology, immediately set
616 // the service state to "Online".
Ben Chanfad4a0b2012-04-18 15:49:59 -0700617 SLOG(Device, 2) << "Device " << FriendlyName()
618 << ": Portal detection is disabled; "
619 << "marking service online.";
Paul Stewart20088d82012-02-16 06:58:55 -0800620 SetServiceConnectedState(Service::kStateOnline);
621 return false;
622 }
623
Paul Stewart20088d82012-02-16 06:58:55 -0800624 if (selected_service_->HasProxyConfig()) {
625 // Services with HTTP proxy configurations should not be checked by the
626 // connection manager, since we don't have the ability to evaluate
627 // arbitrary proxy configs and their possible credentials.
Ben Chanfad4a0b2012-04-18 15:49:59 -0700628 SLOG(Device, 2) << "Device " << FriendlyName()
629 << ": Service has proxy config; marking it online.";
Paul Stewart20088d82012-02-16 06:58:55 -0800630 SetServiceConnectedState(Service::kStateOnline);
631 return false;
632 }
633
634 portal_detector_.reset(new PortalDetector(connection_,
635 dispatcher_,
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500636 portal_detector_callback_));
Paul Stewart20088d82012-02-16 06:58:55 -0800637 if (!portal_detector_->Start(manager_->GetPortalCheckURL())) {
638 LOG(ERROR) << "Device " << FriendlyName()
639 << ": Portal detection failed to start: likely bad URL: "
640 << manager_->GetPortalCheckURL();
641 SetServiceConnectedState(Service::kStateOnline);
642 return false;
643 }
644
Ben Chanfad4a0b2012-04-18 15:49:59 -0700645 SLOG(Device, 2) << "Device " << FriendlyName()
646 << ": Portal detection has started.";
Paul Stewart20088d82012-02-16 06:58:55 -0800647 return true;
648}
649
650void Device::StopPortalDetection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700651 SLOG(Device, 2) << "Device " << FriendlyName()
652 << ": Portal detection has stopped.";
Paul Stewart20088d82012-02-16 06:58:55 -0800653 portal_detector_.reset();
654}
655
656void Device::SetServiceConnectedState(Service::ConnectState state) {
657 DCHECK(selected_service_.get());
658
659 if (!selected_service_.get()) {
660 LOG(ERROR) << FriendlyName() << ": "
661 << "Portal detection completed but no selected service exists!";
662 return;
663 }
664
665 if (!selected_service_->IsConnected()) {
666 LOG(ERROR) << FriendlyName() << ": "
667 << "Portal detection completed but selected service "
668 << selected_service_->UniqueName()
669 << " is in non-connected state.";
670 return;
671 }
672
Paul Stewartc681fa02012-03-02 19:40:04 -0800673 if (state == Service::kStatePortal && connection_->is_default() &&
674 manager_->GetPortalCheckInterval() != 0) {
675 CHECK(portal_detector_.get());
676 if (!portal_detector_->StartAfterDelay(
677 manager_->GetPortalCheckURL(),
678 manager_->GetPortalCheckInterval())) {
679 LOG(ERROR) << "Device " << FriendlyName()
680 << ": Portal detection failed to restart: likely bad URL: "
681 << manager_->GetPortalCheckURL();
682 SetServiceState(Service::kStateOnline);
683 portal_detector_.reset();
684 return;
685 }
Ben Chanfad4a0b2012-04-18 15:49:59 -0700686 SLOG(Device, 2) << "Device " << FriendlyName()
687 << ": Portal detection retrying.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800688 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700689 SLOG(Device, 2) << "Device " << FriendlyName()
690 << ": Portal will not retry.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800691 portal_detector_.reset();
692 }
693
Paul Stewart20088d82012-02-16 06:58:55 -0800694 SetServiceState(state);
695}
696
697void Device::PortalDetectorCallback(const PortalDetector::Result &result) {
698 if (!result.final) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700699 SLOG(Device, 2) << "Device " << FriendlyName()
700 << ": Received non-final status: "
701 << PortalDetector::StatusToString(result.status);
Paul Stewart20088d82012-02-16 06:58:55 -0800702 return;
703 }
704
Ben Chanfad4a0b2012-04-18 15:49:59 -0700705 SLOG(Device, 2) << "Device " << FriendlyName()
706 << ": Received final status: "
707 << PortalDetector::StatusToString(result.status);
Paul Stewart20088d82012-02-16 06:58:55 -0800708
Thieu Le85e050b2012-03-13 15:04:38 -0700709 portal_attempts_to_online_ += result.num_attempts;
710
711 metrics()->SendEnumToUMA(
712 metrics()->GetFullMetricName(Metrics::kMetricPortalResult, technology()),
713 Metrics::PortalDetectionResultToEnum(result),
714 Metrics::kPortalResultMax);
715
Paul Stewart20088d82012-02-16 06:58:55 -0800716 if (result.status == PortalDetector::kStatusSuccess) {
717 SetServiceConnectedState(Service::kStateOnline);
Thieu Le85e050b2012-03-13 15:04:38 -0700718
719 metrics()->SendToUMA(
720 metrics()->GetFullMetricName(
721 Metrics::kMetricPortalAttemptsToOnline, technology()),
722 portal_attempts_to_online_,
723 Metrics::kMetricPortalAttemptsToOnlineMin,
724 Metrics::kMetricPortalAttemptsToOnlineMax,
725 Metrics::kMetricPortalAttemptsToOnlineNumBuckets);
Paul Stewart20088d82012-02-16 06:58:55 -0800726 } else {
727 SetServiceConnectedState(Service::kStatePortal);
Thieu Le85e050b2012-03-13 15:04:38 -0700728
729 metrics()->SendToUMA(
730 metrics()->GetFullMetricName(
731 Metrics::kMetricPortalAttempts, technology()),
732 result.num_attempts,
733 Metrics::kMetricPortalAttemptsMin,
734 Metrics::kMetricPortalAttemptsMax,
735 Metrics::kMetricPortalAttemptsNumBuckets);
Paul Stewart20088d82012-02-16 06:58:55 -0800736 }
737}
738
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800739vector<string> Device::AvailableIPConfigs(Error */*error*/) {
Jason Glasgow08afdff2012-04-03 10:22:26 -0400740 if (ipconfig_.get()) {
741 string id = ipconfig_->GetRpcIdentifier();
742 return vector<string>(1, id);
743 }
744 return vector<string>();
Chris Masone4e851612011-07-01 10:46:53 -0700745}
746
747string Device::GetRpcConnectionIdentifier() {
748 return adaptor_->GetRpcConnectionIdentifier();
749}
750
Paul Stewart6ff27f52012-07-11 06:51:41 -0700751uint64 Device::GetReceiveByteCount(Error */*error*/) {
752 uint64 rx_byte_count = 0, tx_byte_count = 0;
753 manager_->device_info()->GetByteCounts(
754 interface_index_, &rx_byte_count, &tx_byte_count);
755 return rx_byte_count - receive_byte_offset_;
756}
757
758uint64 Device::GetTransmitByteCount(Error */*error*/) {
759 uint64 rx_byte_count = 0, tx_byte_count = 0;
760 manager_->device_info()->GetByteCounts(
761 interface_index_, &rx_byte_count, &tx_byte_count);
762 return tx_byte_count - transmit_byte_offset_;
763}
764
Eric Shienbrood7fce52c2012-04-13 19:11:02 -0400765bool Device::IsUnderlyingDeviceEnabled() const {
766 return false;
767}
768
Eric Shienbrood9a245532012-03-07 14:20:39 -0500769// callback
770void Device::OnEnabledStateChanged(const ResultCallback &callback,
771 const Error &error) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700772 SLOG(Device, 2) << __func__ << "(" << enabled_pending_ << ")";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500773 if (error.IsSuccess()) {
774 enabled_ = enabled_pending_;
775 manager_->UpdateEnabledTechnologies();
776 adaptor_->EmitBoolChanged(flimflam::kPoweredProperty, enabled_);
777 adaptor_->UpdateEnabled();
778 }
Gary Morainbaeefdf2012-04-30 14:53:35 -0700779 enabled_pending_ = enabled_;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500780 if (!callback.is_null())
781 callback.Run(error);
782}
783
784void Device::SetEnabled(bool enable) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700785 SLOG(Device, 2) << __func__ << "(" << enable << ")";
Jason Glasgow4a490792012-04-10 15:02:05 -0400786 Error error;
787 SetEnabledInternal(enable, false, &error, ResultCallback());
Jason Glasgow7234ec32012-05-23 16:01:21 -0400788 LOG_IF(ERROR, error.IsFailure() && !error.IsOngoing())
Jason Glasgow4a490792012-04-10 15:02:05 -0400789 << "Enabled failed, but no way to report the failure.";
Eric Shienbrood9a245532012-03-07 14:20:39 -0500790}
791
792void Device::SetEnabledPersistent(bool enable,
793 Error *error,
794 const ResultCallback &callback) {
795 SetEnabledInternal(enable, true, error, callback);
796}
797
798void Device::SetEnabledInternal(bool enable,
799 bool persist,
800 Error *error,
801 const ResultCallback &callback) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400802 DCHECK(error);
Ben Chanfad4a0b2012-04-18 15:49:59 -0700803 SLOG(Device, 2) << "Device " << link_name_ << " "
804 << (enable ? "starting" : "stopping");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500805 if (enable == enabled_) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400806 error->Reset();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500807 return;
808 }
809
810 if (enabled_pending_ == enable) {
Jason Glasgow4a490792012-04-10 15:02:05 -0400811 Error::PopulateAndLog(error, Error::kInProgress,
812 "Enable operation already in progress");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500813 return;
814 }
815
816 if (persist) {
817 enabled_persistent_ = enable;
Darin Petkove7c6ad32012-06-29 10:22:09 +0200818 manager_->UpdateDevice(this);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500819 }
820
821 enabled_pending_ = enable;
822 EnabledStateChangedCallback enabled_callback =
823 Bind(&Device::OnEnabledStateChanged,
824 weak_ptr_factory_.GetWeakPtr(), callback);
825 if (enable) {
826 running_ = true;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500827 Start(error, enabled_callback);
828 } else {
829 running_ = false;
830 DestroyIPConfig(); // breaks a reference cycle
831 SelectService(NULL); // breaks a reference cycle
832 rtnl_handler_->SetInterfaceFlags(interface_index(), 0, IFF_UP);
Ben Chanfad4a0b2012-04-18 15:49:59 -0700833 SLOG(Device, 3) << "Device " << link_name_ << " ipconfig_ "
834 << (ipconfig_ ? "is set." : "is not set.");
835 SLOG(Device, 3) << "Device " << link_name_ << " connection_ "
836 << (connection_ ? "is set." : "is not set.");
837 SLOG(Device, 3) << "Device " << link_name_ << " selected_service_ "
838 << (selected_service_ ? "is set." : "is not set.");
Eric Shienbrood9a245532012-03-07 14:20:39 -0500839 Stop(error, enabled_callback);
840 }
841}
842
Paul Stewart75897df2011-04-27 09:05:53 -0700843} // namespace shill