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"; 25