blob: 52d270e81bc3ee97dc0fe81fea15685463319e90 [file] [log] [blame]
Paul Stewart75897df2011-04-27 09:05:53 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// 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
Paul Stewart2bf1d352011-12-06 15:02:55 -080015#include <base/file_util.h>
Chris Masoneee929b72011-05-10 10:02:18 -070016#include <base/logging.h>
Chris Masone487b8bf2011-05-13 16:27:57 -070017#include <base/memory/ref_counted.h>
Chris Masone5dec5f42011-07-22 14:07:55 -070018#include <base/stringprintf.h>
Chris Masone3bd3c8c2011-06-13 08:20:26 -070019#include <chromeos/dbus/service_constants.h>
Chris Masoneee929b72011-05-10 10:02:18 -070020
Paul Stewarte6132022011-08-16 09:11:02 -070021#include "shill/connection.h"
Paul Stewart75897df2011-04-27 09:05:53 -070022#include "shill/control_interface.h"
Chris Masoned7732e42011-05-20 11:08:56 -070023#include "shill/device_dbus_adaptor.h"
Chris Masone2b105542011-06-22 10:58:09 -070024#include "shill/dhcp_config.h"
Darin Petkovafa6fc42011-06-21 16:21:08 -070025#include "shill/dhcp_provider.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070026#include "shill/error.h"
Paul Stewart26b327e2011-10-19 11:38:09 -070027#include "shill/event_dispatcher.h"
Paul Stewartf65320c2011-10-13 14:34:52 -070028#include "shill/http_proxy.h"
Chris Masone8fe2c7e2011-06-09 15:51:19 -070029#include "shill/manager.h"
Chris Masone95207da2011-06-29 16:50:49 -070030#include "shill/property_accessor.h"
Chris Masone2b105542011-06-22 10:58:09 -070031#include "shill/refptr_types.h"
Paul Stewartc39f1132011-06-22 12:02:28 -070032#include "shill/rtnl_handler.h"
Chris Masone2b105542011-06-22 10:58:09 -070033#include "shill/service.h"
Chris Masone5dec5f42011-07-22 14:07:55 -070034#include "shill/store_interface.h"
Gaurav Shah435de2c2011-11-17 19:01:07 -080035#include "shill/technology.h"
Paul Stewart75897df2011-04-27 09:05:53 -070036
Chris Masone5dec5f42011-07-22 14:07:55 -070037using base::StringPrintf;
Chris Masone8fe2c7e2011-06-09 15:51:19 -070038using std::string;
39using std::vector;
40
Paul Stewart75897df2011-04-27 09:05:53 -070041namespace shill {
Chris Masone5dec5f42011-07-22 14:07:55 -070042
43// static
Paul Stewart2bf1d352011-12-06 15:02:55 -080044const char Device::kIPFlagTemplate[] = "/proc/sys/net/%s/conf/%s/%s";
45// static
46const char Device::kIPFlagVersion4[] = "ipv4";
47// static
48const char Device::kIPFlagVersion6[] = "ipv6";
49// static
50const char Device::kIPFlagDisableIPv6[] = "disable_ipv6";
51// static
52const char Device::kIPFlagUseTempAddr[] = "use_tempaddr";
53// static
54const char Device::kIPFlagUseTempAddrUsedAndDefault[] = "2";
55
56// static
Chris Masone5dec5f42011-07-22 14:07:55 -070057const char Device::kStoragePowered[] = "Powered";
58
59// static
60const char Device::kStorageIPConfigs[] = "IPConfigs";
61
Paul Stewart75897df2011-04-27 09:05:53 -070062Device::Device(ControlInterface *control_interface,
Paul Stewartb50f0b92011-05-16 16:31:42 -070063 EventDispatcher *dispatcher,
Paul Stewartf1ce5d22011-05-19 13:10:20 -070064 Manager *manager,
Darin Petkovafa6fc42011-06-21 16:21:08 -070065 const string &link_name,
Chris Masone626719f2011-08-18 16:58:48 -070066 const string &address,
Gaurav Shah435de2c2011-11-17 19:01:07 -080067 int interface_index,
68 Technology::Identifier technology)
Chris Masone853b81b2011-06-24 14:11:41 -070069 : powered_(true),
Chris Masoneb925cc82011-06-22 15:39:57 -070070 reconnect_(true),
Chris Masone626719f2011-08-18 16:58:48 -070071 hardware_address_(address),
mukesh agrawalf60e4062011-05-27 13:13:41 -070072 interface_index_(interface_index),
73 running_(false),
Darin Petkovafa6fc42011-06-21 16:21:08 -070074 link_name_(link_name),
Chris Masone19e30402011-07-19 15:48:47 -070075 unique_id_(link_name),
Darin Petkovd9661952011-08-03 16:25:42 -070076 control_interface_(control_interface),
77 dispatcher_(dispatcher),
Chris Masone7df0c672011-07-15 10:24:54 -070078 manager_(manager),
Darin Petkov77cb6812011-08-15 16:19:41 -070079 adaptor_(control_interface->CreateDeviceAdaptor(this)),
Gaurav Shah435de2c2011-11-17 19:01:07 -080080 technology_(technology),
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -070081 dhcp_provider_(DHCPProvider::GetInstance()),
82 rtnl_handler_(RTNLHandler::GetInstance()) {
Chris Masone27c4aa52011-07-02 13:10:14 -070083 store_.RegisterConstString(flimflam::kAddressProperty, &hardware_address_);
Chris Masone4d42df82011-07-02 17:09:39 -070084
85 // flimflam::kBgscanMethodProperty: Registered in WiFi
86 // flimflam::kBgscanShortIntervalProperty: Registered in WiFi
87 // flimflam::kBgscanSignalThresholdProperty: Registered in WiFi
88
89 // flimflam::kCellularAllowRoamingProperty: Registered in Cellular
90 // flimflam::kCarrierProperty: Registered in Cellular
91 // flimflam::kEsnProperty: Registered in Cellular
Darin Petkov3335b372011-08-22 11:05:32 -070092 // flimflam::kHomeProviderProperty: Registered in Cellular
Chris Masone4d42df82011-07-02 17:09:39 -070093 // flimflam::kImeiProperty: Registered in Cellular
94 // flimflam::kImsiProperty: Registered in Cellular
95 // flimflam::kManufacturerProperty: Registered in Cellular
96 // flimflam::kMdnProperty: Registered in Cellular
97 // flimflam::kMeidProperty: Registered in Cellular
98 // flimflam::kMinProperty: Registered in Cellular
99 // flimflam::kModelIDProperty: Registered in Cellular
100 // flimflam::kFirmwareRevisionProperty: Registered in Cellular
101 // flimflam::kHardwareRevisionProperty: Registered in Cellular
102 // flimflam::kPRLVersionProperty: Registered in Cellular
103 // flimflam::kSIMLockStatusProperty: Registered in Cellular
104 // flimflam::kFoundNetworksProperty: Registered in Cellular
Darin Petkove9d12e02011-07-27 15:09:37 -0700105 // flimflam::kDBusConnectionProperty: Registered in Cellular
106 // flimflam::kDBusObjectProperty: Register in Cellular
Chris Masone4d42df82011-07-02 17:09:39 -0700107
Chris Masoneb925cc82011-06-22 15:39:57 -0700108 // TODO(cmasone): Chrome doesn't use this...does anyone?
Chris Masone27c4aa52011-07-02 13:10:14 -0700109 // store_.RegisterConstString(flimflam::kInterfaceProperty, &link_name_);
110 HelpRegisterDerivedStrings(flimflam::kIPConfigsProperty,
111 &Device::AvailableIPConfigs,
112 NULL);
113 store_.RegisterConstString(flimflam::kNameProperty, &link_name_);
114 store_.RegisterBool(flimflam::kPoweredProperty, &powered_);
Chris Masoneb925cc82011-06-22 15:39:57 -0700115 // TODO(cmasone): Chrome doesn't use this...does anyone?
Chris Masone27c4aa52011-07-02 13:10:14 -0700116 // store_.RegisterConstBool(flimflam::kReconnectProperty, &reconnect_);
Chris Masoneb925cc82011-06-22 15:39:57 -0700117
Chris Masone4e851612011-07-01 10:46:53 -0700118 // TODO(cmasone): Figure out what shill concept maps to flimflam's "Network".
Chris Masoneb925cc82011-06-22 15:39:57 -0700119 // known_properties_.push_back(flimflam::kNetworksProperty);
120
Chris Masone4d42df82011-07-02 17:09:39 -0700121 // flimflam::kScanningProperty: Registered in WiFi, Cellular
122 // flimflam::kScanIntervalProperty: Registered in WiFi, Cellular
123
124 // TODO(pstew): Initialize Interface monitor, so we can detect new interfaces
Paul Stewartb50f0b92011-05-16 16:31:42 -0700125 VLOG(2) << "Device " << link_name_ << " index " << interface_index;
Paul Stewart75897df2011-04-27 09:05:53 -0700126}
127
128Device::~Device() {
Paul Stewartb50f0b92011-05-16 16:31:42 -0700129 VLOG(2) << "Device " << link_name_ << " destroyed.";
Paul Stewart75897df2011-04-27 09:05:53 -0700130}
131
132void Device::Start() {
133 running_ = true;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700134 VLOG(2) << "Device " << link_name_ << " starting.";
Chris Masone413a3192011-05-09 17:10:05 -0700135 adaptor_->UpdateEnabled();
Paul Stewart75897df2011-04-27 09:05:53 -0700136}
137
138void Device::Stop() {
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700139 VLOG(2) << "Device " << link_name_ << " stopping.";
Paul Stewart75897df2011-04-27 09:05:53 -0700140 running_ = false;
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700141 DestroyIPConfig(); // breaks a reference cycle
142 SelectService(NULL); // breaks a reference cycle
Chris Masone413a3192011-05-09 17:10:05 -0700143 adaptor_->UpdateEnabled();
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700144 rtnl_handler_->SetInterfaceFlags(interface_index(), 0, IFF_UP);
145
mukesh agrawal5c4dd0b2011-09-14 13:53:14 -0700146 VLOG(3) << "Device " << link_name_ << " ipconfig_ "
147 << (ipconfig_.get() ? "is set." : "is not set.");
148 VLOG(3) << "Device " << link_name_ << " connection_ "
149 << (connection_.get() ? "is set." : "is not set.");
150 VLOG(3) << "Device " << link_name_ << " selected_service_ "
151 << (selected_service_.get() ? "is set." : "is not set.");
Paul Stewart75897df2011-04-27 09:05:53 -0700152}
153
mukesh agrawal1830fa12011-09-26 14:31:40 -0700154bool Device::TechnologyIs(const Technology::Identifier /*type*/) const {
Darin Petkovafa6fc42011-06-21 16:21:08 -0700155 return false;
156}
157
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700158void Device::LinkEvent(unsigned flags, unsigned change) {
mukesh agrawal47009f82011-08-25 14:07:35 -0700159 VLOG(2) << "Device " << link_name_
160 << std::showbase << std::hex
161 << " flags " << flags << " changed " << change
162 << std::dec << std::noshowbase;
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700163}
164
Darin Petkovc0865312011-09-16 15:31:20 -0700165void Device::Scan(Error *error) {
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700166 VLOG(2) << "Device " << link_name_ << " scan requested.";
Paul Stewartbe005172011-11-02 18:10:29 -0700167 Error::PopulateAndLog(error, Error::kNotSupported,
168 "Device doesn't support scan.");
Paul Stewartf1ce5d22011-05-19 13:10:20 -0700169}
170
mukesh agrawal1830fa12011-09-26 14:31:40 -0700171void Device::RegisterOnNetwork(const std::string &/*network_id*/,
172 Error *error) {
Paul Stewartbe005172011-11-02 18:10:29 -0700173 Error::PopulateAndLog(error, Error::kNotSupported,
174 "Device doesn't support network registration.");
Darin Petkov9ae310f2011-08-30 15:41:13 -0700175}
176
mukesh agrawal1830fa12011-09-26 14:31:40 -0700177void Device::RequirePIN(const string &/*pin*/, bool /*require*/, Error *error) {
Paul Stewartbe005172011-11-02 18:10:29 -0700178 Error::PopulateAndLog(error, Error::kNotSupported,
179 "Device doesn't support RequirePIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700180}
181
mukesh agrawal1830fa12011-09-26 14:31:40 -0700182void Device::EnterPIN(const string &/*pin*/, Error *error) {
Paul Stewartbe005172011-11-02 18:10:29 -0700183 Error::PopulateAndLog(error, Error::kNotSupported,
184 "Device doesn't support EnterPIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700185}
186
mukesh agrawal1830fa12011-09-26 14:31:40 -0700187void Device::UnblockPIN(const string &/*unblock_code*/,
188 const string &/*pin*/,
Darin Petkove42e1012011-08-31 12:35:04 -0700189 Error *error) {
Paul Stewartbe005172011-11-02 18:10:29 -0700190 Error::PopulateAndLog(error, Error::kNotSupported,
191 "Device doesn't support UnblockPIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700192}
193
mukesh agrawal1830fa12011-09-26 14:31:40 -0700194void Device::ChangePIN(const string &/*old_pin*/,
195 const string &/*new_pin*/,
Darin Petkove42e1012011-08-31 12:35:04 -0700196 Error *error) {
Paul Stewartbe005172011-11-02 18:10:29 -0700197 Error::PopulateAndLog(error, Error::kNotSupported,
198 "Device doesn't support ChangePIN.");
Darin Petkove42e1012011-08-31 12:35:04 -0700199}
200
Paul Stewart2bf1d352011-12-06 15:02:55 -0800201void Device::DisableIPv6() {
202 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagDisableIPv6, "1");
203}
204
205void Device::EnableIPv6() {
206 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagDisableIPv6, "0");
207}
208
209void Device::EnableIPv6Privacy() {
210 SetIPFlag(IPAddress::kFamilyIPv6, kIPFlagUseTempAddr,
211 kIPFlagUseTempAddrUsedAndDefault);
212}
213
Gaurav Shah435de2c2011-11-17 19:01:07 -0800214bool Device::IsConnected() const {
215 if (selected_service_)
216 return selected_service_->IsConnected();
217 return false;
218}
219
Chris Masone27c4aa52011-07-02 13:10:14 -0700220string Device::GetRpcIdentifier() {
221 return adaptor_->GetRpcIdentifier();
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700222}
223
Chris Masone5dec5f42011-07-22 14:07:55 -0700224string Device::GetStorageIdentifier() {
225 string id = GetRpcIdentifier();
226 ControlInterface::RpcIdToStorageId(&id);
Chris Masone626719f2011-08-18 16:58:48 -0700227 size_t needle = id.find('_');
Chris Masone34af2182011-08-22 11:59:36 -0700228 DLOG_IF(ERROR, needle == string::npos) << "No _ in storage id?!?!";
Chris Masone626719f2011-08-18 16:58:48 -0700229 id.replace(id.begin() + needle + 1, id.end(), hardware_address_);
Chris Masone5dec5f42011-07-22 14:07:55 -0700230 return id;
231}
232
Chris Masone19e30402011-07-19 15:48:47 -0700233const string& Device::FriendlyName() const {
Chris Masone7df0c672011-07-15 10:24:54 -0700234 return link_name_;
Darin Petkovafa6fc42011-06-21 16:21:08 -0700235}
236
Chris Masone19e30402011-07-19 15:48:47 -0700237const string& Device::UniqueName() const {
238 return unique_id_;
239}
240
Chris Masone5dec5f42011-07-22 14:07:55 -0700241bool Device::Load(StoreInterface *storage) {
242 const string id = GetStorageIdentifier();
243 if (!storage->ContainsGroup(id)) {
244 LOG(WARNING) << "Device is not available in the persistent store: " << id;
245 return false;
246 }
247 storage->GetBool(id, kStoragePowered, &powered_);
248 // TODO(cmasone): What does it mean to load an IPConfig identifier??
249 return true;
250}
251
252bool Device::Save(StoreInterface *storage) {
253 const string id = GetStorageIdentifier();
254 storage->SetBool(id, kStoragePowered, powered_);
Chris Masone34af2182011-08-22 11:59:36 -0700255 if (ipconfig_.get()) {
256 // The _0 is an index into the list of IPConfigs that this device might
257 // have. We only have one IPConfig right now, and I hope to never have
258 // to support more, as sleffler indicates that associating IPConfigs
259 // with devices is wrong and due to be changed in flimflam anyhow.
260 string suffix = hardware_address_ + "_0";
261 ipconfig_->Save(storage, suffix);
262 storage->SetString(id, kStorageIPConfigs, SerializeIPConfigs(suffix));
263 }
Chris Masone5dec5f42011-07-22 14:07:55 -0700264 return true;
265}
266
Darin Petkovafa6fc42011-06-21 16:21:08 -0700267void Device::DestroyIPConfig() {
Paul Stewart2bf1d352011-12-06 15:02:55 -0800268 DisableIPv6();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700269 if (ipconfig_.get()) {
270 ipconfig_->ReleaseIP();
271 ipconfig_ = NULL;
272 }
Paul Stewarte6132022011-08-16 09:11:02 -0700273 DestroyConnection();
Darin Petkovafa6fc42011-06-21 16:21:08 -0700274}
275
Paul Stewart2bf1d352011-12-06 15:02:55 -0800276bool Device::AcquireIPConfig() {
Darin Petkovafa6fc42011-06-21 16:21:08 -0700277 DestroyIPConfig();
Paul Stewart2bf1d352011-12-06 15:02:55 -0800278 EnableIPv6();
Darin Petkov77cb6812011-08-15 16:19:41 -0700279 ipconfig_ = dhcp_provider_->CreateConfig(link_name_);
Darin Petkovafa6fc42011-06-21 16:21:08 -0700280 ipconfig_->RegisterUpdateCallback(
281 NewCallback(this, &Device::IPConfigUpdatedCallback));
282 return ipconfig_->RequestIP();
283}
284
mukesh agrawalffa3d042011-10-06 15:26:10 -0700285void Device::HelpRegisterDerivedStrings(
286 const string &name,
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800287 Strings(Device::*get)(Error *),
mukesh agrawalffa3d042011-10-06 15:26:10 -0700288 void(Device::*set)(const Strings&, Error *)) {
Chris Masone27c4aa52011-07-02 13:10:14 -0700289 store_.RegisterDerivedStrings(
290 name,
291 StringsAccessor(new CustomAccessor<Device, Strings>(this, get, set)));
Chris Masone4e851612011-07-01 10:46:53 -0700292}
293
Chris Masone2b105542011-06-22 10:58:09 -0700294void Device::IPConfigUpdatedCallback(const IPConfigRefPtr &ipconfig,
295 bool success) {
Paul Stewarte6132022011-08-16 09:11:02 -0700296 VLOG(2) << __func__ << " " << " success: " << success;
Paul Stewartc39f1132011-06-22 12:02:28 -0700297 if (success) {
Paul Stewarte6132022011-08-16 09:11:02 -0700298 CreateConnection();
299 connection_->UpdateFromIPConfig(ipconfig);
Paul Stewart03dba0b2011-08-22 16:32:45 -0700300 SetServiceState(Service::kStateConnected);
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800301 if (selected_service_.get()) {
302 selected_service_->CreateHTTPProxy(connection_);
303 }
Paul Stewarte6132022011-08-16 09:11:02 -0700304 } else {
305 // TODO(pstew): This logic gets more complex when multiple IPConfig types
306 // are run in parallel (e.g. DHCP and DHCP6)
Paul Stewart03dba0b2011-08-22 16:32:45 -0700307 SetServiceState(Service::kStateDisconnected);
Paul Stewarte6132022011-08-16 09:11:02 -0700308 DestroyConnection();
Paul Stewartc39f1132011-06-22 12:02:28 -0700309 }
Chris Masone8fe2c7e2011-06-09 15:51:19 -0700310}
311
Paul Stewarte6132022011-08-16 09:11:02 -0700312void Device::CreateConnection() {
313 VLOG(2) << __func__;
314 if (!connection_.get()) {
Paul Stewart9a908082011-08-31 12:18:48 -0700315 connection_ = new Connection(interface_index_,
316 link_name_,
317 manager_->device_info());
Paul Stewarte6132022011-08-16 09:11:02 -0700318 }
319}
320
321void Device::DestroyConnection() {
322 VLOG(2) << __func__;
323 connection_ = NULL;
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800324 if (selected_service_.get()) {
325 selected_service_->DestroyHTTPProxy();
326 }
Paul Stewarte6132022011-08-16 09:11:02 -0700327}
328
Paul Stewart03dba0b2011-08-22 16:32:45 -0700329void Device::SelectService(const ServiceRefPtr &service) {
Paul Stewarta2b8cd12011-08-25 14:55:32 -0700330 VLOG(2) << __func__ << ": "
mukesh agrawal15908392011-11-16 18:29:25 +0000331 << (service.get() ?
332 StringPrintf("%s (%s)",
333 service->UniqueName().c_str(),
334 service->friendly_name().c_str()) :
335 "*reset*");
Paul Stewartbe5f5b32011-12-07 17:11:11 -0800336 if (selected_service_.get()) {
337 if (selected_service_->state() != Service::kStateFailure) {
338 selected_service_->SetState(Service::kStateIdle);
339 }
340 // TODO(pstew): We need to revisit the model here: should the Device
341 // subclass be responsible for calling DestroyIPConfig() (which would
342 // trigger DestroyConnection() and Service::DestroyHTTPProxy())?
343 // Ethernet does, but WiFi currently does not. crosbug.com/23929
344 selected_service_->DestroyHTTPProxy();
Paul Stewart03dba0b2011-08-22 16:32:45 -0700345 }
346 selected_service_ = service;
347}
348
349void Device::SetServiceState(Service::ConnectState state) {
350 if (selected_service_.get()) {
351 selected_service_->SetState(state);
352 }
353}
354
355void Device::SetServiceFailure(Service::ConnectFailure failure_state) {
356 if (selected_service_.get()) {
357 selected_service_->SetFailure(failure_state);
358 }
359}
360
Chris Masone34af2182011-08-22 11:59:36 -0700361string Device::SerializeIPConfigs(const string &suffix) {
362 return StringPrintf("%s:%s", suffix.c_str(), ipconfig_->type().c_str());
Chris Masone5dec5f42011-07-22 14:07:55 -0700363}
364
Paul Stewart2bf1d352011-12-06 15:02:55 -0800365bool Device::SetIPFlag(IPAddress::Family family, const string &flag,
366 const string &value) {
367 string ip_version;
368 if (family == IPAddress::kFamilyIPv4) {
369 ip_version = kIPFlagVersion4;
370 } else if (family == IPAddress::kFamilyIPv6) {
371 ip_version = kIPFlagVersion6;
372 } else {
373 NOTIMPLEMENTED();
374 }
375 FilePath flag_file(StringPrintf(kIPFlagTemplate, ip_version.c_str(),
376 link_name_.c_str(), flag.c_str()));
377 VLOG(2) << "Writing " << value << " to flag file " << flag_file.value();
378 if (file_util::WriteFile(flag_file, value.c_str(), value.length()) != 1) {
379 LOG(ERROR) << StringPrintf("IP flag write failed: %s to %s",
380 value.c_str(), flag_file.value().c_str());
381 return false;
382 }
383 return true;
384}
385
Gaurav Shah1b7a6162011-11-09 11:41:01 -0800386vector<string> Device::AvailableIPConfigs(Error */*error*/) {
Chris Masone4e851612011-07-01 10:46:53 -0700387 string id = (ipconfig_.get() ? ipconfig_->GetRpcIdentifier() : string());
388 return vector<string>(1, id);
389}
390
391string Device::GetRpcConnectionIdentifier() {
392 return adaptor_->GetRpcConnectionIdentifier();
393}
394
Paul Stewart75897df2011-04-27 09:05:53 -0700395} // namespace shill