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(()) }