xref: /linux/tools/testing/selftests/bpf/progs/tailcall_cgrp_storage_owner.c (revision b2128290c29902315e632ea59e0504d6bc9e9b42)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 #include <vmlinux.h>
4 #include <bpf/bpf_helpers.h>
5 
6 struct {
7 	__uint(type, BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE);
8 	__type(key, struct bpf_cgroup_storage_key);
9 	__type(value, __u64);
10 } storage_map SEC(".maps");
11 
12 struct {
13 	__uint(type, BPF_MAP_TYPE_PROG_ARRAY);
14 	__uint(max_entries, 1);
15 	__uint(key_size, sizeof(__u32));
16 	__uint(value_size, sizeof(__u32));
17 } prog_array SEC(".maps");
18 
19 SEC("cgroup_skb/egress")
20 int prog_array_owner(struct __sk_buff *skb)
21 {
22 	__u64 *storage;
23 
24 	storage = bpf_get_local_storage(&storage_map, 0);
25 	if (storage)
26 		*storage = 1;
27 
28 	bpf_tail_call(skb, &prog_array, 0);
29 	return 1;
30 }
31 
32 char _license[] SEC("license") = "GPL";
33