Here's how I'm trying to initialize a BPF_MAP_TYPE_PERCPU_ARRAY
of structs to a default value. The array contains counters the user space program will read.
#include <linux/bpf.h>
#include <bpf/bpf_helpers.h>
struct xdp_stats_t {
__u64 total_packets;
};
struct xdp_stats_t xdp_stats = {0};
struct {
__uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
__uint(key_size, sizeof(__u32));
__uint(value_size, sizeof(struct xdp_stats_t));
__uint(max_entries, 1);
__array(values, struct xdp_stats_t);
} counter_table SEC(".maps") = {
.values = {
[0] = &xdp_stats
}
};
SEC("xdp")
int main_prog(struct xdp_md *ctx) {
return XDP_PASS;
}
char _license[] SEC("license") = "GPL";
But I get this error when I try to load the BPF program:
libbpf: map 'counter_table': should be map-in-map.