From 49404367d818bf0bc2e2a7ca62c4f2bec186b0c0 Mon Sep 17 00:00:00 2001 From: tiann Date: Thu, 10 Nov 2022 15:21:33 +0800 Subject: [PATCH] bpf: Add bindings for uid and gid --- bpf/aya-bpf/src/lib.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bpf/aya-bpf/src/lib.rs b/bpf/aya-bpf/src/lib.rs index d6855584..57e0e372 100644 --- a/bpf/aya-bpf/src/lib.rs +++ b/bpf/aya-bpf/src/lib.rs @@ -25,7 +25,7 @@ pub use aya_bpf_cty as cty; use core::ffi::c_void; use cty::{c_int, c_long}; -use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid}; +use helpers::{bpf_get_current_comm, bpf_get_current_pid_tgid, bpf_get_current_uid_gid}; pub use aya_bpf_macros as macros; @@ -46,6 +46,14 @@ pub trait BpfContext { fn tgid(&self) -> u32 { (bpf_get_current_pid_tgid() >> 32) as u32 } + + fn uid(&self) -> u32 { + bpf_get_current_uid_gid() as u32 + } + + fn gid(&self) -> u32 { + (bpf_get_current_uid_gid() >> 32) as u32 + } } #[no_mangle]