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:
Sebastien Boeuf
2022-09-21 11:56:24 +02:00
parent d95220108a
commit 76dbf85b79
12 changed files with 131 additions and 10 deletions

View File

@@ -2411,9 +2411,9 @@ mod common_parallel {
.args(["--memory", "size=512M"])
.args(["--kernel", direct_kernel_boot_path().to_str().unwrap()])
.args(["--cmdline", DIRECT_KERNEL_BOOT_CMDLINE])
.args(["--net", guest.default_net_string_w_mtu(3000).as_str()])
.capture_output()
.default_disks()
.default_net();
.default_disks();
let mut child = cmd.spawn().unwrap();
@@ -2434,6 +2434,13 @@ mod common_parallel {
.trim(),
"success"
);
assert_eq!(
guest
.ssh_command(format!("cat /sys/class/net/{}/mtu", iface).as_str())
.unwrap()
.trim(),
"3000"
);
});
let _ = child.kill();
@@ -6098,6 +6105,7 @@ mod common_parallel {
Some(std::net::Ipv4Addr::from_str(&guest.network.host_ip).unwrap()),
None,
&mut None,
None,
num_queue_pairs,
Some(libc::O_RDWR | libc::O_NONBLOCK),
)