如何获得EBPF地图的大小?
我是EBPF的新手,我想将元素插入BPF_Array,所以有什么方法可以像C ++ push_back()
size> size()
函数吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我是EBPF的新手,我想将元素插入BPF_Array,所以有什么方法可以像C ++ push_back()
size> size()
函数吗?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(1)
是,否。您可以在数组映射中更改元素(通过系统调用
BPF(BPF_MAP_UPDATE_ELEM,...)
),但此时您无法动态地调整映射大小(另请参见 this Answer ),尽管将来可能会以以前曾在该方向上提出一些工作。因此,现在您有一个固定尺寸的数组,可以从BPF程序或用户空间中更新。对于用户空间端,在C ++中,您可能要使用libbpf来更新地图。 You have a low-level wrapper around the syscall in bpf.h,
BPF_MAP_UPDATE_ELEM()
以及在Libbpf.h中管理的地图对象上工作的高级函数:要回答您标题的问题:是的,您可以通过
bpf()
系统调用获得地图大小。 LIBBPF提供了一个包装器: ,填充struct bpf_map_info
您可以从中检索地图的大小。Yes and no. You can change elements in an array map (through the system call
bpf(BPF_MAP_UPDATE_ELEM, ...)
), but you cannot dynamically resize your map at this time (see also this answer), although this might be possible in the future as some work in that direction has been presented before.So for now you have a fixed-size array that you can update either from your BPF program, or from user space. For the user space side, in C++, you probably want to use libbpf to update your map. You have a low-level wrapper around the syscall in bpf.h,
bpf_map_update_elem()
, as well as a higher-level function that works on map objects managed by the library, in libbpf.h:bpf_map__update_elem()
.To answer to the question from your title: Yes you can obtain the map size, again through the
bpf()
system call. Libbpf provides a wrapper:bpf_obj_get_info_by_fd()
, which fills astruct bpf_map_info
from which you can retrieve the size of the map.