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 7 struct ipv_counts { 8 unsigned int v4; 9 unsigned int v6; 10 }; 11 12 #pragma GCC diagnostic push 13 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" 14 /* just to validate we can handle maps in multiple sections */ 15 struct bpf_map_def SEC("maps") btf_map_legacy = { 16 .type = BPF_MAP_TYPE_ARRAY, 17 .key_size = sizeof(int), 18 .value_size = sizeof(long long), 19 .max_entries = 4, 20 }; 21 #pragma GCC diagnostic pop 22 23 BPF_ANNOTATE_KV_PAIR(btf_map_legacy, int, struct ipv_counts); 24 25 struct { 26 __uint(type, BPF_MAP_TYPE_ARRAY); 27 __uint(max_entries, 4); 28 __type(key, int); 29 __type(value, struct ipv_counts); 30 } btf_map SEC(".maps"); 31 32 __attribute__((noinline)) 33 int test_long_fname_2(void) 34 { 35 struct ipv_counts *counts; 36 int key = 0; 37 38 counts = bpf_map_lookup_elem(&btf_map, &key); 39 if (!counts) 40 return 0; 41 42 counts->v6++; 43 44 /* just verify we can reference both maps */ 45 counts = bpf_map_lookup_elem(&btf_map_legacy, &key); 46 if (!counts) 47 return 0; 48 49 return 0; 50 } 51 52 __attribute__((noinline)) 53 int test_long_fname_1(void) 54 { 55 return test_long_fname_2(); 56 } 57 58 SEC("dummy_tracepoint") 59 int _dummy_tracepoint(void *arg) 60 { 61 return test_long_fname_1(); 62 } 63 64 char _license[] SEC("license") = "GPL"; 65