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" |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 16 | #include "shill/scope_logger.h" |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 17 | |
| 18 | using std::string; |
| 19 | |
| 20 | namespace shill { |
| 21 | |
| 22 | VirtioEthernet::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 Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 36 | SLOG(Ethernet, 2) << "VirtioEthernet device " << link_name << " initialized."; |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | VirtioEthernet::~VirtioEthernet() { |
| 40 | // Nothing to be done beyond what Ethernet dtor does. |
| 41 | } |
| 42 | |
| 43 | void 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 Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 56 | SLOG(Ethernet, 2) << "Sleeping to let virtio initialize."; |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 57 | sleep(2); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 58 | SLOG(Ethernet, 2) << "Starting virtio Ethernet."; |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 59 | Ethernet::Start(error, callback); |
| 60 | } |
| 61 | |
| 62 | } // namespace shill |