From b305797cb40fd024647c0087251f4ced7bdbedcb Mon Sep 17 00:00:00 2001 From: whitequark Date: Tue, 7 Mar 2017 06:20:51 +0000 Subject: [PATCH] Trace eviction and fill in SliceArpCache. --- src/iface/arp_cache.rs | 12 ++++++++++-- src/lib.rs | 12 +++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/iface/arp_cache.rs b/src/iface/arp_cache.rs index 39174af..a54735f 100644 --- a/src/iface/arp_cache.rs +++ b/src/iface/arp_cache.rs @@ -97,6 +97,15 @@ impl<'a> Cache for SliceCache<'a> { fn fill(&mut self, protocol_addr: &IpAddress, hardware_addr: &EthernetAddress) { if let None = self.find(protocol_addr) { let lru_index = self.lru(); + + if net_trace_enabled!() { + let (old_protocol_addr, old_hardware_addr, _counter) = self.storage[lru_index]; + if !old_protocol_addr.is_unspecified() { + net_trace!("evicting {} => {}", old_protocol_addr, old_hardware_addr); + } + net_trace!("filling {} => {}", protocol_addr, hardware_addr); + } + self.counter += 1; self.storage[lru_index] = (*protocol_addr, *hardware_addr, self.counter); @@ -106,8 +115,7 @@ impl<'a> Cache for SliceCache<'a> { fn lookup(&mut self, protocol_addr: &IpAddress) -> Option { if let Some(index) = self.find(protocol_addr) { - let (_protocol_addr, hardware_addr, ref mut counter) = - self.storage[index]; + let (_protocol_addr, hardware_addr, ref mut counter) = self.storage[index]; self.counter += 1; *counter = self.counter; Some(hardware_addr) diff --git a/src/lib.rs b/src/lib.rs index 37dcc7c..51d4938 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,7 @@ extern crate libc; #[cfg(feature = "alloc")] extern crate alloc; #[cfg(any(test, feature = "log"))] -#[macro_use(trace, log)] +#[macro_use(trace, log, log_enabled)] extern crate log; macro_rules! net_trace { @@ -89,6 +89,16 @@ macro_rules! net_trace { } } +macro_rules! net_trace_enabled { + () => ({ + #[cfg(feature = "log")] + fn enabled() -> bool { log_enabled!($crate::log::LogLevel::Trace) } + #[cfg(not(feature = "log"))] + fn enabled() -> bool { false } + enabled() + }) +} + use core::fmt; pub mod phy;