|
|
@ -196,48 +196,27 @@ impl<T: Borrow<MapData>, K: Pod, V: Pod> IterableMap<Key<K>, V> for LpmTrie<T, K
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
mod tests {
|
|
|
|
use std::{ffi::c_long, io, mem, net::Ipv4Addr};
|
|
|
|
use std::{ffi::c_long, io, net::Ipv4Addr};
|
|
|
|
|
|
|
|
|
|
|
|
use assert_matches::assert_matches;
|
|
|
|
use assert_matches::assert_matches;
|
|
|
|
use libc::{EFAULT, ENOENT};
|
|
|
|
use libc::{EFAULT, ENOENT};
|
|
|
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
use super::*;
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
bpf_map_def,
|
|
|
|
|
|
|
|
generated::{
|
|
|
|
generated::{
|
|
|
|
bpf_cmd,
|
|
|
|
bpf_cmd,
|
|
|
|
bpf_map_type::{BPF_MAP_TYPE_LPM_TRIE, BPF_MAP_TYPE_PERF_EVENT_ARRAY},
|
|
|
|
bpf_map_type::{BPF_MAP_TYPE_LPM_TRIE, BPF_MAP_TYPE_PERF_EVENT_ARRAY},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
maps::Map,
|
|
|
|
maps::{
|
|
|
|
obj::{self, maps::LegacyMap, EbpfSectionKind},
|
|
|
|
test_utils::{self, new_map},
|
|
|
|
|
|
|
|
Map,
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
obj,
|
|
|
|
sys::{override_syscall, SysResult, Syscall},
|
|
|
|
sys::{override_syscall, SysResult, Syscall},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
fn new_obj_map() -> obj::Map {
|
|
|
|
fn new_obj_map() -> obj::Map {
|
|
|
|
obj::Map::Legacy(LegacyMap {
|
|
|
|
test_utils::new_obj_map::<Key<u32>>(BPF_MAP_TYPE_LPM_TRIE)
|
|
|
|
def: bpf_map_def {
|
|
|
|
|
|
|
|
map_type: BPF_MAP_TYPE_LPM_TRIE as u32,
|
|
|
|
|
|
|
|
key_size: mem::size_of::<Key<u32>>() as u32,
|
|
|
|
|
|
|
|
value_size: 4,
|
|
|
|
|
|
|
|
max_entries: 1024,
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
section_index: 0,
|
|
|
|
|
|
|
|
section_kind: EbpfSectionKind::Maps,
|
|
|
|
|
|
|
|
symbol_index: None,
|
|
|
|
|
|
|
|
data: Vec::new(),
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn new_map(obj: obj::Map) -> MapData {
|
|
|
|
|
|
|
|
override_syscall(|call| match call {
|
|
|
|
|
|
|
|
Syscall::Ebpf {
|
|
|
|
|
|
|
|
cmd: bpf_cmd::BPF_MAP_CREATE,
|
|
|
|
|
|
|
|
..
|
|
|
|
|
|
|
|
} => Ok(1337),
|
|
|
|
|
|
|
|
call => panic!("unexpected syscall {:?}", call),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
MapData::create(obj, "foo", None).unwrap()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn sys_error(value: i32) -> SysResult<c_long> {
|
|
|
|
fn sys_error(value: i32) -> SysResult<c_long> {
|
|
|
@ -270,20 +249,9 @@ mod tests {
|
|
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[test]
|
|
|
|
fn test_try_from_wrong_map() {
|
|
|
|
fn test_try_from_wrong_map() {
|
|
|
|
let map = new_map(obj::Map::Legacy(LegacyMap {
|
|
|
|
let map = new_map(test_utils::new_obj_map::<u32>(
|
|
|
|
def: bpf_map_def {
|
|
|
|
BPF_MAP_TYPE_PERF_EVENT_ARRAY,
|
|
|
|
map_type: BPF_MAP_TYPE_PERF_EVENT_ARRAY as u32,
|
|
|
|
));
|
|
|
|
key_size: 4,
|
|
|
|
|
|
|
|
value_size: 4,
|
|
|
|
|
|
|
|
max_entries: 1024,
|
|
|
|
|
|
|
|
..Default::default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
section_index: 0,
|
|
|
|
|
|
|
|
section_kind: EbpfSectionKind::Maps,
|
|
|
|
|
|
|
|
symbol_index: None,
|
|
|
|
|
|
|
|
data: Vec::new(),
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let map = Map::PerfEventArray(map);
|
|
|
|
let map = Map::PerfEventArray(map);
|
|
|
|
|
|
|
|
|
|
|
|
assert_matches!(
|
|
|
|
assert_matches!(
|
|
|
|