virtio-devices: net: Provide custom functions for fuzzing

Three functions are added:
* 'Tap::new_for_fuzzing()' a custom constructor that creates a dummy
`Tap` interface directly from `File` backed by Unix domain socket;
* 'Tap::mtu()' a custom function that returns hard-coded mtu;
* 'Net::wait_for_epoll_threads()'.

Two functions are reused with modifications to work with the dummy 'Tap'
interface:
* 'Net::new_with_tap()' is made public for fuzzing;
* 'Net::activate()' is modified to not call into 'Tap::set_offload()'
for fuzzing.

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen
2022-11-21 16:17:36 -08:00
committed by Rob Bradford
parent 30a7a8033e
commit 83ab5ea528
2 changed files with 19 additions and 1 deletions

View File

@@ -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<Tap>,
guest_mac: Option<MacAddr>,
@@ -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);