diff --git a/aya/src/maps/mod.rs b/aya/src/maps/mod.rs index 9e69e3af..4abcf3af 100644 --- a/aya/src/maps/mod.rs +++ b/aya/src/maps/mod.rs @@ -413,7 +413,7 @@ impl_try_from_map_generic_key_and_value!(HashMap, PerCpuHashMap, LpmTrie); /// A generic handle to a BPF map. /// /// You should never need to use this unless you're implementing a new map type. -#[derive(Debug, Clone)] +#[derive(Debug)] pub struct MapData { pub(crate) obj: obj::Map, pub(crate) fd: Option, @@ -577,6 +577,22 @@ impl Drop for MapData { } } +impl Clone for MapData { + fn clone(&self) -> MapData { + MapData { + obj: self.obj.clone(), + fd: { + if let Some(fd) = self.fd { + unsafe { Some(libc::dup(fd)) }; + } + None + }, + btf_fd: self.btf_fd, + pinned: self.pinned, + } + } +} + /// An iterable map pub trait IterableMap { /// Get a generic map handle