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> |
Alex Vakulenko | a41ab51 | 2014-07-23 14:24:23 -0700 | [diff] [blame] | 8 | #include <linux/if.h> // NOLINT - Needs definitions from netinet/ether.h |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 9 | |
| 10 | #include "shill/logging.h" |
Peter Qiu | 8d6b597 | 2014-10-28 15:33:34 -0700 | [diff] [blame] | 11 | #include "shill/net/rtnl_handler.h" |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 12 | |
| 13 | using std::string; |
| 14 | |
| 15 | namespace shill { |
| 16 | |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 17 | namespace Logging { |
| 18 | static auto kModuleLogScope = ScopeLogger::kDevice; |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 19 | static string ObjectID(VirtualDevice* v) { return "(virtual_device)"; } |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 20 | } |
| 21 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 22 | namespace { |
| 23 | const char kHardwareAddressEmpty[] = ""; |
Alex Vakulenko | 8a53229 | 2014-06-16 17:18:44 -0700 | [diff] [blame] | 24 | } // namespace |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 25 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 26 | VirtualDevice::VirtualDevice(ControlInterface* control, |
| 27 | EventDispatcher* dispatcher, |
| 28 | Metrics* metrics, |
| 29 | Manager* manager, |
| 30 | const string& link_name, |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 31 | int interface_index, |
| 32 | Technology::Identifier technology) |
| 33 | : Device(control, dispatcher, metrics, manager, link_name, |
| 34 | kHardwareAddressEmpty, interface_index, technology) {} |
| 35 | |
| 36 | VirtualDevice::~VirtualDevice() {} |
| 37 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 38 | bool VirtualDevice::Load(StoreInterface* /*storage*/) { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 39 | // Virtual devices have no persistent state. |
| 40 | return true; |
| 41 | } |
| 42 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 43 | bool VirtualDevice::Save(StoreInterface* /*storage*/) { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 44 | // Virtual devices have no persistent state. |
| 45 | return true; |
| 46 | } |
| 47 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 48 | void VirtualDevice::Start(Error* error, |
| 49 | const EnabledStateChangedCallback& /*callback*/) { |
mukesh agrawal | 4a16558 | 2013-08-02 15:58:21 -0700 | [diff] [blame] | 50 | rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP); |
| 51 | // TODO(quiche): Should we call OnEnabledStateChanged, like other Devices? |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 52 | if (error) |
mukesh agrawal | 4a16558 | 2013-08-02 15:58:21 -0700 | [diff] [blame] | 53 | error->Reset(); // indicate immediate completion |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 56 | void VirtualDevice::Stop(Error* error, |
| 57 | const EnabledStateChangedCallback& /*callback*/) { |
mukesh agrawal | 4a16558 | 2013-08-02 15:58:21 -0700 | [diff] [blame] | 58 | // TODO(quiche): Should we call OnEnabledStateChanged, like other Devices? |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 59 | if (error) |
mukesh agrawal | 4a16558 | 2013-08-02 15:58:21 -0700 | [diff] [blame] | 60 | error->Reset(); // indicate immediate completion |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 63 | void VirtualDevice::UpdateIPConfig(const IPConfig::Properties& properties) { |
Rebecca Silberstein | c9c31d8 | 2014-10-21 15:01:00 -0700 | [diff] [blame] | 64 | SLOG(this, 2) << __func__ << " on " << link_name(); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 65 | if (!ipconfig()) { |
| 66 | set_ipconfig(new IPConfig(control_interface(), link_name())); |
| 67 | } |
| 68 | ipconfig()->set_properties(properties); |
Samuel Tan | 3c3c36a | 2014-12-16 16:53:19 -0800 | [diff] [blame] | 69 | OnIPConfigUpdated(ipconfig(), true); |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void VirtualDevice::DropConnection() { |
| 73 | Device::DropConnection(); |
| 74 | } |
| 75 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 76 | void VirtualDevice::SelectService(const ServiceRefPtr& service) { |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 77 | Device::SelectService(service); |
| 78 | } |
| 79 | |
mukesh agrawal | 0381f9a | 2013-07-11 16:41:52 -0700 | [diff] [blame] | 80 | void VirtualDevice::SetServiceState(Service::ConnectState state) { |
| 81 | Device::SetServiceState(state); |
| 82 | } |
| 83 | |
| 84 | void VirtualDevice::SetServiceFailure(Service::ConnectFailure failure_state) { |
| 85 | Device::SetServiceFailure(failure_state); |
| 86 | } |
| 87 | |
| 88 | void VirtualDevice::SetServiceFailureSilent( |
| 89 | Service::ConnectFailure failure_state) { |
| 90 | Device::SetServiceFailureSilent(failure_state); |
| 91 | } |
| 92 | |
mukesh agrawal | 9da0777 | 2013-05-15 14:15:17 -0700 | [diff] [blame] | 93 | } // namespace shill |