summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/progs/tailcall_cgrp_storage.c
blob: 4dd3a0033d75607e15ba91fdc6d8dd0b28cf0e7d (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// SPDX-License-Identifier: GPL-2.0

#include <vmlinux.h>
#include <bpf/bpf_helpers.h>

struct {
	__uint(type, BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE);
	__type(key, struct bpf_cgroup_storage_key);
	__type(value, __u64);
} storage_map SEC(".maps");

struct {
	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
	__uint(max_entries, 1);
	__uint(key_size, sizeof(__u32));
	__uint(value_size, sizeof(__u32));
} prog_array SEC(".maps");

SEC("cgroup_skb/egress")
int caller_prog(struct __sk_buff *skb)
{
	__u64 *storage;

	storage = bpf_get_local_storage(&storage_map, 0);
	if (storage)
		*storage = 1;

	bpf_tail_call(skb, &prog_array, 0);
	return 1;
}

SEC("cgroup_skb/egress")
int callee_prog(struct __sk_buff *skb)
{
	__u64 *storage;

	storage = bpf_get_local_storage(&storage_map, 0);
	if (storage)
		*storage = 1;

	return 1;
}

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