pub struct Interface { /* 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 Interface
impl Interface
Sourcepub fn new(
config: Config,
device: &mut (impl Device + ?Sized),
now: Instant,
) -> Self
pub fn new( config: Config, device: &mut (impl Device + ?Sized), now: Instant, ) -> Self
Create a network interface using the previously provided configuration.
§Panics
This function panics if the [Config::hardware_address
] does not match
the medium of the device.
Sourcepub fn context(&mut self) -> &mut InterfaceInner
pub fn context(&mut self) -> &mut InterfaceInner
Get the socket context.
The context is needed for some socket methods.
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 ipv4_addr(&self) -> Option<Ipv4Address>
pub fn ipv4_addr(&self) -> Option<Ipv4Address>
Get the first IPv4 address if present.
Sourcepub fn ipv6_addr(&self) -> Option<Ipv6Address>
pub fn ipv6_addr(&self) -> Option<Ipv6Address>
Get the first IPv6 address if present.
Sourcepub fn get_source_address(&self, dst_addr: &IpAddress) -> Option<IpAddress>
pub fn get_source_address(&self, dst_addr: &IpAddress) -> Option<IpAddress>
Get an address from the interface that could be used as source address. For IPv4, this is the first IPv4 address from the list of addresses. For IPv6, the address is based on the destination address and uses RFC6724 for selecting the source address.
Sourcepub fn get_source_address_ipv4(
&self,
dst_addr: &Ipv4Address,
) -> Option<Ipv4Address>
pub fn get_source_address_ipv4( &self, dst_addr: &Ipv4Address, ) -> Option<Ipv4Address>
Get an address from the interface that could be used as source address. This is the first IPv4 address from the list of addresses in the interface.
Sourcepub fn get_source_address_ipv6(&self, dst_addr: &Ipv6Address) -> Ipv6Address
pub fn get_source_address_ipv6(&self, dst_addr: &Ipv6Address) -> Ipv6Address
Get an address from the interface that could be used as source address. The selection is based on RFC6724.
Sourcepub fn update_ip_addrs<F: FnOnce(&mut Vec<IpCidr, IFACE_MAX_ADDR_COUNT>)>(
&mut self,
f: F,
)
pub fn update_ip_addrs<F: FnOnce(&mut Vec<IpCidr, IFACE_MAX_ADDR_COUNT>)>( &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.
pub fn routes(&self) -> &Routes
pub fn routes_mut(&mut self) -> &mut Routes
Sourcepub fn set_any_ip(&mut self, any_ip: bool)
pub fn set_any_ip(&mut self, any_ip: bool)
Enable or disable the AnyIP capability.
AnyIP allowins packets to be received
locally on IP addresses other than the interface’s configured [ip_addrs].
When AnyIP is enabled and a route prefix in routes
specifies one of
the interface’s ip_addrs
as its gateway, the interface will accept
packets addressed to that prefix.
Sourcepub fn any_ip(&self) -> bool
pub fn any_ip(&self) -> bool
Get whether AnyIP is enabled.
See set_any_ip
for details on AnyIP
Sourcepub fn reassembly_timeout(&self) -> Duration
pub fn reassembly_timeout(&self) -> Duration
Get the packet reassembly timeout.
Sourcepub fn set_reassembly_timeout(&mut self, timeout: Duration)
pub fn set_reassembly_timeout(&mut self, timeout: Duration)
Set the packet reassembly timeout.
Sourcepub fn poll(
&mut self,
timestamp: Instant,
device: &mut (impl Device + ?Sized),
sockets: &mut SocketSet<'_>,
) -> PollResult
pub fn poll( &mut self, timestamp: Instant, device: &mut (impl Device + ?Sized), sockets: &mut SocketSet<'_>, ) -> PollResult
Transmit packets queued in the sockets, and receive packets queued in the device.
This function returns a value indicating whether the state of any socket might have changed.
§DoS warning
This function processes all packets in the device’s queue. This can be an unbounded amount of work if packets arrive faster than they’re processed.
If this is a concern for your application (i.e. your environment doesn’t
have preemptive scheduling, or poll()
is called from a main loop where
other important things are processed), you may use the lower-level methods
poll_egress()
and poll_ingress_single()
.
This allows you to insert yields or process other events between processing
individual ingress packets.
Sourcepub fn poll_egress(
&mut self,
timestamp: Instant,
device: &mut (impl Device + ?Sized),
sockets: &mut SocketSet<'_>,
) -> PollResult
pub fn poll_egress( &mut self, timestamp: Instant, device: &mut (impl Device + ?Sized), sockets: &mut SocketSet<'_>, ) -> PollResult
Transmit packets queued in the sockets.
This function returns a value indicating whether the state of any socket might have changed.
This is guaranteed to always perform a bounded amount of work.
Sourcepub fn poll_ingress_single(
&mut self,
timestamp: Instant,
device: &mut (impl Device + ?Sized),
sockets: &mut SocketSet<'_>,
) -> PollIngressSingleResult
pub fn poll_ingress_single( &mut self, timestamp: Instant, device: &mut (impl Device + ?Sized), sockets: &mut SocketSet<'_>, ) -> PollIngressSingleResult
Process one incoming packet queued in the device.
Returns a value indicating:
- whether a packet was processed, in which case you have to call this method again in case there’s more packets queued.
- whether the state of any socket might have changed.
Since it processes at most one packet, this is guaranteed to always perform a bounded amount of work.
Sourcepub fn poll_delay(
&mut self,
timestamp: Instant,
sockets: &SocketSet<'_>,
) -> Option<Duration>
pub fn poll_delay( &mut self, timestamp: Instant, sockets: &SocketSet<'_>, ) -> 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.