From ece00ac35f5f7314586bddc42c62660e6cc2a5d4 Mon Sep 17 00:00:00 2001 From: Thibaut Vandervelden Date: Fri, 8 Dec 2023 08:58:41 +0100 Subject: [PATCH] neigh: add fill_with_expiration method This method is useful when we want to fill the cache with an entry that has a specific expiration time. --- src/iface/neighbor.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/iface/neighbor.rs b/src/iface/neighbor.rs index 959cd7133..0c451fa0e 100644 --- a/src/iface/neighbor.rs +++ b/src/iface/neighbor.rs @@ -72,8 +72,21 @@ impl Cache { debug_assert!(protocol_addr.is_unicast()); debug_assert!(hardware_addr.is_unicast()); + let expires_at = timestamp + Self::ENTRY_LIFETIME; + self.fill_with_expiration(protocol_addr, hardware_addr, expires_at); + } + + pub fn fill_with_expiration( + &mut self, + protocol_addr: IpAddress, + hardware_addr: HardwareAddress, + expires_at: Instant, + ) { + debug_assert!(protocol_addr.is_unicast()); + debug_assert!(hardware_addr.is_unicast()); + let neighbor = Neighbor { - expires_at: timestamp + Self::ENTRY_LIFETIME, + expires_at, hardware_addr, }; match self.storage.insert(protocol_addr, neighbor) {