vmm/devices/virtio/net/
mod.rs

1// Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2// SPDX-License-Identifier: Apache-2.0
3
4//! Implements a virtio network device.
5
6use std::io;
7
8/// Maximum size of the queue for network device.
9pub const NET_QUEUE_MAX_SIZE: u16 = 256;
10/// Maximum size of the frame buffers handled by this device.
11pub const MAX_BUFFER_SIZE: usize = 65562;
12/// The number of queues of the network device.
13pub const NET_NUM_QUEUES: usize = 2;
14pub const NET_QUEUE_SIZES: [u16; NET_NUM_QUEUES] = [NET_QUEUE_MAX_SIZE; NET_NUM_QUEUES];
15/// The index of the rx queue from Net device queues/queues_evts vector.
16pub const RX_INDEX: usize = 0;
17/// The index of the tx queue from Net device queues/queues_evts vector.
18pub const TX_INDEX: usize = 1;
19
20pub mod device;
21mod event_handler;
22pub mod metrics;
23pub mod persist;
24mod tap;
25pub mod test_utils;
26
27mod generated;
28
29pub use tap::{Tap, TapError};
30use vm_memory::VolatileMemoryError;
31
32pub use self::device::Net;
33use super::iovec::IoVecError;
34use crate::devices::virtio::queue::{InvalidAvailIdx, QueueError};
35
36/// Enum representing the Net device queue types
37#[derive(Debug)]
38pub enum NetQueue {
39    /// The RX queue
40    Rx,
41    /// The TX queue
42    Tx,
43}
44
45/// Errors the network device can trigger.
46#[derive(Debug, thiserror::Error, displaydoc::Display)]
47pub enum NetError {
48    /// Open tap device failed: {0}
49    TapOpen(TapError),
50    /// Setting vnet header size failed: {0}
51    TapSetVnetHdrSize(TapError),
52    /// EventFd error: {0}
53    EventFd(io::Error),
54    /// IO error: {0}
55    IO(io::Error),
56    /// Error writing in guest memory: {0}
57    GuestMemoryError(#[from] VolatileMemoryError),
58    /// The VNET header is missing from the frame
59    VnetHeaderMissing,
60    /// IoVecBuffer(Mut) error: {0}
61    IoVecError(#[from] IoVecError),
62    /// virtio queue error: {0}
63    QueueError(#[from] QueueError),
64    /// {0}
65    InvalidAvailIdx(#[from] InvalidAvailIdx),
66}