mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
net: Give the user the ability to set MTU
Add a new "mtu" parameter to the NetConfig structure and therefore to the --net option. This allows Cloud Hypervisor's users to define the Maximum Transmission Unit (MTU) they want to use for the network interface that they create. In details, there are two main aspects. On the one hand, the TAP interface is created with the proper MTU if it is provided. And on the other hand the guest is made aware of the MTU through the VIRTIO configuration. That means the MTU is properly set on both the TAP on the host and the network interface in the guest. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
@@ -819,6 +819,11 @@ components:
|
||||
default: "255.255.255.0"
|
||||
mac:
|
||||
type: string
|
||||
host_mac:
|
||||
type: string
|
||||
mtu:
|
||||
type: integer
|
||||
default: 1280
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
@@ -180,6 +180,8 @@ pub enum ValidationError {
|
||||
IommuNotSupported,
|
||||
/// Duplicated device path (device added twice)
|
||||
DuplicateDevicePath(String),
|
||||
/// Provided MTU is lower than what the VIRTIO specification expects
|
||||
InvalidMtu(u16),
|
||||
}
|
||||
|
||||
type ValidationResult<T> = std::result::Result<T, ValidationError>;
|
||||
@@ -280,6 +282,13 @@ impl fmt::Display for ValidationError {
|
||||
write!(f, "Device does not support being placed behind IOMMU")
|
||||
}
|
||||
DuplicateDevicePath(p) => write!(f, "Duplicated device path: {}", p),
|
||||
&InvalidMtu(mtu) => {
|
||||
write!(
|
||||
f,
|
||||
"Provided MTU {} is lower than 1280 (expected by VIRTIO specification)",
|
||||
mtu
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1238,6 +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 iommu: bool,
|
||||
#[serde(default = "default_netconfig_num_queues")]
|
||||
@@ -1275,6 +1286,10 @@ 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
|
||||
}
|
||||
@@ -1291,6 +1306,7 @@ impl Default for NetConfig {
|
||||
mask: default_netconfig_mask(),
|
||||
mac: default_netconfig_mac(),
|
||||
host_mac: None,
|
||||
mtu: default_netconfig_mtu(),
|
||||
iommu: false,
|
||||
num_queues: default_netconfig_num_queues(),
|
||||
queue_size: default_netconfig_queue_size(),
|
||||
@@ -1322,6 +1338,7 @@ impl NetConfig {
|
||||
.add("mask")
|
||||
.add("mac")
|
||||
.add("host_mac")
|
||||
.add("mtu")
|
||||
.add("iommu")
|
||||
.add("queue_size")
|
||||
.add("num_queues")
|
||||
@@ -1353,6 +1370,10 @@ impl NetConfig {
|
||||
.map_err(Error::ParseNetwork)?
|
||||
.unwrap_or_else(default_netconfig_mac);
|
||||
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);
|
||||
let iommu = parser
|
||||
.convert::<Toggle>("iommu")
|
||||
.map_err(Error::ParseNetwork)?
|
||||
@@ -1442,6 +1463,7 @@ impl NetConfig {
|
||||
mask,
|
||||
mac,
|
||||
host_mac,
|
||||
mtu,
|
||||
iommu,
|
||||
num_queues,
|
||||
queue_size,
|
||||
@@ -1493,6 +1515,10 @@ impl NetConfig {
|
||||
}
|
||||
}
|
||||
|
||||
if self.mtu < virtio_devices::net::MIN_MTU {
|
||||
return Err(ValidationError::InvalidMtu(self.mtu));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2241,6 +2241,7 @@ impl DeviceManager {
|
||||
match virtio_devices::vhost_user::Net::new(
|
||||
id.clone(),
|
||||
net_cfg.mac,
|
||||
Some(net_cfg.mtu),
|
||||
vu_cfg,
|
||||
server,
|
||||
self.seccomp_action.clone(),
|
||||
@@ -2271,6 +2272,7 @@ impl DeviceManager {
|
||||
None,
|
||||
Some(net_cfg.mac),
|
||||
&mut net_cfg.host_mac,
|
||||
None,
|
||||
self.force_iommu | net_cfg.iommu,
|
||||
net_cfg.num_queues,
|
||||
net_cfg.queue_size,
|
||||
@@ -2307,6 +2309,7 @@ impl DeviceManager {
|
||||
Some(net_cfg.mask),
|
||||
Some(net_cfg.mac),
|
||||
&mut net_cfg.host_mac,
|
||||
Some(net_cfg.mtu),
|
||||
self.force_iommu | net_cfg.iommu,
|
||||
net_cfg.num_queues,
|
||||
net_cfg.queue_size,
|
||||
|
||||
@@ -66,6 +66,8 @@ const SIOCGIFFLAGS: u64 = 0x8913;
|
||||
const SIOCGIFHWADDR: u64 = 0x8927;
|
||||
const SIOCSIFFLAGS: u64 = 0x8914;
|
||||
const SIOCSIFADDR: u64 = 0x8916;
|
||||
const SIOCGIFMTU: u64 = 0x8921;
|
||||
const SIOCSIFMTU: u64 = 0x8922;
|
||||
const SIOCSIFHWADDR: u64 = 0x8924;
|
||||
const SIOCSIFNETMASK: u64 = 0x891c;
|
||||
|
||||
@@ -252,9 +254,11 @@ fn create_vmm_ioctl_seccomp_rule_common(
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, FIONBIO)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, SIOCGIFFLAGS)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, SIOCGIFHWADDR)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, SIOCGIFMTU)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, SIOCSIFADDR)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, SIOCSIFFLAGS)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, SIOCSIFHWADDR)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, SIOCSIFMTU)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, SIOCSIFNETMASK)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, TCSETS)?],
|
||||
and![Cond::new(1, ArgLen::Dword, Eq, TCGETS)?],
|
||||
|
||||
Reference in New Issue
Block a user