Enable the tap interface.
(&self)
| 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<()> { |