pub struct Iface<'d> { /* private fields */ }Expand description
An interface added to a Stack.
Returned by Stack::add_iface_borrowed 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 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,
) -> Result<(), MediumMismatch>
pub fn set_hardware_addr( &self, addr: HardwareAddress, ) -> Result<(), MediumMismatch>
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. Send a gratuitous ARP or unsolicited neighbor advertisement from a raw socket if that matters.
An IEEE 802.15.4 interface must use an extended address. A short address is accepted, but the stack can not put it in NDISC link-layer address options, so neighbor discovery does not work with one.
§Errors
MediumMismatch: if the address is not of the kind the interface’s medium uses. The interface is left unchanged.
Sourcepub fn pan_id(&self) -> Option<Ieee802154Pan>
pub fn pan_id(&self) -> Option<Ieee802154Pan>
The PAN identifier of an IEEE 802.15.4 interface, None for any PAN.
Sourcepub fn set_pan_id(&self, pan_id: Option<Ieee802154Pan>)
pub fn set_pan_id(&self, pan_id: Option<Ieee802154Pan>)
Set the PAN identifier of an IEEE 802.15.4 interface.
With a PAN set, frames for another PAN are dropped, except broadcast
ones. With None, the default, frames for every PAN are accepted.
Sent frames carry the PAN, or a zero PAN with None.
Does nothing on other media.
Sourcepub fn sixlowpan_address_context<R>(
&self,
f: impl FnOnce(&[SixlowpanAddressContext]) -> R,
) -> R
pub fn sixlowpan_address_context<R>( &self, f: impl FnOnce(&[SixlowpanAddressContext]) -> R, ) -> R
The 6LoWPAN address contexts, by context identifier, passed to f.
Sourcepub fn set_sixlowpan_address_context(
&self,
contexts: impl IntoIterator<Item = SixlowpanAddressContext>,
) -> Result<(), Full>
pub fn set_sixlowpan_address_context( &self, contexts: impl IntoIterator<Item = SixlowpanAddressContext>, ) -> Result<(), Full>
Replace the 6LoWPAN address contexts.
Received packets whose addresses are compressed against a context identifier are resolved with the context at that index. Sent packets never use contexts.
§Errors
Full: if the contexts do not fit. Only possible without theallocfeature, where the limit isSIXLOWPAN_ADDRESS_CONTEXT_COUNT. The interface is left unchanged.
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, with their origin.
Sourcepub fn has_ip_addr(&self, addr: impl Into<IpAddr>) -> bool
pub fn has_ip_addr(&self, addr: impl Into<IpAddr>) -> bool
Check whether the given address is assigned to the interface.
Sourcepub fn add_ip_addr(&self, cidr: IpCidr) -> Result<Option<IpCidr>, AddrError>
pub fn add_ip_addr(&self, cidr: IpCidr) -> Result<Option<IpCidr>, AddrError>
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. Source address selection prefers the first address matching the
destination’s subnet, so ordering only matters between addresses of the same
subnet.
§Errors
NotUnicast: if the address is not unicast.Full: if the interface has no room for another address. Only possible without theallocfeature, where the limit isIFACE_ADDR_COUNT.
Sourcepub fn remove_ip_addr(&self, addr: impl Into<IpAddr>) -> Option<IpCidr>
pub fn remove_ip_addr(&self, addr: impl Into<IpAddr>) -> 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<(), AddrError>
pub fn set_ip_addrs( &self, addrs: impl IntoIterator<Item = IpCidr>, ) -> Result<(), AddrError>
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.
On error the interface is left unchanged.
§Errors
NotUnicast: if any of the addresses is not unicast.Full: if the addresses do not fit. Only possible without theallocfeature, where the limit isIFACE_ADDR_COUNT.
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>,
) -> Result<(), MediumMismatch>
pub fn set_dhcpv4( &self, config: Option<DhcpConfig>, ) -> Result<(), MediumMismatch>
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.
§Errors
MediumMismatch: if the interface is not an Ethernet interface.
Sourcepub fn dhcpv4_lease(&self) -> Option<DhcpLease>
pub fn dhcpv4_lease(&self) -> Option<DhcpLease>
The lease the DHCPv4 client currently holds, if any.
Sourcepub fn restart_dhcpv4(&self)
pub fn restart_dhcpv4(&self)
Drop the DHCPv4 lease, if any, and look for a server again.
The Runner does this when the link comes back up; call it
directly for a driver that cannot report link state. Does nothing if the client
is off.
Sourcepub fn set_dhcpv4_server(
&self,
config: Option<DhcpServerConfig>,
) -> Result<(), DhcpServerError>
pub fn set_dhcpv4_server( &self, config: Option<DhcpServerConfig>, ) -> Result<(), DhcpServerError>
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.
On error the server is left as it was.
§Errors
MediumMismatch: if the interface is not an Ethernet interface.InvalidPool: ifpool_endis belowpool_start.
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: Ipv4Addr) -> bool
pub fn remove_dhcpv4_server_lease(&self, address: Ipv4Addr) -> 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>,
) -> Result<(), MediumMismatch>
pub fn set_slaac( &self, config: Option<SlaacConfig>, ) -> Result<(), MediumMismatch>
Turn IPv6 stateless address autoconfiguration on, with the given
configuration, or off with None.
While on, the stack sends router solicitations from the Runner.
Every prefix a router advertises for autoconfiguration becomes an address on the
interface (the prefix plus the EUI-64 of the hardware address), and every
advertising router becomes a default route. Both are removed when their
lifetime runs out or when SLAAC is turned off. Turning it on when it is
already on restarts it.
§Errors
MediumMismatch: if the interface is not an Ethernet or IEEE 802.15.4 interface.
Sourcepub fn slaac(&self) -> Option<SlaacState>
pub fn slaac(&self) -> Option<SlaacState>
What SLAAC has learned from the routers on the link, or None if SLAAC is off.
Sourcepub fn restart_slaac(&self)
pub fn restart_slaac(&self)
Solicit routers again, keeping the addresses and routes already configured.
The Runner does this when the link comes back up; call it
directly for a driver that cannot report link state. Does nothing if SLAAC is off.
Sourcepub fn join_multicast_group(
&self,
addr: impl Into<IpAddr>,
) -> Result<(), MulticastError>
pub fn join_multicast_group( &self, addr: impl Into<IpAddr>, ) -> Result<(), MulticastError>
Sourcepub fn leave_multicast_group(
&self,
addr: impl Into<IpAddr>,
) -> Result<(), MulticastError>
pub fn leave_multicast_group( &self, addr: impl Into<IpAddr>, ) -> Result<(), MulticastError>
Sourcepub fn has_multicast_group(&self, addr: impl Into<IpAddr>) -> bool
pub fn has_multicast_group(&self, addr: impl Into<IpAddr>) -> bool
Check whether the interface listens to the given multicast address.
Besides the joined groups, this is true for the groups every host is a member of: the IPv4 all systems group, the IPv6 all nodes group, and the IPv6 solicited node group of each address assigned to the interface.
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.