0001
0002
0003
0004
0005
0006
0007 #include <errno.h>
0008 #include <linux/bpf.h>
0009 #include <linux/ip.h>
0010 #include <linux/udp.h>
0011 #include <bpf/bpf_helpers.h>
0012
0013 #include "progs/cg_storage_multi.h"
0014
0015 struct {
0016 __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE);
0017 __type(key, __u64);
0018 __type(value, struct cgroup_value);
0019 } cgroup_storage SEC(".maps");
0020
0021 __u32 invocations = 0;
0022
0023 SEC("cgroup_skb/egress")
0024 int egress1(struct __sk_buff *skb)
0025 {
0026 struct cgroup_value *ptr_cg_storage =
0027 bpf_get_local_storage(&cgroup_storage, 0);
0028
0029 __sync_fetch_and_add(&ptr_cg_storage->egress_pkts, 1);
0030 __sync_fetch_and_add(&invocations, 1);
0031
0032 return 1;
0033 }
0034
0035 SEC("cgroup_skb/egress")
0036 int egress2(struct __sk_buff *skb)
0037 {
0038 struct cgroup_value *ptr_cg_storage =
0039 bpf_get_local_storage(&cgroup_storage, 0);
0040
0041 __sync_fetch_and_add(&ptr_cg_storage->egress_pkts, 1);
0042 __sync_fetch_and_add(&invocations, 1);
0043
0044 return 1;
0045 }
0046
0047 SEC("cgroup_skb/ingress")
0048 int ingress(struct __sk_buff *skb)
0049 {
0050 struct cgroup_value *ptr_cg_storage =
0051 bpf_get_local_storage(&cgroup_storage, 0);
0052
0053 __sync_fetch_and_add(&ptr_cg_storage->ingress_pkts, 1);
0054 __sync_fetch_and_add(&invocations, 1);
0055
0056 return 1;
0057 }