mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 11:25:20 +00:00
virtio-devices: net: Support creating a device from a TAP fd
Add support for creating virtio-net device from existing TAP fd. Currently only a single fd and thus no-more than 2 queues (one pair) is suppored. Fixes: #2052 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
444905071b
commit
ca48f1c995
@ -18,13 +18,13 @@ use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
|||||||
use crate::VirtioInterrupt;
|
use crate::VirtioInterrupt;
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use net_util::{
|
use net_util::{
|
||||||
open_tap, MacAddr, NetCounters, NetQueuePair, OpenTapError, RxVirtio, Tap, TxVirtio,
|
open_tap, MacAddr, NetCounters, NetQueuePair, OpenTapError, RxVirtio, Tap, TapError, TxVirtio,
|
||||||
};
|
};
|
||||||
use seccomp::{SeccompAction, SeccompFilter};
|
use seccomp::{SeccompAction, SeccompFilter};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::Ipv4Addr;
|
use std::net::Ipv4Addr;
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::{AsRawFd, RawFd};
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, Barrier};
|
use std::sync::{Arc, Barrier};
|
||||||
@ -50,6 +50,9 @@ pub const RX_TAP_EVENT: u16 = EPOLL_HELPER_EVENT_LAST + 3;
|
|||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Failed to open taps.
|
/// Failed to open taps.
|
||||||
OpenTap(OpenTapError),
|
OpenTap(OpenTapError),
|
||||||
|
|
||||||
|
// Using existing tap
|
||||||
|
TapError(TapError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
@ -293,6 +296,26 @@ impl Net {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_tap_fd(
|
||||||
|
id: String,
|
||||||
|
fd: RawFd,
|
||||||
|
guest_mac: Option<MacAddr>,
|
||||||
|
iommu: bool,
|
||||||
|
queue_size: u16,
|
||||||
|
seccomp_action: SeccompAction,
|
||||||
|
) -> Result<Self> {
|
||||||
|
let tap = Tap::from_tap_fd(fd).map_err(Error::TapError)?;
|
||||||
|
Self::new_with_tap(
|
||||||
|
id,
|
||||||
|
vec![tap],
|
||||||
|
guest_mac,
|
||||||
|
iommu,
|
||||||
|
2,
|
||||||
|
queue_size,
|
||||||
|
seccomp_action,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fn state(&self) -> NetState {
|
fn state(&self) -> NetState {
|
||||||
NetState {
|
NetState {
|
||||||
avail_features: self.common.avail_features,
|
avail_features: self.common.avail_features,
|
||||||
|
Loading…
Reference in New Issue
Block a user