xref: /linux/tools/testing/selftests/bpf/progs/test_skb_helpers.c (revision b83deaa741558babf4b8d51d34f6637ccfff1b26)
1 // SPDX-License-Identifier: GPL-2.0-only
2 #include "vmlinux.h"
3 #include <bpf/bpf_helpers.h>
4 #include <bpf/bpf_endian.h>
5 
6 #define TEST_COMM_LEN 16
7 
8 struct {
9 	__uint(type, BPF_MAP_TYPE_CGROUP_ARRAY);
10 	__uint(max_entries, 1);
11 	__type(key, u32);
12 	__type(value, u32);
13 } cgroup_map SEC(".maps");
14 
15 char _license[] SEC("license") = "GPL";
16 
17 SEC("tc")
18 int test_skb_helpers(struct __sk_buff *skb)
19 {
20 	struct task_struct *task;
21 	char comm[TEST_COMM_LEN];
22 	__u32 tpid;
23 
24 	task = (struct task_struct *)bpf_get_current_task();
25 	bpf_probe_read_kernel(&tpid , sizeof(tpid), &task->tgid);
26 	bpf_probe_read_kernel_str(&comm, sizeof(comm), &task->comm);
27 	return 0;
28 }
29