mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Sebastien Boeuf
parent
1f8b6fa947
commit
9b71ba20ac
@@ -465,7 +465,7 @@ impl Net {
|
||||
ip_addr: Option<Ipv4Addr>,
|
||||
netmask: Option<Ipv4Addr>,
|
||||
guest_mac: Option<MacAddr>,
|
||||
host_mac: Option<MacAddr>,
|
||||
host_mac: &mut Option<MacAddr>,
|
||||
iommu: bool,
|
||||
num_queues: usize,
|
||||
queue_size: u16,
|
||||
|
||||
@@ -122,6 +122,8 @@ pub enum Error {
|
||||
TapSetNetmask(TapError),
|
||||
/// Setting MAC address failed
|
||||
TapSetMac(TapError),
|
||||
/// Getting MAC address failed
|
||||
TapGetMac(TapError),
|
||||
/// Setting tap interface offload flags failed.
|
||||
TapSetOffload(TapError),
|
||||
/// Setting vnet header size failed.
|
||||
@@ -539,7 +541,7 @@ pub fn open_tap(
|
||||
if_name: Option<&str>,
|
||||
ip_addr: Option<Ipv4Addr>,
|
||||
netmask: Option<Ipv4Addr>,
|
||||
host_mac: Option<MacAddr>,
|
||||
host_mac: &mut Option<MacAddr>,
|
||||
num_rx_q: usize,
|
||||
) -> Result<Vec<Tap>> {
|
||||
let mut taps: Vec<Tap> = Vec::new();
|
||||
@@ -568,7 +570,9 @@ pub fn open_tap(
|
||||
tap.set_netmask(mask).map_err(Error::TapSetNetmask)?;
|
||||
}
|
||||
if let Some(mac) = host_mac {
|
||||
tap.set_mac_addr(mac).map_err(Error::TapSetMac)?
|
||||
tap.set_mac_addr(*mac).map_err(Error::TapSetMac)?
|
||||
} else {
|
||||
*host_mac = Some(tap.get_mac_addr().map_err(Error::TapGetMac)?)
|
||||
}
|
||||
tap.enable().map_err(Error::TapEnable)?;
|
||||
tap.set_offload(flag).map_err(Error::TapSetOffload)?;
|
||||
|
||||
Reference in New Issue
Block a user