github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/testdata/strings.c (about) 1 #include "common.h" 2 3 char __license[] __section("license") = "MIT"; 4 5 typedef char custkey[48]; 6 7 struct { 8 __uint(type, BPF_MAP_TYPE_HASH); 9 __uint(max_entries, 2); 10 __type(key, custkey); 11 __type(value, uint32_t); 12 } my_map __section(".maps"); 13 14 static void *(*bpf_map_lookup_elem)(void *map, const void *key) = (void *)1; 15 static long (*bpf_map_update_elem)(void *map, const void *key, const void *value, uint64_t flags) = (void *)2; 16 17 #define KEY "This string is allocated in the string section\n" 18 19 __section("xdp") int filter() { 20 uint32_t *value = bpf_map_lookup_elem(&my_map, KEY); 21 if (value) 22 (*value)++; 23 else { 24 uint32_t newValue = 1; 25 bpf_map_update_elem(&my_map, KEY, &newValue, 0); 26 } 27 28 return 2; 29 }