ebpf: add peak() method to Queue and Stack

Signed-off-by: Xiaobo Liu <cppcoffee@gmail.com>
reviewable/pr1319/r1
Xiaobo Liu 1 month ago
parent 9a367c11b0
commit 90059a9e70

@ -2,7 +2,7 @@ use core::{cell::UnsafeCell, marker::PhantomData, mem};
use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_QUEUE},
helpers::{bpf_map_pop_elem, bpf_map_push_elem},
helpers::{bpf_map_peek_elem, bpf_map_pop_elem, bpf_map_push_elem},
maps::PinningType,
};
@ -63,4 +63,12 @@ impl<T> Queue<T> {
(ret == 0).then_some(value.assume_init())
}
}
pub fn peek(&self) -> Option<T> {
unsafe {
let mut value = mem::MaybeUninit::uninit();
let ret = bpf_map_peek_elem(self.def.get() as *mut _, value.as_mut_ptr() as *mut _);
(ret == 0).then_some(value.assume_init())
}
}
}

@ -2,7 +2,7 @@ use core::{marker::PhantomData, mem};
use crate::{
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_STACK},
helpers::{bpf_map_pop_elem, bpf_map_push_elem},
helpers::{bpf_map_peek_elem, bpf_map_pop_elem, bpf_map_push_elem},
maps::PinningType,
};
@ -64,4 +64,15 @@ impl<T> Stack<T> {
(ret == 0).then_some(value.assume_init())
}
}
pub fn peek(&self) -> Option<T> {
unsafe {
let mut value = mem::MaybeUninit::uninit();
let ret = bpf_map_peek_elem(
&self.def as *const _ as *mut _,
value.as_mut_ptr() as *mut _,
);
(ret == 0).then_some(value.assume_init())
}
}
}

@ -438,6 +438,7 @@ pub fn aya_ebpf::maps::program_array::ProgramArray::from(t: T) -> T
pub mod aya_ebpf::maps::queue
#[repr(transparent)] pub struct aya_ebpf::maps::queue::Queue<T>
impl<T> aya_ebpf::maps::queue::Queue<T>
pub fn aya_ebpf::maps::queue::Queue<T>::peek(&self) -> core::option::Option<T>
pub const fn aya_ebpf::maps::queue::Queue<T>::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::queue::Queue<T>
pub fn aya_ebpf::maps::queue::Queue<T>::pop(&self) -> core::option::Option<T>
pub fn aya_ebpf::maps::queue::Queue<T>::push(&self, value: &T, flags: u64) -> core::result::Result<(), i64>
@ -592,6 +593,7 @@ pub fn aya_ebpf::maps::sock_map::SockMap::from(t: T) -> T
pub mod aya_ebpf::maps::stack
#[repr(transparent)] pub struct aya_ebpf::maps::stack::Stack<T>
impl<T> aya_ebpf::maps::stack::Stack<T>
pub fn aya_ebpf::maps::stack::Stack<T>::peek(&self) -> core::option::Option<T>
pub const fn aya_ebpf::maps::stack::Stack<T>::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::stack::Stack<T>
pub fn aya_ebpf::maps::stack::Stack<T>::pop(&mut self) -> core::option::Option<T>
pub fn aya_ebpf::maps::stack::Stack<T>::push(&mut self, value: &T, flags: u64) -> core::result::Result<(), i64>
@ -1166,6 +1168,7 @@ impl<T> core::convert::From<T> for aya_ebpf::maps::program_array::ProgramArray
pub fn aya_ebpf::maps::program_array::ProgramArray::from(t: T) -> T
#[repr(transparent)] pub struct aya_ebpf::maps::Queue<T>
impl<T> aya_ebpf::maps::queue::Queue<T>
pub fn aya_ebpf::maps::queue::Queue<T>::peek(&self) -> core::option::Option<T>
pub const fn aya_ebpf::maps::queue::Queue<T>::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::queue::Queue<T>
pub fn aya_ebpf::maps::queue::Queue<T>::pop(&self) -> core::option::Option<T>
pub fn aya_ebpf::maps::queue::Queue<T>::push(&self, value: &T, flags: u64) -> core::result::Result<(), i64>
@ -1283,6 +1286,7 @@ impl<T> core::convert::From<T> for aya_ebpf::maps::sock_map::SockMap
pub fn aya_ebpf::maps::sock_map::SockMap::from(t: T) -> T
#[repr(transparent)] pub struct aya_ebpf::maps::Stack<T>
impl<T> aya_ebpf::maps::stack::Stack<T>
pub fn aya_ebpf::maps::stack::Stack<T>::peek(&self) -> core::option::Option<T>
pub const fn aya_ebpf::maps::stack::Stack<T>::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::stack::Stack<T>
pub fn aya_ebpf::maps::stack::Stack<T>::pop(&mut self) -> core::option::Option<T>
pub fn aya_ebpf::maps::stack::Stack<T>::push(&mut self, value: &T, flags: u64) -> core::result::Result<(), i64>

Loading…
Cancel
Save