linux/tools/testing/selftests/bpf/progs/bpf_iter_bpf_sk_storage_map.c
<<
>>
Prefs
   1// SPDX-License-Identifier: GPL-2.0
   2/* Copyright (c) 2020 Facebook */
   3#include "bpf_iter.h"
   4#include "bpf_tracing_net.h"
   5#include <bpf/bpf_helpers.h>
   6#include <bpf/bpf_tracing.h>
   7
   8char _license[] SEC("license") = "GPL";
   9
  10struct {
  11        __uint(type, BPF_MAP_TYPE_SK_STORAGE);
  12        __uint(map_flags, BPF_F_NO_PREALLOC);
  13        __type(key, int);
  14        __type(value, int);
  15} sk_stg_map SEC(".maps");
  16
  17__u32 val_sum = 0;
  18__u32 ipv6_sk_count = 0;
  19
  20SEC("iter/bpf_sk_storage_map")
  21int dump_bpf_sk_storage_map(struct bpf_iter__bpf_sk_storage_map *ctx)
  22{
  23        struct sock *sk = ctx->sk;
  24        __u32 *val = ctx->value;
  25
  26        if (sk == (void *)0 || val == (void *)0)
  27                return 0;
  28
  29        if (sk->sk_family == AF_INET6)
  30                ipv6_sk_count++;
  31
  32        val_sum += *val;
  33        return 0;
  34}
  35