vhost_user_net: Allow user to set MTU

Adding the support for the user to set the MTU for the vhost-user-net
backend, which allows the integration test to be extended with the test
of the MTU parameter.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2022-09-26 16:28:40 +02:00 committed by Rob Bradford
parent 903c08f8a1
commit 3bf3cca70a
3 changed files with 48 additions and 18 deletions

View File

@ -202,23 +202,25 @@ fn prepare_vhost_user_net_daemon(
tmp_dir: &TempDir,
ip: &str,
tap: Option<&str>,
mtu: Option<u16>,
num_queues: usize,
client_mode: bool,
) -> (std::process::Command, String) {
let vunet_socket_path = String::from(tmp_dir.as_path().join("vunet.sock").to_str().unwrap());
// Start the daemon
let net_params = if let Some(tap_str) = tap {
format!(
"tap={},ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024,client={}",
tap_str, ip, vunet_socket_path, num_queues, client_mode
)
} else {
format!(
"ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024,client={}",
ip, vunet_socket_path, num_queues, client_mode
)
};
let mut net_params = format!(
"ip={},mask=255.255.255.0,socket={},num_queues={},queue_size=1024,client={}",
ip, vunet_socket_path, num_queues, client_mode
);
if let Some(tap) = tap {
net_params.push_str(format!(",tap={}", tap).as_str());
}
if let Some(mtu) = mtu {
net_params.push_str(format!(",mtu={}", mtu).as_str());
}
let mut command = Command::new(clh_command("vhost_user_net"));
command.args(["--net-backend", net_params.as_str()]);
@ -757,8 +759,14 @@ fn _test_power_button(acpi: bool) {
handle_child_output(r, &output);
}
type PrepareNetDaemon =
dyn Fn(&TempDir, &str, Option<&str>, usize, bool) -> (std::process::Command, String);
type PrepareNetDaemon = dyn Fn(
&TempDir,
&str,
Option<&str>,
Option<u16>,
usize,
bool,
) -> (std::process::Command, String);
fn test_vhost_user_net(
tap: Option<&str>,
@ -779,16 +787,19 @@ fn test_vhost_user_net(
None
};
let mtu = Some(3000);
let (mut daemon_command, vunet_socket_path) = prepare_daemon(
&guest.tmp_dir,
&guest.network.host_ip,
tap,
mtu,
num_queues,
client_mode_daemon,
);
let net_params = format!(
"vhost_user=true,mac={},socket={},num_queues={},queue_size=1024{},vhost_mode={}",
"vhost_user=true,mac={},socket={},num_queues={},queue_size=1024{},vhost_mode={},mtu=3000",
guest.network.guest_mac,
vunet_socket_path,
num_queues,
@ -843,6 +854,19 @@ fn test_vhost_user_net(
assert_eq!(String::from_utf8_lossy(&mac_count.stdout).trim(), "1");
}
#[cfg(target_arch = "aarch64")]
let iface = "enp0s4";
#[cfg(target_arch = "x86_64")]
let iface = "ens4";
assert_eq!(
guest
.ssh_command(format!("cat /sys/class/net/{}/mtu", iface).as_str())
.unwrap()
.trim(),
"3000"
);
// 1 network interface + default localhost ==> 2 interfaces
// It's important to note that this test is fully exercising the
// vhost-user-net implementation and the associated backend since

View File

@ -119,10 +119,12 @@ pub struct VhostUserNetBackend {
}
impl VhostUserNetBackend {
#[allow(clippy::too_many_arguments)]
fn new(
ip_addr: Ipv4Addr,
host_mac: MacAddr,
netmask: Ipv4Addr,
mtu: Option<u16>,
num_queues: usize,
queue_size: u16,
ifname: Option<&str>,
@ -133,7 +135,7 @@ impl VhostUserNetBackend {
Some(ip_addr),
Some(netmask),
&mut Some(host_mac),
None,
mtu,
num_queues / 2,
None,
)
@ -182,6 +184,7 @@ impl VhostUserBackendMut<VringRwLock<GuestMemoryAtomic<GuestMemoryMmap>>, Atomic
| 1 << VIRTIO_NET_F_CTRL_VQ
| 1 << VIRTIO_NET_F_MQ
| 1 << VIRTIO_NET_F_MAC
| 1 << VIRTIO_NET_F_MTU
| 1 << VIRTIO_F_NOTIFY_ON_EMPTY
| 1 << VIRTIO_F_VERSION_1
| VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits()
@ -273,6 +276,7 @@ pub struct VhostUserNetBackendConfig {
pub ip: Ipv4Addr,
pub host_mac: MacAddr,
pub mask: Ipv4Addr,
pub mtu: Option<u16>,
pub socket: String,
pub num_queues: usize,
pub queue_size: u16,
@ -289,6 +293,7 @@ impl VhostUserNetBackendConfig {
.add("ip")
.add("host_mac")
.add("mask")
.add("mtu")
.add("queue_size")
.add("num_queues")
.add("socket")
@ -309,6 +314,7 @@ impl VhostUserNetBackendConfig {
.convert("mask")
.map_err(Error::FailedConfigParse)?
.unwrap_or_else(|| Ipv4Addr::new(255, 255, 255, 0));
let mtu = parser.convert("mtu").map_err(Error::FailedConfigParse)?;
let queue_size = parser
.convert("queue_size")
.map_err(Error::FailedConfigParse)?
@ -328,6 +334,7 @@ impl VhostUserNetBackendConfig {
ip,
host_mac,
mask,
mtu,
socket,
num_queues,
queue_size,
@ -355,6 +362,7 @@ pub fn start_net_backend(backend_command: &str) {
backend_config.ip,
backend_config.host_mac,
backend_config.mask,
backend_config.mtu,
backend_config.num_queues,
backend_config.queue_size,
tap,

View File

@ -1366,9 +1366,7 @@ 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)?;
let mtu = parser.convert("mtu").map_err(Error::ParseNetwork)?;
let iommu = parser
.convert::<Toggle>("iommu")
.map_err(Error::ParseNetwork)?