Skip to content

Commit 1621b2c

Browse files
committed
tests: Add vmnet-helper tests
Signed-off-by: Matej Hrica <mhrica@redhat.com>
1 parent d09264b commit 1621b2c

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

tests/test_cases/src/net_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub fn add_default_route(gateway: [u8; 4]) -> nix::Result<()> {
104104
rt.rt_dst = make_sockaddr_in([0, 0, 0, 0]);
105105
rt.rt_gateway = make_sockaddr_in(gateway);
106106
rt.rt_genmask = make_sockaddr_in([0, 0, 0, 0]);
107-
rt.rt_flags = (libc::RTF_UP | libc::RTF_GATEWAY) as u16;
107+
rt.rt_flags = libc::RTF_UP | libc::RTF_GATEWAY;
108108

109109
let ret = unsafe { libc::ioctl(sock.as_raw_fd(), libc::SIOCADDRT as _, &rt) };
110110
if ret < 0 {

tests/test_cases/src/test_net/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,8 @@ impl TestNet {
9999
#[cfg(feature = "guest")]
100100
netmask: [255, 255, 255, 0],
101101
#[cfg(feature = "guest")]
102-
gateway: Some([192, 168, 105, 1]),
103-
// HACK: hardcoded host LAN IP for testing; guest needs a default
104-
// route via the vmnet gateway (192.168.105.1) to reach it.
105-
tcp_tester: TcpTester::new(9003, [10, 42, 0, 115].into()),
102+
gateway: None,
103+
tcp_tester: TcpTester::new(9003, [192, 168, 105, 1].into()),
106104
#[cfg(feature = "host")]
107105
should_run: vmnet_helper::should_run,
108106
#[cfg(feature = "host")]
@@ -175,8 +173,7 @@ mod guest {
175173
.expect("Failed to configure eth0");
176174

177175
if let Some(gw) = self.gateway {
178-
crate::net_config::add_default_route(gw)
179-
.expect("Failed to add default route");
176+
crate::net_config::add_default_route(gw).expect("Failed to add default route");
180177
}
181178

182179
self.tcp_tester.run_client();

tests/test_cases/src/test_net/vmnet_helper.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! vmnet-helper backend for virtio-net test (macOS only)
22
33
use crate::{krun_call, ShouldRun, TestSetup};
4-
use krun_sys::COMPAT_NET_FEATURES;
54
use nix::libc;
65
use std::ffi::CString;
76
use std::io::{BufRead, BufReader, Read};
@@ -187,6 +186,26 @@ fn start_vmnet_helper(log_path: &std::path::Path) -> std::io::Result<VmnetConfig
187186
let mac = parse_mac(mac_str)
188187
.ok_or_else(|| std::io::Error::other(format!("invalid MAC address: {mac_str}")))?;
189188

189+
// Increase socket buffer sizes so libkrun's Unixgram backend (which uses
190+
// the fd path and does NOT set these) can batch frames without drops.
191+
let buf_size: libc::c_int = 7 * 1024 * 1024;
192+
unsafe {
193+
libc::setsockopt(
194+
our_fd,
195+
libc::SOL_SOCKET,
196+
libc::SO_SNDBUF,
197+
&buf_size as *const _ as *const libc::c_void,
198+
std::mem::size_of_val(&buf_size) as libc::socklen_t,
199+
);
200+
libc::setsockopt(
201+
our_fd,
202+
libc::SOL_SOCKET,
203+
libc::SO_RCVBUF,
204+
&buf_size as *const _ as *const libc::c_void,
205+
std::mem::size_of_val(&buf_size) as libc::socklen_t,
206+
);
207+
}
208+
190209
Ok(VmnetConfig { fd: our_fd, mac })
191210
}
192211

@@ -218,8 +237,8 @@ pub(crate) fn setup_backend(ctx: u32, test_setup: &TestSetup) -> anyhow::Result<
218237
std::ptr::null(),
219238
config.fd,
220239
config.mac.as_mut_ptr(),
221-
COMPAT_NET_FEATURES,
222-
0, // no VFKIT flag - vmnet-helper uses raw datagrams
240+
0, // no offloading - vmnet-helper uses raw ethernet frames
241+
0, // no VFKIT flag
223242
))?;
224243
}
225244
Ok(())

0 commit comments

Comments
 (0)