pub struct Stack<'d> { /* private fields */ }Expand description
A network stack.
This is a handle to the stack created by Stack::new. It’s Copy, so
you can pass it by value instead of by reference.
Implementations§
Source§impl<'d> Stack<'d>
impl<'d> Stack<'d>
Sourcepub fn new(
storage: &'d mut StackStorage<'d>,
random_seed: u64,
) -> (Self, Runner<'d>)
pub fn new( storage: &'d mut StackStorage<'d>, random_seed: u64, ) -> (Self, Runner<'d>)
Create a new network stack.
The stack starts out with no interfaces: add them with
add_iface.
Sourcepub fn poll_tx_timestamp(&self) -> Option<TxTimestamp>
pub fn poll_tx_timestamp(&self) -> Option<TxTimestamp>
Take a TX timestamp from the stack-wide queue.
Run the network runner concurrently to collect TX timestamps. The queue has one consumer. Coordinate packet IDs across senders and remember their interface and clock; do not reuse IDs while old timestamps can still arrive. Timestamps may be lost or arrive out of order. Use timeouts for missing timestamps.
Sourcepub fn tx_timestamp(&self) -> impl Future<Output = TxTimestamp> + '_
pub fn tx_timestamp(&self) -> impl Future<Output = TxTimestamp> + '_
Wait for a TX timestamp from the stack-wide queue.
Only one task may wait at a time. See Self::poll_tx_timestamp for packet ID
and delivery requirements. Cancelling a pending wait consumes no timestamp.
Sourcepub fn add_iface(
&self,
driver: &'d mut dyn Driver,
) -> Result<Iface<'d>, AddIfaceError>
pub fn add_iface( &self, driver: &'d mut dyn Driver, ) -> Result<Iface<'d>, AddIfaceError>
Add an interface to the stack, borrowing the driver.
The driver is borrowed for as long as the stack lives. With a StaticCell
that is 'static; with a local, the enclosing scope.
§Example
static ETH: StaticCell<Device> = StaticCell::new();
let eth = stack.add_iface(ETH.init(device)).unwrap();Errors:
Fullif the stack has no room for another interface.UnsupportedMediumif the build has nomedium-*feature for the driver’s medium.HardwareAddrMismatchif the hardware address the driver reports is not of the kind its medium uses.
Sourcepub fn iface(&self, handle: IfaceHandle) -> Iface<'d>
pub fn iface(&self, handle: IfaceHandle) -> Iface<'d>
Get an interface by its handle.
§Panics
Panics if the handle does not belong to an interface on this stack.
Sourcepub fn remove_iface(&self, handle: IfaceHandle)
pub fn remove_iface(&self, handle: IfaceHandle)
Remove an interface from the stack.
Its addresses, routes and neighbor cache entries go with it. Sockets bound to one of its addresses are not closed, they just stop receiving.
§Panics
Panics if the handle does not belong to an interface on this stack.
Sourcepub fn hostname<R>(&self, f: impl FnOnce(Option<&str>) -> R) -> R
pub fn hostname<R>(&self, f: impl FnOnce(Option<&str>) -> R) -> R
The stack’s hostname, or None if not set.
Sourcepub fn set_hostname(&self, hostname: &str) -> Result<(), HostnameTooLong>
pub fn set_hostname(&self, hostname: &str) -> Result<(), HostnameTooLong>
Set the stack’s hostname.
If set, it is sent to the DHCP server in outgoing DHCP messages, as the host name option.
An empty string clears the hostname.
Errors:
HostnameTooLongifhostnameis longer than 63 bytes. The stack is left unchanged.
Sourcepub fn neighbor_cache(&self) -> NeighborCache<'d>
pub fn neighbor_cache(&self) -> NeighborCache<'d>
The stack’s neighbor cache, shared by all interfaces.
Sourcepub fn set_dns_servers(&self, servers: &[IpAddr])
pub fn set_dns_servers(&self, servers: &[IpAddr])
Set the DNS servers to use, on top of the ones learned from DHCPv4.
The runner keeps the DNS client’s server list in step with the DHCPv4 leases of every interface. The servers set here are used in addition to those, and come first.