]> Git Repo - linux.git/blob - tools/testing/selftests/bpf/progs/cgroup_storage.c
Linux 6.14-rc3
[linux.git] / tools / testing / selftests / bpf / progs / cgroup_storage.c
1 // SPDX-License-Identifier: GPL-2.0
2
3 #include <linux/bpf.h>
4 #include <bpf/bpf_helpers.h>
5
6 struct {
7         __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
8         __type(key, struct bpf_cgroup_storage_key);
9         __type(value, __u64);
10 } cgroup_storage SEC(".maps");
11
12 SEC("cgroup_skb/egress")
13 int bpf_prog(struct __sk_buff *skb)
14 {
15         __u64 *counter;
16
17         counter = bpf_get_local_storage(&cgroup_storage, 0);
18         __sync_fetch_and_add(counter, 1);
19
20         /* Drop one out of every two packets */
21         return (*counter & 1);
22 }
23
24 char _license[] SEC("license") = "GPL";
This page took 0.031652 seconds and 4 git commands to generate.