• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2012 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "shill/virtual_device.h"
18 
19 #include <netinet/ether.h>
20 #include <linux/if.h>  // NOLINT - Needs definitions from netinet/ether.h
21 
22 #include "shill/logging.h"
23 #include "shill/net/rtnl_handler.h"
24 
25 using std::string;
26 
27 namespace shill {
28 
29 namespace Logging {
30 static auto kModuleLogScope = ScopeLogger::kDevice;
ObjectID(VirtualDevice * v)31 static string ObjectID(VirtualDevice* v) { return "(virtual_device)"; }
32 }
33 
34 namespace {
35 const char kHardwareAddressEmpty[] = "";
36 }  // namespace
37 
VirtualDevice(ControlInterface * control,EventDispatcher * dispatcher,Metrics * metrics,Manager * manager,const string & link_name,int interface_index,Technology::Identifier technology)38 VirtualDevice::VirtualDevice(ControlInterface* control,
39                              EventDispatcher* dispatcher,
40                              Metrics* metrics,
41                              Manager* manager,
42                              const string& link_name,
43                              int interface_index,
44                              Technology::Identifier technology)
45     : Device(control, dispatcher, metrics, manager, link_name,
46              kHardwareAddressEmpty, interface_index, technology) {}
47 
~VirtualDevice()48 VirtualDevice::~VirtualDevice() {}
49 
Load(StoreInterface *)50 bool VirtualDevice::Load(StoreInterface* /*storage*/) {
51   // Virtual devices have no persistent state.
52   return true;
53 }
54 
Save(StoreInterface *)55 bool VirtualDevice::Save(StoreInterface* /*storage*/) {
56   // Virtual devices have no persistent state.
57   return true;
58 }
59 
Start(Error * error,const EnabledStateChangedCallback &)60 void VirtualDevice::Start(Error* error,
61                           const EnabledStateChangedCallback& /*callback*/) {
62   rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP);
63   // TODO(quiche): Should we call OnEnabledStateChanged, like other Devices?
64   if (error)
65     error->Reset();  // indicate immediate completion
66 }
67 
Stop(Error * error,const EnabledStateChangedCallback &)68 void VirtualDevice::Stop(Error* error,
69                          const EnabledStateChangedCallback& /*callback*/) {
70   // TODO(quiche): Should we call OnEnabledStateChanged, like other Devices?
71   if (error)
72     error->Reset();  // indicate immediate completion
73 }
74 
UpdateIPConfig(const IPConfig::Properties & properties)75 void VirtualDevice::UpdateIPConfig(const IPConfig::Properties& properties) {
76   SLOG(this, 2) << __func__ << " on " << link_name();
77   if (!ipconfig()) {
78     set_ipconfig(new IPConfig(control_interface(), link_name()));
79   }
80   ipconfig()->set_properties(properties);
81   OnIPConfigUpdated(ipconfig(), true);
82 }
83 
DropConnection()84 void VirtualDevice::DropConnection() {
85   Device::DropConnection();
86 }
87 
SelectService(const ServiceRefPtr & service)88 void VirtualDevice::SelectService(const ServiceRefPtr& service) {
89   Device::SelectService(service);
90 }
91 
SetServiceState(Service::ConnectState state)92 void VirtualDevice::SetServiceState(Service::ConnectState state) {
93   Device::SetServiceState(state);
94 }
95 
SetServiceFailure(Service::ConnectFailure failure_state)96 void VirtualDevice::SetServiceFailure(Service::ConnectFailure failure_state) {
97   Device::SetServiceFailure(failure_state);
98 }
99 
SetServiceFailureSilent(Service::ConnectFailure failure_state)100 void VirtualDevice::SetServiceFailureSilent(
101     Service::ConnectFailure failure_state) {
102   Device::SetServiceFailureSilent(failure_state);
103 }
104 
105 }  // namespace shill
106