WIP FPC-III support
[linux/fpc-iii.git] / tools / testing / selftests / bpf / progs / cg_storage_multi_shared.c
bloba149f33bc533797e459a370b1ebf23f8b6479e1c
1 // SPDX-License-Identifier: GPL-2.0-only
3 /*
4 * Copyright 2020 Google LLC.
5 */
7 #include <errno.h>
8 #include <linux/bpf.h>
9 #include <linux/ip.h>
10 #include <linux/udp.h>
11 #include <bpf/bpf_helpers.h>
13 #include "progs/cg_storage_multi.h"
15 struct {
16 __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
17 __type(key, __u64);
18 __type(value, struct cgroup_value);
19 } cgroup_storage SEC(".maps");
21 __u32 invocations = 0;
23 SEC("cgroup_skb/egress/1")
24 int egress1(struct __sk_buff *skb)
26 struct cgroup_value *ptr_cg_storage =
27 bpf_get_local_storage(&cgroup_storage, 0);
29 __sync_fetch_and_add(&ptr_cg_storage->egress_pkts, 1);
30 __sync_fetch_and_add(&invocations, 1);
32 return 1;
35 SEC("cgroup_skb/egress/2")
36 int egress2(struct __sk_buff *skb)
38 struct cgroup_value *ptr_cg_storage =
39 bpf_get_local_storage(&cgroup_storage, 0);
41 __sync_fetch_and_add(&ptr_cg_storage->egress_pkts, 1);
42 __sync_fetch_and_add(&invocations, 1);
44 return 1;
47 SEC("cgroup_skb/ingress")
48 int ingress(struct __sk_buff *skb)
50 struct cgroup_value *ptr_cg_storage =
51 bpf_get_local_storage(&cgroup_storage, 0);
53 __sync_fetch_and_add(&ptr_cg_storage->ingress_pkts, 1);
54 __sync_fetch_and_add(&invocations, 1);
56 return 1;