diff --git a/bpf/aya-bpf/src/helpers.rs b/bpf/aya-bpf/src/helpers.rs index 7fd6f8da..6b4ae715 100644 --- a/bpf/aya-bpf/src/helpers.rs +++ b/bpf/aya-bpf/src/helpers.rs @@ -48,11 +48,11 @@ pub unsafe fn bpf_probe_read(src: *const T) -> Result { mem::size_of::() as u32, src as *const c_void, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(v.assume_init()) + } else { + Err(ret) } - - Ok(v.assume_init()) } /// Read bytes from the pointer `src` into the provided destination buffer. @@ -84,11 +84,11 @@ pub unsafe fn bpf_probe_read_buf(src: *const u8, dst: &mut [u8]) -> Result<(), c dst.len() as u32, src as *const c_void, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(()) + } else { + Err(ret) } - - Ok(()) } /// Read bytes stored at the _user space_ pointer `src` and store them as a `T`. @@ -121,11 +121,11 @@ pub unsafe fn bpf_probe_read_user(src: *const T) -> Result { mem::size_of::() as u32, src as *const c_void, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(v.assume_init()) + } else { + Err(ret) } - - Ok(v.assume_init()) } /// Read bytes from the _user space_ pointer `src` into the provided destination @@ -155,11 +155,11 @@ pub unsafe fn bpf_probe_read_user_buf(src: *const u8, dst: &mut [u8]) -> Result< dst.len() as u32, src as *const c_void, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(()) + } else { + Err(ret) } - - Ok(()) } /// Read bytes stored at the _kernel space_ pointer `src` and store them as a `T`. @@ -192,11 +192,11 @@ pub unsafe fn bpf_probe_read_kernel(src: *const T) -> Result { mem::size_of::() as u32, src as *const c_void, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(v.assume_init()) + } else { + Err(ret) } - - Ok(v.assume_init()) } /// Read bytes from the _kernel space_ pointer `src` into the provided destination @@ -226,11 +226,11 @@ pub unsafe fn bpf_probe_read_kernel_buf(src: *const u8, dst: &mut [u8]) -> Resul dst.len() as u32, src as *const c_void, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(()) + } else { + Err(ret) } - - Ok(()) } /// Read a null-terminated string stored at `src` into `dest`. @@ -397,11 +397,11 @@ pub unsafe fn bpf_probe_write_user(dst: *mut T, src: *const T) -> Result<(), src as *const c_void, mem::size_of::() as u32, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(()) + } else { + Err(ret) } - - Ok(()) } /// Read the `comm` field associated with the current task struct diff --git a/bpf/aya-bpf/src/maps/hash_map.rs b/bpf/aya-bpf/src/maps/hash_map.rs index 35383e05..175cb147 100644 --- a/bpf/aya-bpf/src/maps/hash_map.rs +++ b/bpf/aya-bpf/src/maps/hash_map.rs @@ -348,7 +348,7 @@ fn insert(def: *mut bpf_map_def, key: &K, value: &V, flags: u64) -> Result flags, ) }; - (ret >= 0).then(|| ()).ok_or(ret) + (ret == 0).then(|| ()).ok_or(ret) } #[inline] diff --git a/bpf/aya-bpf/src/maps/lpm_trie.rs b/bpf/aya-bpf/src/maps/lpm_trie.rs index bbe6662e..fc40e506 100644 --- a/bpf/aya-bpf/src/maps/lpm_trie.rs +++ b/bpf/aya-bpf/src/maps/lpm_trie.rs @@ -78,7 +78,7 @@ impl LpmTrie { flags, ) }; - (ret >= 0).then(|| ()).ok_or(ret) + (ret == 0).then(|| ()).ok_or(ret) } #[inline] diff --git a/bpf/aya-bpf/src/maps/queue.rs b/bpf/aya-bpf/src/maps/queue.rs index fd0e73c1..bb6b29c0 100644 --- a/bpf/aya-bpf/src/maps/queue.rs +++ b/bpf/aya-bpf/src/maps/queue.rs @@ -53,14 +53,14 @@ impl Queue { flags, ) }; - (ret >= 0).then(|| ()).ok_or(ret) + (ret == 0).then(|| ()).ok_or(ret) } pub fn pop(&self) -> Option { unsafe { let mut value = mem::MaybeUninit::uninit(); let ret = bpf_map_pop_elem(self.def.get() as *mut _, value.as_mut_ptr() as *mut _); - (ret >= 0).then(|| value.assume_init()) + (ret == 0).then(|| value.assume_init()) } } } diff --git a/bpf/aya-bpf/src/maps/sock_hash.rs b/bpf/aya-bpf/src/maps/sock_hash.rs index 052fb33b..0bbb5f39 100644 --- a/bpf/aya-bpf/src/maps/sock_hash.rs +++ b/bpf/aya-bpf/src/maps/sock_hash.rs @@ -61,7 +61,7 @@ impl SockHash { flags, ) }; - (ret >= 0).then(|| ()).ok_or(ret) + (ret == 0).then(|| ()).ok_or(ret) } pub fn redirect_msg(&self, ctx: &SkMsgContext, key: &mut K, flags: u64) -> i64 { @@ -102,7 +102,7 @@ impl SockHash { } let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags); bpf_sk_release(sk); - (ret >= 0).then(|| ()).ok_or(1) + (ret == 0).then(|| ()).ok_or(1) } } } diff --git a/bpf/aya-bpf/src/maps/sock_map.rs b/bpf/aya-bpf/src/maps/sock_map.rs index 4ecafdda..9f9a1636 100644 --- a/bpf/aya-bpf/src/maps/sock_map.rs +++ b/bpf/aya-bpf/src/maps/sock_map.rs @@ -61,10 +61,10 @@ impl SockMap { &mut index as *mut _ as *mut c_void, flags, ); - if ret < 0 { - Err(ret) - } else { + if ret == 0 { Ok(()) + } else { + Err(ret) } } @@ -102,7 +102,7 @@ impl SockMap { } let ret = bpf_sk_assign(ctx.as_ptr() as *mut _, sk, flags); bpf_sk_release(sk); - (ret >= 0).then(|| ()).ok_or(1) + (ret == 0).then(|| ()).ok_or(1) } } } diff --git a/bpf/aya-bpf/src/maps/stack_trace.rs b/bpf/aya-bpf/src/maps/stack_trace.rs index 647e3dd4..bcaa1589 100644 --- a/bpf/aya-bpf/src/maps/stack_trace.rs +++ b/bpf/aya-bpf/src/maps/stack_trace.rs @@ -47,10 +47,10 @@ impl StackTrace { pub unsafe fn get_stackid(&self, ctx: &C, flags: u64) -> Result { let ret = bpf_get_stackid(ctx.as_ptr(), self.def.get() as *mut _, flags); - if ret < 0 { - Err(ret) + if ret == 0 { + Ok(()) } else { - Ok(ret) + Err(ret) } } } diff --git a/bpf/aya-bpf/src/programs/sk_buff.rs b/bpf/aya-bpf/src/programs/sk_buff.rs index 86b9c541..a442e163 100644 --- a/bpf/aya-bpf/src/programs/sk_buff.rs +++ b/bpf/aya-bpf/src/programs/sk_buff.rs @@ -57,11 +57,11 @@ impl SkBuffContext { &mut data as *mut _ as *mut _, mem::size_of::() as u32, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(data.assume_init()) + } else { + Err(ret) } - - Ok(data.assume_init()) } } @@ -75,12 +75,12 @@ impl SkBuffContext { mem::size_of::() as u32, flags, ); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(()) + } else { + Err(ret) } } - - Ok(()) } #[inline] @@ -93,12 +93,12 @@ impl SkBuffContext { ) -> Result<(), c_long> { unsafe { let ret = bpf_l3_csum_replace(self.skb as *mut _, offset as u32, from, to, size); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(()) + } else { + Err(ret) } } - - Ok(()) } #[inline] @@ -111,41 +111,41 @@ impl SkBuffContext { ) -> Result<(), c_long> { unsafe { let ret = bpf_l4_csum_replace(self.skb as *mut _, offset as u32, from, to, flags); - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(()) + } else { + Err(ret) } } - - Ok(()) } #[inline] pub fn adjust_room(&self, len_diff: i32, mode: u32, flags: u64) -> Result<(), c_long> { let ret = unsafe { bpf_skb_adjust_room(self.as_ptr() as *mut _, len_diff, mode, flags) }; - if ret < 0 { - return Err(ret); + if ret == 0 { + Ok(()) + } else { + Err(ret) } - - Ok(()) } #[inline] pub fn clone_redirect(&self, if_index: u32, flags: u64) -> Result<(), c_long> { let ret = unsafe { bpf_clone_redirect(self.as_ptr() as *mut _, if_index, flags) }; - if ret < 0 { - Err(ret) - } else { + if ret == 0 { Ok(()) + } else { + Err(ret) } } #[inline] pub fn change_type(&self, ty: u32) -> Result<(), c_long> { let ret = unsafe { bpf_skb_change_type(self.as_ptr() as *mut _, ty) }; - if ret < 0 { - Err(ret) - } else { + if ret == 0 { Ok(()) + } else { + Err(ret) } } } diff --git a/bpf/aya-bpf/src/programs/sock_ops.rs b/bpf/aya-bpf/src/programs/sock_ops.rs index 902cab46..4baa469b 100644 --- a/bpf/aya-bpf/src/programs/sock_ops.rs +++ b/bpf/aya-bpf/src/programs/sock_ops.rs @@ -27,10 +27,10 @@ impl SockOpsContext { pub fn set_cb_flags(&self, flags: i32) -> Result<(), i64> { let ret = unsafe { bpf_sock_ops_cb_flags_set(self.ops, flags) }; - if ret < 0 { - Err(ret) - } else { + if ret == 0 { Ok(()) + } else { + Err(ret) } }