mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-04 19:11:11 +00:00
vmm: Make NetConfig owned
Convert str to String and remove the associated lifetime. Fixes #298 Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
675e46355c
commit
0688bec298
@ -217,15 +217,15 @@ impl DiskConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct NetConfig<'a> {
|
||||
pub tap: Option<&'a str>,
|
||||
pub struct NetConfig {
|
||||
pub tap: Option<String>,
|
||||
pub ip: Ipv4Addr,
|
||||
pub mask: Ipv4Addr,
|
||||
pub mac: MacAddr,
|
||||
}
|
||||
|
||||
impl<'a> NetConfig<'a> {
|
||||
pub fn parse(net: &'a str) -> Result<Self> {
|
||||
impl NetConfig {
|
||||
pub fn parse(net: &str) -> Result<Self> {
|
||||
// Split the parameters based on the comma delimiter
|
||||
let params_list: Vec<&str> = net.split(',').collect();
|
||||
|
||||
@ -246,13 +246,13 @@ impl<'a> NetConfig<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
let mut tap: Option<&str> = None;
|
||||
let mut tap: Option<String> = None;
|
||||
let mut ip: Ipv4Addr = Ipv4Addr::new(192, 168, 249, 1);
|
||||
let mut mask: Ipv4Addr = Ipv4Addr::new(255, 255, 255, 0);;
|
||||
let mut mac: MacAddr = MacAddr::local_random();
|
||||
|
||||
if !tap_str.is_empty() {
|
||||
tap = Some(tap_str);
|
||||
tap = Some(tap_str.to_string());
|
||||
}
|
||||
if !ip_str.is_empty() {
|
||||
ip = ip_str.parse().map_err(Error::ParseNetIpParam)?;
|
||||
@ -614,7 +614,7 @@ pub struct VmConfig<'a> {
|
||||
pub kernel: KernelConfig,
|
||||
pub cmdline: CmdlineConfig,
|
||||
pub disks: Option<Vec<DiskConfig>>,
|
||||
pub net: Option<Vec<NetConfig<'a>>>,
|
||||
pub net: Option<Vec<NetConfig>>,
|
||||
pub rng: RngConfig<'a>,
|
||||
pub fs: Option<Vec<FsConfig<'a>>>,
|
||||
pub pmem: Option<Vec<PmemConfig<'a>>>,
|
||||
|
@ -576,7 +576,7 @@ impl DeviceManager {
|
||||
// Add virtio-net if required
|
||||
if let Some(net_list_cfg) = &vm_info.vm_cfg.net {
|
||||
for net_cfg in net_list_cfg.iter() {
|
||||
let virtio_net_device = if let Some(tap_if_name) = net_cfg.tap {
|
||||
let virtio_net_device = if let Some(ref tap_if_name) = net_cfg.tap {
|
||||
let tap = Tap::open_named(tap_if_name).map_err(DeviceManagerError::OpenTap)?;
|
||||
vm_virtio::Net::new_with_tap(tap, Some(&net_cfg.mac))
|
||||
.map_err(DeviceManagerError::CreateVirtioNet)?
|
||||
|
Loading…
Reference in New Issue
Block a user