|
|
@ -46,21 +46,21 @@ impl DevMapHash {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
#[inline(always)]
|
|
|
|
pub unsafe fn get(&self, index: u32) -> Option<&bpf_devmap_val> {
|
|
|
|
pub fn get(&self, key: u32) -> Option<bpf_devmap_val> {
|
|
|
|
let value = bpf_map_lookup_elem(
|
|
|
|
unsafe {
|
|
|
|
self.def.get() as *mut _,
|
|
|
|
let value =
|
|
|
|
&index as *const _ as *const c_void,
|
|
|
|
bpf_map_lookup_elem(self.def.get() as *mut _, &key as *const _ as *const c_void);
|
|
|
|
);
|
|
|
|
NonNull::new(value as *mut bpf_devmap_val).map(|p| *p.as_ref())
|
|
|
|
NonNull::new(value as *mut bpf_devmap_val).map(|p| p.as_ref())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[inline(always)]
|
|
|
|
#[inline(always)]
|
|
|
|
pub fn redirect(&self, index: u32, flags: u64) -> u32 {
|
|
|
|
pub fn redirect(&self, key: u32, flags: u64) -> u32 {
|
|
|
|
unsafe {
|
|
|
|
unsafe {
|
|
|
|
// Return XDP_REDIRECT on success, or the value of the two lower bits of the flags
|
|
|
|
// Return XDP_REDIRECT on success, or the value of the two lower bits of the flags
|
|
|
|
// argument on error. Thus I have no idea why it returns a long (i64) instead of
|
|
|
|
// argument on error. Thus I have no idea why it returns a long (i64) instead of
|
|
|
|
// something saner, hence the unsigned_abs.
|
|
|
|
// something saner, hence the unsigned_abs.
|
|
|
|
bpf_redirect_map(self.def.get() as *mut _, index.into(), flags).unsigned_abs() as u32
|
|
|
|
bpf_redirect_map(self.def.get() as *mut _, key.into(), flags).unsigned_abs() as u32
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|