From 488e5c55c3fb4f8d7454a8da55e28930c8ddcad8 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 +++++++++- 1 file changed, 9 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) + } }