Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /* Copyright (c) 2020 Facebook */
0003 #include "bpf_iter.h"
0004 #include <bpf/bpf_helpers.h>
0005 #include <bpf/bpf_tracing.h>
0006 
0007 char _license[] SEC("license") = "GPL";
0008 
0009 struct key_t {
0010     int a;
0011     int b;
0012     int c;
0013 };
0014 
0015 struct {
0016     __uint(type, BPF_MAP_TYPE_ARRAY);
0017     __uint(max_entries, 3);
0018     __type(key, __u32);
0019     __type(value, __u64);
0020 } arraymap1 SEC(".maps");
0021 
0022 __u32 key_sum = 0;
0023 __u64 val_sum = 0;
0024 
0025 SEC("iter/bpf_map_elem")
0026 int dump_bpf_array_map(struct bpf_iter__bpf_map_elem *ctx)
0027 {
0028     __u32 *key = ctx->key;
0029     __u64 *val = ctx->value;
0030 
0031     if (key == (void *)0 || val == (void *)0)
0032         return 0;
0033 
0034     bpf_seq_write(ctx->meta->seq, key, sizeof(__u32));
0035     bpf_seq_write(ctx->meta->seq, val, sizeof(__u64));
0036     key_sum += *key;
0037     val_sum += *val;
0038     *val = *key;
0039     return 0;
0040 }