summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/bpf/progs/test_skb_helpers.c
blob: bb3fbf1a29e34fed32d306b469f88b0e5890f7bd (plain)
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
// SPDX-License-Identifier: GPL-2.0-only
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
#include <bpf/bpf_endian.h>

#define TEST_COMM_LEN 16

struct {
	__uint(type, BPF_MAP_TYPE_CGROUP_ARRAY);
	__uint(max_entries, 1);
	__type(key, u32);
	__type(value, u32);
} cgroup_map SEC(".maps");

char _license[] SEC("license") = "GPL";

SEC("classifier/test_skb_helpers")
int test_skb_helpers(struct __sk_buff *skb)
{
	struct task_struct *task;
	char comm[TEST_COMM_LEN];
	__u32 tpid;

	task = (struct task_struct *)bpf_get_current_task();
	bpf_probe_read_kernel(&tpid , sizeof(tpid), &task->tgid);
	bpf_probe_read_kernel_str(&comm, sizeof(comm), &task->comm);
	return 0;
}