如何获得EBPF地图的大小?

发布于 2025-02-11 02:02:37 字数 109 浏览 2 评论 0 原文

我是EBPF的新手,我想将元素插入BPF_Array,所以有什么方法可以像C ++ push_back() size> size()函数吗?

I'm new to eBPF, I want to insert elements to a BPF_ARRAY, so is there any way to do like C++ push_back() size() function?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生生漫 2025-02-18 02:02:37

是,否。您可以在数组映射中更改元素(通过系统调用 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 a struct bpf_map_info from which you can retrieve the size of the map.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文