xarxa

Crates

git

Versions

default

Flavors

Skip to main content

Iface

Struct Iface 

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

Source

pub fn capabilities(&self) -> Capabilities

The capabilities reported by the device.

Source

pub fn driver_mut(&mut self) -> &mut dyn Driver

The interface’s driver.

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 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( &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:

  • MediumMismatch if the address is not of the kind the interface’s medium uses. The interface is left unchanged.
Source

pub fn ip_addrs(&self) -> &[IfaceAddr]

The IP addresses assigned to the interface, with their origin.

Source

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

Check whether the given address is assigned to the interface.

Source

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:

  • NotUnicast if the address is not unicast.
  • Full if the interface has no room for another address. Only possible without the alloc feature, where the limit is IFACE_ADDR_COUNT.
Source

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.

Source

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:

  • NotUnicast if any of the addresses is not unicast.
  • Full if the addresses do not fit. Only possible without the alloc feature, where the limit is IFACE_ADDR_COUNT.
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 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.

Source

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:

  • MediumMismatch if the interface is not an Ethernet interface.
Source

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:

  • MediumMismatch if the interface is not an Ethernet or IEEE 802.15.4 interface.
Source

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.

Source

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

What SLAAC has learned from the routers on the link, or None if SLAAC is off.

Source

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

The lease the DHCPv4 client currently holds, if any.

Source

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.

Source

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:

  • MediumMismatch if the interface is not an Ethernet interface.
  • InvalidPool if pool_end is below pool_start.
Source

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.

Source

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<'_, '_>

Source

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:

  • Unaddressable if the address is not a multicast address.
Source

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:

  • Unaddressable if the address is not a multicast address.
Source

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<'_, '_>

Source

pub fn pan_id(&self) -> Option<Ieee802154Pan>

The PAN identifier of an IEEE 802.15.4 interface, None for any PAN.

Source

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.

Source

pub fn sixlowpan_address_context(&self) -> &[SixlowpanAddressContext]

The 6LoWPAN address contexts, by context identifier.

Source

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:

  • Full if the contexts do not fit. Only possible without the alloc feature, where the limit is SIXLOWPAN_ADDRESS_CONTEXT_COUNT. The interface is left unchanged.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

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