linux/tools/testing/selftests/bpf/progs/test_btf_haskv.c
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/* Copyright (c) 2018 Facebook */
   3#include <linux/bpf.h>
   4#include "bpf_helpers.h"
   5#include "bpf_legacy.h"
   6
   7int _version SEC("version") = 1;
   8
   9struct ipv_counts {
  10        unsigned int v4;
  11        unsigned int v6;
  12};
  13
  14struct bpf_map_def SEC("maps") btf_map = {
  15        .type = BPF_MAP_TYPE_ARRAY,
  16        .key_size = sizeof(int),
  17        .value_size = sizeof(struct ipv_counts),
  18        .max_entries = 4,
  19};
  20
  21BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts);
  22
  23struct dummy_tracepoint_args {
  24        unsigned long long pad;
  25        struct sock *sock;
  26};
  27
  28__attribute__((noinline))
  29int test_long_fname_2(struct dummy_tracepoint_args *arg)
  30{
  31        struct ipv_counts *counts;
  32        int key = 0;
  33
  34        if (!arg->sock)
  35                return 0;
  36
  37        counts = bpf_map_lookup_elem(&btf_map, &key);
  38        if (!counts)
  39                return 0;
  40
  41        counts->v6++;
  42
  43        return 0;
  44}
  45
  46__attribute__((noinline))
  47int test_long_fname_1(struct dummy_tracepoint_args *arg)
  48{
  49        return test_long_fname_2(arg);
  50}
  51
  52SEC("dummy_tracepoint")
  53int _dummy_tracepoint(struct dummy_tracepoint_args *arg)
  54{
  55        return test_long_fname_1(arg);
  56}
  57
  58char _license[] SEC("license") = "GPL";
  59