pub struct NeighborCache { /* 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 and Stack::neighbor_cache_mut.
Implementations§
Source§impl NeighborCache
impl NeighborCache
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(
&mut self,
iface: IfaceHandle,
addr: IpAddr,
hardware_addr: HardwareAddress,
expires_at: Instant,
) -> Result<(), NotUnicast>
pub fn insert( &mut 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.
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(&mut self, iface: IfaceHandle, addr: IpAddr) -> Option<Neighbor>
pub fn remove(&mut 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(&mut self, f: impl FnMut(&Neighbor) -> bool)
pub fn retain(&mut 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(&mut self, iface: IfaceHandle)
pub fn clear_iface(&mut self, iface: IfaceHandle)
Remove all entries for one interface.
Same caveat as NeighborCache::remove for entries being resolved.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all entries.
Same caveat as NeighborCache::remove for entries being resolved.