1 // SPDX-License-Identifier: GPL-2.0-only 2 3 /* 4 * Copyright 2020 Google LLC. 5 */ 6 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> 12 13 #include "progs/cg_storage_multi.h" 14 15 struct { 16 __uint(type, BPF_MAP_TYPE_CGROUP_STORAGE); 17 __type(key, struct bpf_cgroup_storage_key); 18 __type(value, struct cgroup_value); 19 } cgroup_storage SEC(".maps"); 20 21 __u32 invocations = 0; 22 23 SEC("cgroup_skb/egress") egress(struct __sk_buff * skb)24int egress(struct __sk_buff *skb) 25 { 26 struct cgroup_value *ptr_cg_storage = 27 bpf_get_local_storage(&cgroup_storage, 0); 28 29 __sync_fetch_and_add(&ptr_cg_storage->egress_pkts, 1); 30 __sync_fetch_and_add(&invocations, 1); 31 32 return 1; 33 } 34