vmm, vm-virtio: Stop always autogenerating a host MAC address

This removes the need to use CAP_NET_ADMIN privileges and instead the
host MAC addres is either provided by the user or alternatively it is
retrieved from the kernel.

TEST=Run cloud-hypervisor without CAP_NET_ADMIN permission and a
preconfigured tap device:

sudo ip tuntap add name tap0 mode tap
sudo ifconfig tap0 192.168.249.1 netmask 255.255.255.0 up
cargo clean
cargo build
target/debug/cloud-hypervisor --serial tty --console off --kernel ~/src/rust-hypervisor-firmware/target/target/release/hypervisor-fw --disk path=~/workloads/clear-33190-kvm.img --net tap=tap0

VM was also rebooted to check that works correctly.

Fixes: #1274

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2020-06-05 12:00:34 +01:00
committed by Sebastien Boeuf
parent 1f8b6fa947
commit 9b71ba20ac
5 changed files with 25 additions and 20 deletions

View File

@@ -1512,13 +1512,17 @@ impl DeviceManager {
.args(&[
"--net-backend",
&format!(
"ip={},mask={},socket={},num_queues={},queue_size={},host_mac={}",
"ip={},mask={},socket={},num_queues={},queue_size={}{}",
net_cfg.ip,
net_cfg.mask,
&socket,
net_cfg.num_queues,
net_cfg.queue_size,
net_cfg.host_mac
if let Some(mac) = net_cfg.host_mac {
format!(",host_mac={:}", mac)
} else {
"".to_owned()
}
),
])
.spawn()
@@ -1583,7 +1587,7 @@ impl DeviceManager {
None,
None,
Some(net_cfg.mac),
Some(net_cfg.host_mac),
&mut net_cfg.host_mac,
net_cfg.iommu,
net_cfg.num_queues,
net_cfg.queue_size,
@@ -1598,7 +1602,7 @@ impl DeviceManager {
Some(net_cfg.ip),
Some(net_cfg.mask),
Some(net_cfg.mac),
Some(net_cfg.host_mac),
&mut net_cfg.host_mac,
net_cfg.iommu,
net_cfg.num_queues,
net_cfg.queue_size,