blob: b4f994e3f25ad821123357454b567fcd6a628e55 [file] [log] [blame]
Peter Qiuc0beca52015-09-03 11:25:46 -07001//
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//
mukesh agrawal93a29ed2012-04-17 16:13:01 -070016
Ben Chan87602512014-11-07 20:50:05 -080017#include "shill/ethernet/virtio_ethernet.h"
mukesh agrawal93a29ed2012-04-17 16:13:01 -070018
19#include <unistd.h>
20
21#include <string>
22
mukesh agrawal93a29ed2012-04-17 16:13:01 -070023#include "shill/control_interface.h"
24#include "shill/event_dispatcher.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070025#include "shill/logging.h"
mukesh agrawal93a29ed2012-04-17 16:13:01 -070026#include "shill/manager.h"
27
28using std::string;
29
30namespace shill {
31
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070032namespace Logging {
33static auto kModuleLogScope = ScopeLogger::kEthernet;
Paul Stewart7e779d82015-06-16 13:13:10 -070034static string ObjectID(VirtioEthernet* v) { return v->GetRpcIdentifier(); }
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070035}
36
Paul Stewart7e779d82015-06-16 13:13:10 -070037VirtioEthernet::VirtioEthernet(ControlInterface* control_interface,
38 EventDispatcher* dispatcher,
39 Metrics* metrics,
40 Manager* manager,
41 const string& link_name,
42 const string& address,
mukesh agrawal93a29ed2012-04-17 16:13:01 -070043 int interface_index)
44 : Ethernet(control_interface,
45 dispatcher,
46 metrics,
47 manager,
48 link_name,
49 address,
50 interface_index) {
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070051 SLOG(this, 2) << "VirtioEthernet device " << link_name << " initialized.";
mukesh agrawal93a29ed2012-04-17 16:13:01 -070052}
53
54VirtioEthernet::~VirtioEthernet() {
55 // Nothing to be done beyond what Ethernet dtor does.
56}
57
Paul Stewart7e779d82015-06-16 13:13:10 -070058void VirtioEthernet::Start(Error* error,
59 const EnabledStateChangedCallback& callback) {
mukesh agrawal93a29ed2012-04-17 16:13:01 -070060 // We are sometimes instantiated (by DeviceInfo) before the Linux kernel
61 // has completed the setup function for the device (virtio_net:virtnet_probe).
62 //
63 // Furthermore, setting the IFF_UP flag on the device (as done in
64 // Ethernet::Start) may cause the kernel IPv6 code to send packets even
65 // though virtnet_probe has not completed.
66 //
67 // When that happens, the device gets stuck in a state where it cannot
Paul Stewartee6b3d72013-07-12 16:07:51 -070068 // transmit any frames. (See crbug.com/212041)
mukesh agrawal93a29ed2012-04-17 16:13:01 -070069 //
70 // To avoid this, we sleep to let the device setup function complete.
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070071 SLOG(this, 2) << "Sleeping to let virtio initialize.";
mukesh agrawal93a29ed2012-04-17 16:13:01 -070072 sleep(2);
Rebecca Silbersteinc9c31d82014-10-21 15:01:00 -070073 SLOG(this, 2) << "Starting virtio Ethernet.";
mukesh agrawal93a29ed2012-04-17 16:13:01 -070074 Ethernet::Start(error, callback);
75}
76
77} // namespace shill