pub struct Iface<'a, 'd> { /* private fields */ }Expand description
An interface borrowed from a Stack, returned by Stack::iface.
Implementations§
Source§impl<'d> Iface<'_, 'd>
impl<'d> Iface<'_, 'd>
Sourcepub fn capabilities(&self) -> Capabilities
pub fn capabilities(&self) -> Capabilities
The capabilities reported by the device.
Sourcepub fn driver_mut(&mut self) -> &mut dyn Driver
pub fn driver_mut(&mut self) -> &mut dyn Driver
The interface’s driver.
Sourcepub fn link_state(&mut self) -> LinkState
pub fn link_state(&mut 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(
&mut self,
addr: HardwareAddress,
) -> Result<(), MediumMismatch>
pub fn set_hardware_addr( &mut 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:
MediumMismatchif the address is not of the kind the interface’s medium uses. The interface is left unchanged.
Sourcepub fn ip_addrs(&self) -> &[IfaceAddr]
pub fn ip_addrs(&self) -> &[IfaceAddr]
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(&mut self, cidr: IpCidr) -> Result<Option<IpCidr>, AddrError>
pub fn add_ip_addr(&mut 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:
NotUnicastif the address is not unicast.Fullif the interface has no room for another address. Only possible without theallocfeature, where the limit isIFACE_ADDR_COUNT.
Sourcepub fn remove_ip_addr(&mut self, addr: impl Into<IpAddr>) -> Option<IpCidr>
pub fn remove_ip_addr(&mut 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(
&mut self,
new_addrs: impl IntoIterator<Item = IpCidr>,
) -> Result<(), AddrError>
pub fn set_ip_addrs( &mut self, new_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:
NotUnicastif any of the addresses is not unicast.Fullif 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 register_waker(&mut self, waker: &Waker)
pub fn register_waker(&mut self, waker: &Waker)
Register a waker to be woken when the interface changes state.
It is woken when the link goes up or down, and when
config_generation changes: addresses or routes
added or removed, whether by hand or by DHCPv4 or SLAAC.
Only one waker is kept. Registering another replaces it. A woken waker must be registered again to be woken again. Wakes are allowed to be spurious.
Sourcepub fn set_dhcpv4(
&mut self,
config: Option<DhcpConfig>,
) -> Result<(), MediumMismatch>
pub fn set_dhcpv4( &mut 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 Stack::poll. 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:
MediumMismatchif the interface is not an Ethernet interface.
Sourcepub fn set_slaac(
&mut self,
config: Option<SlaacConfig>,
) -> Result<(), MediumMismatch>
pub fn set_slaac( &mut 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 Stack::poll. 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:
MediumMismatchif the interface is not an Ethernet or IEEE 802.15.4 interface.
Sourcepub fn restart_slaac(&mut self)
pub fn restart_slaac(&mut self)
Solicit routers again, keeping the addresses and routes already configured.
Stack::poll 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 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 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(&mut self)
pub fn restart_dhcpv4(&mut self)
Drop the DHCPv4 lease, if any, and look for a server again.
Stack::poll 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(
&mut self,
config: Option<DhcpServerConfig>,
) -> Result<(), DhcpServerError>
pub fn set_dhcpv4_server( &mut 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:
MediumMismatchif the interface is not an Ethernet interface.InvalidPoolifpool_endis belowpool_start.
Sourcepub fn dhcpv4_server_leases(&self) -> &[DhcpServerLease]
pub fn dhcpv4_server_leases(&self) -> &[DhcpServerLease]
The DHCP server’s lease table. Empty if the server is off.
All entries are returned, whether their lease is running or already over.
Check each entry’s state
and expires_at.
Sourcepub fn remove_dhcpv4_server_lease(&mut self, address: Ipv4Addr) -> bool
pub fn remove_dhcpv4_server_lease(&mut 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.
Source§impl Iface<'_, '_>
impl Iface<'_, '_>
Sourcepub fn join_multicast_group(
&mut self,
addr: impl Into<IpAddr>,
) -> Result<(), MulticastError>
pub fn join_multicast_group( &mut self, addr: impl Into<IpAddr>, ) -> Result<(), MulticastError>
Join a multicast group.
The stack accepts packets sent to the group right away, and reports the
membership to the routers on the link from the next Stack::poll.
Errors:
Unaddressableif the address is not a multicast address.
Sourcepub fn leave_multicast_group(
&mut self,
addr: impl Into<IpAddr>,
) -> Result<(), MulticastError>
pub fn leave_multicast_group( &mut self, addr: impl Into<IpAddr>, ) -> Result<(), MulticastError>
Leave a multicast group.
The stack stops accepting packets sent to the group right away, and
reports the leave to the routers on the link from the next
Stack::poll. Leaving a group that was not joined
does nothing.
Errors:
Unaddressableif the address is not a multicast address.
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.
Source§impl Iface<'_, '_>
impl Iface<'_, '_>
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(&mut self, pan_id: Option<Ieee802154Pan>)
pub fn set_pan_id(&mut 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(&self) -> &[SixlowpanAddressContext]
pub fn sixlowpan_address_context(&self) -> &[SixlowpanAddressContext]
The 6LoWPAN address contexts, by context identifier.
Sourcepub fn set_sixlowpan_address_context(
&mut self,
contexts: impl IntoIterator<Item = SixlowpanAddressContext>,
) -> Result<(), Full>
pub fn set_sixlowpan_address_context( &mut 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:
Fullif the contexts do not fit. Only possible without theallocfeature, where the limit isSIXLOWPAN_ADDRESS_CONTEXT_COUNT. The interface is left unchanged.