Skip to content

Commit 1977469

Browse files
committed
Reset expiry of entries in the neighbor cache on packet reception
1 parent 53caf70 commit 1977469

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

src/iface/interface/ethernet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ impl InterfaceInner {
2525
EthernetProtocol::Ipv4 => {
2626
let ipv4_packet = check!(Ipv4Packet::new_checked(eth_frame.payload()));
2727

28-
self.process_ipv4(sockets, meta, &ipv4_packet, fragments)
28+
self.process_ipv4(sockets, self.now, meta, &ipv4_packet, fragments)
2929
.map(EthernetPacket::Ip)
3030
}
3131
#[cfg(feature = "proto-ipv6")]
3232
EthernetProtocol::Ipv6 => {
3333
let ipv6_packet = check!(Ipv6Packet::new_checked(eth_frame.payload()));
34-
self.process_ipv6(sockets, meta, &ipv6_packet)
34+
self.process_ipv6(sockets, self.now, meta, &ipv6_packet)
3535
.map(EthernetPacket::Ip)
3636
}
3737
// Drop all other traffic.

src/iface/interface/ipv4.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl InterfaceInner {
9090
pub(super) fn process_ipv4<'a>(
9191
&mut self,
9292
sockets: &mut SocketSet,
93+
timestamp: Instant,
9394
meta: PacketMeta,
9495
ipv4_packet: &Ipv4Packet<&'a [u8]>,
9596
frag: &'a mut FragmentsBuffer,
@@ -196,6 +197,9 @@ impl InterfaceInner {
196197
}
197198
}
198199

200+
self.neighbor_cache
201+
.reset_expiry_if_existing(IpAddress::Ipv4(ipv4_repr.src_addr), timestamp);
202+
199203
match ipv4_repr.next_header {
200204
IpProtocol::Icmp => self.process_icmpv4(sockets, ipv4_repr, ip_payload),
201205

src/iface/interface/ipv6.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ impl InterfaceInner {
186186
pub(super) fn process_ipv6<'frame>(
187187
&mut self,
188188
sockets: &mut SocketSet,
189+
timestamp: Instant,
189190
meta: PacketMeta,
190191
ipv6_packet: &Ipv6Packet<&'frame [u8]>,
191192
) -> Option<Packet<'frame>> {
@@ -228,6 +229,9 @@ impl InterfaceInner {
228229
#[cfg(not(feature = "socket-raw"))]
229230
let handled_by_raw_socket = false;
230231

232+
self.neighbor_cache
233+
.reset_expiry_if_existing(IpAddress::Ipv6(ipv6_repr.src_addr), timestamp);
234+
231235
self.process_nxt_hdr(
232236
sockets,
233237
meta,

src/iface/neighbor.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ impl Cache {
6363
}
6464
}
6565

66+
pub fn reset_expiry_if_existing(&mut self, protocol_addr: IpAddress, timestamp: Instant) {
67+
if let Some(Neighbor {
68+
expires_at,
69+
hardware_addr: _,
70+
}) = self.storage.get_mut(&protocol_addr)
71+
{
72+
net_trace!("reseting expiry for {}", protocol_addr);
73+
*expires_at = timestamp + Self::ENTRY_LIFETIME;
74+
}
75+
}
76+
6677
pub fn fill(
6778
&mut self,
6879
protocol_addr: IpAddress,

0 commit comments

Comments
 (0)