xarxa

Crates

git

Versions

default

Flavors

Skip to main content

Stack

Struct Stack 

Source
pub struct Stack<'d> { /* private fields */ }
Expand description

A network stack.

Implementations§

Source§

impl Stack<'_>

Source

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.

Source

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>

Source

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.

Source

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:

  • Full if the stack has no room for another interface. Only possible without the alloc feature, where the limit is IFACE_COUNT.
Source

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:

  • Full if the stack has no room for another interface. Only possible without the alloc feature, where the limit is IFACE_COUNT.
Source

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

Source

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

Source

pub fn neighbor_cache(&self) -> &NeighborCache

Access the neighbor cache.

Source

pub fn neighbor_cache_mut(&mut self) -> &mut NeighborCache

Access the neighbor cache for modification.

Source

pub fn routes(&self) -> &Routes

Access the routing table.

Source

pub fn routes_mut(&mut self) -> &mut Routes

Access the routing table for modification.

Source

pub fn add_udp_socket(&mut self) -> Result<UdpHandle, Full>

Add a UDP socket to the stack, returning a handle to it.

Errors:

  • Full if the stack has no room for another UDP socket. Only possible without the alloc feature, where the limit is UDP_SOCKET_COUNT.
Source

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

Source

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

Source

pub fn add_raw_socket(&mut self) -> Result<RawHandle, Full>

Add a raw socket to the stack, returning a handle to it.

Errors:

  • Full if the stack has no room for another raw socket. Only possible without the alloc feature, where the limit is RAW_SOCKET_COUNT.
Source

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

Source

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

Source

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:

  • Full if the stack has no room for another TCP socket. Only possible without the alloc feature, where the limit is TCP_SOCKET_COUNT.
Source

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:

  • Full if the stack has no room for another TCP socket. Only possible without the alloc feature, where the limit is TCP_SOCKET_COUNT.
Source

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

Source

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

Source

pub fn add_tcp_listener(&mut self) -> Result<TcpListenerHandle, Full>

Add a TCP listener to the stack, returning a handle to it.

Errors:

  • Full if the stack has no room for another listener. Only possible without the alloc feature, where the limit is TCP_LISTENER_COUNT.
Source

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

Source

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

Source

pub fn ifaces(&mut self) -> IfaceIter<'_, 'd>

Iterate over the interfaces added to the stack.

See IfaceIter for how to use it.

Source

pub fn udp_sockets(&mut self) -> UdpSocketIter<'_, 'd>

Iterate over the UDP sockets added to the stack.

See UdpSocketIter for how to use it.

Source

pub fn raw_sockets(&mut self) -> RawSocketIter<'_, 'd>

Iterate over the raw sockets added to the stack.

See RawSocketIter for how to use it.

Source

pub fn tcp_sockets(&mut self) -> TcpSocketIter<'_, 'd>

Iterate over the TCP sockets added to the stack.

See TcpSocketIter for how to use it.

Source

pub fn tcp_listeners(&mut self) -> TcpListenerIter<'_, 'd>

Iterate over the TCP listeners added to the stack.

See TcpListenerIter for how to use it.

Source

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::MIN or in the past, poll should be called again immediately.
  • If no timer is pending, Instant::MAX is returned. No need to call poll on a timer, only after a packet is received or an operation is done on the Stack, a socket or an interface.

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