2019-05-08 00:26:37 +00:00
|
|
|
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
//
|
|
|
|
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the THIRD-PARTY file.
|
|
|
|
|
2019-12-31 10:49:11 +00:00
|
|
|
use super::Error as DeviceError;
|
|
|
|
use super::{
|
2021-10-21 10:41:16 +00:00
|
|
|
ActivateError, ActivateResult, EpollHelper, EpollHelperError, EpollHelperHandler,
|
2021-03-17 22:41:52 +00:00
|
|
|
RateLimiterConfig, VirtioCommon, VirtioDevice, VirtioDeviceType, VirtioInterruptType,
|
|
|
|
EPOLL_HELPER_EVENT_LAST,
|
2019-12-31 10:49:11 +00:00
|
|
|
};
|
2021-09-03 10:43:30 +00:00
|
|
|
use crate::seccomp_filters::Thread;
|
|
|
|
use crate::thread_helper::spawn_virtio_thread;
|
2021-06-02 19:08:04 +00:00
|
|
|
use crate::GuestMemoryMmap;
|
2019-12-31 10:49:11 +00:00
|
|
|
use crate::VirtioInterrupt;
|
2021-05-21 10:52:07 +00:00
|
|
|
use net_util::CtrlQueue;
|
2020-07-07 15:06:54 +00:00
|
|
|
use net_util::{
|
2021-05-21 10:25:18 +00:00
|
|
|
build_net_config_space, build_net_config_space_with_mq, open_tap,
|
|
|
|
virtio_features_to_tap_offload, MacAddr, NetCounters, NetQueuePair, OpenTapError, RxVirtio,
|
|
|
|
Tap, TapError, TxVirtio, VirtioNetConfig,
|
2020-07-07 15:06:54 +00:00
|
|
|
};
|
2021-09-03 10:43:30 +00:00
|
|
|
use seccompiler::SeccompAction;
|
2019-05-08 00:26:37 +00:00
|
|
|
use std::net::Ipv4Addr;
|
2020-06-23 15:28:41 +00:00
|
|
|
use std::num::Wrapping;
|
2020-12-16 17:00:59 +00:00
|
|
|
use std::os::unix::io::{AsRawFd, RawFd};
|
2019-05-08 00:26:37 +00:00
|
|
|
use std::result;
|
2020-07-07 15:50:13 +00:00
|
|
|
use std::sync::atomic::{AtomicBool, Ordering};
|
2020-08-11 14:05:06 +00:00
|
|
|
use std::sync::{Arc, Barrier};
|
2019-05-08 00:26:37 +00:00
|
|
|
use std::thread;
|
|
|
|
use std::vec::Vec;
|
2021-03-17 22:41:52 +00:00
|
|
|
use std::{collections::HashMap, convert::TryInto};
|
2021-05-06 13:34:31 +00:00
|
|
|
use versionize::{VersionMap, Versionize, VersionizeResult};
|
|
|
|
use versionize_derive::Versionize;
|
2019-09-19 13:42:29 +00:00
|
|
|
use virtio_bindings::bindings::virtio_net::*;
|
2021-11-03 16:22:03 +00:00
|
|
|
use virtio_bindings::bindings::virtio_ring::{
|
|
|
|
VIRTIO_RING_F_EVENT_IDX, VIRTIO_RING_F_INDIRECT_DESC,
|
|
|
|
};
|
2021-10-21 10:41:16 +00:00
|
|
|
use virtio_queue::Queue;
|
|
|
|
use vm_memory::{ByteValued, GuestMemoryAtomic};
|
2021-05-06 13:34:31 +00:00
|
|
|
use vm_migration::VersionMapped;
|
2021-04-08 09:20:10 +00:00
|
|
|
use vm_migration::{Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable};
|
2019-08-02 14:23:52 +00:00
|
|
|
use vmm_sys_util::eventfd::EventFd;
|
2019-05-08 00:26:37 +00:00
|
|
|
|
2021-05-21 10:59:49 +00:00
|
|
|
/// Control queue
|
|
|
|
// Event available on the control queue.
|
|
|
|
const CTRL_QUEUE_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 1;
|
|
|
|
|
|
|
|
pub struct NetCtrlEpollHandler {
|
|
|
|
pub kill_evt: EventFd,
|
|
|
|
pub pause_evt: EventFd,
|
|
|
|
pub ctrl_q: CtrlQueue,
|
|
|
|
pub queue_evt: EventFd,
|
2021-10-21 10:41:16 +00:00
|
|
|
pub queue: Queue<GuestMemoryAtomic<GuestMemoryMmap>>,
|
2021-05-21 10:59:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl NetCtrlEpollHandler {
|
|
|
|
pub fn run_ctrl(
|
|
|
|
&mut self,
|
|
|
|
paused: Arc<AtomicBool>,
|
|
|
|
paused_sync: Arc<Barrier>,
|
|
|
|
) -> std::result::Result<(), EpollHelperError> {
|
|
|
|
let mut helper = EpollHelper::new(&self.kill_evt, &self.pause_evt)?;
|
|
|
|
helper.add_event(self.queue_evt.as_raw_fd(), CTRL_QUEUE_EVENT)?;
|
|
|
|
helper.run(paused, paused_sync, self)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl EpollHelperHandler for NetCtrlEpollHandler {
|
|
|
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
|
|
|
let ev_type = event.data as u16;
|
|
|
|
match ev_type {
|
|
|
|
CTRL_QUEUE_EVENT => {
|
|
|
|
if let Err(e) = self.queue_evt.read() {
|
|
|
|
error!("failed to get ctl queue event: {:?}", e);
|
|
|
|
return true;
|
|
|
|
}
|
2021-10-21 10:41:16 +00:00
|
|
|
if let Err(e) = self.ctrl_q.process(&mut self.queue) {
|
2021-05-21 10:59:49 +00:00
|
|
|
error!("failed to process ctrl queue: {:?}", e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {
|
|
|
|
error!("Unknown event for virtio-net");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Rx/Tx queue pair
|
2020-07-23 16:16:10 +00:00
|
|
|
// The guest has made a buffer available to receive a frame into.
|
|
|
|
pub const RX_QUEUE_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 1;
|
|
|
|
// The transmit queue has a frame that is ready to send from the guest.
|
|
|
|
pub const TX_QUEUE_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 2;
|
|
|
|
// A frame is available for reading from the tap device to receive in the guest.
|
|
|
|
pub const RX_TAP_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 3;
|
2021-06-28 14:28:26 +00:00
|
|
|
// The TAP can be written to. Used after an EAGAIN error to retry TX.
|
|
|
|
pub const TX_TAP_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 4;
|
2021-03-25 21:17:05 +00:00
|
|
|
// New 'wake up' event from the rx rate limiter
|
2021-06-28 14:28:26 +00:00
|
|
|
pub const RX_RATE_LIMITER_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 5;
|
2021-03-17 22:41:52 +00:00
|
|
|
// New 'wake up' event from the tx rate limiter
|
2021-06-28 14:28:26 +00:00
|
|
|
pub const TX_RATE_LIMITER_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 6;
|
2020-07-23 16:16:10 +00:00
|
|
|
|
2019-05-08 00:26:37 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Error {
|
2020-01-09 11:56:21 +00:00
|
|
|
/// Failed to open taps.
|
2020-07-07 14:02:18 +00:00
|
|
|
OpenTap(OpenTapError),
|
2020-12-16 17:00:59 +00:00
|
|
|
|
|
|
|
// Using existing tap
|
|
|
|
TapError(TapError),
|
2021-04-22 09:24:15 +00:00
|
|
|
|
|
|
|
// Error calling dup() on tap fd
|
|
|
|
DuplicateTapFd(std::io::Error),
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub type Result<T> = result::Result<T, Error>;
|
|
|
|
|
2020-05-29 13:50:11 +00:00
|
|
|
struct NetEpollHandler {
|
|
|
|
net: NetQueuePair,
|
|
|
|
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
|
|
|
kill_evt: EventFd,
|
|
|
|
pause_evt: EventFd,
|
2021-10-21 10:41:16 +00:00
|
|
|
queue_pair: Vec<Queue<GuestMemoryAtomic<GuestMemoryMmap>>>,
|
2020-07-23 16:16:10 +00:00
|
|
|
queue_evt_pair: Vec<EventFd>,
|
2020-06-02 16:00:31 +00:00
|
|
|
// Always generate interrupts until the driver has signalled to the device.
|
|
|
|
// This mitigates a problem with interrupts from tap events being "lost" upon
|
|
|
|
// a restore as the vCPU thread isn't ready to handle the interrupt. This causes
|
|
|
|
// issues when combined with VIRTIO_RING_F_EVENT_IDX interrupt suppression.
|
|
|
|
driver_awake: bool,
|
2020-05-29 13:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl NetEpollHandler {
|
2021-10-21 10:41:16 +00:00
|
|
|
fn signal_used_queue(
|
|
|
|
&self,
|
|
|
|
queue: &Queue<GuestMemoryAtomic<GuestMemoryMmap>>,
|
|
|
|
) -> result::Result<(), DeviceError> {
|
2020-05-29 13:50:11 +00:00
|
|
|
self.interrupt_cb
|
|
|
|
.trigger(&VirtioInterruptType::Queue, Some(queue))
|
|
|
|
.map_err(|e| {
|
|
|
|
error!("Failed to signal used queue: {:?}", e);
|
|
|
|
DeviceError::FailedSignalingUsedQueue(e)
|
|
|
|
})
|
|
|
|
}
|
2019-05-08 00:26:37 +00:00
|
|
|
|
2020-07-23 16:16:10 +00:00
|
|
|
fn handle_rx_event(&mut self) -> result::Result<(), DeviceError> {
|
|
|
|
let queue_evt = &self.queue_evt_pair[0];
|
2020-01-09 11:56:21 +00:00
|
|
|
if let Err(e) = queue_evt.read() {
|
|
|
|
error!("Failed to get rx queue event: {:?}", e);
|
|
|
|
}
|
|
|
|
|
2021-03-25 21:17:05 +00:00
|
|
|
self.net.rx_desc_avail = true;
|
|
|
|
|
|
|
|
let rate_limit_reached = self
|
|
|
|
.net
|
|
|
|
.rx_rate_limiter
|
|
|
|
.as_ref()
|
|
|
|
.map_or(false, |r| r.is_blocked());
|
|
|
|
|
|
|
|
// Start to listen on RX_TAP_EVENT only when the rate limit is not reached
|
|
|
|
if !self.net.rx_tap_listening && !rate_limit_reached {
|
2021-02-16 21:17:37 +00:00
|
|
|
net_util::register_listener(
|
|
|
|
self.net.epoll_fd.unwrap(),
|
|
|
|
self.net.tap.as_raw_fd(),
|
|
|
|
epoll::Events::EPOLLIN,
|
2021-06-28 13:51:34 +00:00
|
|
|
u64::from(self.net.tap_rx_event_id),
|
2021-02-16 21:17:37 +00:00
|
|
|
)
|
|
|
|
.map_err(DeviceError::IoError)?;
|
|
|
|
self.net.rx_tap_listening = true;
|
2020-01-09 11:56:21 +00:00
|
|
|
}
|
2020-05-29 12:33:59 +00:00
|
|
|
|
|
|
|
Ok(())
|
2019-08-21 12:44:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 16:35:04 +00:00
|
|
|
fn process_tx(&mut self) -> result::Result<(), DeviceError> {
|
2020-07-07 15:50:13 +00:00
|
|
|
if self
|
|
|
|
.net
|
2020-07-23 16:16:10 +00:00
|
|
|
.process_tx(&mut self.queue_pair[1])
|
2020-07-07 15:50:13 +00:00
|
|
|
.map_err(DeviceError::NetQueuePair)?
|
|
|
|
|| !self.driver_awake
|
|
|
|
{
|
2020-07-23 16:16:10 +00:00
|
|
|
self.signal_used_queue(&self.queue_pair[1])?;
|
2021-01-05 16:25:40 +00:00
|
|
|
debug!("Signalling TX queue");
|
2020-06-02 15:59:22 +00:00
|
|
|
} else {
|
2021-01-05 16:25:40 +00:00
|
|
|
debug!("Not signalling TX queue");
|
2020-05-29 12:33:59 +00:00
|
|
|
}
|
2020-05-29 13:50:11 +00:00
|
|
|
Ok(())
|
2020-01-09 11:56:21 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 16:35:04 +00:00
|
|
|
fn handle_tx_event(&mut self) -> result::Result<(), DeviceError> {
|
2021-03-17 22:41:52 +00:00
|
|
|
let rate_limit_reached = self
|
|
|
|
.net
|
|
|
|
.tx_rate_limiter
|
|
|
|
.as_ref()
|
|
|
|
.map_or(false, |r| r.is_blocked());
|
|
|
|
|
|
|
|
if !rate_limit_reached {
|
|
|
|
self.process_tx()?;
|
|
|
|
}
|
2021-03-18 16:35:04 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-07-23 16:16:10 +00:00
|
|
|
fn handle_rx_tap_event(&mut self) -> result::Result<(), DeviceError> {
|
2020-07-07 15:50:13 +00:00
|
|
|
if self
|
|
|
|
.net
|
2021-02-16 21:17:37 +00:00
|
|
|
.process_rx(&mut self.queue_pair[0])
|
2020-07-07 15:50:13 +00:00
|
|
|
.map_err(DeviceError::NetQueuePair)?
|
|
|
|
|| !self.driver_awake
|
|
|
|
{
|
2020-07-23 16:16:10 +00:00
|
|
|
self.signal_used_queue(&self.queue_pair[0])?;
|
2021-01-05 16:25:40 +00:00
|
|
|
debug!("Signalling RX queue");
|
2020-06-02 15:59:22 +00:00
|
|
|
} else {
|
2021-01-05 16:25:40 +00:00
|
|
|
debug!("Not signalling RX queue");
|
2020-01-09 11:56:21 +00:00
|
|
|
}
|
2020-05-29 12:33:59 +00:00
|
|
|
Ok(())
|
2019-08-21 12:44:49 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 14:05:06 +00:00
|
|
|
fn run(
|
|
|
|
&mut self,
|
|
|
|
paused: Arc<AtomicBool>,
|
|
|
|
paused_sync: Arc<Barrier>,
|
|
|
|
) -> result::Result<(), EpollHelperError> {
|
2020-07-23 16:16:10 +00:00
|
|
|
let mut helper = EpollHelper::new(&self.kill_evt, &self.pause_evt)?;
|
|
|
|
helper.add_event(self.queue_evt_pair[0].as_raw_fd(), RX_QUEUE_EVENT)?;
|
|
|
|
helper.add_event(self.queue_evt_pair[1].as_raw_fd(), TX_QUEUE_EVENT)?;
|
2021-03-25 21:17:05 +00:00
|
|
|
if let Some(rate_limiter) = &self.net.rx_rate_limiter {
|
|
|
|
helper.add_event(rate_limiter.as_raw_fd(), RX_RATE_LIMITER_EVENT)?;
|
|
|
|
}
|
2021-03-17 22:41:52 +00:00
|
|
|
if let Some(rate_limiter) = &self.net.tx_rate_limiter {
|
|
|
|
helper.add_event(rate_limiter.as_raw_fd(), TX_RATE_LIMITER_EVENT)?;
|
|
|
|
}
|
2019-05-08 00:26:37 +00:00
|
|
|
|
2020-04-21 15:28:59 +00:00
|
|
|
// If there are some already available descriptors on the RX queue,
|
|
|
|
// then we can start the thread while listening onto the TAP.
|
2020-07-23 16:16:10 +00:00
|
|
|
if self.queue_pair[0]
|
2021-10-21 10:41:16 +00:00
|
|
|
.used_idx(Ordering::Acquire)
|
|
|
|
.map_err(EpollHelperError::QueueRingIndex)?
|
|
|
|
< self.queue_pair[0]
|
|
|
|
.avail_idx(Ordering::Acquire)
|
|
|
|
.map_err(EpollHelperError::QueueRingIndex)?
|
2020-05-29 13:50:11 +00:00
|
|
|
{
|
2020-07-23 16:16:10 +00:00
|
|
|
helper.add_event(self.net.tap.as_raw_fd(), RX_TAP_EVENT)?;
|
2020-05-29 13:50:11 +00:00
|
|
|
self.net.rx_tap_listening = true;
|
2020-07-23 16:16:10 +00:00
|
|
|
info!("Listener registered at start");
|
2020-04-21 15:28:59 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 16:16:10 +00:00
|
|
|
// The NetQueuePair needs the epoll fd.
|
|
|
|
self.net.epoll_fd = Some(helper.as_raw_fd());
|
2019-05-08 00:26:37 +00:00
|
|
|
|
2020-08-11 14:05:06 +00:00
|
|
|
helper.run(paused, paused_sync, self)?;
|
2020-07-23 16:16:10 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 14:00:02 +00:00
|
|
|
|
2020-07-23 16:16:10 +00:00
|
|
|
impl EpollHelperHandler for NetEpollHandler {
|
2020-08-11 17:12:02 +00:00
|
|
|
fn handle_event(&mut self, _helper: &mut EpollHelper, event: &epoll::Event) -> bool {
|
|
|
|
let ev_type = event.data as u16;
|
|
|
|
match ev_type {
|
2020-07-23 16:16:10 +00:00
|
|
|
RX_QUEUE_EVENT => {
|
|
|
|
self.driver_awake = true;
|
|
|
|
if let Err(e) = self.handle_rx_event() {
|
|
|
|
error!("Error processing RX queue: {:?}", e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TX_QUEUE_EVENT => {
|
2021-06-28 14:28:26 +00:00
|
|
|
let queue_evt = &self.queue_evt_pair[1];
|
|
|
|
if let Err(e) = queue_evt.read() {
|
|
|
|
error!("Failed to get tx queue event: {:?}", e);
|
|
|
|
}
|
2020-07-23 16:16:10 +00:00
|
|
|
self.driver_awake = true;
|
|
|
|
if let Err(e) = self.handle_tx_event() {
|
|
|
|
error!("Error processing TX queue: {:?}", e);
|
|
|
|
return true;
|
2019-08-01 20:08:47 +00:00
|
|
|
}
|
2020-07-23 16:16:10 +00:00
|
|
|
}
|
2021-06-28 14:28:26 +00:00
|
|
|
TX_TAP_EVENT => {
|
|
|
|
if let Err(e) = self.handle_tx_event() {
|
|
|
|
error!("Error processing TX queue (TAP event): {:?}", e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 16:16:10 +00:00
|
|
|
RX_TAP_EVENT => {
|
|
|
|
if let Err(e) = self.handle_rx_tap_event() {
|
|
|
|
error!("Error processing tap queue: {:?}", e);
|
|
|
|
return true;
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-25 21:17:05 +00:00
|
|
|
RX_RATE_LIMITER_EVENT => {
|
|
|
|
if let Some(rate_limiter) = &mut self.net.rx_rate_limiter {
|
|
|
|
// Upon rate limiter event, call the rate limiter handler and register the
|
|
|
|
// TAP fd for further processing if some RX buffers are available
|
|
|
|
match rate_limiter.event_handler() {
|
|
|
|
Ok(_) => {
|
|
|
|
if !self.net.rx_tap_listening && self.net.rx_desc_avail {
|
|
|
|
if let Err(e) = net_util::register_listener(
|
|
|
|
self.net.epoll_fd.unwrap(),
|
|
|
|
self.net.tap.as_raw_fd(),
|
|
|
|
epoll::Events::EPOLLIN,
|
2021-06-28 13:51:34 +00:00
|
|
|
u64::from(self.net.tap_rx_event_id),
|
2021-03-25 21:17:05 +00:00
|
|
|
) {
|
|
|
|
error!("Error register_listener with `RX_RATE_LIMITER_EVENT`: {:?}", e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
self.net.rx_tap_listening = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
error!("Error from 'rate_limiter.event_handler()': {:?}", e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error!("Unexpected RX_RATE_LIMITER_EVENT");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-03-17 22:41:52 +00:00
|
|
|
TX_RATE_LIMITER_EVENT => {
|
|
|
|
if let Some(rate_limiter) = &mut self.net.tx_rate_limiter {
|
|
|
|
// Upon rate limiter event, call the rate limiter handler
|
|
|
|
// and restart processing the queue.
|
|
|
|
match rate_limiter.event_handler() {
|
|
|
|
Ok(_) => {
|
|
|
|
self.driver_awake = true;
|
|
|
|
if let Err(e) = self.process_tx() {
|
|
|
|
error!("Error processing TX queue: {:?}", e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Err(e) => {
|
|
|
|
error!("Error from 'rate_limiter.event_handler()': {:?}", e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
error!("Unexpected TX_RATE_LIMITER_EVENT");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2020-07-23 16:16:10 +00:00
|
|
|
_ => {
|
2020-08-11 17:12:02 +00:00
|
|
|
error!("Unknown event: {}", ev_type);
|
2020-07-23 16:16:10 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
2020-07-23 16:16:10 +00:00
|
|
|
false
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Net {
|
2020-09-03 09:37:36 +00:00
|
|
|
common: VirtioCommon,
|
2020-04-27 09:29:16 +00:00
|
|
|
id: String,
|
2021-04-28 14:34:44 +00:00
|
|
|
taps: Vec<Tap>,
|
2020-01-27 16:37:14 +00:00
|
|
|
config: VirtioNetConfig,
|
2020-08-12 10:22:00 +00:00
|
|
|
ctrl_queue_epoll_thread: Option<thread::JoinHandle<()>>,
|
2020-06-23 15:28:41 +00:00
|
|
|
counters: NetCounters,
|
2020-08-04 18:27:17 +00:00
|
|
|
seccomp_action: SeccompAction,
|
2021-03-17 22:41:52 +00:00
|
|
|
rate_limiter_config: Option<RateLimiterConfig>,
|
2021-09-07 15:10:48 +00:00
|
|
|
exit_evt: EventFd,
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 14:02:43 +00:00
|
|
|
#[derive(Versionize)]
|
2020-04-21 15:28:59 +00:00
|
|
|
pub struct NetState {
|
|
|
|
pub avail_features: u64,
|
|
|
|
pub acked_features: u64,
|
|
|
|
pub config: VirtioNetConfig,
|
|
|
|
pub queue_size: Vec<u16>,
|
|
|
|
}
|
|
|
|
|
2021-05-06 13:34:31 +00:00
|
|
|
impl VersionMapped for NetState {}
|
|
|
|
|
2019-05-08 00:26:37 +00:00
|
|
|
impl Net {
|
|
|
|
/// Create a new virtio network device with the given TAP interface.
|
2021-03-17 22:41:52 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-01-09 17:29:00 +00:00
|
|
|
pub fn new_with_tap(
|
2020-04-27 09:29:16 +00:00
|
|
|
id: String,
|
2020-01-09 17:29:00 +00:00
|
|
|
taps: Vec<Tap>,
|
|
|
|
guest_mac: Option<MacAddr>,
|
|
|
|
iommu: bool,
|
|
|
|
num_queues: usize,
|
|
|
|
queue_size: u16,
|
2020-08-04 18:27:17 +00:00
|
|
|
seccomp_action: SeccompAction,
|
2021-03-17 22:41:52 +00:00
|
|
|
rate_limiter_config: Option<RateLimiterConfig>,
|
2021-09-07 15:10:48 +00:00
|
|
|
exit_evt: EventFd,
|
2020-01-09 17:29:00 +00:00
|
|
|
) -> Result<Self> {
|
2021-04-26 15:34:42 +00:00
|
|
|
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
|
2021-04-28 14:35:50 +00:00
|
|
|
| 1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS
|
2021-04-26 15:34:42 +00:00
|
|
|
| 1 << VIRTIO_NET_F_GUEST_CSUM
|
|
|
|
| 1 << VIRTIO_NET_F_GUEST_ECN
|
2019-05-08 00:26:37 +00:00
|
|
|
| 1 << VIRTIO_NET_F_GUEST_TSO4
|
2021-04-26 15:34:42 +00:00
|
|
|
| 1 << VIRTIO_NET_F_GUEST_TSO6
|
2019-05-08 00:26:37 +00:00
|
|
|
| 1 << VIRTIO_NET_F_GUEST_UFO
|
2021-04-26 15:34:42 +00:00
|
|
|
| 1 << VIRTIO_NET_F_HOST_ECN
|
2019-05-08 00:26:37 +00:00
|
|
|
| 1 << VIRTIO_NET_F_HOST_TSO4
|
2021-04-26 15:34:42 +00:00
|
|
|
| 1 << VIRTIO_NET_F_HOST_TSO6
|
2019-05-08 00:26:37 +00:00
|
|
|
| 1 << VIRTIO_NET_F_HOST_UFO
|
2021-11-03 16:22:03 +00:00
|
|
|
| 1 << VIRTIO_NET_F_MRG_RXBUF
|
2020-06-01 12:08:53 +00:00
|
|
|
| 1 << VIRTIO_RING_F_EVENT_IDX
|
2021-11-03 16:22:03 +00:00
|
|
|
| 1 << VIRTIO_RING_F_INDIRECT_DESC
|
2019-05-08 00:26:37 +00:00
|
|
|
| 1 << VIRTIO_F_VERSION_1;
|
|
|
|
|
2019-10-02 21:26:02 +00:00
|
|
|
if iommu {
|
|
|
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
|
|
|
}
|
|
|
|
|
2020-01-15 09:32:05 +00:00
|
|
|
avail_features |= 1 << VIRTIO_NET_F_CTRL_VQ;
|
2020-01-09 17:29:00 +00:00
|
|
|
let queue_num = num_queues + 1;
|
2020-01-15 09:32:05 +00:00
|
|
|
|
2020-01-27 16:37:14 +00:00
|
|
|
let mut config = VirtioNetConfig::default();
|
2019-05-08 00:26:37 +00:00
|
|
|
if let Some(mac) = guest_mac {
|
2020-01-27 16:37:14 +00:00
|
|
|
build_net_config_space(&mut config, mac, num_queues, &mut avail_features);
|
2019-05-08 00:26:37 +00:00
|
|
|
} else {
|
2020-01-27 16:37:14 +00:00
|
|
|
build_net_config_space_with_mq(&mut config, num_queues, &mut avail_features);
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(Net {
|
2020-09-03 09:37:36 +00:00
|
|
|
common: VirtioCommon {
|
2021-03-25 16:54:09 +00:00
|
|
|
device_type: VirtioDeviceType::Net as u32,
|
2020-09-03 09:37:36 +00:00
|
|
|
avail_features,
|
2020-09-04 08:37:37 +00:00
|
|
|
queue_sizes: vec![queue_size; queue_num],
|
|
|
|
paused_sync: Some(Arc::new(Barrier::new((num_queues / 2) + 1))),
|
2021-01-19 06:11:07 +00:00
|
|
|
min_queues: 2,
|
2020-09-03 15:56:32 +00:00
|
|
|
..Default::default()
|
2020-09-03 09:37:36 +00:00
|
|
|
},
|
2020-04-27 09:29:16 +00:00
|
|
|
id,
|
2021-04-28 14:34:44 +00:00
|
|
|
taps,
|
2020-01-27 16:37:14 +00:00
|
|
|
config,
|
2020-01-15 09:32:05 +00:00
|
|
|
ctrl_queue_epoll_thread: None,
|
2020-06-23 15:28:41 +00:00
|
|
|
counters: NetCounters::default(),
|
2020-08-04 18:27:17 +00:00
|
|
|
seccomp_action,
|
2021-03-17 22:41:52 +00:00
|
|
|
rate_limiter_config,
|
2021-09-07 15:10:48 +00:00
|
|
|
exit_evt,
|
2019-05-08 00:26:37 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a new virtio network device with the given IP address and
|
|
|
|
/// netmask.
|
2020-04-27 09:29:16 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2019-10-02 21:26:02 +00:00
|
|
|
pub fn new(
|
2020-04-27 09:29:16 +00:00
|
|
|
id: String,
|
2020-01-09 17:29:00 +00:00
|
|
|
if_name: Option<&str>,
|
|
|
|
ip_addr: Option<Ipv4Addr>,
|
|
|
|
netmask: Option<Ipv4Addr>,
|
2020-01-09 11:56:21 +00:00
|
|
|
guest_mac: Option<MacAddr>,
|
2020-06-05 11:00:34 +00:00
|
|
|
host_mac: &mut Option<MacAddr>,
|
2019-10-02 21:26:02 +00:00
|
|
|
iommu: bool,
|
2020-01-09 17:29:00 +00:00
|
|
|
num_queues: usize,
|
|
|
|
queue_size: u16,
|
2020-08-04 18:27:17 +00:00
|
|
|
seccomp_action: SeccompAction,
|
2021-03-17 22:41:52 +00:00
|
|
|
rate_limiter_config: Option<RateLimiterConfig>,
|
2021-09-07 15:10:48 +00:00
|
|
|
exit_evt: EventFd,
|
2019-10-02 21:26:02 +00:00
|
|
|
) -> Result<Self> {
|
2021-01-27 17:52:22 +00:00
|
|
|
let taps = open_tap(if_name, ip_addr, netmask, host_mac, num_queues / 2, None)
|
2020-05-15 09:00:38 +00:00
|
|
|
.map_err(Error::OpenTap)?;
|
2019-05-08 00:26:37 +00:00
|
|
|
|
2020-08-04 18:27:17 +00:00
|
|
|
Self::new_with_tap(
|
|
|
|
id,
|
|
|
|
taps,
|
|
|
|
guest_mac,
|
|
|
|
iommu,
|
|
|
|
num_queues,
|
|
|
|
queue_size,
|
|
|
|
seccomp_action,
|
2021-03-17 22:41:52 +00:00
|
|
|
rate_limiter_config,
|
2021-09-07 15:10:48 +00:00
|
|
|
exit_evt,
|
2020-08-04 18:27:17 +00:00
|
|
|
)
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
2020-04-21 15:28:59 +00:00
|
|
|
|
2021-09-07 15:10:48 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2021-01-27 04:52:50 +00:00
|
|
|
pub fn from_tap_fds(
|
2020-12-16 17:00:59 +00:00
|
|
|
id: String,
|
2021-01-27 04:52:50 +00:00
|
|
|
fds: &[RawFd],
|
2020-12-16 17:00:59 +00:00
|
|
|
guest_mac: Option<MacAddr>,
|
|
|
|
iommu: bool,
|
|
|
|
queue_size: u16,
|
|
|
|
seccomp_action: SeccompAction,
|
2021-03-17 22:41:52 +00:00
|
|
|
rate_limiter_config: Option<RateLimiterConfig>,
|
2021-09-07 15:10:48 +00:00
|
|
|
exit_evt: EventFd,
|
2020-12-16 17:00:59 +00:00
|
|
|
) -> Result<Self> {
|
2021-01-27 04:52:50 +00:00
|
|
|
let mut taps: Vec<Tap> = Vec::new();
|
|
|
|
let num_queue_pairs = fds.len();
|
|
|
|
|
|
|
|
for fd in fds.iter() {
|
2021-04-22 09:24:15 +00:00
|
|
|
// Duplicate so that it can survive reboots
|
|
|
|
let fd = unsafe { libc::dup(*fd) };
|
|
|
|
if fd < 0 {
|
|
|
|
return Err(Error::DuplicateTapFd(std::io::Error::last_os_error()));
|
|
|
|
}
|
|
|
|
let tap = Tap::from_tap_fd(fd, num_queue_pairs).map_err(Error::TapError)?;
|
2021-01-27 04:52:50 +00:00
|
|
|
taps.push(tap);
|
|
|
|
}
|
|
|
|
|
2020-12-16 17:00:59 +00:00
|
|
|
Self::new_with_tap(
|
|
|
|
id,
|
2021-01-27 04:52:50 +00:00
|
|
|
taps,
|
2020-12-16 17:00:59 +00:00
|
|
|
guest_mac,
|
|
|
|
iommu,
|
2021-01-27 04:52:50 +00:00
|
|
|
num_queue_pairs * 2,
|
2020-12-16 17:00:59 +00:00
|
|
|
queue_size,
|
|
|
|
seccomp_action,
|
2021-03-17 22:41:52 +00:00
|
|
|
rate_limiter_config,
|
2021-09-07 15:10:48 +00:00
|
|
|
exit_evt,
|
2020-12-16 17:00:59 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-04-21 15:28:59 +00:00
|
|
|
fn state(&self) -> NetState {
|
|
|
|
NetState {
|
2020-09-03 09:37:36 +00:00
|
|
|
avail_features: self.common.avail_features,
|
|
|
|
acked_features: self.common.acked_features,
|
2020-04-21 15:28:59 +00:00
|
|
|
config: self.config,
|
2020-09-04 08:37:37 +00:00
|
|
|
queue_size: self.common.queue_sizes.clone(),
|
2020-04-21 15:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-11 16:00:53 +00:00
|
|
|
fn set_state(&mut self, state: &NetState) {
|
2020-09-03 09:37:36 +00:00
|
|
|
self.common.avail_features = state.avail_features;
|
|
|
|
self.common.acked_features = state.acked_features;
|
2020-04-21 15:28:59 +00:00
|
|
|
self.config = state.config;
|
2020-09-04 08:37:37 +00:00
|
|
|
self.common.queue_sizes = state.queue_size.clone();
|
2020-04-21 15:28:59 +00:00
|
|
|
}
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Net {
|
|
|
|
fn drop(&mut self) {
|
2020-09-04 08:37:37 +00:00
|
|
|
if let Some(kill_evt) = self.common.kill_evt.take() {
|
2019-05-08 00:26:37 +00:00
|
|
|
// Ignore the result because there is nothing we can do about it.
|
|
|
|
let _ = kill_evt.write(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl VirtioDevice for Net {
|
|
|
|
fn device_type(&self) -> u32 {
|
2020-09-04 08:37:37 +00:00
|
|
|
self.common.device_type
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn queue_max_sizes(&self) -> &[u16] {
|
2020-09-04 08:37:37 +00:00
|
|
|
&self.common.queue_sizes
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 10:14:38 +00:00
|
|
|
fn features(&self) -> u64 {
|
2020-09-03 09:37:36 +00:00
|
|
|
self.common.avail_features
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
2020-01-23 10:14:38 +00:00
|
|
|
fn ack_features(&mut self, value: u64) {
|
2020-09-03 09:37:36 +00:00
|
|
|
self.common.ack_features(value)
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 09:34:51 +00:00
|
|
|
fn read_config(&self, offset: u64, data: &mut [u8]) {
|
|
|
|
self.read_config_from_slice(self.config.as_slice(), offset, data);
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn activate(
|
|
|
|
&mut self,
|
2021-10-21 10:41:16 +00:00
|
|
|
_mem: GuestMemoryAtomic<GuestMemoryMmap>,
|
2020-01-13 17:52:19 +00:00
|
|
|
interrupt_cb: Arc<dyn VirtioInterrupt>,
|
2021-10-21 10:41:16 +00:00
|
|
|
mut queues: Vec<Queue<GuestMemoryAtomic<GuestMemoryMmap>>>,
|
2019-05-08 00:26:37 +00:00
|
|
|
mut queue_evts: Vec<EventFd>,
|
|
|
|
) -> ActivateResult {
|
2021-04-28 14:34:44 +00:00
|
|
|
self.common.activate(&queues, &queue_evts, &interrupt_cb)?;
|
|
|
|
|
|
|
|
let queue_num = queues.len();
|
|
|
|
if self.common.feature_acked(VIRTIO_NET_F_CTRL_VQ.into()) && queue_num % 2 != 0 {
|
|
|
|
let cvq_queue = queues.remove(queue_num - 1);
|
|
|
|
let cvq_queue_evt = queue_evts.remove(queue_num - 1);
|
|
|
|
|
2021-06-02 18:08:06 +00:00
|
|
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
2021-04-28 14:34:44 +00:00
|
|
|
let mut ctrl_handler = NetCtrlEpollHandler {
|
|
|
|
kill_evt,
|
|
|
|
pause_evt,
|
2021-05-21 10:52:07 +00:00
|
|
|
ctrl_q: CtrlQueue::new(self.taps.clone()),
|
|
|
|
queue: cvq_queue,
|
|
|
|
queue_evt: cvq_queue_evt,
|
2021-04-28 14:34:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let paused = self.common.paused.clone();
|
|
|
|
// Let's update the barrier as we need 1 for each RX/TX pair +
|
|
|
|
// 1 for the control queue + 1 for the main thread signalling
|
|
|
|
// the pause.
|
|
|
|
self.common.paused_sync = Some(Arc::new(Barrier::new(self.taps.len() + 2)));
|
|
|
|
let paused_sync = self.common.paused_sync.clone();
|
|
|
|
|
2021-09-03 10:43:30 +00:00
|
|
|
let mut epoll_threads = Vec::new();
|
|
|
|
spawn_virtio_thread(
|
|
|
|
&format!("{}_ctrl", &self.id),
|
|
|
|
&self.seccomp_action,
|
|
|
|
Thread::VirtioNetCtl,
|
|
|
|
&mut epoll_threads,
|
2021-09-07 15:10:48 +00:00
|
|
|
&self.exit_evt,
|
2021-09-03 10:43:30 +00:00
|
|
|
move || {
|
2021-08-17 00:20:11 +00:00
|
|
|
if let Err(e) = ctrl_handler.run_ctrl(paused, paused_sync.unwrap()) {
|
2021-04-28 14:34:44 +00:00
|
|
|
error!("Error running worker: {:?}", e);
|
|
|
|
}
|
2021-09-03 10:43:30 +00:00
|
|
|
},
|
|
|
|
)?;
|
|
|
|
self.ctrl_queue_epoll_thread = Some(epoll_threads.remove(0));
|
2021-04-28 14:34:44 +00:00
|
|
|
}
|
2020-01-15 09:32:05 +00:00
|
|
|
|
2021-04-28 14:34:44 +00:00
|
|
|
let event_idx = self.common.feature_acked(VIRTIO_RING_F_EVENT_IDX.into());
|
|
|
|
|
|
|
|
let mut epoll_threads = Vec::new();
|
|
|
|
let mut taps = self.taps.clone();
|
2021-05-05 07:22:33 +00:00
|
|
|
for i in 0..queues.len() / 2 {
|
2021-04-28 14:34:44 +00:00
|
|
|
let rx = RxVirtio::new();
|
|
|
|
let tx = TxVirtio::new();
|
|
|
|
let rx_tap_listening = false;
|
|
|
|
|
|
|
|
let mut queue_pair = vec![queues.remove(0), queues.remove(0)];
|
|
|
|
queue_pair[0].set_event_idx(event_idx);
|
|
|
|
queue_pair[1].set_event_idx(event_idx);
|
|
|
|
|
|
|
|
let queue_evt_pair = vec![queue_evts.remove(0), queue_evts.remove(0)];
|
|
|
|
|
2021-06-02 18:08:06 +00:00
|
|
|
let (kill_evt, pause_evt) = self.common.dup_eventfds();
|
2021-04-28 14:34:44 +00:00
|
|
|
|
|
|
|
let rx_rate_limiter: Option<rate_limiter::RateLimiter> = self
|
|
|
|
.rate_limiter_config
|
|
|
|
.map(RateLimiterConfig::try_into)
|
|
|
|
.transpose()
|
|
|
|
.map_err(ActivateError::CreateRateLimiter)?;
|
|
|
|
|
|
|
|
let tx_rate_limiter: Option<rate_limiter::RateLimiter> = self
|
|
|
|
.rate_limiter_config
|
|
|
|
.map(RateLimiterConfig::try_into)
|
|
|
|
.transpose()
|
|
|
|
.map_err(ActivateError::CreateRateLimiter)?;
|
|
|
|
|
|
|
|
let tap = taps.remove(0);
|
|
|
|
tap.set_offload(virtio_features_to_tap_offload(self.common.acked_features))
|
|
|
|
.map_err(|e| {
|
|
|
|
error!("Error programming tap offload: {:?}", e);
|
|
|
|
ActivateError::BadActivate
|
|
|
|
})?;
|
|
|
|
|
|
|
|
let mut handler = NetEpollHandler {
|
|
|
|
net: NetQueuePair {
|
2021-06-28 14:28:26 +00:00
|
|
|
tap_for_write_epoll: tap.clone(),
|
2021-04-28 14:34:44 +00:00
|
|
|
tap,
|
|
|
|
rx,
|
|
|
|
tx,
|
|
|
|
epoll_fd: None,
|
|
|
|
rx_tap_listening,
|
2021-06-28 14:28:26 +00:00
|
|
|
tx_tap_listening: false,
|
2021-04-28 14:34:44 +00:00
|
|
|
counters: self.counters.clone(),
|
2021-06-28 13:51:34 +00:00
|
|
|
tap_rx_event_id: RX_TAP_EVENT,
|
2021-06-28 14:28:26 +00:00
|
|
|
tap_tx_event_id: TX_TAP_EVENT,
|
2021-04-28 14:34:44 +00:00
|
|
|
rx_desc_avail: false,
|
|
|
|
rx_rate_limiter,
|
|
|
|
tx_rate_limiter,
|
|
|
|
},
|
|
|
|
queue_pair,
|
|
|
|
queue_evt_pair,
|
|
|
|
interrupt_cb: interrupt_cb.clone(),
|
|
|
|
kill_evt,
|
|
|
|
pause_evt,
|
|
|
|
driver_awake: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
let paused = self.common.paused.clone();
|
|
|
|
let paused_sync = self.common.paused_sync.clone();
|
2021-09-03 10:43:30 +00:00
|
|
|
|
|
|
|
spawn_virtio_thread(
|
|
|
|
&format!("{}_qp{}", self.id.clone(), i),
|
|
|
|
&self.seccomp_action,
|
|
|
|
Thread::VirtioNet,
|
|
|
|
&mut epoll_threads,
|
2021-09-07 15:10:48 +00:00
|
|
|
&self.exit_evt,
|
2021-09-03 10:43:30 +00:00
|
|
|
move || {
|
2021-08-17 00:20:11 +00:00
|
|
|
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
|
2021-04-28 14:34:44 +00:00
|
|
|
error!("Error running worker: {:?}", e);
|
|
|
|
}
|
2021-09-03 10:43:30 +00:00
|
|
|
},
|
|
|
|
)?;
|
2021-04-28 14:34:44 +00:00
|
|
|
}
|
2020-01-09 17:29:00 +00:00
|
|
|
|
2021-04-28 14:34:44 +00:00
|
|
|
self.common.epoll_threads = Some(epoll_threads);
|
2019-05-08 00:26:37 +00:00
|
|
|
|
2021-04-28 14:34:44 +00:00
|
|
|
event!("virtio-device", "activated", "id", &self.id);
|
|
|
|
Ok(())
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
2019-10-02 18:21:34 +00:00
|
|
|
|
2021-01-18 12:38:08 +00:00
|
|
|
fn reset(&mut self) -> Option<Arc<dyn VirtioInterrupt>> {
|
2021-02-18 15:10:51 +00:00
|
|
|
let result = self.common.reset();
|
|
|
|
event!("virtio-device", "reset", "id", &self.id);
|
|
|
|
result
|
2019-10-02 18:21:34 +00:00
|
|
|
}
|
2020-06-24 09:50:04 +00:00
|
|
|
|
|
|
|
fn counters(&self) -> Option<HashMap<&'static str, Wrapping<u64>>> {
|
|
|
|
let mut counters = HashMap::new();
|
|
|
|
|
|
|
|
counters.insert(
|
|
|
|
"rx_bytes",
|
|
|
|
Wrapping(self.counters.rx_bytes.load(Ordering::Acquire)),
|
|
|
|
);
|
|
|
|
counters.insert(
|
|
|
|
"rx_frames",
|
|
|
|
Wrapping(self.counters.rx_frames.load(Ordering::Acquire)),
|
|
|
|
);
|
|
|
|
counters.insert(
|
|
|
|
"tx_bytes",
|
|
|
|
Wrapping(self.counters.tx_bytes.load(Ordering::Acquire)),
|
|
|
|
);
|
|
|
|
counters.insert(
|
|
|
|
"tx_frames",
|
|
|
|
Wrapping(self.counters.tx_frames.load(Ordering::Acquire)),
|
|
|
|
);
|
|
|
|
|
|
|
|
Some(counters)
|
|
|
|
}
|
2019-05-08 00:26:37 +00:00
|
|
|
}
|
2019-11-19 00:42:31 +00:00
|
|
|
|
2020-09-04 08:37:37 +00:00
|
|
|
impl Pausable for Net {
|
|
|
|
fn pause(&mut self) -> result::Result<(), MigratableError> {
|
|
|
|
self.common.pause()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn resume(&mut self) -> result::Result<(), MigratableError> {
|
|
|
|
self.common.resume()?;
|
|
|
|
|
|
|
|
if let Some(ctrl_queue_epoll_thread) = &self.ctrl_queue_epoll_thread {
|
|
|
|
ctrl_queue_epoll_thread.thread().unpark();
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 15:28:59 +00:00
|
|
|
impl Snapshottable for Net {
|
|
|
|
fn id(&self) -> String {
|
2020-04-27 09:29:16 +00:00
|
|
|
self.id.clone()
|
2020-04-21 15:28:59 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 12:31:58 +00:00
|
|
|
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
2021-05-06 13:34:31 +00:00
|
|
|
Snapshot::new_from_versioned_state(&self.id, &self.state())
|
2020-04-21 15:28:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
|
2021-05-06 13:34:31 +00:00
|
|
|
self.set_state(&snapshot.to_versioned_state(&self.id)?);
|
2021-04-08 09:20:10 +00:00
|
|
|
Ok(())
|
2020-04-21 15:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-01 16:59:51 +00:00
|
|
|
impl Transportable for Net {}
|
2019-11-19 00:42:31 +00:00
|
|
|
impl Migratable for Net {}
|