vimer linux kernel 爱好者

ebpf基础知识

2018-06-03
bpf

bpftool

目前,本人的理解的就是系统带来的库工具,目前都放在内核的tools目录下。 例如,这个bpftools工具就可以提供一个调试、探视内核中由eBPF产生的map.

编译

 cd ~/git/linux/tools/bpf/bpftool/
 sudo make
 sudo make install

具体的用法可以在后面具体展示。

如何正事自己系统的eBPF是否满足

$ cd tools/testing/selftests/bpf/
$ make
$ sudo ./test_verifier

如果有问题,说明需要检查kernel config文件是否完全适配

libbpf

位于tools/lib/bpf.这个库很明显就是为了加载eBPF程序,当然,FB工程师也维护了一个github

git submodule add https://github.com/libbpf/libbpf/ libbpf

将这个添加到自己练习的项目。后面使用:

git submodule update --init

Main features

If you want to learn what type of ebpf program is supported, you can use:

git grep -W 'bpf_prog_type {' include/uapi/linux/bpf.h

in kernel tree source code.

Maps

git grep -W 'bpf_map_type {' include/uapi/linux/bpf.h

“-W” is matching the substring in the text.

XDP

Listing the drivers the XDP supported:

git grep -l XDP_SETUP_PROG drivers/

helper

 git grep 'FN(' include/uapi/linux/bpf.h

Comments

Content