瀏覽代碼

bpf: Add bindings for uid and gid

tiann 2 年之前
父節點
當前提交
49404367d8
共有 1 個文件被更改,包括 9 次插入1 次删除
  1. 9 1
      bpf/aya-bpf/src/lib.rs

+ 9 - 1
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]