2

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?

pchaigno
  • 11,313
  • 2
  • 29
  • 54
Nan Xiao
  • 16,671
  • 18
  • 103
  • 164

2 Answers2

2

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.

  • Thanks for your answer! Is it posible to replace the whole older kernel header files with the newer kernel completely? I use `make headers_install` command, the output is "CHK include/generated/uapi/linux/version.h INSTALL usr/include/linux/ (411 files) ". It install all the files in `/usr/include/linux` directory. – Nan Xiao Jun 10 '15 at 07:15
  • You can use /usr as the argument to INSTALL_HDR_PATH. The better explanation for how to use headers_install is here: http://lxr.free-electrons.com/source/Documentation/kbuild/headers_install.txt. However, I believe the example of "/usr/include" is wrong, as in my experiments this created /usr/include/include. – Brenden Blanco Jun 10 '15 at 23:37
  • However, please be aware that there are conflicting answers to this, and some have reported issues when using /usr as the argument. http://www.linuxquestions.org/questions/linux-newbie-8/make-headers_install-deleted-header-files-944363/ – Brenden Blanco Jun 10 '15 at 23:45
0

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.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • `` is in `libc`? not kernel header files? – Nan Xiao Jun 09 '15 at 09:14
  • `libc` has **own copy** of include files, shared between kernel and user. In the kernel such files are placed under `include/uapi/` and `arch//include/uapi/`. – Tsyvarev Jun 09 '15 at 09:25
  • My `libc` version is `2.17`. How do I know which `libc` supports `SO_ATTACH_BPF`? – Nan Xiao Jun 09 '15 at 09:34
  • Current `glibc`, which is used by the most Linux distros, seems has no support for that option (see repo http://sourceware.org/git/?p=glibc.git). You can try `libc` from other vendors. E.g., this one https://gitlab.com/bminor/musl/tree/70572dce07a631e2f818b34f5679c57eeebc9779 has support for the option you need. – Tsyvarev Jun 09 '15 at 09:55