Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 
0003 /*
0004  * Copyright 2020 Google LLC.
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, struct bpf_cgroup_storage_key);
0018     __type(value, struct cgroup_value);
0019 } cgroup_storage SEC(".maps");
0020 
0021 __u32 invocations = 0;
0022 
0023 SEC("cgroup_skb/egress")
0024 int egress(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 }