19efcc4adSYonghong Song // SPDX-License-Identifier: GPL-2.0 29efcc4adSYonghong Song /* Copyright (c) 2020 Facebook */ 39efcc4adSYonghong Song #include "bpf_iter.h" 49efcc4adSYonghong Song #include <bpf/bpf_helpers.h> 59efcc4adSYonghong Song #include <bpf/bpf_tracing.h> 69efcc4adSYonghong Song 79efcc4adSYonghong Song char _license[] SEC("license") = "GPL"; 89efcc4adSYonghong Song 99efcc4adSYonghong Song struct key_t { 109efcc4adSYonghong Song int a; 119efcc4adSYonghong Song int b; 129efcc4adSYonghong Song int c; 139efcc4adSYonghong Song }; 149efcc4adSYonghong Song 159efcc4adSYonghong Song struct { 169efcc4adSYonghong Song __uint(type, BPF_MAP_TYPE_HASH); 179efcc4adSYonghong Song __uint(max_entries, 3); 189efcc4adSYonghong Song __type(key, struct key_t); 199efcc4adSYonghong Song __type(value, __u64); 209efcc4adSYonghong Song } hashmap1 SEC(".maps"); 219efcc4adSYonghong Song 229efcc4adSYonghong Song __u32 key_sum = 0; 239efcc4adSYonghong Song 249efcc4adSYonghong Song SEC("iter/bpf_map_elem") dump_bpf_hash_map(struct bpf_iter__bpf_map_elem * ctx)259efcc4adSYonghong Songint dump_bpf_hash_map(struct bpf_iter__bpf_map_elem *ctx) 269efcc4adSYonghong Song { 279efcc4adSYonghong Song void *key = ctx->key; 289efcc4adSYonghong Song 299efcc4adSYonghong Song if (key == (void *)0) 309efcc4adSYonghong Song return 0; 319efcc4adSYonghong Song 329efcc4adSYonghong Song /* out of bound access w.r.t. hashmap1 */ 339efcc4adSYonghong Song key_sum += *(__u32 *)(key + sizeof(struct key_t)); 349efcc4adSYonghong Song return 0; 359efcc4adSYonghong Song } 36