From d9eedcd80419304f8e72a243fe84e2b303ceac80 Mon Sep 17 00:00:00 2001 From: Herbert Wolverson Date: Fri, 17 May 2024 14:30:30 -0500 Subject: [PATCH] Add cache invalidation to the hot cache. Whenever an IP mapping changes, the cache is invalidated - meaning it will re-cache the correct values. --- src/rust/lqos_sys/src/ip_mapping/mod.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/rust/lqos_sys/src/ip_mapping/mod.rs b/src/rust/lqos_sys/src/ip_mapping/mod.rs index d5f038fc..6be7b373 100644 --- a/src/rust/lqos_sys/src/ip_mapping/mod.rs +++ b/src/rust/lqos_sys/src/ip_mapping/mod.rs @@ -36,6 +36,7 @@ pub fn add_ip_to_tc( let mut value = IpHashData { cpu: ip_to_add.cpu, tc_handle: ip_to_add.handle() }; bpf_map.insert_or_update(&mut key, &mut value)?; + clear_hot_cache()?; Ok(()) } @@ -56,6 +57,7 @@ pub fn del_ip_from_tc(address: &str, upload: bool) -> Result<()> { let ip = XdpIpAddress::from_ip(ip); let mut key = IpHashKey { prefixlen: ip_to_add.prefix, address: ip.0 }; bpf_map.delete(&mut key)?; + clear_hot_cache()?; Ok(()) } @@ -71,6 +73,8 @@ pub fn clear_ips_from_tc() -> Result<()> { )?; bpf_map.clear()?; + clear_hot_cache()?; + Ok(()) } @@ -89,3 +93,12 @@ pub fn list_mapped_ips() -> Result> { Ok(raw) } + +/// Clears the "hot cache", which should be done whenever you change the IP +/// mappings - because otherwise cached data will keep going to the previous +/// destinations. +fn clear_hot_cache() -> Result<()> { + let mut bpf_map = BpfMap::::from_path("/sys/fs/bpf/ip_to_cpu_and_tc_hotcache")?; + bpf_map.clear()?; + Ok(()) +} \ No newline at end of file