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