blob: 923b72151e23d34c60c019a7978508d8b181e90a [file] [log] [blame]
mukesh agrawal9da07772013-05-15 14:15:17 -07001// 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 Vakulenkoa41ab512014-07-23 14:24:23 -07008#include <linux/if.h> // NOLINT - Needs definitions from netinet/ether.h
mukesh agrawal9da07772013-05-15 14:15:17 -07009
10#include "shill/logging.h"
Peter Qiu8d6b5972014-10-28 15:33:34 -070011#include "shill/net/rtnl_handler.h"
mukesh agrawal9da07772013-05-15 14:15:17 -070012
13using std::string;
14
15namespace shill {
16
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070017namespace Logging {
18static auto kModuleLogScope = ScopeLogger::kDevice;
Paul Stewart1a212a62015-06-16 13:13:10 -070019static string ObjectID(VirtualDevice* v) { return "(virtual_device)"; }
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070020}
21
mukesh agrawal9da07772013-05-15 14:15:17 -070022namespace {
23const char kHardwareAddressEmpty[] = "";
Alex Vakulenko8a532292014-06-16 17:18:44 -070024} // namespace
mukesh agrawal9da07772013-05-15 14:15:17 -070025
Paul Stewart1a212a62015-06-16 13:13:10 -070026VirtualDevice::VirtualDevice(ControlInterface* control,
27 EventDispatcher* dispatcher,
28 Metrics* metrics,
29 Manager* manager,
30 const string& link_name,
mukesh agrawal9da07772013-05-15 14:15:17 -070031 int interface_index,
32 Technology::Identifier technology)
33 : Device(control, dispatcher, metrics, manager, link_name,
34 kHardwareAddressEmpty, interface_index, technology) {}
35
36VirtualDevice::~VirtualDevice() {}
37
Paul Stewart1a212a62015-06-16 13:13:10 -070038bool VirtualDevice::Load(StoreInterface* /*storage*/) {
mukesh agrawal9da07772013-05-15 14:15:17 -070039 // Virtual devices have no persistent state.
40 return true;
41}
42
Paul Stewart1a212a62015-06-16 13:13:10 -070043bool VirtualDevice::Save(StoreInterface* /*storage*/) {
mukesh agrawal9da07772013-05-15 14:15:17 -070044 // Virtual devices have no persistent state.
45 return true;
46}
47
Paul Stewart1a212a62015-06-16 13:13:10 -070048void VirtualDevice::Start(Error* error,
49 const EnabledStateChangedCallback& /*callback*/) {
mukesh agrawal4a165582013-08-02 15:58:21 -070050 rtnl_handler()->SetInterfaceFlags(interface_index(), IFF_UP, IFF_UP);
51 // TODO(quiche): Should we call OnEnabledStateChanged, like other Devices?
mukesh agrawal9da07772013-05-15 14:15:17 -070052 if (error)
mukesh agrawal4a165582013-08-02 15:58:21 -070053 error->Reset(); // indicate immediate completion
mukesh agrawal9da07772013-05-15 14:15:17 -070054}
55
Paul Stewart1a212a62015-06-16 13:13:10 -070056void VirtualDevice::Stop(Error* error,
57 const EnabledStateChangedCallback& /*callback*/) {
mukesh agrawal4a165582013-08-02 15:58:21 -070058 // TODO(quiche): Should we call OnEnabledStateChanged, like other Devices?
mukesh agrawal9da07772013-05-15 14:15:17 -070059 if (error)
mukesh agrawal4a165582013-08-02 15:58:21 -070060 error->Reset(); // indicate immediate completion
mukesh agrawal9da07772013-05-15 14:15:17 -070061}
62
Paul Stewart1a212a62015-06-16 13:13:10 -070063void VirtualDevice::UpdateIPConfig(const IPConfig::Properties& properties) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070064 SLOG(this, 2) << __func__ << " on " << link_name();
mukesh agrawal9da07772013-05-15 14:15:17 -070065 if (!ipconfig()) {
66 set_ipconfig(new IPConfig(control_interface(), link_name()));
67 }
68 ipconfig()->set_properties(properties);
Samuel Tan3c3c36a2014-12-16 16:53:19 -080069 OnIPConfigUpdated(ipconfig(), true);
mukesh agrawal9da07772013-05-15 14:15:17 -070070}
71
72void VirtualDevice::DropConnection() {
73 Device::DropConnection();
74}
75
Paul Stewart1a212a62015-06-16 13:13:10 -070076void VirtualDevice::SelectService(const ServiceRefPtr& service) {
mukesh agrawal9da07772013-05-15 14:15:17 -070077 Device::SelectService(service);
78}
79
mukesh agrawal0381f9a2013-07-11 16:41:52 -070080void VirtualDevice::SetServiceState(Service::ConnectState state) {
81 Device::SetServiceState(state);
82}
83
84void VirtualDevice::SetServiceFailure(Service::ConnectFailure failure_state) {
85 Device::SetServiceFailure(failure_state);
86}
87
88void VirtualDevice::SetServiceFailureSilent(
89 Service::ConnectFailure failure_state) {
90 Device::SetServiceFailureSilent(failure_state);
91}
92
mukesh agrawal9da07772013-05-15 14:15:17 -070093} // namespace shill