diff --git a/aya/src/maps/array/array.rs b/aya/src/maps/array/array.rs index d6f1988a..6b5e5fa2 100644 --- a/aya/src/maps/array/array.rs +++ b/aya/src/maps/array/array.rs @@ -118,7 +118,7 @@ impl + DerefMut, V: Pod> Array { pub fn set(&mut self, index: u32, value: V, flags: u64) -> Result<(), MapError> { let fd = self.inner.fd_or_err()?; self.check_bounds(index)?; - bpf_map_update_elem(fd, &index, &value, flags).map_err(|(code, io_error)| { + bpf_map_update_elem(fd, Some(&index), &value, flags).map_err(|(code, io_error)| { MapError::SyscallError { call: "bpf_map_update_elem".to_owned(), code, diff --git a/aya/src/maps/array/program_array.rs b/aya/src/maps/array/program_array.rs index e74b0856..ae0a28e0 100644 --- a/aya/src/maps/array/program_array.rs +++ b/aya/src/maps/array/program_array.rs @@ -105,7 +105,7 @@ impl + DerefMut> ProgramArray { self.check_bounds(index)?; let prog_fd = program.as_raw_fd(); - bpf_map_update_elem(fd, &index, &prog_fd, flags).map_err(|(code, io_error)| { + bpf_map_update_elem(fd, Some(&index), &prog_fd, flags).map_err(|(code, io_error)| { MapError::SyscallError { call: "bpf_map_update_elem".to_owned(), code, diff --git a/aya/src/maps/hash_map/mod.rs b/aya/src/maps/hash_map/mod.rs index c6e99405..349f67b3 100644 --- a/aya/src/maps/hash_map/mod.rs +++ b/aya/src/maps/hash_map/mod.rs @@ -29,7 +29,7 @@ pub(crate) fn check_kv_size(map: &Map) -> Result<(), MapError> { pub(crate) fn insert(map: &mut Map, key: K, value: V, flags: u64) -> Result<(), MapError> { let fd = map.fd_or_err()?; - bpf_map_update_elem(fd, &key, &value, flags).map_err(|(code, io_error)| { + bpf_map_update_elem(fd, Some(&key), &value, flags).map_err(|(code, io_error)| { MapError::SyscallError { call: "bpf_map_update_elem".to_owned(), code, diff --git a/aya/src/maps/lpm_trie.rs b/aya/src/maps/lpm_trie.rs index 3266a8bf..473d92e4 100644 --- a/aya/src/maps/lpm_trie.rs +++ b/aya/src/maps/lpm_trie.rs @@ -145,7 +145,7 @@ impl, K: Pod, V: Pod> LpmTrie { /// Inserts a key value pair into the map. pub fn insert(&self, key: &Key, value: V, flags: u64) -> Result<(), MapError> { let fd = self.inner.deref().fd_or_err()?; - bpf_map_update_elem(fd, key, &value, flags).map_err(|(code, io_error)| { + bpf_map_update_elem(fd, Some(key), &value, flags).map_err(|(code, io_error)| { MapError::SyscallError { call: "bpf_map_update_elem".to_owned(), code, diff --git a/aya/src/maps/perf/perf_event_array.rs b/aya/src/maps/perf/perf_event_array.rs index ff4d02ac..eede6009 100644 --- a/aya/src/maps/perf/perf_event_array.rs +++ b/aya/src/maps/perf/perf_event_array.rs @@ -191,7 +191,7 @@ impl> PerfEventArray { // this cannot fail as new() checks that the fd is open let map_fd = self.map.fd_or_err().unwrap(); let buf = PerfBuffer::open(index, self.page_size, page_count.unwrap_or(2))?; - bpf_map_update_elem(map_fd, &index, &buf.as_raw_fd(), 0) + bpf_map_update_elem(map_fd, Some(&index), &buf.as_raw_fd(), 0) .map_err(|(_, io_error)| io_error)?; Ok(PerfEventArrayBuffer { diff --git a/aya/src/maps/sock/sock_map.rs b/aya/src/maps/sock/sock_map.rs index 0a0b9c13..d9624a7e 100644 --- a/aya/src/maps/sock/sock_map.rs +++ b/aya/src/maps/sock/sock_map.rs @@ -90,7 +90,7 @@ impl + DerefMut> SockMap { pub fn set(&mut self, index: u32, socket: &I, flags: u64) -> Result<(), MapError> { let fd = self.inner.fd_or_err()?; self.check_bounds(index)?; - bpf_map_update_elem(fd, &index, &socket.as_raw_fd(), flags).map_err( + bpf_map_update_elem(fd, Some(&index), &socket.as_raw_fd(), flags).map_err( |(code, io_error)| MapError::SyscallError { call: "bpf_map_update_elem".to_owned(), code, diff --git a/aya/src/maps/stack.rs b/aya/src/maps/stack.rs index c8f36083..b22b049c 100644 --- a/aya/src/maps/stack.rs +++ b/aya/src/maps/stack.rs @@ -99,7 +99,7 @@ impl + DerefMut, V: Pod> Stack { /// [`MapError::SyscallError`] if `bpf_map_update_elem` fails. pub fn push(&mut self, value: V, flags: u64) -> Result<(), MapError> { let fd = self.inner.fd_or_err()?; - bpf_map_update_elem(fd, &0, &value, flags).map_err(|(code, io_error)| { + bpf_map_update_elem(fd, None::<&u32>, &value, flags).map_err(|(code, io_error)| { MapError::SyscallError { call: "bpf_map_update_elem".to_owned(), code, diff --git a/aya/src/sys/bpf.rs b/aya/src/sys/bpf.rs index cc7f6af8..d26fb5e2 100644 --- a/aya/src/sys/bpf.rs +++ b/aya/src/sys/bpf.rs @@ -225,12 +225,19 @@ pub(crate) fn bpf_map_lookup_elem_ptr( } } -pub(crate) fn bpf_map_update_elem(fd: RawFd, key: &K, value: &V, flags: u64) -> SysResult { +pub(crate) fn bpf_map_update_elem( + fd: RawFd, + key: Option<&K>, + value: &V, + flags: u64, +) -> SysResult { let mut attr = unsafe { mem::zeroed::() }; let u = unsafe { &mut attr.__bindgen_anon_2 }; u.map_fd = fd as u32; - u.key = key as *const _ as u64; + if let Some(key) = key { + u.key = key as *const _ as u64; + } u.__bindgen_anon_1.value = value as *const _ as u64; u.flags = flags;