Skip to content

Commit

Permalink
Reset expiry of entries in the neighbor cache on packet reception
Browse files Browse the repository at this point in the history
  • Loading branch information
korken89 committed Aug 2, 2024
1 parent 53caf70 commit fd75877
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/iface/interface/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ impl InterfaceInner {
}
}

#[cfg(feature = "medium-ethernet")]
self.neighbor_cache
.reset_expiry_if_existing(IpAddress::Ipv4(ipv4_repr.src_addr), self.now);

match ipv4_repr.next_header {
IpProtocol::Icmp => self.process_icmpv4(sockets, ipv4_repr, ip_payload),

Expand Down
4 changes: 4 additions & 0 deletions src/iface/interface/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ impl InterfaceInner {
#[cfg(not(feature = "socket-raw"))]
let handled_by_raw_socket = false;

#[cfg(any(feature = "medium-ethernet", feature = "medium-ieee802154"))]
self.neighbor_cache
.reset_expiry_if_existing(IpAddress::Ipv6(ipv6_repr.src_addr), self.now);

self.process_nxt_hdr(
sockets,
meta,
Expand Down
10 changes: 10 additions & 0 deletions src/iface/neighbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ impl Cache {
}
}

pub fn reset_expiry_if_existing(&mut self, protocol_addr: IpAddress, timestamp: Instant) {
if let Some(Neighbor {
expires_at,
hardware_addr: _,
}) = self.storage.get_mut(&protocol_addr)
{
*expires_at = timestamp + Self::ENTRY_LIFETIME;
}
}

pub fn fill(
&mut self,
protocol_addr: IpAddress,
Expand Down

0 comments on commit fd75877

Please sign in to comment.