embassy-net

Crates

git

Versions

default

Flavors

Skip to main content

Stack

Struct Stack 

Source
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>

Source

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.

Source

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.

Source

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.

Source

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 the alloc feature, where the limit is IFACE_COUNT.
  • UnsupportedMedium: if the build has no medium-* feature for the device’s medium.
  • HardwareAddrMismatch: if the hardware address the device reports is not of the kind its medium uses.
Source

pub fn iface(&self, handle: IfaceHandle) -> Iface<'d>

Get an interface by its handle.

§Panics

Panics if the handle is stale (the interface was removed).

Source

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).

Source

pub fn ifaces(&self) -> impl Iterator<Item = Iface<'d>> + 'd

Iterate over the interfaces added to the stack.

Source

pub fn hostname<R>(&self, f: impl FnOnce(Option<&str>) -> R) -> R

The stack’s hostname, or None if not set.

Source

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: if hostname is longer than 63 bytes. The hostname is left unchanged.
Source

pub fn neighbor_cache(&self) -> NeighborCache<'d>

Access the neighbor cache.

Source

pub fn routes(&self) -> Routes<'d>

Access the routing table.

Source

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.

Source

pub async fn dns_query( &self, name: &str, qtype: DnsQueryType, ) -> Result<Vec<IpAddr, { xarxa::config::DNS_MAX_RESULT_COUNT }>, Error>

Make a query for a given name and return the corresponding IP addresses.

Trait Implementations§

Source§

impl<'d> Clone for Stack<'d>

Source§

fn clone(&self) -> Stack<'d>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'d> Copy for Stack<'d>

Auto Trait Implementations§

§

impl<'d> !RefUnwindSafe for Stack<'d>

§

impl<'d> !Send for Stack<'d>

§

impl<'d> !Sync for Stack<'d>

§

impl<'d> !UnwindSafe for Stack<'d>

§

impl<'d> Freeze for Stack<'d>

§

impl<'d> Unpin for Stack<'d>

§

impl<'d> UnsafeUnpin for Stack<'d>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.