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>,
pool: &'static impl Pool,
random_seed: u64,
) -> (Self, Runner<'d>)
pub fn new( storage: &'d mut StackStorage<'d>, pool: &'static impl Pool, random_seed: u64, ) -> (Self, Runner<'d>)
Create a network stack.
Every packet buffer of the stack and its drivers comes from pool, usually
a StaticPool in a static.
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.
The stack starts out with no interfaces: add them with
add_iface_borrowed.
Sourcepub fn poll_tx_timestamp(&self) -> Option<TxTimestamp>
pub fn poll_tx_timestamp(&self) -> Option<TxTimestamp>
Take the timestamp of an already-transmitted packet, sent with
PacketMeta::request_timestamp set.
The timestamps of every interface land in one queue, which the Runner fills
from the drivers. This only reads it, so run the runner concurrently.
Timestamps arrive an arbitrary time after the packet was sent, possibly out of
order, and possibly never: a device may not support transmit timestamping, may
have run out of timestamp slots, or the queue may have been full (its capacity
is TX_TIMESTAMP_QUEUE_COUNT). Time
out waiting for one rather than expecting it.
The queue has one consumer, so the packet ids it reports back must be unique across everything the application sends, on every interface. Don’t reuse an id while a timestamp for the old packet can still arrive. Removing an interface does not drop the timestamps it already queued.
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_borrowed(
&self,
driver: &'d mut dyn Driver,
) -> Result<Iface<'d>, AddIfaceError>
pub fn add_iface_borrowed( &self, driver: &'d mut dyn Driver, ) -> Result<Iface<'d>, AddIfaceError>
Add an interface to the stack, lending it the device, and returning it.
The device is borrowed for as long as the stack lives. With a StaticCell
that is 'static; with a local, the enclosing scope.
Otherwise this is add_iface.
§Example
static ETH: StaticCell<Device> = StaticCell::new();
let eth = stack.add_iface_borrowed(ETH.init(device)).unwrap();§Errors
Full: if the stack has no room for another interface. Only possible without theallocfeature, where the limit isIFACE_COUNT.UnsupportedMedium: if the build has nomedium-*feature for the device’s medium.HardwareAddrMismatch: if the hardware address the device 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>
Sourcepub fn remove_iface(&self, handle: IfaceHandle)
pub fn remove_iface(&self, handle: IfaceHandle)
Remove an interface from the stack.
§Panics
Panics if the handle is stale (the interface was already removed).
Sourcepub fn ifaces(&self) -> impl Iterator<Item = Iface<'d>> + 'd
pub fn ifaces(&self) -> impl Iterator<Item = Iface<'d>> + 'd
Iterate over the interfaces added to the 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
HostnameTooLong: ifhostnameis longer than 63 bytes. The hostname is left unchanged.
Sourcepub fn neighbor_cache(&self) -> NeighborCache<'d>
pub fn neighbor_cache(&self) -> NeighborCache<'d>
Access the neighbor cache.
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.