diff --git a/net_util/src/tap.rs b/net_util/src/tap.rs index 0bdf0e30f..c795dd8f0 100644 --- a/net_util/src/tap.rs +++ b/net_util/src/tap.rs @@ -305,6 +305,7 @@ impl Tap { unsafe { Self::ioctl_with_ref(&sock, net_gen::sockios::SIOCSIFNETMASK as c_ulong, &ifreq) } } + #[cfg(not(fuzzing))] pub fn mtu(&self) -> Result { let sock = create_unix_socket().map_err(Error::NetUtil)?; @@ -319,6 +320,12 @@ impl Tap { Ok(mtu) } + #[cfg(fuzzing)] + pub fn mtu(&self) -> Result { + // Consistent with the `virtio_devices::net::MIN_MTU` + Ok(1280) + } + pub fn set_mtu(&self, mtu: i32) -> Result<()> { let sock = create_unix_socket().map_err(Error::NetUtil)?; @@ -383,6 +390,11 @@ impl Tap { pub fn get_if_name(&self) -> Vec { self.if_name.clone() } + + #[cfg(fuzzing)] + pub fn new_for_fuzzing(tap_file: File, if_name: Vec) -> Self { + Tap { tap_file, if_name } + } } impl Read for Tap { diff --git a/virtio-devices/src/net.rs b/virtio-devices/src/net.rs index 7ce6e0d85..5ae12aab0 100644 --- a/virtio-devices/src/net.rs +++ b/virtio-devices/src/net.rs @@ -435,7 +435,7 @@ impl VersionMapped for NetState {} impl Net { /// Create a new virtio network device with the given TAP interface. #[allow(clippy::too_many_arguments)] - fn new_with_tap( + pub fn new_with_tap( id: String, taps: Vec, guest_mac: Option, @@ -623,6 +623,11 @@ impl Net { queue_size: self.common.queue_sizes.clone(), } } + + #[cfg(fuzzing)] + pub fn wait_for_epoll_threads(&mut self) { + self.common.wait_for_epoll_threads(); + } } impl Drop for Net { @@ -735,6 +740,7 @@ impl VirtioDevice for Net { .map_err(ActivateError::CreateRateLimiter)?; let tap = taps.remove(0); + #[cfg(not(fuzzing))] tap.set_offload(virtio_features_to_tap_offload(self.common.acked_features)) .map_err(|e| { error!("Error programming tap offload: {:?}", e);