因此,struct bpf_map成员定义的fd和max_entries (我需要)在源文件中(libbpf.c),libbpf.h只包含ebpf映射的声明(如struct bpf_map map; ),因此我不能取消引用指针(我有struct bpf_map )来获取存储在struct中的fd和max外设。
首先,是否有任何方法可以验证这两个函数返回的是有效性。包含libbpf.h足以包含libbpf_get_error函数。
struct bpf_object *obj=bpf_object__open(filename);
if (libbpf_get_error(obj)) {
printf("ERROR: opening BPF object file failed\n");
}
struct bpf_map *map=bpf_object__find_map_by_name(obj,"hash_map");
if (libbpf_get_error(map)) {
printf("ERROR: finding map\n");
}从这里继续前进。如果我有struct bpf_map对象和struct bpf_map_def对象,那么如何获得struct bpf_map和struct bpf_map的成员?
有人能告诉我这个吗?
我对fd和max_entries感兴趣;如果ebpf中不支持fd和max_entries,那么函数中是否有syscall数的值?
long syscall(long number, ...);参数列表给了我这个信息。
谢谢
发布于 2022-08-16 01:14:53
不需要自己取消对指针的引用,结构是不透明的。只需使用相关函数从libbpf
LIBBPF_API int bpf_map__fd(const struct bpf_map *map);
LIBBPF_API __u32 bpf_map__max_entries(const struct bpf_map *map);如果在ebpf中不支持它,那么函数
syscall(...)中是否有syscall数的值?
有,但这只能在创建映射之后从内核检索信息(当然,这是您想要的,因为您无论如何都在寻找fd )。子命令 for bpf() syscall (syscall(__NR_bpf, cmd, attr, size),参见man bpf)将为您提供相关的文件描述符,前提是您知道映射id,而带有相关论点的子命令将允许您找到最大的条目数。但你最终还是会成为重新实现libbpf。
https://stackoverflow.com/questions/73359560
复制相似问题