pub struct SmoltcpBackend { /* private fields */ }Expand description
Network backend that bridges libkrun’s NetWorker to smoltcp via lock-free queues.
- TX path (
write_frame): strips the virtio-net header, pushes the ethernet frame totx_ring, wakes the smoltcp poll thread. - RX path (
read_frame): pops a frame fromrx_ring, prepends a zeroed virtio-net header for the guest. - Wake fd (
raw_socket_fd): returnsrx_wake’s read end so the NetWorker’s epoll can detect new frames.
Implementations§
Source§impl SmoltcpBackend
impl SmoltcpBackend
Sourcepub fn new(shared: Arc<SharedState>) -> Self
pub fn new(shared: Arc<SharedState>) -> Self
Create a new backend connected to the given shared state.
Trait Implementations§
Source§impl NetBackend for SmoltcpBackend
impl NetBackend for SmoltcpBackend
Source§fn write_frame(
&mut self,
hdr_len: usize,
buf: &mut [u8],
) -> Result<(), WriteError>
fn write_frame( &mut self, hdr_len: usize, buf: &mut [u8], ) -> Result<(), WriteError>
Guest is sending a frame. Strip the virtio-net header and enqueue the raw ethernet frame for smoltcp.
Source§fn read_frame(&mut self, buf: &mut [u8]) -> Result<usize, ReadError>
fn read_frame(&mut self, buf: &mut [u8]) -> Result<usize, ReadError>
Deliver a frame from smoltcp to the guest. Prepends a zeroed virtio-net header.
Source§fn has_unfinished_write(&self) -> bool
fn has_unfinished_write(&self) -> bool
No partial writes — queue push is atomic.
Source§fn try_finish_write(
&mut self,
_hdr_len: usize,
_buf: &[u8],
) -> Result<(), WriteError>
fn try_finish_write( &mut self, _hdr_len: usize, _buf: &[u8], ) -> Result<(), WriteError>
No partial writes — nothing to finish.
Source§fn raw_socket_fd(&self) -> RawFd
fn raw_socket_fd(&self) -> RawFd
File descriptor for NetWorker’s epoll. Becomes readable when
rx_ring has frames for the guest (i.e. when smoltcp’s
SmoltcpDevice::transmit() pushes a frame and wakes rx_wake).
Auto Trait Implementations§
impl Freeze for SmoltcpBackend
impl RefUnwindSafe for SmoltcpBackend
impl Send for SmoltcpBackend
impl Sync for SmoltcpBackend
impl Unpin for SmoltcpBackend
impl UnsafeUnpin for SmoltcpBackend
impl UnwindSafe for SmoltcpBackend
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Mutably borrows from an owned value. Read more