How to build Linux kernel to support SO_ATTACH_BPF socket option?

946 views Asked by At

I want to build a application which supports eBPF on CentOS 7 (the kernel version is 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:

CONFIG_BPF=y
CONFIG_BPF_SYSCALL=y

Then follow this link to build and install a 4.0.5 kernel.

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.

How to build Linux kernel to support SO_ATTACH_BPF socket option?

2

There are 2 answers

3
Brenden Blanco On BEST ANSWER

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. As an additional step, I will do the following from the kernel build tree to install the kernel header files into /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,...}. During your test program compile, depending on which build system you use, you may need to prefix gcc/clang with -I/usr/local/include.

4
Tsyvarev On

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).

You need to update libc package as well for use new kernel's features in user space programs.