pub struct Stack<'d> { /* private fields */ }Expand description
A network stack.
Implementations§
Source§impl Stack<'_>
impl Stack<'_>
Sourcepub fn reassembly_timeout(&self) -> Duration
pub fn reassembly_timeout(&self) -> Duration
Get the packet reassembly timeout.
This is how long the fragments of an incoming IPv4 or 6LoWPAN packet are kept while waiting for the rest of it. The default is 60 seconds.
Sourcepub fn set_reassembly_timeout(&mut self, timeout: Duration)
pub fn set_reassembly_timeout(&mut self, timeout: Duration)
Set the packet reassembly timeout.
Fragments of an incoming IPv4 or 6LoWPAN packet that is not complete by then are dropped, and the packet buffer they were kept in is freed.
Source§impl<'d> Stack<'d>
impl<'d> Stack<'d>
Sourcepub fn new(random_seed: u64) -> Self
pub fn new(random_seed: u64) -> Self
Create a network stack.
random_seed seeds the stack’s PRNG, which picks TCP initial sequence
numbers and ephemeral ports. This should be random, or at least different
at every boot.
Sourcepub fn add_iface(
&mut self,
driver: Box<dyn Driver + 'd>,
) -> Result<IfaceHandle, Full>
pub fn add_iface( &mut self, driver: Box<dyn Driver + 'd>, ) -> Result<IfaceHandle, Full>
Add an interface to the stack, returning a handle to it.
The stack owns the boxed device, so this needs the alloc feature.
Without alloc, use add_iface_borrowed.
Configure the interface after adding it. At minimum, you will want to add an IP address to it.
let handle = stack.add_iface(driver).unwrap();
stack
.iface(handle)
.add_ip_addr(IpCidr::new(Ipv4Address::new(192, 168, 1, 1).into(), 24))
.unwrap();§Panics
Panics if the hardware address the device reports is not of the kind its medium uses.
Errors:
Fullif the stack has no room for another interface. Only possible without theallocfeature, where the limit isIFACE_COUNT.
Sourcepub fn add_iface_borrowed(
&mut self,
driver: &'d mut dyn Driver,
) -> Result<IfaceHandle, Full>
pub fn add_iface_borrowed( &mut self, driver: &'d mut dyn Driver, ) -> Result<IfaceHandle, Full>
Add an interface to the stack, lending it the device, and returning a handle to it.
The stack holds the device until it is dropped or the interface is
removed, so the device must be declared before the stack, or be 'static.
Otherwise this is add_iface.
§Panics
Panics if the hardware address the device reports is not of the kind its medium uses.
Errors:
Fullif the stack has no room for another interface. Only possible without theallocfeature, where the limit isIFACE_COUNT.
Sourcepub fn iface(&mut self, handle: IfaceHandle) -> Iface<'_, 'd>
pub fn iface(&mut self, handle: IfaceHandle) -> Iface<'_, 'd>
Borrow an interface from the stack.
§Panics
Panics if the handle is stale (the interface was removed).
Sourcepub fn remove_iface(&mut self, handle: IfaceHandle)
pub fn remove_iface(&mut self, handle: IfaceHandle)
Remove an interface from the stack.
§Panics
Panics if the handle is stale (the interface was already removed).
Sourcepub fn neighbor_cache(&self) -> &NeighborCache
pub fn neighbor_cache(&self) -> &NeighborCache
Access the neighbor cache.
Sourcepub fn neighbor_cache_mut(&mut self) -> &mut NeighborCache
pub fn neighbor_cache_mut(&mut self) -> &mut NeighborCache
Access the neighbor cache for modification.
Sourcepub fn routes_mut(&mut self) -> &mut Routes
pub fn routes_mut(&mut self) -> &mut Routes
Access the routing table for modification.
Sourcepub fn add_udp_socket(&mut self) -> Result<UdpHandle, Full>
pub fn add_udp_socket(&mut self) -> Result<UdpHandle, Full>
Add a UDP socket to the stack, returning a handle to it.
Errors:
Fullif the stack has no room for another UDP socket. Only possible without theallocfeature, where the limit isUDP_SOCKET_COUNT.
Sourcepub fn remove_udp_socket(&mut self, handle: UdpHandle)
pub fn remove_udp_socket(&mut self, handle: UdpHandle)
Remove a UDP socket from the stack.
§Panics
Panics if the handle is stale (the socket was already removed).
Sourcepub fn udp_socket(&mut self, handle: UdpHandle) -> UdpSocket<'_, 'd>
pub fn udp_socket(&mut self, handle: UdpHandle) -> UdpSocket<'_, 'd>
Borrow a UDP socket from the stack.
§Panics
Panics if the handle is stale (the socket was already removed).
Sourcepub fn add_raw_socket(&mut self) -> Result<RawHandle, Full>
pub fn add_raw_socket(&mut self) -> Result<RawHandle, Full>
Add a raw socket to the stack, returning a handle to it.
Errors:
Fullif the stack has no room for another raw socket. Only possible without theallocfeature, where the limit isRAW_SOCKET_COUNT.
Sourcepub fn remove_raw_socket(&mut self, handle: RawHandle)
pub fn remove_raw_socket(&mut self, handle: RawHandle)
Remove a raw socket from the stack.
§Panics
Panics if the handle is stale (the socket was already removed).
Sourcepub fn raw_socket(&mut self, handle: RawHandle) -> RawSocket<'_, 'd>
pub fn raw_socket(&mut self, handle: RawHandle) -> RawSocket<'_, 'd>
Borrow a raw socket from the stack.
§Panics
Panics if the handle is stale (the socket was already removed).
Sourcepub fn add_tcp_socket(
&mut self,
rx_capacity: usize,
tx_capacity: usize,
) -> Result<TcpHandle, Full>
pub fn add_tcp_socket( &mut self, rx_capacity: usize, tx_capacity: usize, ) -> Result<TcpHandle, Full>
Add a TCP socket to the stack, with receive and transmit buffers of the given capacities, returning a handle to it.
The buffers are allocated on the heap, so this needs the alloc feature.
Without it, or to use your own buffers, see
add_tcp_socket_with_bufs.
§Panics
Panics if the receive buffer is larger than 1 GiB.
Errors:
Fullif the stack has no room for another TCP socket. Only possible without theallocfeature, where the limit isTCP_SOCKET_COUNT.
Sourcepub fn add_tcp_socket_with_bufs(
&mut self,
rx_buffer: &'d mut [u8],
tx_buffer: &'d mut [u8],
) -> Result<TcpHandle, Full>
pub fn add_tcp_socket_with_bufs( &mut self, rx_buffer: &'d mut [u8], tx_buffer: &'d mut [u8], ) -> Result<TcpHandle, Full>
Add a TCP socket to the stack, with borrowed receive and transmit buffers, and returning a handle to it.
The stack holds the buffers until it is dropped or the socket is removed,
so they must be declared before the stack, or be 'static. Otherwise
this is add_tcp_socket.
let handle = stack.add_tcp_socket_with_bufs(rx, tx).unwrap();§Panics
Panics if the receive buffer is larger than 1 GiB.
Errors:
Fullif the stack has no room for another TCP socket. Only possible without theallocfeature, where the limit isTCP_SOCKET_COUNT.
Sourcepub fn remove_tcp_socket(&mut self, handle: TcpHandle)
pub fn remove_tcp_socket(&mut self, handle: TcpHandle)
Remove a TCP socket from the stack.
No RST is sent, and any buffered data is lost. To close a connection cleanly,
TcpSocket::close it first and poll until it is fully closed.
§Panics
Panics if the handle is stale (the socket was already removed).
Sourcepub fn tcp_socket(&mut self, handle: TcpHandle) -> TcpSocket<'_, 'd>
pub fn tcp_socket(&mut self, handle: TcpHandle) -> TcpSocket<'_, 'd>
Borrow a TCP socket from the stack.
§Panics
Panics if the handle is stale (the socket was already removed).
Sourcepub fn add_tcp_listener(&mut self) -> Result<TcpListenerHandle, Full>
pub fn add_tcp_listener(&mut self) -> Result<TcpListenerHandle, Full>
Add a TCP listener to the stack, returning a handle to it.
Errors:
Fullif the stack has no room for another listener. Only possible without theallocfeature, where the limit isTCP_LISTENER_COUNT.
Sourcepub fn remove_tcp_listener(&mut self, handle: TcpListenerHandle)
pub fn remove_tcp_listener(&mut self, handle: TcpListenerHandle)
Remove a TCP listener from the stack.
§Panics
Panics if the handle is stale (the listener was already removed).
Sourcepub fn tcp_listener(&mut self, handle: TcpListenerHandle) -> TcpListener<'_, 'd>
pub fn tcp_listener(&mut self, handle: TcpListenerHandle) -> TcpListener<'_, 'd>
Borrow a TCP listener from the stack.
§Panics
Panics if the handle is stale (the listener was already removed).
Sourcepub fn ifaces(&mut self) -> IfaceIter<'_, 'd>
pub fn ifaces(&mut self) -> IfaceIter<'_, 'd>
Iterate over the interfaces added to the stack.
See IfaceIter for how to use it.
Sourcepub fn udp_sockets(&mut self) -> UdpSocketIter<'_, 'd>
pub fn udp_sockets(&mut self) -> UdpSocketIter<'_, 'd>
Iterate over the UDP sockets added to the stack.
See UdpSocketIter for how to use it.
Sourcepub fn raw_sockets(&mut self) -> RawSocketIter<'_, 'd>
pub fn raw_sockets(&mut self) -> RawSocketIter<'_, 'd>
Iterate over the raw sockets added to the stack.
See RawSocketIter for how to use it.
Sourcepub fn tcp_sockets(&mut self) -> TcpSocketIter<'_, 'd>
pub fn tcp_sockets(&mut self) -> TcpSocketIter<'_, 'd>
Iterate over the TCP sockets added to the stack.
See TcpSocketIter for how to use it.
Sourcepub fn tcp_listeners(&mut self) -> TcpListenerIter<'_, 'd>
pub fn tcp_listeners(&mut self) -> TcpListenerIter<'_, 'd>
Iterate over the TCP listeners added to the stack.
See TcpListenerIter for how to use it.
Sourcepub fn poll(&mut self, timestamp: Instant) -> Instant
pub fn poll(&mut self, timestamp: Instant) -> Instant
Process all pending ingress packets on all ifaces, advance the stack’s internal timers, and transmit everything the TCP sockets have made due.
timestamp is the current time.
Returns a “poll deadline” instant. It is the earliest expiring timer. You should call poll at that instant to let it advance timers. Special cases:
- If it’s
Instant::MINor in the past,pollshould be called again immediately. - If no timer is pending,
Instant::MAXis returned. No need to callpollon a timer, only after a packet is received or an operation is done on the Stack, a socket or an interface.