因此,我正在使用具有结构值的散列映射编译xdp程序。
struct hash_elem {
int cnt;
struct bpf_spin_lock lock;
};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__uint(max_entries, 100);
__uint(key_size, sizeof(__u32));
__type(values, struct hash_elem);
} hash_map SEC(".maps");
struct a{struct bpf_spin_lock lock;};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, __u32);
__type(value, long);
__uint(max_entries, 2);
} hash_map1 SEC(".maps");
//static __u32 i=0;
SEC("xdp")
int xdp_prog_simple(struct xdp_md *ctx)
{
int key=1;
struct hash_elem * val = bpf_map_lookup_elem(&hash_map, &key);
if (val) {
bpf_spin_lock(&val->lock);
val->cnt++;
bpf_spin_unlock(&val->lock);
}
}但是,在加载程序时,它会导致异常
libbpf: map 'hash_map': unknown field 'values'.
ERR: loading BPF-OBJ file(./k.o) (-2): No such file or directory
ERR: loading file: ./k.o发布于 2022-08-21 10:05:15
这是因为您的地图定义中出现了错误。我想你想:
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, __u32);
__type(value, struct hash_elem);
__uint(max_entries, 100);
} hash_map SEC(".maps");
struct a{struct bpf_spin_lock lock;};
struct {
__uint(type, BPF_MAP_TYPE_HASH);
__type(key, __u32);
__type(value, long);
__uint(max_entries, 2);
} hash_map1 SEC(".maps");注意第一个value字段的差异。我还在可能的情况下转向使用__type,尽管这不是必需的。
https://stackoverflow.com/questions/73432673
复制相似问题