pub struct TunDevice { /* private fields */ }Expand description
FIPS TUN device wrapper.
Implementations§
Source§impl TunDevice
impl TunDevice
Sourcepub async fn create(
config: &TunConfig,
address: FipsAddress,
) -> Result<Self, TunError>
pub async fn create( config: &TunConfig, address: FipsAddress, ) -> Result<Self, TunError>
Create or open a TUN device.
If the interface already exists, opens it and reconfigures it. Otherwise, creates a new TUN device.
This requires CAP_NET_ADMIN capability (run with sudo or setcap).
Sourcepub fn address(&self) -> &FipsAddress
pub fn address(&self) -> &FipsAddress
Get the FIPS address assigned to this device.
Sourcepub fn device_mut(&mut self) -> &mut Device ⓘ
pub fn device_mut(&mut self) -> &mut Device ⓘ
Get a mutable reference to the underlying tun::Device.
Sourcepub fn read_packet(&mut self, buf: &mut [u8]) -> Result<usize, Error>
pub fn read_packet(&mut self, buf: &mut [u8]) -> Result<usize, Error>
Read a packet from the TUN device.
Returns the number of bytes read into the buffer, or an io::Error.
The buffer should be at least MTU + header size (typically 1500+ bytes).
The tun crate’s Read impl transparently strips the macOS utun
packet information header, so this returns a raw IP packet on all
platforms.
The raw io::Error is returned so callers can inspect ErrorKind
(e.g. WouldBlock) or raw_os_error() without string matching.
Sourcepub async fn shutdown(&self) -> Result<(), TunError>
pub async fn shutdown(&self) -> Result<(), TunError>
Shutdown and delete the TUN device.
This deletes the interface entirely.
Sourcepub fn create_writer(
&self,
max_mss: u16,
path_mtu_lookup: PathMtuLookup,
) -> Result<(TunWriter, TunTx), TunError>
pub fn create_writer( &self, max_mss: u16, path_mtu_lookup: PathMtuLookup, ) -> Result<(TunWriter, TunTx), TunError>
Create a TunWriter for this device.
This duplicates the underlying file descriptor so that reads and writes can happen independently on separate threads. Returns the writer and a channel sender for submitting packets to be written.
max_mss is the global TCP MSS ceiling derived from the local
transport_mtu() floor. path_mtu_lookup is a read-only handle to
the per-destination path MTU map populated by discovery; the writer
reads it on each inbound SYN-ACK to compute a per-flow ceiling that
honors learned narrow paths through the mesh.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TunDevice
impl RefUnwindSafe for TunDevice
impl Send for TunDevice
impl Sync for TunDevice
impl Unpin for TunDevice
impl UnsafeUnpin for TunDevice
impl UnwindSafe for TunDevice
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more