github.com/cilium/cilium@v1.16.2/bpf/custom/bytecount.h (about) 1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright Authors of Cilium */ 3 4 struct { 5 __uint(type, BPF_MAP_TYPE_HASH); 6 __type(key, __u32); 7 __type(value, __u64); 8 __uint(max_entries, 1024); 9 } bytecount_map __section_maps_btf; 10 11 static __always_inline 12 void custom_prog(const struct __ctx_buff *ctx, __u32 identity) 13 { 14 __u64 len, *bytecount; 15 16 len = ctx_full_len(ctx); 17 18 bytecount = map_lookup_elem(&bytecount_map, &identity); 19 if (bytecount) 20 __sync_fetch_and_add(bytecount, len); 21 else 22 /* No entry for endpoint in hashmap, attempt to create one */ 23 map_update_elem(&bytecount_map, &identity, &len, BPF_ANY); 24 }