1// 2// Copyright (C) 2012 The Android Open Source Project 3// 4// Licensed under the Apache License, Version 2.0 (the "License"); 5// you may not use this file except in compliance with the License. 6// You may obtain a copy of the License at 7// 8// http://www.apache.org/licenses/LICENSE-2.0 9// 10// Unless required by applicable law or agreed to in writing, software 11// distributed under the License is distributed on an "AS IS" BASIS, 12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13// See the License for the specific language governing permissions and 14// limitations under the License. 15// 16 17#include "shill/ethernet/virtio_ethernet.h" 18 19#include <unistd.h> 20 21#include <string> 22 23#include "shill/control_interface.h" 24#include "shill/event_dispatcher.h" 25#include "shill/logging.h" 26#include "shill/manager.h" 27 28using std::string; 29 30namespace shill { 31 32namespace Logging { 33static auto kModuleLogScope = ScopeLogger::kEthernet; 34static string ObjectID(VirtioEthernet* v) { return v->GetRpcIdentifier(); } 35} 36 37VirtioEthernet::VirtioEthernet(ControlInterface* control_interface, 38 EventDispatcher* dispatcher, 39 Metrics* metrics, 40 Manager* manager, 41 const string& link_name, 42 const string& address, 43 int interface_index) 44 : Ethernet(control_interface, 45 dispatcher, 46 metrics, 47 manager, 48 link_name, 49 address, 50 interface_index) { 51 SLOG(this, 2) << "VirtioEthernet device " << link_name << " initialized."; 52} 53 54VirtioEthernet::~VirtioEthernet() { 55 // Nothing to be done beyond what Ethernet dtor does. 56} 57 58void VirtioEthernet::Start(Error* error, 59 const EnabledStateChangedCallback& callback) { 60 // We are sometimes instantiated (by DeviceInfo) before the Linux kernel 61 // has completed the setup function for the device (virtio_net:virtnet_probe). 62 // 63 // Furthermore, setting the IFF_UP flag on the device (as done in 64 // Ethernet::Start) may cause the kernel IPv6 code to send packets even 65 // though virtnet_probe has not completed. 66 // 67 // When that happens, the device gets stuck in a state where it cannot 68 // transmit any frames. (See crbug.com/212041) 69 // 70 // To avoid this, we sleep to let the device setup function complete. 71 SLOG(this, 2) << "Sleeping to let virtio initialize."; 72 sleep(2); 73 SLOG(this, 2) << "Starting virtio Ethernet."; 74 Ethernet::Start(error, callback); 75} 76 77} // namespace shill 78