MCPcopy Index your code
hub / github.com/cloud-hypervisor/cloud-hypervisor / enable

Method enable

net_util/src/tap.rs:465–484  ·  view source on GitHub ↗

Enable the tap interface.

(&self)

Source from the content-addressed store, hash-verified

463
464 /// Enable the tap interface.
465 pub fn enable(&self) -> Result<()> {
466 let sock = create_unix_socket().map_err(Error::NetUtil)?;
467
468 let mut ifreq = self.get_ifreq();
469
470 // SAFETY: IOCTL with correct arguments
471 unsafe { Self::ioctl_with_ref(&sock, libc::SIOCGIFFLAGS as c_ulong, &ifreq)? };
472
473 // If TAP device is already up don't try and enable it
474 // SAFETY: access a union field
475 let ifru_flags = unsafe { ifreq.ifr_ifru.ifru_flags };
476 if ifru_flags & libc::IFF_UP as i16 == libc::IFF_UP as i16 {
477 return Ok(());
478 }
479
480 ifreq.ifr_ifru.ifru_flags = libc::IFF_UP as i16;
481
482 // SAFETY: ioctl is safe. Called with a valid sock fd, and we check the return.
483 unsafe { Self::ioctl_with_ref(&sock, libc::SIOCSIFFLAGS as c_ulong, &ifreq) }
484 }
485
486 /// Set the size of the vnet hdr.
487 pub fn set_vnet_hdr_size(&self, size: c_int) -> Result<()> {

Callers 7

newMethod · 0.45
newMethod · 0.45
updateMethod · 0.45
test_tap_enableFunction · 0.45
test_readFunction · 0.45
test_writeFunction · 0.45
open_tap_rx_q_0Function · 0.45

Calls 2

create_unix_socketFunction · 0.85
get_ifreqMethod · 0.80

Tested by 3

test_tap_enableFunction · 0.36
test_readFunction · 0.36
test_writeFunction · 0.36