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