blob: 5206fb43173db10d57b330cba4071bc84e9b1829 [file] [log] [blame]
mukesh agrawal93a29ed2012-04-17 16:13:01 -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/virtio_ethernet.h"
6
7#include <unistd.h>
8
9#include <string>
10
mukesh agrawal93a29ed2012-04-17 16:13:01 -070011#include "shill/control_interface.h"
12#include "shill/event_dispatcher.h"
Christopher Wileyb691efd2012-08-09 13:51:51 -070013#include "shill/logging.h"
mukesh agrawal93a29ed2012-04-17 16:13:01 -070014#include "shill/manager.h"
15
16using std::string;
17
18namespace shill {
19
20VirtioEthernet::VirtioEthernet(ControlInterface *control_interface,
21 EventDispatcher *dispatcher,
22 Metrics *metrics,
23 Manager *manager,
24 const string &link_name,
25 const string &address,
26 int interface_index)
27 : Ethernet(control_interface,
28 dispatcher,
29 metrics,
30 manager,
31 link_name,
32 address,
33 interface_index) {
Ben Chanfad4a0b2012-04-18 15:49:59 -070034 SLOG(Ethernet, 2) << "VirtioEthernet device " << link_name << " initialized.";
mukesh agrawal93a29ed2012-04-17 16:13:01 -070035}
36
37VirtioEthernet::~VirtioEthernet() {
38 // Nothing to be done beyond what Ethernet dtor does.
39}
40
41void VirtioEthernet::Start(Error *error,
42 const EnabledStateChangedCallback &callback) {
43 // We are sometimes instantiated (by DeviceInfo) before the Linux kernel
44 // has completed the setup function for the device (virtio_net:virtnet_probe).
45 //
46 // Furthermore, setting the IFF_UP flag on the device (as done in
47 // Ethernet::Start) may cause the kernel IPv6 code to send packets even
48 // though virtnet_probe has not completed.
49 //
50 // When that happens, the device gets stuck in a state where it cannot
51 // transmit any frames. (See crosbug.com/29494)
52 //
53 // To avoid this, we sleep to let the device setup function complete.
Ben Chanfad4a0b2012-04-18 15:49:59 -070054 SLOG(Ethernet, 2) << "Sleeping to let virtio initialize.";
mukesh agrawal93a29ed2012-04-17 16:13:01 -070055 sleep(2);
Ben Chanfad4a0b2012-04-18 15:49:59 -070056 SLOG(Ethernet, 2) << "Starting virtio Ethernet.";
mukesh agrawal93a29ed2012-04-17 16:13:01 -070057 Ethernet::Start(error, callback);
58}
59
60} // namespace shill