linux/tools/testing/selftests/bpf/progs/cg_storage_multi_isolated.c
<<
>>
Prefs
   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
  15struct {
  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
  23SEC("cgroup_skb/egress/1")
  24int egress1(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
  35SEC("cgroup_skb/egress/2")
  36int egress2(struct __sk_buff *skb)
  37{
  38        struct cgroup_value *ptr_cg_storage =
  39                bpf_get_local_storage(&cgroup_storage, 0);
  40
  41        __sync_fetch_and_add(&ptr_cg_storage->egress_pkts, 1);
  42        __sync_fetch_and_add(&invocations, 1);
  43
  44        return 1;
  45}
  46
  47SEC("cgroup_skb/ingress")
  48int ingress(struct __sk_buff *skb)
  49{
  50        struct cgroup_value *ptr_cg_storage =
  51                bpf_get_local_storage(&cgroup_storage, 0);
  52
  53        __sync_fetch_and_add(&ptr_cg_storage->ingress_pkts, 1);
  54        __sync_fetch_and_add(&invocations, 1);
  55
  56        return 1;
  57}
  58