1// SPDX-License-Identifier: GPL-2.0
2/* Copyright (c) 2020 Facebook */
3#include "bpf_iter.h"
4#include <bpf/bpf_helpers.h>
5#include <bpf/bpf_tracing.h>
6
7char _license[] SEC("license") = "GPL";
8
9struct key_t {
10	int a;
11	int b;
12	int c;
13};
14
15struct {
16	__uint(type, BPF_MAP_TYPE_ARRAY);
17	__uint(max_entries, 3);
18	__type(key, __u32);
19	__type(value, __u64);
20} arraymap1 SEC(".maps");
21
22__u32 key_sum = 0;
23__u64 val_sum = 0;
24
25SEC("iter/bpf_map_elem")
26int dump_bpf_array_map(struct bpf_iter__bpf_map_elem *ctx)
27{
28	__u32 *key = ctx->key;
29	__u64 *val = ctx->value;
30
31	if (key == (void *)0 || val == (void *)0)
32		return 0;
33
34	bpf_seq_write(ctx->meta->seq, key, sizeof(__u32));
35	bpf_seq_write(ctx->meta->seq, val, sizeof(__u64));
36	key_sum += *key;
37	val_sum += *val;
38	*val = *key;
39	return 0;
40}
41