test_btf_haskv.c (965B)
1/* SPDX-License-Identifier: GPL-2.0 */ 2/* Copyright (c) 2018 Facebook */ 3#include <linux/bpf.h> 4#include <bpf/bpf_helpers.h> 5#include "bpf_legacy.h" 6 7struct ipv_counts { 8 unsigned int v4; 9 unsigned int v6; 10}; 11 12#pragma GCC diagnostic push 13#pragma GCC diagnostic ignored "-Wdeprecated-declarations" 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#pragma GCC diagnostic pop 21 22BPF_ANNOTATE_KV_PAIR(btf_map, int, struct ipv_counts); 23 24__attribute__((noinline)) 25int test_long_fname_2(void) 26{ 27 struct ipv_counts *counts; 28 int key = 0; 29 30 counts = bpf_map_lookup_elem(&btf_map, &key); 31 if (!counts) 32 return 0; 33 34 counts->v6++; 35 36 return 0; 37} 38 39__attribute__((noinline)) 40int test_long_fname_1(void) 41{ 42 return test_long_fname_2(); 43} 44 45SEC("dummy_tracepoint") 46int _dummy_tracepoint(void *arg) 47{ 48 return test_long_fname_1(); 49} 50 51char _license[] SEC("license") = "GPL";