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 | |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 11 | #include "shill/control_interface.h" |
| 12 | #include "shill/event_dispatcher.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 13 | #include "shill/logging.h" |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 14 | #include "shill/manager.h" |
| 15 | |
| 16 | using std::string; |
| 17 | |
| 18 | namespace shill { |
| 19 | |
| 20 | VirtioEthernet::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 Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 34 | SLOG(Ethernet, 2) << "VirtioEthernet device " << link_name << " initialized."; |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | VirtioEthernet::~VirtioEthernet() { |
| 38 | // Nothing to be done beyond what Ethernet dtor does. |
| 39 | } |
| 40 | |
| 41 | void 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 Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 54 | SLOG(Ethernet, 2) << "Sleeping to let virtio initialize."; |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 55 | sleep(2); |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 56 | SLOG(Ethernet, 2) << "Starting virtio Ethernet."; |
mukesh agrawal | 93a29ed | 2012-04-17 16:13:01 -0700 | [diff] [blame] | 57 | Ethernet::Start(error, callback); |
| 58 | } |
| 59 | |
| 60 | } // namespace shill |