pub struct NeighborCache<'d> { /* private fields */ }Expand description
The neighbor cache: the stack’s map of IP addresses to hardware addresses.
It holds one entry per neighbor, keyed by the interface it is reachable through plus its IP address. Entries are filled in by ARP and neighbor discovery, and expire after 60 s unless traffic from the neighbor refreshes them.
Access it with Stack::neighbor_cache.
Implementations§
Source§impl<'d> NeighborCache<'d>
impl<'d> NeighborCache<'d>
Sourcepub fn get(&self, iface: IfaceHandle, addr: IpAddr) -> Option<Neighbor>
pub fn get(&self, iface: IfaceHandle, addr: IpAddr) -> Option<Neighbor>
Get the entry for a neighbor.
An entry that expired is reported as NeighborState::Stale from the
next poll on, until the stack reuses its slot. Before that poll it is
still Reachable, with an expires_at that has passed.
Sourcepub fn insert(
&self,
iface: IfaceHandle,
addr: IpAddr,
hardware_addr: HardwareAddress,
expires_at: Instant,
) -> Result<(), NotUnicast>
pub fn insert( &self, iface: IfaceHandle, addr: IpAddr, hardware_addr: HardwareAddress, expires_at: Instant, ) -> Result<(), NotUnicast>
Add or replace an entry, mapping addr on iface to hardware_addr.
expires_at is when the entry stops being used. There are no static
entries. To keep an entry, insert it again before it expires. An
expires_at more than ~12 days away is clamped to that.
The stack changes the entry too:
- Traffic from the neighbor sets it to expire 60 s later.
- ARP or neighbor discovery replaces it if the neighbor answers with a different hardware address.
If the cache is full, another entry is evicted to make room.
§Errors
NotUnicast: ifaddrorhardware_addris not unicast. The cache is left unchanged.
Sourcepub fn remove(&self, iface: IfaceHandle, addr: IpAddr) -> Option<Neighbor>
pub fn remove(&self, iface: IfaceHandle, addr: IpAddr) -> Option<Neighbor>
Remove the entry for a neighbor, returning it if there was one.
Removing an entry whose resolution is still in progress drops the packets parked on it at the next poll.
Sourcepub fn retain(&self, f: impl FnMut(&Neighbor) -> bool)
pub fn retain(&self, f: impl FnMut(&Neighbor) -> bool)
Keep only the entries for which f returns true.
Same caveat as NeighborCache::remove for entries being resolved.
Sourcepub fn clear_iface(&self, iface: IfaceHandle)
pub fn clear_iface(&self, iface: IfaceHandle)
Remove all entries for one interface.
Same caveat as NeighborCache::remove for entries being resolved.
Sourcepub fn clear(&self)
pub fn clear(&self)
Remove all entries.
Same caveat as NeighborCache::remove for entries being resolved.
Trait Implementations§
Source§impl<'d> Clone for NeighborCache<'d>
impl<'d> Clone for NeighborCache<'d>
Source§fn clone(&self) -> NeighborCache<'d>
fn clone(&self) -> NeighborCache<'d>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more