From 72e5ed337287241289b1f1edcdd9305fc148e5d6 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 16 Dec 2020 17:29:05 +0000 Subject: [PATCH] vmm: config: Extend NetConfig to include fd for tap device Add an "fd=" parameter to allow specifying a TAP fd to use. Currently only one fd for one queue pair is supported. Fixes: #2052 Signed-off-by: Rob Bradford --- vmm/src/config.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 22fbcf2cd..1ac3d749f 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -764,6 +764,8 @@ pub struct NetConfig { pub vhost_socket: Option, #[serde(default)] pub id: Option, + #[serde(default)] + pub fd: Option, } fn default_netconfig_tap() -> Option { @@ -804,13 +806,14 @@ impl Default for NetConfig { vhost_user: false, vhost_socket: None, id: None, + fd: None, } } } impl NetConfig { pub const SYNTAX: &'static str = "Network parameters \ - \"tap=,ip=,mask=,mac=,iommu=on|off,\ + \"tap=,ip=,mask=,mac=,fd=,iommu=on|off,\ num_queues=,queue_size=,\ vhost_user=,socket=,id=\""; @@ -828,7 +831,8 @@ impl NetConfig { .add("num_queues") .add("vhost_user") .add("socket") - .add("id"); + .add("id") + .add("fd"); parser.parse(net).map_err(Error::ParseNetwork)?; let tap = parser.get("tap"); @@ -865,6 +869,7 @@ impl NetConfig { .0; let vhost_socket = parser.get("socket"); let id = parser.get("id"); + let fd = parser.convert("fd").map_err(Error::ParseNetwork)?; let config = NetConfig { tap, ip, @@ -877,6 +882,7 @@ impl NetConfig { vhost_user, vhost_socket, id, + fd, }; config.validate().map_err(Error::Validation)?; Ok(config) @@ -1942,6 +1948,15 @@ mod tests { } ); + assert_eq!( + NetConfig::parse("mac=de:ad:be:ef:12:34,fd=3")?, + NetConfig { + mac: MacAddr::parse_str("de:ad:be:ef:12:34").unwrap(), + fd: Some(3), + ..Default::default() + } + ); + Ok(()) }