From 7c6ae769756a9605f7823e36243b69a3a88a1370 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Wed, 10 Mar 2021 07:38:34 +0000 Subject: [PATCH] aya: HashMap: add support for LRU maps --- aya/src/maps/hash_map.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/aya/src/maps/hash_map.rs b/aya/src/maps/hash_map.rs index 29c7e7ac..b90eab54 100644 --- a/aya/src/maps/hash_map.rs +++ b/aya/src/maps/hash_map.rs @@ -8,7 +8,7 @@ use std::{ }; use crate::{ - generated::bpf_map_type::BPF_MAP_TYPE_HASH, + generated::bpf_map_type::{BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_LRU_HASH}, maps::{IterableMap, Map, MapError, MapIter, MapKeys, MapRef, MapRefMut}, sys::{bpf_map_delete_elem, bpf_map_lookup_elem, bpf_map_update_elem}, Pod, @@ -44,7 +44,7 @@ impl, K: Pod, V: Pod> HashMap { let map_type = map.obj.def.map_type; // validate the map definition - if map_type != BPF_MAP_TYPE_HASH as u32 { + if map_type != BPF_MAP_TYPE_HASH as u32 && map_type != BPF_MAP_TYPE_LRU_HASH as u32 { return Err(MapError::InvalidMapType { map_type: map_type as u32, })?; @@ -286,6 +286,27 @@ mod tests { assert!(HashMap::<_, u32, u32>::try_from(&map).is_ok()) } + #[test] + fn test_try_from_ok_lru() { + let map = Map { + obj: obj::Map { + name: "TEST".to_string(), + def: bpf_map_def { + map_type: BPF_MAP_TYPE_LRU_HASH as u32, + key_size: 4, + value_size: 4, + max_entries: 1024, + map_flags: 0, + }, + section_index: 0, + data: Vec::new(), + }, + fd: Some(42), + }; + + assert!(HashMap::<_, u32, u32>::try_from(&map).is_ok()) + } + #[test] fn test_insert_syscall_error() { override_syscall(|_| sys_error(EFAULT));