mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | |
| 5 | #include "shill/virtual_device.h" |
| 6 | |
| 7 | #include <netinet/ether.h> |
| 8 | #include <linux/if.h> // Needs definitions from netinet/ether.h |
| 9 | |
| 10 | #include "shill/logging.h" |
| 11 | #include "shill/rtnl_handler.h" |
| 12 | |
| 13 | using std::string; |
| 14 | |
| 15 | namespace shill { |
| 16 | |
| 17 | namespace { |
| 18 | const char kHardwareAddressEmpty[] = ""; |
| 19 | } // namespace {} |
| 20 | |
| 21 | VirtualDevice::VirtualDevice(ControlInterface *control, |
| 22 | EventDispatcher *dispatcher, |
| 23 | Metrics *metrics, |
| 24 | Manager *manager, |
| 25 | const string &link_name, |
| 26 | int interface_index, |
| 27 | Technology::Identifier technology) |
| 28 | : Device(control, dispatcher, metrics, manager, link_name, |
| 29 | kHardwareAddressEmpty, interface_index, technology) {} |
| 30 | |
| 31 | VirtualDevice::~VirtualDevice() {} |
| 32 | |
| 33 | bool VirtualDevice::Load(StoreInterface */*storage*/) { |
| 34 | // Virtual devices have no persistent state. |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | bool VirtualDevice::Save(StoreInterface */*storage*/) { |
| 39 | // Virtual devices have no persistent state. |
| 40 | return true; |
| 41 | } |
| 42 | |
| 43 | void VirtualDevice::Start(Error *error, |
mukesh agrawal | 6813e76 | 2013-07-10 19:05:08 -0700 | [diff] [blame] | 44 | const EnabledStateChangedCallback &/*callback*/) { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 45 | RTNLHandler::GetInstance()->SetInterfaceFlags(interface_index(), IFF_UP, |
| 46 | IFF_UP); |
| 47 | if (error) |
| 48 | error->Reset(); |
| 49 | } |
| 50 | |
| 51 | void VirtualDevice::Stop(Error *error, |
mukesh agrawal | 6813e76 | 2013-07-10 19:05:08 -0700 | [diff] [blame] | 52 | const EnabledStateChangedCallback &/*callback*/) { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 53 | if (error) |
| 54 | error->Reset(); |
| 55 | } |
| 56 | |
| 57 | void VirtualDevice::UpdateIPConfig(const IPConfig::Properties &properties) { |
| 58 | SLOG(Device, 2) << __func__ << " on " << link_name(); |
| 59 | if (!ipconfig()) { |
| 60 | set_ipconfig(new IPConfig(control_interface(), link_name())); |
| 61 | } |
| 62 | ipconfig()->set_properties(properties); |
| 63 | OnIPConfigUpdated(ipconfig(), true); |
| 64 | } |
| 65 | |
| 66 | void VirtualDevice::DropConnection() { |
| 67 | Device::DropConnection(); |
| 68 | } |
| 69 | |
| 70 | void VirtualDevice::SelectService(const ServiceRefPtr &service) { |
| 71 | Device::SelectService(service); |
| 72 | } |
| 73 | |
mukesh agrawal | 0381f9a | 2013-07-11 16:41:52 -0700 | [diff] [blame^] | 74 | void VirtualDevice::SetServiceState(Service::ConnectState state) { |
| 75 | Device::SetServiceState(state); |
| 76 | } |
| 77 | |
| 78 | void VirtualDevice::SetServiceFailure(Service::ConnectFailure failure_state) { |
| 79 | Device::SetServiceFailure(failure_state); |
| 80 | } |
| 81 | |
| 82 | void VirtualDevice::SetServiceFailureSilent( |
| 83 | Service::ConnectFailure failure_state) { |
| 84 | Device::SetServiceFailureSilent(failure_state); |
| 85 | } |
| 86 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 87 | } // namespace shill |