pub struct Interface<'a, DeviceT: for<'d> Device<'d>> { /* private fields */ }
Expand description
A network interface.
The network interface logically owns a number of other data structures; to avoid
a dependency on heap allocation, it instead owns a BorrowMut<[T]>
, which can be
a &mut [T]
, or Vec<T>
if a heap is available.
Implementations§
source§impl<'a, DeviceT> Interface<'a, DeviceT>where
DeviceT: for<'d> Device<'d>,
impl<'a, DeviceT> Interface<'a, DeviceT>where
DeviceT: for<'d> Device<'d>,
sourcepub fn add_socket<T: AnySocket<'a>>(&mut self, socket: T) -> SocketHandle
pub fn add_socket<T: AnySocket<'a>>(&mut self, socket: T) -> SocketHandle
Add a socket to the interface, and return its handle.
Panics
This function panics if the storage is fixed-size (not a Vec
) and is full.
sourcepub fn get_socket<T: AnySocket<'a>>(&mut self, handle: SocketHandle) -> &mut T
pub fn get_socket<T: AnySocket<'a>>(&mut self, handle: SocketHandle) -> &mut T
Get a socket from the interface by its handle, as mutable.
Panics
This function may panic if the handle does not belong to this socket set or the socket has the wrong type.
sourcepub fn get_socket_and_context<T: AnySocket<'a>>(
&mut self,
handle: SocketHandle
) -> (&mut T, &mut InterfaceInner<'a>)
pub fn get_socket_and_context<T: AnySocket<'a>>(
&mut self,
handle: SocketHandle
) -> (&mut T, &mut InterfaceInner<'a>)
Get a socket by handle, and the socket context.
The context is needed for some socket methods.
Panics
This function may panic if the handle does not belong to this socket set or the socket has the wrong type.
sourcepub fn remove_socket(&mut self, handle: SocketHandle) -> Socket<'a>
pub fn remove_socket(&mut self, handle: SocketHandle) -> Socket<'a>
Remove a socket from the set, without changing its state.
Panics
This function may panic if the handle does not belong to this socket set.
sourcepub fn hardware_addr(&self) -> HardwareAddress
pub fn hardware_addr(&self) -> HardwareAddress
Get the HardwareAddress address of the interface.
Panics
This function panics if the medium is not Ethernet or Ieee802154.
sourcepub fn set_hardware_addr(&mut self, addr: HardwareAddress)
pub fn set_hardware_addr(&mut self, addr: HardwareAddress)
Set the HardwareAddress address of the interface.
Panics
This function panics if the address is not unicast, and if the medium is not Ethernet or Ieee802154.
sourcepub fn device_mut(&mut self) -> &mut DeviceT
pub fn device_mut(&mut self) -> &mut DeviceT
Get a mutable reference to the inner device.
There are no invariants imposed on the device by the interface itself. Furthermore the
trait implementations, required for references of all lifetimes, guarantees that the
mutable reference can not invalidate the device as such. For some devices, such access may
still allow modifications with adverse effects on the usability as a phy
device. You
should not use them this way.
sourcepub fn sockets(&self) -> impl Iterator<Item = (SocketHandle, &Socket<'a>)>
pub fn sockets(&self) -> impl Iterator<Item = (SocketHandle, &Socket<'a>)>
Get an iterator to the inner sockets.
sourcepub fn sockets_mut(
&mut self
) -> impl Iterator<Item = (SocketHandle, &mut Socket<'a>)>
pub fn sockets_mut(
&mut self
) -> impl Iterator<Item = (SocketHandle, &mut Socket<'a>)>
Get a mutable iterator to the inner sockets.
sourcepub fn join_multicast_group<T: Into<IpAddress>>(
&mut self,
addr: T,
timestamp: Instant
) -> Result<bool>
pub fn join_multicast_group<T: Into<IpAddress>>(
&mut self,
addr: T,
timestamp: Instant
) -> Result<bool>
Add an address to a list of subscribed multicast IP addresses.
Returns Ok(announce_sent)
if the address was added successfully, where annouce_sent
indicates whether an initial immediate announcement has been sent.
sourcepub fn leave_multicast_group<T: Into<IpAddress>>(
&mut self,
addr: T,
timestamp: Instant
) -> Result<bool>
pub fn leave_multicast_group<T: Into<IpAddress>>(
&mut self,
addr: T,
timestamp: Instant
) -> Result<bool>
Remove an address from the subscribed multicast IP addresses.
Returns Ok(leave_sent)
if the address was removed successfully, where leave_sent
indicates whether an immediate leave packet has been sent.
sourcepub fn has_multicast_group<T: Into<IpAddress>>(&self, addr: T) -> bool
pub fn has_multicast_group<T: Into<IpAddress>>(&self, addr: T) -> bool
Check whether the interface listens to given destination multicast IP address.
sourcepub fn ipv4_addr(&self) -> Option<Ipv4Address>
pub fn ipv4_addr(&self) -> Option<Ipv4Address>
Get the first IPv4 address if present.
sourcepub fn update_ip_addrs<F: FnOnce(&mut ManagedSlice<'a, IpCidr>)>(&mut self, f: F)
pub fn update_ip_addrs<F: FnOnce(&mut ManagedSlice<'a, IpCidr>)>(&mut self, f: F)
Update the IP addresses of the interface.
Panics
This function panics if any of the addresses are not unicast.
sourcepub fn has_ip_addr<T: Into<IpAddress>>(&self, addr: T) -> bool
pub fn has_ip_addr<T: Into<IpAddress>>(&self, addr: T) -> bool
Check whether the interface has the given IP address assigned.
sourcepub fn ipv4_address(&self) -> Option<Ipv4Address>
pub fn ipv4_address(&self) -> Option<Ipv4Address>
Get the first IPv4 address of the interface.
pub fn routes(&self) -> &Routes<'a>
pub fn routes_mut(&mut self) -> &mut Routes<'a>
sourcepub fn poll(&mut self, timestamp: Instant) -> Result<bool>
pub fn poll(&mut self, timestamp: Instant) -> Result<bool>
Transmit packets queued in the given sockets, and receive packets queued in the device.
This function returns a boolean value indicating whether any packets were processed or emitted, and thus, whether the readiness of any socket might have changed.
Errors
This method will routinely return errors in response to normal network activity as well as certain boundary conditions such as buffer exhaustion. These errors are provided as an aid for troubleshooting, and are meant to be logged and ignored.
As a special case, Err(Error::Unrecognized)
is returned in response to
packets containing any unsupported protocol, option, or form, which is
a very common occurrence and on a production system it should not even
be logged.
sourcepub fn poll_delay(&mut self, timestamp: Instant) -> Option<Duration>
pub fn poll_delay(&mut self, timestamp: Instant) -> Option<Duration>
Return an advisory wait time for calling poll the next time. The Duration returned is the time left to wait before calling poll next. It is harmless (but wastes energy) to call it before the Duration has passed, and potentially harmful (impacting quality of service) to call it after the Duration has passed.