MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / new_with_tap

Method new_with_tap

virtio-devices/src/net.rs:422–530  ·  view source on GitHub ↗
(
        id: String,
        taps: Vec<Tap>,
        guest_mac: Option<MacAddr>,
        access_platform_enabled: bool,
        num_queues: usize,
        queue_size: u16,
        seccomp_action: Sec

Source from the content-addressed store, hash-verified

420 /// Create a new virtio network device with the given TAP interface.
421 #[allow(clippy::too_many_arguments)]
422 pub fn new_with_tap(
423 id: String,
424 taps: Vec<Tap>,
425 guest_mac: Option<MacAddr>,
426 access_platform_enabled: bool,
427 num_queues: usize,
428 queue_size: u16,
429 seccomp_action: SeccompAction,
430 rate_limiter_config: Option<RateLimiterConfig>,
431 exit_evt: EventFd,
432 state: Option<NetState>,
433 offload_tso: bool,
434 offload_ufo: bool,
435 offload_csum: bool,
436 ) -> Result<Self> {
437 assert!(!taps.is_empty());
438
439 // Skip advertising VIRTIO_NET_F_MTU and let the guest fall back to the Ethernet default if querying failed
440 let mtu = match taps[0].mtu() {
441 Ok(m) => Some(m as u16),
442 Err(e) => {
443 warn!("Failed to query tap MTU; not advertising VIRTIO_NET_F_MTU: {e}");
444 None
445 }
446 };
447
448 let (avail_features, acked_features, config, queue_sizes, paused) = if let Some(state) =
449 state
450 {
451 info!("Restoring virtio-net {id}");
452 (
453 state.avail_features,
454 state.acked_features,
455 state.config,
456 state.queue_size,
457 true,
458 )
459 } else {
460 let mut avail_features = (1 << VIRTIO_RING_F_EVENT_IDX) | (1 << VIRTIO_F_VERSION_1);
461
462 if mtu.is_some() {
463 avail_features |= 1 << VIRTIO_NET_F_MTU;
464 }
465
466 if access_platform_enabled {
467 avail_features |= 1u64 << VIRTIO_F_ACCESS_PLATFORM;
468 }
469
470 // Configure TSO/UFO features when hardware checksum offload is enabled.
471 if offload_csum {
472 avail_features |= (1 << VIRTIO_NET_F_CSUM)
473 | (1 << VIRTIO_NET_F_GUEST_CSUM)
474 | (1 << VIRTIO_NET_F_CTRL_GUEST_OFFLOADS);
475
476 if offload_tso {
477 avail_features |= (1 << VIRTIO_NET_F_HOST_ECN)
478 | (1 << VIRTIO_NET_F_HOST_TSO4)
479 | (1 << VIRTIO_NET_F_HOST_TSO6)

Callers

nothing calls this directly

Calls 4

build_net_config_spaceFunction · 0.85
newFunction · 0.85
mtuMethod · 0.80

Tested by

no test coverage detected