mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-22 07:51:16 +00:00
net: Don't override default TAP interface MTU
Adjust MTU logic such that: 1. Apply an MTU to the TAP interface if the user supplies it 2. Always query the TAP interface for the MTU and expose that. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
44d66ec531
commit
903c08f8a1
@ -442,10 +442,9 @@ impl Net {
|
|||||||
rate_limiter_config: Option<RateLimiterConfig>,
|
rate_limiter_config: Option<RateLimiterConfig>,
|
||||||
exit_evt: EventFd,
|
exit_evt: EventFd,
|
||||||
) -> Result<Self> {
|
) -> Result<Self> {
|
||||||
let mut mtu = None;
|
assert!(!taps.is_empty());
|
||||||
if !taps.is_empty() {
|
|
||||||
mtu = Some(taps[0].mtu().map_err(Error::TapError)? as u16);
|
let mtu = taps[0].mtu().map_err(Error::TapError)? as u16;
|
||||||
}
|
|
||||||
|
|
||||||
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
|
let mut avail_features = 1 << VIRTIO_NET_F_CSUM
|
||||||
| 1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS
|
| 1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS
|
||||||
@ -458,12 +457,10 @@ impl Net {
|
|||||||
| 1 << VIRTIO_NET_F_HOST_TSO4
|
| 1 << VIRTIO_NET_F_HOST_TSO4
|
||||||
| 1 << VIRTIO_NET_F_HOST_TSO6
|
| 1 << VIRTIO_NET_F_HOST_TSO6
|
||||||
| 1 << VIRTIO_NET_F_HOST_UFO
|
| 1 << VIRTIO_NET_F_HOST_UFO
|
||||||
|
| 1 << VIRTIO_NET_F_MTU
|
||||||
| 1 << VIRTIO_RING_F_EVENT_IDX
|
| 1 << VIRTIO_RING_F_EVENT_IDX
|
||||||
| 1 << VIRTIO_F_VERSION_1;
|
| 1 << VIRTIO_F_VERSION_1;
|
||||||
|
|
||||||
if mtu.is_some() {
|
|
||||||
avail_features |= 1u64 << VIRTIO_NET_F_MTU;
|
|
||||||
}
|
|
||||||
if iommu {
|
if iommu {
|
||||||
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
avail_features |= 1u64 << VIRTIO_F_IOMMU_PLATFORM;
|
||||||
}
|
}
|
||||||
@ -473,9 +470,9 @@ impl Net {
|
|||||||
|
|
||||||
let mut config = VirtioNetConfig::default();
|
let mut config = VirtioNetConfig::default();
|
||||||
if let Some(mac) = guest_mac {
|
if let Some(mac) = guest_mac {
|
||||||
build_net_config_space(&mut config, mac, num_queues, mtu, &mut avail_features);
|
build_net_config_space(&mut config, mac, num_queues, Some(mtu), &mut avail_features);
|
||||||
} else {
|
} else {
|
||||||
build_net_config_space_with_mq(&mut config, num_queues, mtu, &mut avail_features);
|
build_net_config_space_with_mq(&mut config, num_queues, Some(mtu), &mut avail_features);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Net {
|
Ok(Net {
|
||||||
@ -545,6 +542,7 @@ impl Net {
|
|||||||
id: String,
|
id: String,
|
||||||
fds: &[RawFd],
|
fds: &[RawFd],
|
||||||
guest_mac: Option<MacAddr>,
|
guest_mac: Option<MacAddr>,
|
||||||
|
mtu: Option<u16>,
|
||||||
iommu: bool,
|
iommu: bool,
|
||||||
queue_size: u16,
|
queue_size: u16,
|
||||||
seccomp_action: SeccompAction,
|
seccomp_action: SeccompAction,
|
||||||
@ -565,6 +563,12 @@ impl Net {
|
|||||||
taps.push(tap);
|
taps.push(tap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert!(!taps.is_empty());
|
||||||
|
|
||||||
|
if let Some(mtu) = mtu {
|
||||||
|
taps[0].set_mtu(mtu as i32).map_err(Error::TapError)?;
|
||||||
|
}
|
||||||
|
|
||||||
Self::new_with_tap(
|
Self::new_with_tap(
|
||||||
id,
|
id,
|
||||||
taps,
|
taps,
|
||||||
|
@ -823,7 +823,6 @@ components:
|
|||||||
type: string
|
type: string
|
||||||
mtu:
|
mtu:
|
||||||
type: integer
|
type: integer
|
||||||
default: 1280
|
|
||||||
iommu:
|
iommu:
|
||||||
type: boolean
|
type: boolean
|
||||||
default: false
|
default: false
|
||||||
|
@ -1247,8 +1247,8 @@ pub struct NetConfig {
|
|||||||
pub mac: MacAddr,
|
pub mac: MacAddr,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub host_mac: Option<MacAddr>,
|
pub host_mac: Option<MacAddr>,
|
||||||
#[serde(default = "default_netconfig_mtu")]
|
#[serde(default)]
|
||||||
pub mtu: u16,
|
pub mtu: Option<u16>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub iommu: bool,
|
pub iommu: bool,
|
||||||
#[serde(default = "default_netconfig_num_queues")]
|
#[serde(default = "default_netconfig_num_queues")]
|
||||||
@ -1286,10 +1286,6 @@ fn default_netconfig_mac() -> MacAddr {
|
|||||||
MacAddr::local_random()
|
MacAddr::local_random()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_netconfig_mtu() -> u16 {
|
|
||||||
virtio_devices::net::MIN_MTU
|
|
||||||
}
|
|
||||||
|
|
||||||
fn default_netconfig_num_queues() -> usize {
|
fn default_netconfig_num_queues() -> usize {
|
||||||
DEFAULT_NUM_QUEUES_VUNET
|
DEFAULT_NUM_QUEUES_VUNET
|
||||||
}
|
}
|
||||||
@ -1306,7 +1302,7 @@ impl Default for NetConfig {
|
|||||||
mask: default_netconfig_mask(),
|
mask: default_netconfig_mask(),
|
||||||
mac: default_netconfig_mac(),
|
mac: default_netconfig_mac(),
|
||||||
host_mac: None,
|
host_mac: None,
|
||||||
mtu: default_netconfig_mtu(),
|
mtu: None,
|
||||||
iommu: false,
|
iommu: false,
|
||||||
num_queues: default_netconfig_num_queues(),
|
num_queues: default_netconfig_num_queues(),
|
||||||
queue_size: default_netconfig_queue_size(),
|
queue_size: default_netconfig_queue_size(),
|
||||||
@ -1372,8 +1368,7 @@ impl NetConfig {
|
|||||||
let host_mac = parser.convert("host_mac").map_err(Error::ParseNetwork)?;
|
let host_mac = parser.convert("host_mac").map_err(Error::ParseNetwork)?;
|
||||||
let mtu = parser
|
let mtu = parser
|
||||||
.convert("mtu")
|
.convert("mtu")
|
||||||
.map_err(Error::ParseNetwork)?
|
.map_err(Error::ParseNetwork)?;
|
||||||
.unwrap_or_else(default_netconfig_mtu);
|
|
||||||
let iommu = parser
|
let iommu = parser
|
||||||
.convert::<Toggle>("iommu")
|
.convert::<Toggle>("iommu")
|
||||||
.map_err(Error::ParseNetwork)?
|
.map_err(Error::ParseNetwork)?
|
||||||
@ -1515,8 +1510,10 @@ impl NetConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.mtu < virtio_devices::net::MIN_MTU {
|
if let Some(mtu) = self.mtu {
|
||||||
return Err(ValidationError::InvalidMtu(self.mtu));
|
if mtu < virtio_devices::net::MIN_MTU {
|
||||||
|
return Err(ValidationError::InvalidMtu(mtu));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -2244,7 +2244,7 @@ impl DeviceManager {
|
|||||||
match virtio_devices::vhost_user::Net::new(
|
match virtio_devices::vhost_user::Net::new(
|
||||||
id.clone(),
|
id.clone(),
|
||||||
net_cfg.mac,
|
net_cfg.mac,
|
||||||
Some(net_cfg.mtu),
|
net_cfg.mtu,
|
||||||
vu_cfg,
|
vu_cfg,
|
||||||
server,
|
server,
|
||||||
self.seccomp_action.clone(),
|
self.seccomp_action.clone(),
|
||||||
@ -2275,7 +2275,7 @@ impl DeviceManager {
|
|||||||
None,
|
None,
|
||||||
Some(net_cfg.mac),
|
Some(net_cfg.mac),
|
||||||
&mut net_cfg.host_mac,
|
&mut net_cfg.host_mac,
|
||||||
None,
|
net_cfg.mtu,
|
||||||
self.force_iommu | net_cfg.iommu,
|
self.force_iommu | net_cfg.iommu,
|
||||||
net_cfg.num_queues,
|
net_cfg.num_queues,
|
||||||
net_cfg.queue_size,
|
net_cfg.queue_size,
|
||||||
@ -2293,6 +2293,7 @@ impl DeviceManager {
|
|||||||
id.clone(),
|
id.clone(),
|
||||||
fds,
|
fds,
|
||||||
Some(net_cfg.mac),
|
Some(net_cfg.mac),
|
||||||
|
net_cfg.mtu,
|
||||||
self.force_iommu | net_cfg.iommu,
|
self.force_iommu | net_cfg.iommu,
|
||||||
net_cfg.queue_size,
|
net_cfg.queue_size,
|
||||||
self.seccomp_action.clone(),
|
self.seccomp_action.clone(),
|
||||||
@ -2312,7 +2313,7 @@ impl DeviceManager {
|
|||||||
Some(net_cfg.mask),
|
Some(net_cfg.mask),
|
||||||
Some(net_cfg.mac),
|
Some(net_cfg.mac),
|
||||||
&mut net_cfg.host_mac,
|
&mut net_cfg.host_mac,
|
||||||
Some(net_cfg.mtu),
|
net_cfg.mtu,
|
||||||
self.force_iommu | net_cfg.iommu,
|
self.force_iommu | net_cfg.iommu,
|
||||||
net_cfg.num_queues,
|
net_cfg.num_queues,
|
||||||
net_cfg.queue_size,
|
net_cfg.queue_size,
|
||||||
|
Loading…
Reference in New Issue
Block a user