From 34d74fcd3bf25a5ba9068ffd2da2fc4d06807080 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Mon, 28 Feb 2022 14:57:24 +0000 Subject: [PATCH] bpf: sk_buff: Add get_socket_uid method to SkBuffContext This change exposes the BPF helper bpf_socket_get_uid as a public method of SkBuffContext, which allows to get the owner UID of the socket associated to the sk_buff stored in the context. Signed-off-by: Michal Rostecki --- bpf/aya-bpf/src/programs/sk_buff.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/bpf/aya-bpf/src/programs/sk_buff.rs b/bpf/aya-bpf/src/programs/sk_buff.rs index fea109a6..c445fa32 100644 --- a/bpf/aya-bpf/src/programs/sk_buff.rs +++ b/bpf/aya-bpf/src/programs/sk_buff.rs @@ -4,8 +4,8 @@ use core::{ }; use aya_bpf_bindings::helpers::{ - bpf_clone_redirect, bpf_l3_csum_replace, bpf_l4_csum_replace, bpf_skb_adjust_room, - bpf_skb_change_type, bpf_skb_load_bytes, bpf_skb_store_bytes, + bpf_clone_redirect, bpf_get_socket_uid, bpf_l3_csum_replace, bpf_l4_csum_replace, + bpf_skb_adjust_room, bpf_skb_change_type, bpf_skb_load_bytes, bpf_skb_store_bytes, }; use aya_bpf_cty::c_long; @@ -41,6 +41,12 @@ impl SkBuffContext { unsafe { &mut (*self.skb).cb } } + /// Returns the owner UID of the socket associated to the SKB context. + #[inline] + pub fn get_socket_uid(&self) -> u32 { + unsafe { bpf_get_socket_uid(self.skb) } + } + #[inline] pub fn load(&self, offset: usize) -> Result { unsafe {