From 2fb19f3ee2c95a34382b33762e9fb8841ec8c048 Mon Sep 17 00:00:00 2001 From: jinlong Date: Tue, 30 Jul 2024 20:22:10 +0800 Subject: [PATCH] feat: Add `set` for `Array` Signed-off-by: jinlong --- ebpf/aya-ebpf/src/maps/array.rs | 10 +++++++++- xtask/public-api/aya-ebpf.txt | 2 ++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/ebpf/aya-ebpf/src/maps/array.rs b/ebpf/aya-ebpf/src/maps/array.rs index 87c02e49..d9911547 100644 --- a/ebpf/aya-ebpf/src/maps/array.rs +++ b/ebpf/aya-ebpf/src/maps/array.rs @@ -1,8 +1,10 @@ use core::{cell::UnsafeCell, marker::PhantomData, mem, ptr::NonNull}; +use aya_ebpf_cty::c_long; + use crate::{ bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_ARRAY}, - lookup, + insert, lookup, maps::PinningType, }; @@ -65,4 +67,10 @@ impl Array { unsafe fn lookup(&self, index: u32) -> Option> { lookup(self.def.get(), &index) } + + /// Sets the value of the element at the given index. + #[inline(always)] + pub fn set(&self, index: u32, value: &T, flags: u64) -> Result<(), c_long> { + insert(self.def.get(), &index, value, flags) + } } diff --git a/xtask/public-api/aya-ebpf.txt b/xtask/public-api/aya-ebpf.txt index 9021bce3..83752409 100644 --- a/xtask/public-api/aya-ebpf.txt +++ b/xtask/public-api/aya-ebpf.txt @@ -85,6 +85,7 @@ pub fn aya_ebpf::maps::array::Array::get(&self, index: u32) -> core::option:: pub fn aya_ebpf::maps::array::Array::get_ptr(&self, index: u32) -> core::option::Option<*const T> pub fn aya_ebpf::maps::array::Array::get_ptr_mut(&self, index: u32) -> core::option::Option<*mut T> pub const fn aya_ebpf::maps::array::Array::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array +pub fn aya_ebpf::maps::array::Array::set(&self, index: u32, value: &T, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> pub const fn aya_ebpf::maps::array::Array::with_max_entries(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array impl core::marker::Sync for aya_ebpf::maps::array::Array impl !core::marker::Freeze for aya_ebpf::maps::array::Array @@ -763,6 +764,7 @@ pub fn aya_ebpf::maps::array::Array::get(&self, index: u32) -> core::option:: pub fn aya_ebpf::maps::array::Array::get_ptr(&self, index: u32) -> core::option::Option<*const T> pub fn aya_ebpf::maps::array::Array::get_ptr_mut(&self, index: u32) -> core::option::Option<*mut T> pub const fn aya_ebpf::maps::array::Array::pinned(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array +pub fn aya_ebpf::maps::array::Array::set(&self, index: u32, value: &T, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> pub const fn aya_ebpf::maps::array::Array::with_max_entries(max_entries: u32, flags: u32) -> aya_ebpf::maps::array::Array impl core::marker::Sync for aya_ebpf::maps::array::Array impl !core::marker::Freeze for aya_ebpf::maps::array::Array