embassy-net

Crates

git

Versions

default

Flavors

Skip to main content

Iface

Struct Iface 

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

An interface added to a Stack.

Returned by Stack::add_iface and Stack::iface. It’s Copy, so you can pass it by value instead of by reference.

Implementations§

Source§

impl<'d> Iface<'d>

Source

pub fn stack(&self) -> Stack<'d>

The stack this interface belongs to.

Source

pub fn handle(&self) -> IfaceHandle

This interface’s handle.

Source

pub fn capabilities(&self) -> Capabilities

The capabilities reported by the device.

Source

pub fn with_driver<R>(&self, f: impl FnOnce(&mut dyn Driver) -> R) -> R

Call f with the interface’s device.

The link state reported by the device.

Source

pub fn ip_mtu(&self) -> usize

The interface’s IP-layer MTU: the device MTU minus the link-layer header, clamped to what a PacketBuf can carry.

Source

pub fn poll_tx_timestamp(&self) -> Option<TxTimestamp>

Poll the device for the timestamp of an already-transmitted packet, sent with PacketMeta::request_timestamp set.

Returns None if no timestamp is available right now, which is also all a device without transmit timestamping support ever returns. Timestamps arrive an arbitrary time after the packet was sent, possibly out of order, and possibly never, so poll this repeatedly rather than once after sending.

Source

pub fn hardware_addr(&self) -> HardwareAddress

The hardware address of the interface.

Initially the address the device reported when the interface was added. set_hardware_addr overrides it.

Source

pub fn set_hardware_addr(&self, addr: HardwareAddress)

Set the hardware address of the interface.

The stack starts using it for the frames it sends and for ingress filtering immediately. It does not announce the change on the link, so peers keep the old address in their neighbor caches until it expires.

§Panics

Panics if the address is not of the kind the device’s medium uses.

Source

pub fn ip_addrs(&self) -> Vec<IfaceAddr, IFACE_ADDR_COUNT>

The IP addresses assigned to the interface.

Source

pub fn has_ip_addr(&self, addr: impl Into<IpAddress>) -> bool

Whether the given address is assigned to the interface.

Source

pub fn add_ip_addr(&self, cidr: IpCidr) -> Result<Option<IpCidr>, Full>

Assign an IP address to the interface.

If the same address is already assigned, its prefix is updated and the previous CIDR returned. Otherwise the address is appended and None is returned.

§Panics

Panics if the address is not unicast.

Errors:

  • Full if the interface has no room for another address.
Source

pub fn remove_ip_addr(&self, addr: impl Into<IpAddress>) -> Option<IpCidr>

Unassign an IP address from the interface, returning the CIDR it was assigned with, or None if it was not assigned.

Source

pub fn set_ip_addrs( &self, addrs: impl IntoIterator<Item = IpCidr>, ) -> Result<(), Full>

Replace the interface’s entire set of IP addresses.

Equivalent to removing every address and adding the given ones. The automatic IPv6 link-local address is kept.

§Panics

Panics if any of the addresses is not unicast.

Errors:

  • Full if the addresses do not fit. The interface is left unchanged.
Source

pub fn config_generation(&self) -> u32

A counter that goes up every time the interface’s configuration changes for any reason (manual changes, DHCP, SLAAC).

Compare it with a saved value to find out whether anything changed since.

Source

pub fn set_dhcpv4(&self, config: Option<DhcpConfig>)

Turn the DHCPv4 client on, with the given configuration, or off with None.

While on, the client runs from the Runner. When it gets a lease the leased address and the default route via the leased router are installed on the interface, and removed again when the lease is lost or the client is turned off. Turning it on when it is already on restarts it with the new configuration.

§Panics

Panics if the interface is not an Ethernet interface.

Source

pub fn dhcpv4_lease(&self) -> Option<DhcpLease>

The current DHCPv4 lease, if the client is on and has one.

Source

pub fn restart_dhcpv4(&self)

Restart the DHCPv4 client, dropping the current lease and starting discovery over.

Source

pub fn set_dhcpv4_server(&self, config: Option<DhcpServerConfig>)

Turn the DHCPv4 server on, with the given configuration, or off with None.

While on, the stack answers DHCP requests arriving on this interface, handing out addresses from the configured pool.

You must configure at least one IPv4 address on the interface, and the pool must be inside its subnet.

Turning the server off, or on again with a new configuration, drops all leases.

§Panics

Panics if the interface is not an Ethernet interface, or if the pool is backwards (pool_start above pool_end).

Source

pub fn dhcpv4_server_leases<R>( &self, f: impl FnOnce(&mut dyn Iterator<Item = DhcpServerLease>) -> R, ) -> R

Call f with an iterator over the DHCP server’s lease table. It is empty if the server is off.

All entries are passed, whether their lease is running or already over. Check each entry’s state and expires_at.

Source

pub fn remove_dhcpv4_server_lease(&self, address: Ipv4Address) -> bool

Remove the DHCP server lease of the given address, freeing it for other clients. Returns whether there was one.

The client is not told: it keeps using the address until it next renews.

Source

pub fn set_slaac(&self, config: Option<SlaacConfig>)

Turn SLAAC on, with the given configuration, or off with None.

Source

pub fn slaac(&self) -> Option<SlaacState>

The current SLAAC state, if it is on.

Source

pub fn restart_slaac(&self)

Restart SLAAC, soliciting routers again.

Source

pub fn join_multicast_group( &self, addr: impl Into<IpAddress>, ) -> Result<(), MulticastError>

Join a multicast group.

Source

pub fn leave_multicast_group( &self, addr: impl Into<IpAddress>, ) -> Result<(), MulticastError>

Leave a multicast group.

Source

pub fn has_multicast_group(&self, addr: impl Into<IpAddress>) -> bool

Whether the interface has joined the given multicast group.

Whether the link is up.

Source

pub fn is_config_up(&self) -> bool

Whether the interface has an address that something other than IPv6 link-local autoconfiguration put there.

That is: a static address was assigned, or DHCPv4 or SLAAC completed.

Source

pub fn is_config_v4_up(&self) -> bool

Check whether the network stack has a valid IPv4 configuration.

Source

pub fn is_config_v6_up(&self) -> bool

Check whether the network stack has a valid non link-local IPv6 configuration.

Wait for the network device to obtain a link signal.

Wait for the network device to lose link signal.

Source

pub async fn wait_config_up(&self)

Wait for the interface to obtain a valid IP configuration.

Source

pub async fn wait_config_down(&self)

Wait for the interface to lose a valid IP configuration.

Source

pub async fn wait_config_v4_up(&self)

Wait for the interface to obtain a valid IPv4 configuration.

Source

pub async fn wait_config_v4_down(&self)

Wait for the interface to lose a valid IPv4 configuration.

Source

pub async fn wait_config_v6_up(&self)

Wait for the interface to obtain a valid IPv6 configuration.

This does not include link-local addresses.

Source

pub async fn wait_config_v6_down(&self)

Wait for the interface to lose a valid IPv6 configuration.

This does not include link-local addresses.

Trait Implementations§

Source§

impl<'d> Clone for Iface<'d>

Source§

fn clone(&self) -> Iface<'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 Iface<'d>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<'d> Freeze for Iface<'d>

§

impl<'d> Unpin for Iface<'d>

§

impl<'d> UnsafeUnpin for Iface<'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.