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:
Sebastien Boeuf
2022-09-26 15:58:54 +02:00
committed by Rob Bradford
parent 44d66ec531
commit 903c08f8a1
4 changed files with 25 additions and 24 deletions

View File

@@ -823,7 +823,6 @@ components:
type: string
mtu:
type: integer
default: 1280
iommu:
type: boolean
default: false

View File

@@ -1247,8 +1247,8 @@ pub struct NetConfig {
pub mac: MacAddr,
#[serde(default)]
pub host_mac: Option<MacAddr>,
#[serde(default = "default_netconfig_mtu")]
pub mtu: u16,
#[serde(default)]
pub mtu: Option<u16>,
#[serde(default)]
pub iommu: bool,
#[serde(default = "default_netconfig_num_queues")]
@@ -1286,10 +1286,6 @@ fn default_netconfig_mac() -> MacAddr {
MacAddr::local_random()
}
fn default_netconfig_mtu() -> u16 {
virtio_devices::net::MIN_MTU
}
fn default_netconfig_num_queues() -> usize {
DEFAULT_NUM_QUEUES_VUNET
}
@@ -1306,7 +1302,7 @@ impl Default for NetConfig {
mask: default_netconfig_mask(),
mac: default_netconfig_mac(),
host_mac: None,
mtu: default_netconfig_mtu(),
mtu: None,
iommu: false,
num_queues: default_netconfig_num_queues(),
queue_size: default_netconfig_queue_size(),
@@ -1372,8 +1368,7 @@ impl NetConfig {
let host_mac = parser.convert("host_mac").map_err(Error::ParseNetwork)?;
let mtu = parser
.convert("mtu")
.map_err(Error::ParseNetwork)?
.unwrap_or_else(default_netconfig_mtu);
.map_err(Error::ParseNetwork)?;
let iommu = parser
.convert::<Toggle>("iommu")
.map_err(Error::ParseNetwork)?
@@ -1515,8 +1510,10 @@ impl NetConfig {
}
}
if self.mtu < virtio_devices::net::MIN_MTU {
return Err(ValidationError::InvalidMtu(self.mtu));
if let Some(mtu) = self.mtu {
if mtu < virtio_devices::net::MIN_MTU {
return Err(ValidationError::InvalidMtu(mtu));
}
}
Ok(())

View File

@@ -2244,7 +2244,7 @@ impl DeviceManager {
match virtio_devices::vhost_user::Net::new(
id.clone(),
net_cfg.mac,
Some(net_cfg.mtu),
net_cfg.mtu,
vu_cfg,
server,
self.seccomp_action.clone(),
@@ -2275,7 +2275,7 @@ impl DeviceManager {
None,
Some(net_cfg.mac),
&mut net_cfg.host_mac,
None,
net_cfg.mtu,
self.force_iommu | net_cfg.iommu,
net_cfg.num_queues,
net_cfg.queue_size,
@@ -2293,6 +2293,7 @@ impl DeviceManager {
id.clone(),
fds,
Some(net_cfg.mac),
net_cfg.mtu,
self.force_iommu | net_cfg.iommu,
net_cfg.queue_size,
self.seccomp_action.clone(),
@@ -2312,7 +2313,7 @@ impl DeviceManager {
Some(net_cfg.mask),
Some(net_cfg.mac),
&mut net_cfg.host_mac,
Some(net_cfg.mtu),
net_cfg.mtu,
self.force_iommu | net_cfg.iommu,
net_cfg.num_queues,
net_cfg.queue_size,