-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathbpf_sys.c
More file actions
42 lines (33 loc) · 989 Bytes
/
bpf_sys.c
File metadata and controls
42 lines (33 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <linux/bpf.h>
#include <stdbool.h>
#include <stdint.h>
#include <bpf_helpers.h>
DEFINE_BPF_MAP(sys_enter_map, HASH, int, uint32_t, 1024);
struct syscalls_enter_args {
unsigned short common_type;
unsigned char common_flags;
unsigned char common_preempt_count;
int common_pid;
long id;
unsigned long args[6];
};
struct task_struct {
int pid;
int tgid;
char comm[16];
struct task_struct *group_leader;
};
// SEC("raw_syscalls/sys_enter")
DEFINE_BPF_PROG("tracepoint/raw_syscalls/sys_enter", AID_ROOT, AID_NET_ADMIN, sys_enter)
(struct syscalls_enter_args *args)
{
//获取进程信息
// struct task_struct *task = (void *)bpf_get_current_task();
// int key = bpf_get_smp_processor_id();
int key = bpf_get_current_pid_tgid();//这里是强制取低32位,也就是pid
uint32_t syscall_id=args->id;
bpf_sys_enter_map_update_elem(&key, &syscall_id, BPF_ANY);
return 0;
}
// char _license[] SEC("license") = "GPL";
LICENSE("Apache 2.0");