简体   繁体   English

如何构建 Linux 内核以支持 SO_ATTACH_BPF 套接字选项?

[英]How to build Linux kernel to support SO_ATTACH_BPF socket option?

I want to build a application which supports eBPF on CentOS 7 (the kernel version is 3.10.0 ):我想在CentOS 7上构建一个支持eBPF的应用程序(内核版本是3.10.0 ):

if(setsockopt(sock, SOL_SOCKET, SO_ATTACH_BPF, prog_fd, sizeof(prog_f)) {
    ......
}

So I download a 4.0.5 version, make the following configurations on:于是我下载了一个4.0.5版本,在上做如下配置:

CONFIG_BPF=y
CONFIG_BPF_SYSCALL=y

Then follow this link to build and install a 4.0.5 kernel.然后按照此链接构建并安装4.0.5内核。

After executing make modules_install install , I find there is still no SO_ATTACH_BPF in <asm-generic/socket.h> , so the above code can't be compiled successfully.执行make modules_install install后发现<asm-generic/socket.h>仍然没有SO_ATTACH_BPF ,所以上面的代码无法编译成功。

How to build Linux kernel to support SO_ATTACH_BPF socket option?如何构建 Linux 内核以支持SO_ATTACH_BPF套接字选项?

In my setup, which is based on Fedora 21, I use very similar steps to those you linked to compile and install the latest kernel.在我基于 Fedora 21 的设置中,我使用与您链接的步骤非常相似的步骤来编译和安装最新内核。 As an additional step, I will do the following from the kernel build tree to install the kernel header files into /usr/local/include:作为附加步骤,我将从内核构建树执行以下操作,将内核头文件安装到 /usr/local/include 中:

sudo make INSTALL_HDR_PATH=/usr/local headers_install

This will cause both the stock kernel header files to remain installed in /usr/include/{linux,asm,asm-generic,...} , and the new kernel header files to be installed in /usr/local/include/{linux,asm,asm-generic,...} .这将导致原始内核头文件仍然安装在/usr/include/{linux,asm,asm-generic,...} ,而新的内核头文件将安装在/usr/local/include/{linux,asm,asm-generic,...} During your test program compile, depending on which build system you use, you may need to prefix gcc/clang with -I/usr/local/include .在您的测试程序编译期间,根据您使用的构建系统,您可能需要在 gcc/clang 前面加上-I/usr/local/include前缀。

Your newly installed kernel supports SO_ATTACH_BPF , but your current libc package doesn't now about that (as you mention, distro's native 3.10.0 kernel lacks of given option support).您新安装的内核支持SO_ATTACH_BPF ,但您当前的libc包现在不支持(正如您提到的,发行版的本机 3.10.0 内核缺乏给定的选项支持)。

You need to update libc package as well for use new kernel's features in user space programs.您还需要更新libc包以在用户空间程序中使用新内核的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM