1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (c) 2019 Carlos Neira cneirabustos@gmail.com */
3 
4 #include <linux/bpf.h>
5 #include <stdint.h>
6 #include <bpf/bpf_helpers.h>
7 
8 __u64 user_pid = 0;
9 __u64 user_tgid = 0;
10 __u64 dev = 0;
11 __u64 ino = 0;
12 
get_pid_tgid(void)13 static void get_pid_tgid(void)
14 {
15 	struct bpf_pidns_info nsdata;
16 
17 	if (bpf_get_ns_current_pid_tgid(dev, ino, &nsdata, sizeof(struct bpf_pidns_info)))
18 		return;
19 
20 	user_pid = nsdata.pid;
21 	user_tgid = nsdata.tgid;
22 }
23 
24 SEC("?tracepoint/syscalls/sys_enter_nanosleep")
tp_handler(const void * ctx)25 int tp_handler(const void *ctx)
26 {
27 	get_pid_tgid();
28 	return 0;
29 }
30 
31 SEC("?cgroup/bind4")
cgroup_bind4(struct bpf_sock_addr * ctx)32 int cgroup_bind4(struct bpf_sock_addr *ctx)
33 {
34 	get_pid_tgid();
35 	return 1;
36 }
37 
38 char _license[] SEC("license") = "GPL";
39