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>
impl<'d> Iface<'d>
Sourcepub fn handle(&self) -> IfaceHandle
pub fn handle(&self) -> IfaceHandle
This interface’s handle.
Sourcepub fn capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
The capabilities reported by the device.
Sourcepub fn with_driver<R>(&self, f: impl FnOnce(&mut dyn Driver) -> R) -> R
pub fn with_driver<R>(&self, f: impl FnOnce(&mut dyn Driver) -> R) -> R
Call f with the interface’s device.
Sourcepub fn link_state(&self) -> LinkState
pub fn link_state(&self) -> LinkState
The link state reported by the device.
Sourcepub fn ip_mtu(&self) -> usize
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.
Sourcepub fn poll_tx_timestamp(&self) -> Option<TxTimestamp>
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.
Sourcepub fn hardware_addr(&self) -> HardwareAddress
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.
Sourcepub fn set_hardware_addr(&self, addr: HardwareAddress)
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.
Sourcepub fn ip_addrs(&self) -> Vec<IfaceAddr, IFACE_ADDR_COUNT>
pub fn ip_addrs(&self) -> Vec<IfaceAddr, IFACE_ADDR_COUNT>
The IP addresses assigned to the interface.
Sourcepub fn has_ip_addr(&self, addr: impl Into<IpAddress>) -> bool
pub fn has_ip_addr(&self, addr: impl Into<IpAddress>) -> bool
Whether the given address is assigned to the interface.
Sourcepub fn add_ip_addr(&self, cidr: IpCidr) -> Result<Option<IpCidr>, Full>
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:
Fullif the interface has no room for another address.
Sourcepub fn remove_ip_addr(&self, addr: impl Into<IpAddress>) -> Option<IpCidr>
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.
Sourcepub fn set_ip_addrs(
&self,
addrs: impl IntoIterator<Item = IpCidr>,
) -> Result<(), Full>
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:
Fullif the addresses do not fit. The interface is left unchanged.
Sourcepub fn config_generation(&self) -> u32
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.
Sourcepub fn set_dhcpv4(&self, config: Option<DhcpConfig>)
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.
Sourcepub fn dhcpv4_lease(&self) -> Option<DhcpLease>
pub fn dhcpv4_lease(&self) -> Option<DhcpLease>
The current DHCPv4 lease, if the client is on and has one.
Sourcepub fn restart_dhcpv4(&self)
pub fn restart_dhcpv4(&self)
Restart the DHCPv4 client, dropping the current lease and starting discovery over.
Sourcepub fn set_dhcpv4_server(&self, config: Option<DhcpServerConfig>)
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).
Sourcepub fn dhcpv4_server_leases<R>(
&self,
f: impl FnOnce(&mut dyn Iterator<Item = DhcpServerLease>) -> R,
) -> R
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.
Sourcepub fn remove_dhcpv4_server_lease(&self, address: Ipv4Address) -> bool
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.
Sourcepub fn set_slaac(&self, config: Option<SlaacConfig>)
pub fn set_slaac(&self, config: Option<SlaacConfig>)
Turn SLAAC on, with the given configuration, or off with None.
Sourcepub fn slaac(&self) -> Option<SlaacState>
pub fn slaac(&self) -> Option<SlaacState>
The current SLAAC state, if it is on.
Sourcepub fn restart_slaac(&self)
pub fn restart_slaac(&self)
Restart SLAAC, soliciting routers again.
Sourcepub fn join_multicast_group(
&self,
addr: impl Into<IpAddress>,
) -> Result<(), MulticastError>
pub fn join_multicast_group( &self, addr: impl Into<IpAddress>, ) -> Result<(), MulticastError>
Join a multicast group.
Sourcepub fn leave_multicast_group(
&self,
addr: impl Into<IpAddress>,
) -> Result<(), MulticastError>
pub fn leave_multicast_group( &self, addr: impl Into<IpAddress>, ) -> Result<(), MulticastError>
Leave a multicast group.
Sourcepub fn has_multicast_group(&self, addr: impl Into<IpAddress>) -> bool
pub fn has_multicast_group(&self, addr: impl Into<IpAddress>) -> bool
Whether the interface has joined the given multicast group.
Sourcepub fn is_link_up(&self) -> bool
pub fn is_link_up(&self) -> bool
Whether the link is up.
Sourcepub fn is_config_up(&self) -> bool
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.
Sourcepub fn is_config_v4_up(&self) -> bool
pub fn is_config_v4_up(&self) -> bool
Check whether the network stack has a valid IPv4 configuration.
Sourcepub fn is_config_v6_up(&self) -> bool
pub fn is_config_v6_up(&self) -> bool
Check whether the network stack has a valid non link-local IPv6 configuration.
Sourcepub async fn wait_link_up(&self)
pub async fn wait_link_up(&self)
Wait for the network device to obtain a link signal.
Sourcepub async fn wait_link_down(&self)
pub async fn wait_link_down(&self)
Wait for the network device to lose link signal.
Sourcepub async fn wait_config_up(&self)
pub async fn wait_config_up(&self)
Wait for the interface to obtain a valid IP configuration.
Sourcepub async fn wait_config_down(&self)
pub async fn wait_config_down(&self)
Wait for the interface to lose a valid IP configuration.
Sourcepub async fn wait_config_v4_up(&self)
pub async fn wait_config_v4_up(&self)
Wait for the interface to obtain a valid IPv4 configuration.
Sourcepub async fn wait_config_v4_down(&self)
pub async fn wait_config_v4_down(&self)
Wait for the interface to lose a valid IPv4 configuration.
Sourcepub async fn wait_config_v6_up(&self)
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.
Sourcepub async fn wait_config_v6_down(&self)
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.