blob: f47c65b9349272bb641df3dc58cfc95f9825ef62 [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 Masone487b8bf2011-05-13 16:27:57 -070017#include <base/memory/ref_counted.h>
Ben Chana0ddf462014-02-06 11:32:42 -080018#include <base/strings/stringprintf.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070019#include <chromeos/dbus/service_constants.h>
Chris Masoneee929b72011-05-10 10:02:18 -070020
Arman Ugurayf84a4242013-04-09 20:01:07 -070021#include "shill/async_connection.h"
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"
Gaurav Shah6d2c72d2012-10-16 16:30:44 -070029#include "shill/geolocation_info.h"
Paul Stewartf65320c2011-10-13 14:34:52 -070030#include "shill/http_proxy.h"
Arman Ugurayf84a4242013-04-09 20:01:07 -070031#include "shill/ip_address.h"
Paul Stewart036dba02012-08-07 12:34:41 -070032#include "shill/link_monitor.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070033#include "shill/logging.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070034#include "shill/manager.h"
Thieu Le85e050b2012-03-13 15:04:38 -070035#include "shill/metrics.h"
Chris Masone95207da2011-06-29 16:50:49 -070036#include "shill/property_accessor.h"
Chris Masone2b105542011-06-22 10:58:09 -070037#include "shill/refptr_types.h"
Paul Stewartc39f1132011-06-22 12:02:28 -070038#include "shill/rtnl_handler.h"
Chris Masone2b105542011-06-22 10:58:09 -070039#include "shill/service.h"
Arman Ugurayf84a4242013-04-09 20:01:07 -070040#include "shill/socket_info_reader.h"
Chris Masone5dec5f42011-07-22 14:07:55 -070041#include "shill/store_interface.h"
Gaurav Shah435de2c2011-11-17 19:01:07 -080042#include "shill/technology.h"
Paul Stewartfa11e282013-12-02 22:04:25 -080043#include "shill/tethering.h"
Peter Qiudc335f82014-05-15 10:33:17 -070044#include "shill/traffic_monitor.h"
Paul Stewart75897df2011-04-27 09:05:53 -070045
Eric Shienbrood3e20a232012-02-16 11:35:56 -050046using base::Bind;
Peter Qiu6f5618b2014-06-05 15:19:01 -070047using base::Callback;
Albert Chaulk0e1cdea2013-02-27 15:32:55 -080048using base::FilePath;
Chris Masone5dec5f42011-07-22 14:07:55 -070049using base::StringPrintf;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070050using std::string;
51using std::vector;
52
Paul Stewart75897df2011-04-27 09:05:53 -070053namespace shill {
Chris Masone5dec5f42011-07-22 14:07:55 -070054
55// static
Paul Stewart2bf1d352011-12-06 15:02:55 -080056const char Device::kIPFlagTemplate[] = "/proc/sys/net/%s/conf/%s/%s";
57// static
58const char Device::kIPFlagVersion4[] = "ipv4";
59// static
60const char Device::kIPFlagVersion6[] = "ipv6";
61// static
62const char Device::kIPFlagDisableIPv6[] = "disable_ipv6";
63// static
64const char Device::kIPFlagUseTempAddr[] = "use_tempaddr";
65// static
66const char Device::kIPFlagUseTempAddrUsedAndDefault[] = "2";
Paul Stewartc8f4bef2011-12-13 09:45:51 -080067// static
68const char Device::kIPFlagReversePathFilter[] = "rp_filter";
69// static
70const char Device::kIPFlagReversePathFilterEnabled[] = "1";
71// static
72const char Device::kIPFlagReversePathFilterLooseMode[] = "2";
Paul Stewart2bf1d352011-12-06 15:02:55 -080073// static
Prathmesh Prabhuba99b592013-04-17 15:13:14 -070074const char Device::kStoragePowered[] = "Powered";
75// static
Paul Stewart6ff27f52012-07-11 06:51:41 -070076const char Device::kStorageReceiveByteCount[] = "ReceiveByteCount";
77// static
78const char Device::kStorageTransmitByteCount[] = "TransmitByteCount";
Peter Qiub9256f32014-05-09 15:27:29 -070079// static
80const char Device::kFallbackDnsTestHostname[] = "www.gstatic.com";
81// static
82const char* Device::kFallbackDnsServers[] = {
83 "8.8.8.8",
Peter Qiua89154b2014-05-23 15:45:42 -070084 "8.8.4.4"
Peter Qiub9256f32014-05-09 15:27:29 -070085};
86
87// static
88const int Device::kDNSTimeoutMilliseconds = 5000;
Chris Masone5dec5f42011-07-22 14:07:55 -070089
Paul Stewart75897df2011-04-27 09:05:53 -070090Device::Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070091 EventDispatcher *dispatcher,
Thieu Le3426c8f2012-01-11 17:35:11 -080092 Metrics *metrics,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070093 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070094 const string &link_name,
Chris Masone626719f2011-08-18 16:58:48 -070095 const string &address,
Gaurav Shah435de2c2011-11-17 19:01:07 -080096 int interface_index,
97 Technology::Identifier technology)
Eric Shienbrood9a245532012-03-07 14:20:39 -050098 : enabled_(false),
99 enabled_persistent_(true),
100 enabled_pending_(enabled_),
Chris Masoneb925cc82011-06-22 15:39:57 -0700101 reconnect_(true),
Chris Masone626719f2011-08-18 16:58:48 -0700102 hardware_address_(address),
mukesh agrawalf60e4062011-05-27 13:13:41 -0700103 interface_index_(interface_index),
104 running_(false),
Darin Petkovafa6fc42011-06-21 16:21:08 -0700105 link_name_(link_name),
Chris Masone19e30402011-07-19 15:48:47 -0700106 unique_id_(link_name),
Darin Petkovd9661952011-08-03 16:25:42 -0700107 control_interface_(control_interface),
108 dispatcher_(dispatcher),
Thieu Le3426c8f2012-01-11 17:35:11 -0800109 metrics_(metrics),
Chris Masone7df0c672011-07-15 10:24:54 -0700110 manager_(manager),
Eric Shienbrood9a245532012-03-07 14:20:39 -0500111 weak_ptr_factory_(this),
Darin Petkov77cb6812011-08-15 16:19:41 -0700112 adaptor_(control_interface->CreateDeviceAdaptor(this)),
Eric Shienbrood9a245532012-03-07 14:20:39 -0500113 portal_detector_callback_(Bind(&Device::PortalDetectorCallback,
114 weak_ptr_factory_.GetWeakPtr())),
Gaurav Shah435de2c2011-11-17 19:01:07 -0800115 technology_(technology),
Thieu Le85e050b2012-03-13 15:04:38 -0700116 portal_attempts_to_online_(0),
Paul Stewart6ff27f52012-07-11 06:51:41 -0700117 receive_byte_offset_(0),
118 transmit_byte_offset_(0),
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700119 dhcp_provider_(DHCPProvider::GetInstance()),
120 rtnl_handler_(RTNLHandler::GetInstance()) {
Ben Chan923a5022013-09-20 11:23:23 -0700121 store_.RegisterConstString(kAddressProperty, &hardware_address_);
Chris Masone4d42df82011-07-02 17:09:39 -0700122
Ben Chan923a5022013-09-20 11:23:23 -0700123 // kBgscanMethodProperty: Registered in WiFi
124 // kBgscanShortIntervalProperty: Registered in WiFi
125 // kBgscanSignalThresholdProperty: Registered in WiFi
Chris Masone4d42df82011-07-02 17:09:39 -0700126
Ben Chan923a5022013-09-20 11:23:23 -0700127 // kCellularAllowRoamingProperty: Registered in Cellular
128 // kCarrierProperty: Registered in Cellular
129 // kEsnProperty: Registered in Cellular
130 // kHomeProviderProperty: Registered in Cellular
131 // kImeiProperty: Registered in Cellular
132 // kIccidProperty: Registered in Cellular
133 // kImsiProperty: Registered in Cellular
134 // kManufacturerProperty: Registered in Cellular
135 // kMdnProperty: Registered in Cellular
136 // kMeidProperty: Registered in Cellular
137 // kMinProperty: Registered in Cellular
138 // kModelIDProperty: Registered in Cellular
139 // kFirmwareRevisionProperty: Registered in Cellular
140 // kHardwareRevisionProperty: Registered in Cellular
141 // kPRLVersionProperty: Registered in Cellular
142 // kSIMLockStatusProperty: Registered in Cellular
143 // kFoundNetworksProperty: Registered in Cellular
Ben Chan923a5022013-09-20 11:23:23 -0700144 // kDBusObjectProperty: Register in Cellular
Chris Masone4d42df82011-07-02 17:09:39 -0700145
Ben Chan923a5022013-09-20 11:23:23 -0700146 store_.RegisterConstString(kInterfaceProperty, &link_name_);
147 HelpRegisterConstDerivedRpcIdentifiers(kIPConfigsProperty,
Jason Glasgow08afdff2012-04-03 10:22:26 -0400148 &Device::AvailableIPConfigs);
Ben Chan923a5022013-09-20 11:23:23 -0700149 store_.RegisterConstString(kNameProperty, &link_name_);
150 store_.RegisterConstBool(kPoweredProperty, &enabled_);
151 HelpRegisterConstDerivedString(kTypeProperty,
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700152 &Device::GetTechnologyString);
Ben Chan39a7beb2013-09-21 11:28:00 -0700153 HelpRegisterConstDerivedUint64(kLinkMonitorResponseTimeProperty,
Paul Stewart036dba02012-08-07 12:34:41 -0700154 &Device::GetLinkMonitorResponseTime);
Jason Glasgowb5790052012-01-27 01:03:52 -0500155
Chris Masoneb925cc82011-06-22 15:39:57 -0700156 // TODO(cmasone): Chrome doesn't use this...does anyone?
Ben Chan923a5022013-09-20 11:23:23 -0700157 // store_.RegisterConstBool(kReconnectProperty, &reconnect_);
Chris Masoneb925cc82011-06-22 15:39:57 -0700158
Chris Masone4e851612011-07-01 10:46:53 -0700159 // TODO(cmasone): Figure out what shill concept maps to flimflam's "Network".
Ben Chan923a5022013-09-20 11:23:23 -0700160 // known_properties_.push_back(kNetworksProperty);
Chris Masoneb925cc82011-06-22 15:39:57 -0700161
Wade Guthrie227c7742013-10-10 11:06:33 -0700162 // kRoamThresholdProperty: Registered in WiFi
Ben Chan923a5022013-09-20 11:23:23 -0700163 // kScanningProperty: Registered in WiFi, Cellular
164 // kScanIntervalProperty: Registered in WiFi, Cellular
Paul Stewart6ff27f52012-07-11 06:51:41 -0700165
166 if (manager_ && manager_->device_info()) { // Unit tests may not have these.
167 manager_->device_info()->GetByteCounts(
168 interface_index_, &receive_byte_offset_, &transmit_byte_offset_);
Ben Chan39a7beb2013-09-21 11:28:00 -0700169 HelpRegisterConstDerivedUint64(kReceiveByteCountProperty,
Ben Chanb061f892013-02-27 17:46:55 -0800170 &Device::GetReceiveByteCountProperty);
Ben Chan39a7beb2013-09-21 11:28:00 -0700171 HelpRegisterConstDerivedUint64(kTransmitByteCountProperty,
Ben Chanb061f892013-02-27 17:46:55 -0800172 &Device::GetTransmitByteCountProperty);
Paul Stewart6ff27f52012-07-11 06:51:41 -0700173 }
174
Darin Petkova0a0efe2012-06-27 12:50:01 +0200175 LOG(INFO) << "Device created: " << link_name_
176 << " index " << interface_index_;
Paul Stewart75897df2011-04-27 09:05:53 -0700177}
178
179Device::~Device() {
Darin Petkova0a0efe2012-06-27 12:50:01 +0200180 LOG(INFO) << "Device destructed: " << link_name_
181 << " index " << interface_index_;
Paul Stewart75897df2011-04-27 09:05:53 -0700182}
183
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700184void Device::LinkEvent(unsigned flags, unsigned change) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700185 SLOG(Device, 2) << "Device " << link_name_
186 << std::showbase << std::hex
187 << " flags " << flags << " changed " << change
188 << std::dec << std::noshowbase;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700189}
190
Wade Guthrie4823f4f2013-07-25 10:03:03 -0700191void Device::Scan(ScanType scan_type, Error *error, const string &reason) {
192 SLOG(Device, 2) << __func__ << " [Device] on " << link_name() << " from "
193 << reason;
Paul Stewartbe005172011-11-02 18:10:29 -0700194 Error::PopulateAndLog(error, Error::kNotSupported,
195 "Device doesn't support scan.");
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700196}
197
Eric Shienbrood9a245532012-03-07 14:20:39 -0500198void Device::RegisterOnNetwork(const std::string &/*network_id*/, Error *error,
199 const ResultCallback &/*callback*/) {
200 Error::PopulateAndLog(error, Error::kNotSupported,
Paul Stewartbe005172011-11-02 18:10:29 -0700201 "Device doesn't support network registration.");
Darin Petkov9ae310f2011-08-30 15:41:13 -0700202}
203
Darin Petkovc64fe5e2012-01-11 12:46:13 +0100204void Device::RequirePIN(
Eric Shienbrood9a245532012-03-07 14:20:39 -0500205 const string &/*pin*/, bool /*require*/,
206 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700207 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500208 Error::PopulateAndLog(error, Error::kNotSupported,
209 "Device doesn't support RequirePIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700210}
211
Eric Shienbrood9a245532012-03-07 14:20:39 -0500212void Device::EnterPIN(const string &/*pin*/,
213 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700214 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500215 Error::PopulateAndLog(error, Error::kNotSupported,
216 "Device doesn't support EnterPIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700217}
218
mukesh agrawal1830fa12011-09-26 14:31:40 -0700219void Device::UnblockPIN(const string &/*unblock_code*/,
220 const string &/*pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500221 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700222 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500223 Error::PopulateAndLog(error, Error::kNotSupported,
224 "Device doesn't support UnblockPIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700225}
226
mukesh agrawal1830fa12011-09-26 14:31:40 -0700227void Device::ChangePIN(const string &/*old_pin*/,
228 const string &/*new_pin*/,
Eric Shienbrood9a245532012-03-07 14:20:39 -0500229 Error *error, const ResultCallback &/*callback*/) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700230 SLOG(Device, 2) << __func__;
Eric Shienbrood9a245532012-03-07 14:20:39 -0500231 Error::PopulateAndLog(error, Error::kNotSupported,
232 "Device doesn't support ChangePIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700233}
234
Ben Chanad663e12013-01-08 01:58:47 -0800235void Device::Reset(Error *error, const ResultCallback &/*callback*/) {
236 SLOG(Device, 2) << __func__;
237 Error::PopulateAndLog(error, Error::kNotSupported,
238 "Device doesn't support Reset.");
239}
240
Darin Petkovc37a9c42012-09-06 15:28:22 +0200241void Device::SetCarrier(const string &/*carrier*/,
242 Error *error, const ResultCallback &/*callback*/) {
243 SLOG(Device, 2) << __func__;
244 Error::PopulateAndLog(error, Error::kNotSupported,
245 "Device doesn't support SetCarrier.");
246}
247
Ben Chanbcc6e012013-11-04 14:28:37 -0800248bool Device::IsIPv6Allowed() const {
249 return true;
250}
251
Paul Stewart2bf1d352011-12-06 15:02:55 -0800252void Device::DisableIPv6() {
Ben Chanbcc6e012013-11-04 14:28:37 -0800253 SLOG(Device, 2) << __func__;
Paul Stewart2bf1d352011-12-06 15:02:55 -0800254 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagDisableIPv6, "1");
255}
256
257void Device::EnableIPv6() {
Ben Chanbcc6e012013-11-04 14:28:37 -0800258 SLOG(Device, 2) << __func__;
259 if (!IsIPv6Allowed()) {
260 LOG(INFO) << "Skip enabling IPv6 on " << link_name_
261 << " as it is not allowed.";
262 return;
263 }
Paul Stewart2bf1d352011-12-06 15:02:55 -0800264 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagDisableIPv6, "0");
265}
266
267void Device::EnableIPv6Privacy() {
268 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagUseTempAddr,
269 kIPFlagUseTempAddrUsedAndDefault);
270}
271
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800272void Device::DisableReversePathFilter() {
273 // TODO(pstew): Current kernel doesn't offer reverse-path filtering flag
Paul Stewartee6b3d72013-07-12 16:07:51 -0700274 // for IPv6. crbug.com/207193
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800275 SetIPFlag(IPAddress::kFamilyIPv4, kIPFlagReversePathFilter,
276 kIPFlagReversePathFilterLooseMode);
277}
278
279void Device::EnableReversePathFilter() {
280 SetIPFlag(IPAddress::kFamilyIPv4, kIPFlagReversePathFilter,
281 kIPFlagReversePathFilterEnabled);
282}
283
Gaurav Shah435de2c2011-11-17 19:01:07 -0800284bool Device::IsConnected() const {
285 if (selected_service_)
286 return selected_service_->IsConnected();
287 return false;
288}
289
Paul Stewartd215af62012-04-24 23:25:50 -0700290bool Device::IsConnectedToService(const ServiceRefPtr &service) const {
291 return service == selected_service_ && IsConnected();
292}
293
Paul Stewartfa11e282013-12-02 22:04:25 -0800294bool Device::IsConnectedViaTether() const {
295 return
296 ipconfig_.get() &&
297 ipconfig_->properties().vendor_encapsulated_options ==
298 Tethering::kAndroidVendorEncapsulatedOptions;
299}
300
mukesh agrawalf6b32092013-04-10 15:49:55 -0700301string Device::GetRpcIdentifier() const {
Chris Masone27c4aa52011-07-02 13:10:14 -0700302 return adaptor_->GetRpcIdentifier();
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700303}
304
Chris Masone5dec5f42011-07-22 14:07:55 -0700305string Device::GetStorageIdentifier() {
306 string id = GetRpcIdentifier();
307 ControlInterface::RpcIdToStorageId(&id);
Chris Masone626719f2011-08-18 16:58:48 -0700308 size_t needle = id.find('_');
Chris Masone34af2182011-08-22 11:59:36 -0700309 DLOG_IF(ERROR, needle == string::npos) << "No _ in storage id?!?!";
Chris Masone626719f2011-08-18 16:58:48 -0700310 id.replace(id.begin() + needle + 1, id.end(), hardware_address_);
Chris Masone5dec5f42011-07-22 14:07:55 -0700311 return id;
312}
313
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700314vector<GeolocationInfo> Device::GetGeolocationObjects() const {
315 return vector<GeolocationInfo>();
Wade Guthrie227c7742013-10-10 11:06:33 -0700316}
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700317
Jason Glasgowb5790052012-01-27 01:03:52 -0500318string Device::GetTechnologyString(Error */*error*/) {
319 return Technology::NameFromIdentifier(technology());
320}
321
Chris Masone19e30402011-07-19 15:48:47 -0700322const string& Device::FriendlyName() const {
Chris Masone7df0c672011-07-15 10:24:54 -0700323 return link_name_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700324}
325
Chris Masone19e30402011-07-19 15:48:47 -0700326const string& Device::UniqueName() const {
327 return unique_id_;
328}
329
Chris Masone5dec5f42011-07-22 14:07:55 -0700330bool Device::Load(StoreInterface *storage) {
331 const string id = GetStorageIdentifier();
332 if (!storage->ContainsGroup(id)) {
333 LOG(WARNING) << "Device is not available in the persistent store: " << id;
334 return false;
335 }
Eric Shienbrood9a245532012-03-07 14:20:39 -0500336 enabled_persistent_ = true;
337 storage->GetBool(id, kStoragePowered, &enabled_persistent_);
Paul Stewart6ff27f52012-07-11 06:51:41 -0700338 uint64 rx_byte_count = 0, tx_byte_count = 0;
339
340 manager_->device_info()->GetByteCounts(
341 interface_index_, &rx_byte_count, &tx_byte_count);
342 // If there is a byte-count present in the profile, the return value
343 // of Device::Get*ByteCount() should be the this stored value plus
344 // whatever additional bytes we receive since time-of-load. We
345 // accomplish this by the subtractions below, which can validly
346 // roll over "negative" in the subtractions below and in Get*ByteCount.
347 uint64 profile_byte_count;
348 if (storage->GetUint64(id, kStorageReceiveByteCount, &profile_byte_count)) {
349 receive_byte_offset_ = rx_byte_count - profile_byte_count;
350 }
351 if (storage->GetUint64(id, kStorageTransmitByteCount, &profile_byte_count)) {
352 transmit_byte_offset_ = tx_byte_count - profile_byte_count;
353 }
354
Chris Masone5dec5f42011-07-22 14:07:55 -0700355 return true;
356}
357
358bool Device::Save(StoreInterface *storage) {
359 const string id = GetStorageIdentifier();
Eric Shienbrood9a245532012-03-07 14:20:39 -0500360 storage->SetBool(id, kStoragePowered, enabled_persistent_);
Ben Chanb061f892013-02-27 17:46:55 -0800361 storage->SetUint64(id, kStorageReceiveByteCount, GetReceiveByteCount());
362 storage->SetUint64(id, kStorageTransmitByteCount, GetTransmitByteCount());
Chris Masone5dec5f42011-07-22 14:07:55 -0700363 return true;
364}
365
mukesh agrawal784566d2012-08-08 18:32:58 -0700366void Device::OnBeforeSuspend() {
367 // Nothing to be done in the general case.
368}
369
370void Device::OnAfterResume() {
371 if (ipconfig_) {
372 SLOG(Device, 3) << "Renewing IP address on resume.";
373 ipconfig_->RenewIP();
374 }
mukesh agrawalbb2231c2013-07-17 16:32:24 -0700375 if (link_monitor_) {
376 SLOG(Device, 3) << "Informing Link Monitor of resume.";
377 link_monitor_->OnAfterResume();
378 }
mukesh agrawal784566d2012-08-08 18:32:58 -0700379}
380
Darin Petkov2b8e44e2012-06-25 15:13:26 +0200381void Device::DropConnection() {
382 SLOG(Device, 2) << __func__;
383 DestroyIPConfig();
384 SelectService(NULL);
385}
386
Darin Petkovafa6fc42011-06-21 16:21:08 -0700387void Device::DestroyIPConfig() {
Paul Stewart2bf1d352011-12-06 15:02:55 -0800388 DisableIPv6();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700389 if (ipconfig_.get()) {
Paul Stewart217c61d2013-06-13 15:12:02 -0700390 ipconfig_->ReleaseIP(IPConfig::kReleaseReasonDisconnect);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700391 ipconfig_ = NULL;
Paul Stewartd4f26482014-04-25 19:12:03 -0700392 UpdateIPConfigsProperty();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700393 }
Paul Stewarte6132022011-08-16 09:11:02 -0700394 DestroyConnection();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700395}
396
Paul Stewartd4f26482014-04-25 19:12:03 -0700397void Device::OnIPv6AddressChanged() {
398 IPAddress address(IPAddress::kFamilyIPv6);
399 if (!manager_->device_info()->GetPrimaryIPv6Address(
400 interface_index_, &address)) {
401 if (ip6config_) {
402 ip6config_ = NULL;
403 UpdateIPConfigsProperty();
404 }
405 return;
406 }
407
408 IPConfig::Properties properties;
409 if (!address.IntoString(&properties.address)) {
410 LOG(ERROR) << "Unable to convert IPv6 address into a string!";
411 return;
412 }
413 properties.subnet_prefix = address.prefix();
414
415 if (!ip6config_) {
416 ip6config_ = new IPConfig(control_interface_, link_name_);
417 } else if (properties.address == ip6config_->properties().address &&
418 properties.subnet_prefix ==
419 ip6config_->properties().subnet_prefix) {
420 SLOG(Device, 2) << __func__ << " primary address for "
421 << link_name_ << " is unchanged.";
422 return;
423 }
424
425 properties.address_family = IPAddress::kFamilyIPv6;
426 properties.method = kTypeIPv6;
427 ip6config_->set_properties(properties);
428 UpdateIPConfigsProperty();
429}
430
Arman Ugurayed8e6102012-11-29 14:47:20 -0800431bool Device::ShouldUseArpGateway() const {
432 return false;
433}
434
Paul Stewart316acef2014-05-29 18:40:48 -0700435bool Device::IsUsingStaticIP() const {
436 if (!selected_service_) {
437 return false;
438 }
439 return selected_service_->HasStaticIPAddress();
440}
441
Paul Stewart2bf1d352011-12-06 15:02:55 -0800442bool Device::AcquireIPConfig() {
Paul Stewartd408fdf2012-05-07 17:15:57 -0700443 return AcquireIPConfigWithLeaseName(string());
444}
445
446bool Device::AcquireIPConfigWithLeaseName(const string &lease_name) {
Darin Petkovafa6fc42011-06-21 16:21:08 -0700447 DestroyIPConfig();
Paul Stewart2bf1d352011-12-06 15:02:55 -0800448 EnableIPv6();
Arman Ugurayed8e6102012-11-29 14:47:20 -0800449 bool arp_gateway = manager_->GetArpGateway() && ShouldUseArpGateway();
Paul Stewartd408fdf2012-05-07 17:15:57 -0700450 ipconfig_ = dhcp_provider_->CreateConfig(link_name_,
451 manager_->GetHostName(),
452 lease_name,
Paul Stewartb1083182014-06-25 03:04:53 -0700453 arp_gateway);
Eric Shienbrood9a245532012-03-07 14:20:39 -0500454 ipconfig_->RegisterUpdateCallback(Bind(&Device::OnIPConfigUpdated,
455 weak_ptr_factory_.GetWeakPtr()));
Paul Stewartc5099532013-12-12 07:53:15 -0800456 ipconfig_->RegisterFailureCallback(Bind(&Device::OnIPConfigFailed,
457 weak_ptr_factory_.GetWeakPtr()));
Paul Stewart82236532013-12-10 15:33:11 -0800458 ipconfig_->RegisterRefreshCallback(Bind(&Device::OnIPConfigRefreshed,
459 weak_ptr_factory_.GetWeakPtr()));
Paul Stewart1f916e42013-12-23 09:52:54 -0800460 ipconfig_->RegisterExpireCallback(Bind(&Device::OnIPConfigExpired,
461 weak_ptr_factory_.GetWeakPtr()));
Paul Stewart1062d9d2012-04-27 10:42:27 -0700462 dispatcher_->PostTask(Bind(&Device::ConfigureStaticIPTask,
463 weak_ptr_factory_.GetWeakPtr()));
Darin Petkovafa6fc42011-06-21 16:21:08 -0700464 return ipconfig_->RequestIP();
465}
466
Ben Chan539ab022014-02-03 16:34:57 -0800467void Device::AssignIPConfig(const IPConfig::Properties &properties) {
468 DestroyIPConfig();
469 EnableIPv6();
470 ipconfig_ = new IPConfig(control_interface_, link_name_);
471 ipconfig_->set_properties(properties);
472 dispatcher_->PostTask(Bind(&Device::OnIPConfigUpdated,
473 weak_ptr_factory_.GetWeakPtr(), ipconfig_));
474}
475
Albert Chaulk0e1cdea2013-02-27 15:32:55 -0800476void Device::DestroyIPConfigLease(const string &name) {
477 dhcp_provider_->DestroyLease(name);
478}
479
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700480void Device::HelpRegisterConstDerivedString(
Jason Glasgowb5790052012-01-27 01:03:52 -0500481 const string &name,
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700482 string(Device::*get)(Error *error)) {
Jason Glasgowb5790052012-01-27 01:03:52 -0500483 store_.RegisterDerivedString(
484 name,
mukesh agrawalbebf1b82013-04-23 15:06:33 -0700485 StringAccessor(new CustomAccessor<Device, string>(this, get, NULL)));
Chris Masone4e851612011-07-01 10:46:53 -0700486}
487
Jason Glasgow08afdff2012-04-03 10:22:26 -0400488void Device::HelpRegisterConstDerivedRpcIdentifiers(
489 const string &name,
490 RpcIdentifiers(Device::*get)(Error *)) {
491 store_.RegisterDerivedRpcIdentifiers(
492 name,
493 RpcIdentifiersAccessor(
494 new CustomAccessor<Device, RpcIdentifiers>(this, get, NULL)));
495}
496
Paul Stewart6ff27f52012-07-11 06:51:41 -0700497void Device::HelpRegisterConstDerivedUint64(
498 const string &name,
499 uint64(Device::*get)(Error *)) {
500 store_.RegisterDerivedUint64(
501 name,
502 Uint64Accessor(
503 new CustomAccessor<Device, uint64>(this, get, NULL)));
504}
505
Paul Stewart1062d9d2012-04-27 10:42:27 -0700506void Device::ConfigureStaticIPTask() {
507 SLOG(Device, 2) << __func__ << " selected_service " << selected_service_.get()
508 << " ipconfig " << ipconfig_.get();
509
510 if (!selected_service_ || !ipconfig_) {
511 return;
512 }
513
Paul Stewart316acef2014-05-29 18:40:48 -0700514 if (IsUsingStaticIP()) {
Paul Stewart1062d9d2012-04-27 10:42:27 -0700515 SLOG(Device, 2) << __func__ << " " << " configuring static IP parameters.";
516 // If the parameters contain an IP address, apply them now and bring
517 // the interface up. When DHCP information arrives, it will supplement
518 // the static information.
Paul Stewartc5099532013-12-12 07:53:15 -0800519 OnIPConfigUpdated(ipconfig_);
Paul Stewart1062d9d2012-04-27 10:42:27 -0700520 } else {
Paul Stewart82236532013-12-10 15:33:11 -0800521 // Either |ipconfig_| has just been created in AcquireIPConfig() or
522 // we're being called by OnIPConfigRefreshed(). In either case a
523 // DHCP client has been started, and will take care of calling
524 // OnIPConfigUpdated() when it completes.
Paul Stewart1062d9d2012-04-27 10:42:27 -0700525 SLOG(Device, 2) << __func__ << " " << " no static IP address.";
526 }
527}
528
Paul Stewartc5099532013-12-12 07:53:15 -0800529void Device::OnIPConfigUpdated(const IPConfigRefPtr &ipconfig) {
530 SLOG(Device, 2) << __func__;
531 CreateConnection();
532 if (selected_service_) {
533 ipconfig->ApplyStaticIPParameters(
534 selected_service_->mutable_static_ip_parameters());
Paul Stewart316acef2014-05-29 18:40:48 -0700535 if (IsUsingStaticIP()) {
Paul Stewartc5099532013-12-12 07:53:15 -0800536 // If we are using a statically configured IP address instead
537 // of a leased IP address, release any acquired lease so it may
538 // be used by others. This allows us to merge other non-leased
539 // parameters (like DNS) when they're available from a DHCP server
540 // and not overridden by static parameters, but at the same time
541 // we avoid taking up a dynamic IP address the DHCP server could
542 // assign to someone else who might actually use it.
543 ipconfig->ReleaseIP(IPConfig::kReleaseReasonStaticIP);
Paul Stewart1062d9d2012-04-27 10:42:27 -0700544 }
Paul Stewartc39f1132011-06-22 12:02:28 -0700545 }
Paul Stewartc5099532013-12-12 07:53:15 -0800546 connection_->UpdateFromIPConfig(ipconfig);
547 // SetConnection must occur after the UpdateFromIPConfig so the
548 // service can use the values derived from the connection.
549 if (selected_service_) {
Paul Stewartc5099532013-12-12 07:53:15 -0800550 selected_service_->SetConnection(connection_);
551 }
552 // The service state change needs to happen last, so that at the
553 // time we report the state change to the manager, the service
554 // has its connection.
555 SetServiceState(Service::kStateConnected);
556 OnConnected();
557 portal_attempts_to_online_ = 0;
558 // Subtle: Start portal detection after transitioning the service
559 // to the Connected state because this call may immediately transition
560 // to the Online state.
561 if (selected_service_) {
562 StartPortalDetection();
563 }
564 StartLinkMonitor();
Peter Qiudc335f82014-05-15 10:33:17 -0700565 StartTrafficMonitor();
Paul Stewartd4f26482014-04-25 19:12:03 -0700566 UpdateIPConfigsProperty();
Paul Stewartc5099532013-12-12 07:53:15 -0800567}
568
569void Device::OnIPConfigFailed(const IPConfigRefPtr &ipconfig) {
570 SLOG(Device, 2) << __func__;
571 // TODO(pstew): This logic gets yet more complex when multiple
572 // IPConfig types are run in parallel (e.g. DHCP and DHCP6)
573 if (selected_service_) {
Paul Stewart316acef2014-05-29 18:40:48 -0700574 if (IsUsingStaticIP()) {
Paul Stewartc5099532013-12-12 07:53:15 -0800575 // Consider three cases:
576 //
577 // 1. We're here because DHCP failed while starting up. There
578 // are two subcases:
579 // a. DHCP has failed, and Static IP config has _not yet_
580 // completed. It's fine to do nothing, because we'll
581 // apply the static config shortly.
582 // b. DHCP has failed, and Static IP config has _already_
583 // completed. It's fine to do nothing, because we can
584 // continue to use the static config that's already
585 // been applied.
586 //
587 // 2. We're here because a previously valid DHCP configuration
588 // is no longer valid. There's still a static IP config,
589 // because the condition in the if clause evaluated to true.
590 // Furthermore, the static config includes an IP address for
591 // us to use.
592 //
593 // The current configuration may include some DHCP
594 // parameters, overriden by any static parameters
595 // provided. We continue to use this configuration, because
596 // the only configuration element that is leased to us (IP
597 // address) will be overriden by a static parameter.
598 return;
599 }
600 }
601
602 ipconfig->ResetProperties();
603 OnIPConfigFailure();
Paul Stewartd4f26482014-04-25 19:12:03 -0700604 UpdateIPConfigsProperty();
Paul Stewartc5099532013-12-12 07:53:15 -0800605 DestroyConnection();
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700606}
607
Paul Stewart82236532013-12-10 15:33:11 -0800608void Device::OnIPConfigRefreshed(const IPConfigRefPtr &ipconfig) {
609 // Clear the previously applied static IP parameters.
610 ipconfig->RestoreSavedIPParameters(
611 selected_service_->mutable_static_ip_parameters());
612
613 dispatcher_->PostTask(Bind(&Device::ConfigureStaticIPTask,
614 weak_ptr_factory_.GetWeakPtr()));
615}
616
Paul Stewartf6f96482013-07-12 12:49:15 -0700617void Device::OnIPConfigFailure() {
618 if (selected_service_) {
619 Error error;
Samuel Tan0d061192014-07-07 15:45:15 -0700620 selected_service_->DisconnectWithFailure(Service::kFailureDHCP,
621 &error,
622 __func__);
Paul Stewartf6f96482013-07-12 12:49:15 -0700623 }
624}
625
Paul Stewart1f916e42013-12-23 09:52:54 -0800626void Device::OnIPConfigExpired(const IPConfigRefPtr &ipconfig) {
627 metrics()->SendToUMA(
628 metrics()->GetFullMetricName(
mukesh agrawal132e96f2014-04-24 11:49:42 -0700629 Metrics::kMetricExpiredLeaseLengthSecondsSuffix, technology()),
Paul Stewart1f916e42013-12-23 09:52:54 -0800630 ipconfig->properties().lease_duration_seconds,
631 Metrics::kMetricExpiredLeaseLengthSecondsMin,
632 Metrics::kMetricExpiredLeaseLengthSecondsMax,
633 Metrics::kMetricExpiredLeaseLengthSecondsNumBuckets);
634}
635
Christopher Wiley5519e9e2013-01-08 16:55:56 -0800636void Device::OnConnected() {}
637
Paul Stewart8596f9f2013-03-14 07:58:26 -0700638void Device::OnConnectionUpdated() {
639 if (selected_service_) {
640 manager_->UpdateService(selected_service_);
641 }
642}
643
Paul Stewarte6132022011-08-16 09:11:02 -0700644void Device::CreateConnection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700645 SLOG(Device, 2) << __func__;
Paul Stewarte6132022011-08-16 09:11:02 -0700646 if (!connection_.get()) {
mukesh agrawal23ac6b72013-01-31 18:52:37 -0800647 connection_ = new Connection(interface_index_,
648 link_name_,
649 technology_,
650 manager_->device_info());
Paul Stewarte6132022011-08-16 09:11:02 -0700651 }
652}
653
654void Device::DestroyConnection() {
mukesh agrawal6813e762013-07-10 19:05:08 -0700655 SLOG(Device, 2) << __func__ << " on " << link_name_;
Peter Qiudc335f82014-05-15 10:33:17 -0700656 StopTrafficMonitor();
Paul Stewart20088d82012-02-16 06:58:55 -0800657 StopPortalDetection();
Paul Stewart036dba02012-08-07 12:34:41 -0700658 StopLinkMonitor();
Peter Qiu6f5618b2014-06-05 15:19:01 -0700659 StopDNSTest();
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800660 if (selected_service_.get()) {
mukesh agrawal6813e762013-07-10 19:05:08 -0700661 SLOG(Device, 3) << "Clearing connection of service "
662 << selected_service_->unique_name();
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800663 selected_service_->SetConnection(NULL);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800664 }
Paul Stewartc8f4bef2011-12-13 09:45:51 -0800665 connection_ = NULL;
Paul Stewarte6132022011-08-16 09:11:02 -0700666}
667
Paul Stewart03dba0b2011-08-22 16:32:45 -0700668void Device::SelectService(const ServiceRefPtr &service) {
Darin Petkov457728b2013-01-09 09:49:08 +0100669 SLOG(Device, 2) << __func__ << ": service "
mukesh agrawal6813e762013-07-10 19:05:08 -0700670 << (service ? service->unique_name() : "*reset*")
671 << " on " << link_name_;
mukesh agrawal8a3188d2011-12-01 20:56:44 +0000672
673 if (selected_service_.get() == service.get()) {
674 // No change to |selected_service_|. Return early to avoid
675 // changing its state.
676 return;
677 }
678
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800679 if (selected_service_.get()) {
680 if (selected_service_->state() != Service::kStateFailure) {
681 selected_service_->SetState(Service::kStateIdle);
682 }
Paul Stewart20b0a092012-05-22 20:39:57 -0700683 // Just in case the Device subclass has not already done so, make
684 // sure the previously selected service has its connection removed.
Paul Stewartc1dec4d2011-12-08 15:25:28 -0800685 selected_service_->SetConnection(NULL);
Peter Qiudc335f82014-05-15 10:33:17 -0700686 StopTrafficMonitor();
Paul Stewartc8860612012-09-28 07:36:21 -0700687 StopLinkMonitor();
688 StopPortalDetection();
Peter Qiu6f5618b2014-06-05 15:19:01 -0700689 StopDNSTest();
Paul Stewart03dba0b2011-08-22 16:32:45 -0700690 }
691 selected_service_ = service;
692}
693
694void Device::SetServiceState(Service::ConnectState state) {
695 if (selected_service_.get()) {
696 selected_service_->SetState(state);
697 }
698}
699
700void Device::SetServiceFailure(Service::ConnectFailure failure_state) {
701 if (selected_service_.get()) {
702 selected_service_->SetFailure(failure_state);
703 }
704}
705
Eric Shienbroodcc95c5d2012-03-30 15:25:49 -0400706void Device::SetServiceFailureSilent(Service::ConnectFailure failure_state) {
707 if (selected_service_.get()) {
708 selected_service_->SetFailureSilent(failure_state);
709 }
710}
711
Paul Stewart2bf1d352011-12-06 15:02:55 -0800712bool Device::SetIPFlag(IPAddress::Family family, const string &flag,
713 const string &value) {
714 string ip_version;
715 if (family == IPAddress::kFamilyIPv4) {
716 ip_version = kIPFlagVersion4;
717 } else if (family == IPAddress::kFamilyIPv6) {
718 ip_version = kIPFlagVersion6;
719 } else {
720 NOTIMPLEMENTED();
721 }
722 FilePath flag_file(StringPrintf(kIPFlagTemplate, ip_version.c_str(),
723 link_name_.c_str(), flag.c_str()));
Ben Chanfad4a0b2012-04-18 15:49:59 -0700724 SLOG(Device, 2) << "Writing " << value << " to flag file "
725 << flag_file.value();
Ben Chan6fbf64f2014-05-21 18:07:01 -0700726 if (base::WriteFile(flag_file, value.c_str(), value.length()) != 1) {
Paul Stewart2bf1d352011-12-06 15:02:55 -0800727 LOG(ERROR) << StringPrintf("IP flag write failed: %s to %s",
728 value.c_str(), flag_file.value().c_str());
729 return false;
730 }
731 return true;
732}
733
Paul Stewartc6fbad92013-11-13 14:50:52 -0800734string Device::PerformTDLSOperation(const string &/* operation */,
735 const string &/* peer */,
736 Error */* error */) {
737 return "";
738}
739
Paul Stewart6ff27f52012-07-11 06:51:41 -0700740void Device::ResetByteCounters() {
741 manager_->device_info()->GetByteCounts(
742 interface_index_, &receive_byte_offset_, &transmit_byte_offset_);
743 manager_->UpdateDevice(this);
744}
745
Paul Stewartd215af62012-04-24 23:25:50 -0700746bool Device::RestartPortalDetection() {
747 StopPortalDetection();
748 return StartPortalDetection();
749}
750
Paul Stewartc681fa02012-03-02 19:40:04 -0800751bool Device::RequestPortalDetection() {
752 if (!selected_service_) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700753 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800754 << ": No selected service, so no need for portal check.";
755 return false;
756 }
757
758 if (!connection_.get()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700759 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800760 << ": No connection, so no need for portal check.";
761 return false;
762 }
763
764 if (selected_service_->state() != Service::kStatePortal) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700765 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800766 << ": Service is not in portal state. No need to start check.";
767 return false;
768 }
769
770 if (!connection_->is_default()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700771 SLOG(Device, 2) << FriendlyName()
Paul Stewartc681fa02012-03-02 19:40:04 -0800772 << ": Service is not the default connection. Don't start check.";
773 return false;
774 }
775
776 if (portal_detector_.get() && portal_detector_->IsInProgress()) {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700777 SLOG(Device, 2) << FriendlyName()
778 << ": Portal detection is already running.";
Paul Stewartc681fa02012-03-02 19:40:04 -0800779 return true;
780 }
781
782 return StartPortalDetection();
783}
784
Paul Stewart20088d82012-02-16 06:58:55 -0800785bool Device::StartPortalDetection() {
Darin Petkov457728b2013-01-09 09:49:08 +0100786 DCHECK(selected_service_);
Paul Stewartd215af62012-04-24 23:25:50 -0700787 if (selected_service_->IsPortalDetectionDisabled()) {
Darin Petkov457728b2013-01-09 09:49:08 +0100788 SLOG(Device, 2) << "Service " << selected_service_->unique_name()
Paul Stewartd215af62012-04-24 23:25:50 -0700789 << ": Portal detection is disabled; "
790 << "marking service online.";
791 SetServiceConnectedState(Service::kStateOnline);
792 return false;
793 }
794
795 if (selected_service_->IsPortalDetectionAuto() &&
796 !manager_->IsPortalDetectionEnabled(technology())) {
Paul Stewart20088d82012-02-16 06:58:55 -0800797 // If portal detection is disabled for this technology, immediately set
798 // the service state to "Online".
Ben Chanfad4a0b2012-04-18 15:49:59 -0700799 SLOG(Device, 2) << "Device " << FriendlyName()
800 << ": Portal detection is disabled; "
801 << "marking service online.";
Paul Stewart20088d82012-02-16 06:58:55 -0800802 SetServiceConnectedState(Service::kStateOnline);
803 return false;
804 }
805
Paul Stewart20088d82012-02-16 06:58:55 -0800806 if (selected_service_->HasProxyConfig()) {
807 // Services with HTTP proxy configurations should not be checked by the
808 // connection manager, since we don't have the ability to evaluate
809 // arbitrary proxy configs and their possible credentials.
Ben Chanfad4a0b2012-04-18 15:49:59 -0700810 SLOG(Device, 2) << "Device " << FriendlyName()
811 << ": Service has proxy config; marking it online.";
Paul Stewart20088d82012-02-16 06:58:55 -0800812 SetServiceConnectedState(Service::kStateOnline);
813 return false;
814 }
815
816 portal_detector_.reset(new PortalDetector(connection_,
817 dispatcher_,
Eric Shienbrood3e20a232012-02-16 11:35:56 -0500818 portal_detector_callback_));
Paul Stewart20088d82012-02-16 06:58:55 -0800819 if (!portal_detector_->Start(manager_->GetPortalCheckURL())) {
820 LOG(ERROR) << "Device " << FriendlyName()
821 << ": Portal detection failed to start: likely bad URL: "
822 << manager_->GetPortalCheckURL();
823 SetServiceConnectedState(Service::kStateOnline);
824 return false;
825 }
826
Ben Chanfad4a0b2012-04-18 15:49:59 -0700827 SLOG(Device, 2) << "Device " << FriendlyName()
828 << ": Portal detection has started.";
Paul Stewart20088d82012-02-16 06:58:55 -0800829 return true;
830}
831
832void Device::StopPortalDetection() {
Ben Chanfad4a0b2012-04-18 15:49:59 -0700833 SLOG(Device, 2) << "Device " << FriendlyName()
mukesh agrawalbb2231c2013-07-17 16:32:24 -0700834 << ": Portal detection stopping.";
Paul Stewart20088d82012-02-16 06:58:55 -0800835 portal_detector_.reset();
836}
837
Paul Stewart036dba02012-08-07 12:34:41 -0700838void Device::set_link_monitor(LinkMonitor *link_monitor) {
839 link_monitor_.reset(link_monitor);
840}
841
842bool Device::StartLinkMonitor() {
843 if (!manager_->IsTechnologyLinkMonitorEnabled(technology())) {
844 SLOG(Device, 2) << "Device " << FriendlyName()
845 << ": Link Monitoring is disabled.";
846 return false;
847 }
848
849 if (!link_monitor()) {
850 set_link_monitor(
851 new LinkMonitor(
852 connection_, dispatcher_, metrics(), manager_->device_info(),
Peter Qiub5d124f2014-04-14 12:05:02 -0700853 Bind(&Device::OnLinkMonitorFailure, weak_ptr_factory_.GetWeakPtr()),
854 Bind(&Device::OnLinkMonitorGatewayChange,
855 weak_ptr_factory_.GetWeakPtr())));
Paul Stewart036dba02012-08-07 12:34:41 -0700856 }
857
858 SLOG(Device, 2) << "Device " << FriendlyName()
859 << ": Link Monitor starting.";
860 return link_monitor_->Start();
861}
862
863void Device::StopLinkMonitor() {
864 SLOG(Device, 2) << "Device " << FriendlyName()
865 << ": Link Monitor stopping.";
866 link_monitor_.reset();
867}
868
869void Device::OnLinkMonitorFailure() {
870 LOG(ERROR) << "Device " << FriendlyName()
871 << ": Link Monitor indicates failure.";
872}
873
Peter Qiu9d581932014-04-14 16:37:37 -0700874void Device::OnLinkMonitorGatewayChange() {
875 string gateway_mac = link_monitor()->gateway_mac_address().HexEncode();
876 int connection_id = manager_->CalcConnectionId(
877 ipconfig_->properties().gateway, gateway_mac);
878
879 CHECK(selected_service_);
880 selected_service_->set_connection_id(connection_id);
881
882 manager_->ReportServicesOnSameNetwork(connection_id);
883}
884
Peter Qiu6f5618b2014-06-05 15:19:01 -0700885bool Device::StartDNSTest(
886 const vector<string> &dns_servers,
887 bool retry_until_success,
888 const Callback<void(const DNSServerTester::Status)> &callback) {
889 if (dns_server_tester_.get()) {
890 LOG(ERROR) << FriendlyName() << ": "
891 << "Failed to start DNS Test: current test still running";
892 return false;
Peter Qiub9256f32014-05-09 15:27:29 -0700893 }
894
Peter Qiu6f5618b2014-06-05 15:19:01 -0700895 dns_server_tester_.reset(new DNSServerTester(connection_,
896 dispatcher_,
897 dns_servers,
898 retry_until_success,
899 callback));
900 dns_server_tester_->Start();
901 return true;
902}
903
904void Device::StopDNSTest() {
905 dns_server_tester_.reset();
Peter Qiub9256f32014-05-09 15:27:29 -0700906}
907
Peter Qiud670d032014-06-03 15:04:43 -0700908void Device::FallbackDNSResultCallback(const DNSServerTester::Status status) {
Peter Qiu6f5618b2014-06-05 15:19:01 -0700909 StopDNSTest();
Peter Qiuf18e7712014-05-20 09:59:46 -0700910 int result = Metrics::kFallbackDNSTestResultFailure;
Peter Qiud670d032014-06-03 15:04:43 -0700911 if (status == DNSServerTester::kStatusSuccess) {
Peter Qiuf18e7712014-05-20 09:59:46 -0700912 result = Metrics::kFallbackDNSTestResultSuccess;
Peter Qiua89154b2014-05-23 15:45:42 -0700913
914 // Switch to fallback DNS server if service is configured to allow DNS
915 // fallback.
916 CHECK(selected_service_);
917 if (selected_service_->is_dns_auto_fallback_allowed()) {
Peter Qiu6f5618b2014-06-05 15:19:01 -0700918 LOG(INFO) << "Device " << FriendlyName()
919 << ": Switching to fallback DNS servers.";
920 // Save the DNS servers from ipconfig.
921 config_dns_servers_ = ipconfig_->properties().dns_servers;
Peter Qiua89154b2014-05-23 15:45:42 -0700922 SwitchDNSServers(vector<string>(std::begin(kFallbackDnsServers),
923 std::end(kFallbackDnsServers)));
Peter Qiu6f5618b2014-06-05 15:19:01 -0700924 // Start DNS test for configured DNS servers.
925 StartDNSTest(config_dns_servers_,
926 true,
927 Bind(&Device::ConfigDNSResultCallback,
928 weak_ptr_factory_.GetWeakPtr()));
Peter Qiua89154b2014-05-23 15:45:42 -0700929 }
Peter Qiub9256f32014-05-09 15:27:29 -0700930 }
Peter Qiuf18e7712014-05-20 09:59:46 -0700931 metrics()->NotifyFallbackDNSTestResult(technology_, result);
Peter Qiu6f5618b2014-06-05 15:19:01 -0700932}
933
934void Device::ConfigDNSResultCallback(const DNSServerTester::Status status) {
935 StopDNSTest();
936 // DNS test failed to start due to internal error.
937 if (status == DNSServerTester::kStatusFailure) {
938 return;
939 }
940
941 // Switch back to the configured DNS servers.
942 LOG(INFO) << "Device " << FriendlyName()
943 << ": Switching back to configured DNS servers.";
944 SwitchDNSServers(config_dns_servers_);
Peter Qiub9256f32014-05-09 15:27:29 -0700945}
946
Peter Qiua89154b2014-05-23 15:45:42 -0700947void Device::SwitchDNSServers(const vector<string> &dns_servers) {
948 CHECK(ipconfig_);
949 CHECK(connection_);
950 // Push new DNS servers setting to the IP config object.
951 ipconfig_->UpdateDNSServers(dns_servers);
952 // Push new DNS servers setting to the current connection, so the resolver
953 // will be updated to use the new DNS servers.
954 connection_->UpdateDNSServers(dns_servers);
955 // Allow the service to notify Chrome of ipconfig changes.
956 selected_service_->NotifyIPConfigChanges();
Peter Qiu6f5618b2014-06-05 15:19:01 -0700957 // Restart the portal detection with the new DNS setting.
958 RestartPortalDetection();
Peter Qiua89154b2014-05-23 15:45:42 -0700959}
960
Peter Qiudc335f82014-05-15 10:33:17 -0700961void Device::set_traffic_monitor(TrafficMonitor *traffic_monitor) {
962 traffic_monitor_.reset(traffic_monitor);
963}
964
965bool Device::IsTrafficMonitorEnabled() const {
966 return false;
967}
968
969void Device::StartTrafficMonitor() {
970 // Return if traffic monitor is not enabled for this device.
971 if (!IsTrafficMonitorEnabled()) {
972 return;
973 }
974
975 SLOG(Device, 2) << "Device " << FriendlyName()
976 << ": Traffic Monitor starting.";
977 if (!traffic_monitor_.get()) {
978 traffic_monitor_.reset(new TrafficMonitor(this, dispatcher_));
979 traffic_monitor_->set_network_problem_detected_callback(
980 Bind(&Device::OnEncounterNetworkProblem,
981 weak_ptr_factory_.GetWeakPtr()));
982 }
983 traffic_monitor_->Start();
984}
985
986void Device::StopTrafficMonitor() {
987 // Return if traffic monitor is not enabled for this device.
988 if (!IsTrafficMonitorEnabled()) {
989 return;
990 }
991
992 if (traffic_monitor_.get()) {
993 SLOG(Device, 2) << "Device " << FriendlyName()
994 << ": Traffic Monitor stopping.";
995 traffic_monitor_->Stop();
996 }
997 traffic_monitor_.reset();
998}
999
1000void Device::OnEncounterNetworkProblem(int reason) {
1001 int metric_code;
1002 switch (reason) {
1003 case TrafficMonitor::kNetworkProblemCongestedTxQueue:
1004 metric_code = Metrics::kNetworkProblemCongestedTCPTxQueue;
1005 break;
1006 case TrafficMonitor::kNetworkProblemDNSFailure:
1007 metric_code = Metrics::kNetworkProblemDNSFailure;
1008 break;
1009 default:
1010 LOG(ERROR) << "Invalid network problem code: " << reason;
1011 return;
1012 }
1013
1014 metrics()->NotifyNetworkProblemDetected(technology_, metric_code);
1015 // Stop the traffic monitor, only report the first network problem detected
1016 // on the connection for now.
1017 StopTrafficMonitor();
1018}
1019
Paul Stewart20088d82012-02-16 06:58:55 -08001020void Device::SetServiceConnectedState(Service::ConnectState state) {
1021 DCHECK(selected_service_.get());
1022
1023 if (!selected_service_.get()) {
1024 LOG(ERROR) << FriendlyName() << ": "
1025 << "Portal detection completed but no selected service exists!";
1026 return;
1027 }
1028
1029 if (!selected_service_->IsConnected()) {
1030 LOG(ERROR) << FriendlyName() << ": "
1031 << "Portal detection completed but selected service "
Darin Petkov457728b2013-01-09 09:49:08 +01001032 << selected_service_->unique_name()
Paul Stewart20088d82012-02-16 06:58:55 -08001033 << " is in non-connected state.";
1034 return;
1035 }
1036
Paul Stewartc681fa02012-03-02 19:40:04 -08001037 if (state == Service::kStatePortal && connection_->is_default() &&
1038 manager_->GetPortalCheckInterval() != 0) {
1039 CHECK(portal_detector_.get());
1040 if (!portal_detector_->StartAfterDelay(
1041 manager_->GetPortalCheckURL(),
1042 manager_->GetPortalCheckInterval())) {
1043 LOG(ERROR) << "Device " << FriendlyName()
1044 << ": Portal detection failed to restart: likely bad URL: "
1045 << manager_->GetPortalCheckURL();
1046 SetServiceState(Service::kStateOnline);
1047 portal_detector_.reset();
1048 return;
1049 }
Ben Chanfad4a0b2012-04-18 15:49:59 -07001050 SLOG(Device, 2) << "Device " << FriendlyName()
1051 << ": Portal detection retrying.";
Paul Stewartc681fa02012-03-02 19:40:04 -08001052 } else {
Ben Chanfad4a0b2012-04-18 15:49:59 -07001053 SLOG(Device, 2) << "Device " << FriendlyName()
1054 << ": Portal will not retry.";
Paul Stewartc681fa02012-03-02 19:40:04 -08001055 portal_detector_.reset();
1056 }
1057
Paul Stewart20088d82012-02-16 06:58:55 -08001058 SetServiceState(state);
1059}
1060
1061void Device::PortalDetectorCallback(const PortalDetector::Result &result) {
1062 if (!result.final) {
Ben Chanfad4a0b2012-04-18 15:49:59 -07001063 SLOG(Device, 2) << "Device " << FriendlyName()
1064 << ": Received non-final status: "
1065 << PortalDetector::StatusToString(result.status);
Paul Stewart20088d82012-02-16 06:58:55 -08001066 return;
1067 }
1068
Ben Chanfad4a0b2012-04-18 15:49:59 -07001069 SLOG(Device, 2) << "Device " << FriendlyName()
1070 << ": Received final status: "
1071 << PortalDetector::StatusToString(result.status);
Paul Stewart20088d82012-02-16 06:58:55 -08001072
Thieu Le85e050b2012-03-13 15:04:38 -07001073 portal_attempts_to_online_ += result.num_attempts;
1074
Peter Qiub9256f32014-05-09 15:27:29 -07001075 int portal_status = Metrics::PortalDetectionResultToEnum(result);
Thieu Le85e050b2012-03-13 15:04:38 -07001076 metrics()->SendEnumToUMA(
mukesh agrawal132e96f2014-04-24 11:49:42 -07001077 metrics()->GetFullMetricName(Metrics::kMetricPortalResultSuffix,
1078 technology()),
Peter Qiub9256f32014-05-09 15:27:29 -07001079 portal_status,
Thieu Le85e050b2012-03-13 15:04:38 -07001080 Metrics::kPortalResultMax);
1081
Paul Stewart20088d82012-02-16 06:58:55 -08001082 if (result.status == PortalDetector::kStatusSuccess) {
1083 SetServiceConnectedState(Service::kStateOnline);
Thieu Le85e050b2012-03-13 15:04:38 -07001084
1085 metrics()->SendToUMA(
1086 metrics()->GetFullMetricName(
mukesh agrawal132e96f2014-04-24 11:49:42 -07001087 Metrics::kMetricPortalAttemptsToOnlineSuffix, technology()),
Thieu Le85e050b2012-03-13 15:04:38 -07001088 portal_attempts_to_online_,
1089 Metrics::kMetricPortalAttemptsToOnlineMin,
1090 Metrics::kMetricPortalAttemptsToOnlineMax,
1091 Metrics::kMetricPortalAttemptsToOnlineNumBuckets);
Paul Stewart20088d82012-02-16 06:58:55 -08001092 } else {
1093 SetServiceConnectedState(Service::kStatePortal);
Thieu Le85e050b2012-03-13 15:04:38 -07001094
1095 metrics()->SendToUMA(
1096 metrics()->GetFullMetricName(
mukesh agrawal132e96f2014-04-24 11:49:42 -07001097 Metrics::kMetricPortalAttemptsSuffix, technology()),
Thieu Le85e050b2012-03-13 15:04:38 -07001098 result.num_attempts,
1099 Metrics::kMetricPortalAttemptsMin,
1100 Metrics::kMetricPortalAttemptsMax,
1101 Metrics::kMetricPortalAttemptsNumBuckets);
Peter Qiub9256f32014-05-09 15:27:29 -07001102
1103 // Perform fallback DNS test if the portal failure is DNS related.
1104 // The test will send a DNS request to Google's DNS server to determine
1105 // if the DNS failure is due to bad DNS server settings.
1106 if ((portal_status == Metrics::kPortalResultDNSFailure) ||
1107 (portal_status == Metrics::kPortalResultDNSTimeout)) {
Peter Qiu6f5618b2014-06-05 15:19:01 -07001108 StartDNSTest(vector<string>(std::begin(kFallbackDnsServers),
1109 std::end(kFallbackDnsServers)),
1110 false,
1111 Bind(&Device::FallbackDNSResultCallback,
1112 weak_ptr_factory_.GetWeakPtr()));
Peter Qiub9256f32014-05-09 15:27:29 -07001113 }
Paul Stewart20088d82012-02-16 06:58:55 -08001114 }
1115}
1116
Gaurav Shah1b7a6162011-11-09 11:41:01 -08001117vector<string> Device::AvailableIPConfigs(Error */*error*/) {
Paul Stewartd4f26482014-04-25 19:12:03 -07001118 vector<string> ipconfigs;
1119 if (ipconfig_) {
1120 ipconfigs.push_back(ipconfig_->GetRpcIdentifier());
Jason Glasgow08afdff2012-04-03 10:22:26 -04001121 }
Paul Stewartd4f26482014-04-25 19:12:03 -07001122 if (ip6config_) {
1123 ipconfigs.push_back(ip6config_->GetRpcIdentifier());
1124 }
1125 return ipconfigs;
Chris Masone4e851612011-07-01 10:46:53 -07001126}
1127
1128string Device::GetRpcConnectionIdentifier() {
1129 return adaptor_->GetRpcConnectionIdentifier();
1130}
1131
Paul Stewart036dba02012-08-07 12:34:41 -07001132uint64 Device::GetLinkMonitorResponseTime(Error *error) {
1133 if (!link_monitor_.get()) {
1134 // It is not strictly an error that the link monitor does not
1135 // exist, but returning an error here allows the GetProperties
1136 // call in our Adaptor to omit this parameter.
1137 error->Populate(Error::kNotFound, "Device is not running LinkMonitor");
1138 return 0;
1139 }
1140 return link_monitor_->GetResponseTimeMilliseconds();
1141}
1142
Ben Chanb061f892013-02-27 17:46:55 -08001143uint64 Device::GetReceiveByteCount() {
Paul Stewart6ff27f52012-07-11 06:51:41 -07001144 uint64 rx_byte_count = 0, tx_byte_count = 0;
1145 manager_->device_info()->GetByteCounts(
1146 interface_index_, &rx_byte_count, &tx_byte_count);
1147 return rx_byte_count - receive_byte_offset_;
1148}
1149
Ben Chanb061f892013-02-27 17:46:55 -08001150uint64 Device::GetTransmitByteCount() {
Paul Stewart6ff27f52012-07-11 06:51:41 -07001151 uint64 rx_byte_count = 0, tx_byte_count = 0;
1152 manager_->device_info()->GetByteCounts(
1153 interface_index_, &rx_byte_count, &tx_byte_count);
1154 return tx_byte_count - transmit_byte_offset_;
1155}
1156
Ben Chanb061f892013-02-27 17:46:55 -08001157uint64 Device::GetReceiveByteCountProperty(Error */*error*/) {
1158 return GetReceiveByteCount();
1159}
1160
1161uint64 Device::GetTransmitByteCountProperty(Error */*error*/) {
1162 return GetTransmitByteCount();
1163}
1164
Eric Shienbrood7fce52c2012-04-13 19:11:02 -04001165bool Device::IsUnderlyingDeviceEnabled() const {
1166 return false;
1167}
1168
Eric Shienbrood9a245532012-03-07 14:20:39 -05001169// callback
1170void Device::OnEnabledStateChanged(const ResultCallback &callback,
1171 const Error &error) {
mukesh agrawal46c27cc2013-07-10 16:39:10 -07001172 SLOG(Device, 2) << __func__
1173 << " (target: " << enabled_pending_ << ","
1174 << " success: " << error.IsSuccess() << ")"
1175 << " on " << link_name_;
Eric Shienbrood9a245532012-03-07 14:20:39 -05001176 if (error.IsSuccess()) {
1177 enabled_ = enabled_pending_;
1178 manager_->UpdateEnabledTechnologies();
Ben Chan923a5022013-09-20 11:23:23 -07001179 adaptor_->EmitBoolChanged(kPoweredProperty, enabled_);
Eric Shienbrood9a245532012-03-07 14:20:39 -05001180 }
Gary Morainbaeefdf2012-04-30 14:53:35 -07001181 enabled_pending_ = enabled_;
Eric Shienbrood9a245532012-03-07 14:20:39 -05001182 if (!callback.is_null())
1183 callback.Run(error);
1184}
1185
1186void Device::SetEnabled(bool enable) {
Ben Chanfad4a0b2012-04-18 15:49:59 -07001187 SLOG(Device, 2) << __func__ << "(" << enable << ")";
Jason Glasgow4a490792012-04-10 15:02:05 -04001188 Error error;
mukesh agrawal28185512013-10-18 16:57:09 -07001189 SetEnabledChecked(enable, false, &error, ResultCallback());
Arman Uguray8bf6a5c2013-08-12 14:18:03 -07001190
1191 // SetEnabledInternal might fail here if there is an unfinished enable or
1192 // disable operation. Don't log error in this case, as this method is only
1193 // called when the underlying device is already in the target state and the
1194 // pending operation should eventually bring the device to the expected
1195 // state.
1196 LOG_IF(ERROR,
1197 error.IsFailure() &&
1198 !error.IsOngoing() &&
1199 error.type() != Error::kInProgress)
Jason Glasgow4a490792012-04-10 15:02:05 -04001200 << "Enabled failed, but no way to report the failure.";
Eric Shienbrood9a245532012-03-07 14:20:39 -05001201}
1202
Ben Chan9f3dcf82013-09-25 18:04:58 -07001203void Device::SetEnabledNonPersistent(bool enable,
1204 Error *error,
1205 const ResultCallback &callback) {
mukesh agrawal28185512013-10-18 16:57:09 -07001206 SetEnabledChecked(enable, false, error, callback);
Ben Chan9f3dcf82013-09-25 18:04:58 -07001207}
1208
Eric Shienbrood9a245532012-03-07 14:20:39 -05001209void Device::SetEnabledPersistent(bool enable,
1210 Error *error,
1211 const ResultCallback &callback) {
mukesh agrawal28185512013-10-18 16:57:09 -07001212 SetEnabledChecked(enable, true, error, callback);
Eric Shienbrood9a245532012-03-07 14:20:39 -05001213}
1214
mukesh agrawal28185512013-10-18 16:57:09 -07001215void Device::SetEnabledChecked(bool enable,
1216 bool persist,
1217 Error *error,
1218 const ResultCallback &callback) {
Jason Glasgow4a490792012-04-10 15:02:05 -04001219 DCHECK(error);
Ben Chanfad4a0b2012-04-18 15:49:59 -07001220 SLOG(Device, 2) << "Device " << link_name_ << " "
1221 << (enable ? "starting" : "stopping");
Eric Shienbrood9a245532012-03-07 14:20:39 -05001222 if (enable == enabled_) {
Arman Uguray2f352e62013-08-28 19:12:53 -07001223 if (enable != enabled_pending_ && persist) {
1224 // Return an error, as there is an ongoing operation to achieve the
1225 // opposite.
1226 Error::PopulateAndLog(
1227 error, Error::kOperationFailed,
1228 enable ? "Cannot enable while the device is disabling." :
1229 "Cannot disable while the device is enabling.");
1230 return;
1231 }
mukesh agrawal28185512013-10-18 16:57:09 -07001232 LOG(INFO) << "Already in desired enable state.";
Jason Glasgow4a490792012-04-10 15:02:05 -04001233 error->Reset();
Eric Shienbrood9a245532012-03-07 14:20:39 -05001234 return;
1235 }
1236
1237 if (enabled_pending_ == enable) {
Jason Glasgow4a490792012-04-10 15:02:05 -04001238 Error::PopulateAndLog(error, Error::kInProgress,
1239 "Enable operation already in progress");
Eric Shienbrood9a245532012-03-07 14:20:39 -05001240 return;
1241 }
1242
1243 if (persist) {
1244 enabled_persistent_ = enable;
Darin Petkove7c6ad32012-06-29 10:22:09 +02001245 manager_->UpdateDevice(this);
Eric Shienbrood9a245532012-03-07 14:20:39 -05001246 }
1247
mukesh agrawal28185512013-10-18 16:57:09 -07001248 SetEnabledUnchecked(enable, error, callback);
1249}
1250
1251void Device::SetEnabledUnchecked(bool enable, Error *error,
1252 const ResultCallback &on_enable_complete) {
Eric Shienbrood9a245532012-03-07 14:20:39 -05001253 enabled_pending_ = enable;
mukesh agrawal28185512013-10-18 16:57:09 -07001254 EnabledStateChangedCallback chained_callback =
Eric Shienbrood9a245532012-03-07 14:20:39 -05001255 Bind(&Device::OnEnabledStateChanged,
mukesh agrawal28185512013-10-18 16:57:09 -07001256 weak_ptr_factory_.GetWeakPtr(), on_enable_complete);
Eric Shienbrood9a245532012-03-07 14:20:39 -05001257 if (enable) {
1258 running_ = true;
mukesh agrawal28185512013-10-18 16:57:09 -07001259 Start(error, chained_callback);
Eric Shienbrood9a245532012-03-07 14:20:39 -05001260 } else {
1261 running_ = false;
1262 DestroyIPConfig(); // breaks a reference cycle
1263 SelectService(NULL); // breaks a reference cycle
1264 rtnl_handler_->SetInterfaceFlags(interface_index(), 0, IFF_UP);
Ben Chanfad4a0b2012-04-18 15:49:59 -07001265 SLOG(Device, 3) << "Device " << link_name_ << " ipconfig_ "
1266 << (ipconfig_ ? "is set." : "is not set.");
Paul Stewartd4f26482014-04-25 19:12:03 -07001267 SLOG(Device, 3) << "Device " << link_name_ << " ip6config_ "
1268 << (ip6config_ ? "is set." : "is not set.");
Ben Chanfad4a0b2012-04-18 15:49:59 -07001269 SLOG(Device, 3) << "Device " << link_name_ << " connection_ "
1270 << (connection_ ? "is set." : "is not set.");
1271 SLOG(Device, 3) << "Device " << link_name_ << " selected_service_ "
1272 << (selected_service_ ? "is set." : "is not set.");
mukesh agrawal28185512013-10-18 16:57:09 -07001273 Stop(error, chained_callback);
Eric Shienbrood9a245532012-03-07 14:20:39 -05001274 }
1275}
1276
Paul Stewartd4f26482014-04-25 19:12:03 -07001277void Device::UpdateIPConfigsProperty() {
1278 adaptor_->EmitRpcIdentifierArrayChanged(
1279 kIPConfigsProperty, AvailableIPConfigs(NULL));
1280}
1281
Paul Stewart75897df2011-04-27 09:05:53 -07001282} // namespace shill