mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vhost-user_net, vm-virtio, vmm: Permit host MAC address setting
Add a new "host_mac" parameter to "--net" and "--net-backend" and use this to set the MAC address on the tap interface. If no address is given one is randomly assigned and is stored in the config. Support for vhost-user-net self spawning was also included. Fixes: #1177 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
@@ -392,11 +392,13 @@ impl Net {
|
||||
ip_addr: Option<Ipv4Addr>,
|
||||
netmask: Option<Ipv4Addr>,
|
||||
guest_mac: Option<MacAddr>,
|
||||
host_mac: Option<MacAddr>,
|
||||
iommu: bool,
|
||||
num_queues: usize,
|
||||
queue_size: u16,
|
||||
) -> Result<Self> {
|
||||
let taps = open_tap(if_name, ip_addr, netmask, num_queues / 2).map_err(Error::OpenTap)?;
|
||||
let taps = open_tap(if_name, ip_addr, netmask, host_mac, num_queues / 2)
|
||||
.map_err(Error::OpenTap)?;
|
||||
|
||||
Self::new_with_tap(id, taps, guest_mac, iommu, num_queues, queue_size)
|
||||
}
|
||||
|
||||
@@ -119,6 +119,8 @@ pub enum Error {
|
||||
TapSetIp(TapError),
|
||||
/// Setting tap netmask failed.
|
||||
TapSetNetmask(TapError),
|
||||
/// Setting MAC address failed
|
||||
TapSetMac(TapError),
|
||||
/// Setting tap interface offload flags failed.
|
||||
TapSetOffload(TapError),
|
||||
/// Setting vnet header size failed.
|
||||
@@ -531,6 +533,7 @@ pub fn open_tap(
|
||||
if_name: Option<&str>,
|
||||
ip_addr: Option<Ipv4Addr>,
|
||||
netmask: Option<Ipv4Addr>,
|
||||
host_mac: Option<MacAddr>,
|
||||
num_rx_q: usize,
|
||||
) -> Result<Vec<Tap>> {
|
||||
let mut taps: Vec<Tap> = Vec::new();
|
||||
@@ -558,6 +561,9 @@ pub fn open_tap(
|
||||
if let Some(mask) = netmask {
|
||||
tap.set_netmask(mask).map_err(Error::TapSetNetmask)?;
|
||||
}
|
||||
if let Some(mac) = host_mac {
|
||||
tap.set_mac_addr(mac).map_err(Error::TapSetMac)?
|
||||
}
|
||||
tap.enable().map_err(Error::TapEnable)?;
|
||||
tap.set_offload(flag).map_err(Error::TapSetOffload)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user