vimerbf and borkmann bpf, tracex3_user: erase "ARRAY_SIZE" redefined
There is a warning when compiling bpf sample programs in sample/bpf:

  make -C /home/foo/bpf/samples/bpf/../../tools/lib/bpf/ RM='rm -rf' LDFLAGS= srctree=/home/foo/bpf/samples/bpf/../../ O=
    HOSTCC  /home/foo/bpf/samples/bpf/tracex3_user.o
  /home/foo/bpf/samples/bpf/tracex3_user.c:20:0: warning: "ARRAY_SIZE" redefined
   #define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))

  In file included from /home/foo/bpf/samples/bpf/tracex3_user.c:18:0:
  ./tools/testing/selftests/bpf/bpf_util.h:48:0: note: this is the location of the previous definition
   # define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

Signed-off-by: Bo YU <tsu.yubo@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Latest commit 20cdeb5 Oct 3, 2018
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
.gitignore samples/bpf: add .gitignore file Jul 5, 2018
Makefile bpf: add TCP_SAVE_SYN/TCP_SAVED_SYN sample program Aug 31, 2018
README.rst samples/bpf: Add documentation on cross compilation Sep 21, 2017
bpf_insn.h samples: bpf: rename libbpf.h to bpf_insn.h May 15, 2018
bpf_load.c samples/bpf: remove duplicated includes Sep 18, 2018
bpf_load.h samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
cookie_uid_helper_example.c samples: bpf: rename libbpf.h to bpf_insn.h May 15, 2018
cpustat_kern.c samples/bpf: Add program for CPU state statistics Feb 26, 2018
cpustat_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
fds_example.c samples: bpf: rename libbpf.h to bpf_insn.h May 15, 2018
hash_func01.h samples/bpf: add Paul Hsieh's (LGPL 2.1) hash function SuperFastHash Aug 10, 2018
lathist_kern.c bpf: BPF based latency tracing Jun 23, 2015
lathist_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
load_sock_ops.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
lwt_len_hist.sh License cleanup: add SPDX GPL-2.0 license identifier to files with no… Nov 2, 2017
lwt_len_hist_kern.c bpf: Add tests and samples for LWT-BPF Dec 2, 2016
lwt_len_hist_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
map_perf_test_kern.c samples/bpf: Use getppid instead of getpgrp for array map stress Sep 21, 2017
map_perf_test_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
offwaketime_kern.c bpf, samples: don't zero data when not needed Apr 15, 2016
offwaketime_user.c samples/bpf: move common-purpose trace functions to selftests Apr 29, 2018
parse_ldabs.c bpf: fix samples to add fake KBUILD_MODNAME Oct 29, 2016
parse_simple.c bpf: fix samples to add fake KBUILD_MODNAME Oct 29, 2016
parse_varlen.c samples/bpf: add missing <linux/if_vlan.h> Jul 5, 2018
run_cookie_uid_helper_example.sh License cleanup: add SPDX GPL-2.0 license identifier to files with no… Nov 2, 2017
sampleip_kern.c bpf/samples: Fix PT_REGS_IP on s390x and use it Nov 28, 2016
sampleip_user.c samples/bpf: remove duplicated includes Sep 18, 2018
sock_example.c samples: bpf: rename libbpf.h to bpf_insn.h May 15, 2018
sock_example.h samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
sock_flags_kern.c samples/bpf: Update cgroup socket examples to use uid gid helper Sep 1, 2017
sockex1_kern.c samples: bpf: add skb->field examples and tests Mar 16, 2015
sockex1_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
sockex2_kern.c samples/bpf: fix compilation failure Sep 21, 2018
sockex2_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
sockex3_kern.c samples/bpf: fix compilation failure Sep 21, 2018
sockex3_user.c samples/bpf: fix compilation failure Sep 21, 2018
spintest_kern.c samples/bpf: Enable powerpc support Apr 6, 2016
spintest_user.c samples/bpf: move common-purpose trace functions to selftests Apr 29, 2018
syscall_nrs.c License cleanup: add SPDX GPL-2.0 license identifier to files with no… Nov 2, 2017
syscall_tp_kern.c bpf: add a test case for syscalls/sys_{enter|exit}_* tracepoints Aug 7, 2017
syscall_tp_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
task_fd_query_kern.c samples/bpf: add a samples/bpf test for BPF_TASK_FD_QUERY May 25, 2018
task_fd_query_user.c samples/bpf: add a samples/bpf test for BPF_TASK_FD_QUERY May 25, 2018
tc_l2_redirect.sh License cleanup: add SPDX GPL-2.0 license identifier to files with no… Nov 2, 2017
tc_l2_redirect_kern.c bpf: fix samples xdp_tx_iptunnel and tc_l2_redirect with fake KBUILD_… Jan 20, 2017
tc_l2_redirect_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
tcbpf1_kern.c bpf: fix samples to add fake KBUILD_MODNAME Oct 29, 2016
tcp_basertt_kern.c bpf: sample BPF_SOCKET_OPS_BASE_RTT program Oct 22, 2017
tcp_bpf.readme bpf: Rename tcp_bbf.readme to tcp_bpf.readme Nov 8, 2017
tcp_bufs_kern.c bpf: Fix tcp_bufs_kern.c sample program Nov 11, 2017
tcp_clamp_kern.c bpf: Fix tcp_clamp_kern.c sample program Nov 11, 2017
tcp_cong_kern.c bpf: Fix tcp_cong_kern.c sample program Nov 11, 2017
tcp_iw_kern.c bpf: Fix tcp_iw_kern.c sample program Nov 11, 2017
tcp_rwnd_kern.c bpf: Fix tcp_rwnd_kern.c sample program Nov 11, 2017
tcp_synrto_kern.c bpf: Fix tcp_synrto_kern.c sample program Nov 11, 2017
tcp_tos_reflect_kern.c bpf: add TCP_SAVE_SYN/TCP_SAVED_SYN sample program Aug 31, 2018
test_cgrp2_array_pin.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
test_cgrp2_attach.c samples: bpf: rename libbpf.h to bpf_insn.h May 15, 2018
test_cgrp2_attach2.c samples/bpf: extend test_cgrp2_attach2 test to use per-cpu cgroup sto… Oct 1, 2018
test_cgrp2_sock.c samples: bpf: rename libbpf.h to bpf_insn.h May 15, 2018
test_cgrp2_sock.sh samples/bpf: detach prog from cgroup Mar 1, 2018
test_cgrp2_sock2.c samples/bpf: test_cgrp2_sock2: fix an off by one Jul 16, 2018
test_cgrp2_sock2.sh samples/bpf: detach prog from cgroup Mar 1, 2018
test_cgrp2_tc.sh License cleanup: add SPDX GPL-2.0 license identifier to files with no… Nov 2, 2017
test_cgrp2_tc_kern.c bpf: fix samples to add fake KBUILD_MODNAME Oct 29, 2016
test_cls_bpf.sh License cleanup: add SPDX GPL-2.0 license identifier to files with no… Nov 2, 2017
test_current_task_under_cgroup_kern.c samples/bpf: Add test_current_task_under_cgroup test Aug 13, 2016
test_current_task_under_cgroup_user.c samples/bpf: remove duplicated includes Sep 18, 2018
test_ipip.sh License cleanup: add SPDX GPL-2.0 license identifier to files with no… Nov 2, 2017
test_lru_dist.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
test_lwt_bpf.c bpf: Add tests and samples for LWT-BPF Dec 2, 2016
test_lwt_bpf.sh License cleanup: add SPDX GPL-2.0 license identifier to files with no… Nov 2, 2017
test_map_in_map_kern.c bpf: Add tests for map-in-map Mar 22, 2017
test_map_in_map_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
test_overhead_kprobe_kern.c samples/bpf: add tracepoint vs kprobe performance tests Apr 8, 2016
test_overhead_raw_tp_kern.c samples/bpf: raw tracepoint test Mar 28, 2018
test_overhead_tp_kern.c samples/bpf: add tracepoint vs kprobe performance tests Apr 8, 2016
test_overhead_user.c samples/bpf: Check the error of write() and read() Jul 5, 2018
test_override_return.sh samples/bpf: add a test for bpf_override_return Dec 12, 2017
test_probe_write_user_kern.c samples/bpf: Add test/example of using bpf_probe_write_user bpf helper Jul 26, 2016
test_probe_write_user_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
trace_event_kern.c samples/bpf: add example to test reading address Mar 8, 2018
trace_event_user.c samples/bpf: Check the result of system() Jul 5, 2018
trace_output_kern.c samples/bpf: fix trace_output example Apr 28, 2016
trace_output_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
tracex1_kern.c bpf, samples: don't zero data when not needed Apr 15, 2016
tracex1_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
tracex2_kern.c bpf, samples: don't zero data when not needed Apr 15, 2016
tracex2_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
tracex3_kern.c samples/bpf: update tracex[23] examples to use per-cpu maps Feb 6, 2016
tracex3_user.c bpf, tracex3_user: erase "ARRAY_SIZE" redefined Oct 4, 2018
tracex4_kern.c samples/bpf: Enable powerpc support Apr 6, 2016
tracex4_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
tracex5_kern.c samples/bpf: Fix tracex5 to work with MIPS syscalls. Jun 14, 2017
tracex5_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
tracex6_kern.c bpf: add a test case for helper bpf_perf_event_read_value Oct 7, 2017
tracex6_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
tracex7_kern.c samples/bpf: add a test for bpf_override_return Dec 12, 2017
tracex7_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
xdp1_kern.c bpf: make xdp sample variable names more meaningful Jul 21, 2016
xdp1_user.c samples: bpf: convert some XDP samples from bpf_load to libbpf May 10, 2018
xdp2_kern.c bpf: make xdp sample variable names more meaningful Jul 21, 2016
xdp2skb_meta.sh samples/bpf: Fix tc and ip paths in xdp2skb_meta.sh Jul 10, 2018
xdp2skb_meta_kern.c samples/bpf: xdp2skb_meta comment explain why pkt-data pointers are i… Jan 18, 2018
xdp_adjust_tail_kern.c bpf: add bpf_xdp_adjust_tail sample prog Apr 18, 2018
xdp_adjust_tail_user.c samples: bpf: convert some XDP samples from bpf_load to libbpf May 10, 2018
xdp_fwd_kern.c bpf: Change bpf_fib_lookup to return lookup status Jun 28, 2018
xdp_fwd_user.c samples: bpf: convert xdp_fwd_user.c to libbpf Jul 27, 2018
xdp_monitor_kern.c samples/bpf: xdp_monitor use err code from tracepoint xdp:xdp_devmap_… May 25, 2018
xdp_monitor_user.c samples/bpf: xdp_monitor use err code from tracepoint xdp:xdp_devmap_… May 25, 2018
xdp_redirect_cpu_kern.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next Aug 13, 2018
xdp_redirect_cpu_user.c samples/bpf: all XDP samples should unload xdp/bpf prog on SIGTERM Aug 16, 2018
xdp_redirect_kern.c samples/bpf: Fix compilation issue in redirect dummy program Aug 31, 2017
xdp_redirect_map_kern.c samples/bpf: Fix compilation issue in redirect dummy program Aug 31, 2017
xdp_redirect_map_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
xdp_redirect_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
xdp_router_ipv4_kern.c xdp: Sample xdp program implementing ip forward Nov 8, 2017
xdp_router_ipv4_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
xdp_rxq_info_kern.c samples/bpf: xdp_rxq_info action XDP_TX must adjust MAC-addrs Jun 28, 2018
xdp_rxq_info_user.c samples/bpf: all XDP samples should unload xdp/bpf prog on SIGTERM Aug 16, 2018
xdp_sample_pkts_kern.c samples/bpf: Add xdp_sample_pkts example Jun 27, 2018
xdp_sample_pkts_user.c samples/bpf: Add xdp_sample_pkts example Jun 27, 2018
xdp_tx_iptunnel_common.h bpf: xdp: Add XDP example for head adjustment Dec 8, 2016
xdp_tx_iptunnel_kern.c bpf: fix samples xdp_tx_iptunnel and tc_l2_redirect with fake KBUILD_… Jan 20, 2017
xdp_tx_iptunnel_user.c samples: bpf: include bpf/bpf.h instead of local libbpf.h May 15, 2018
xdpsock.h samples/bpf: sample application and documentation for AF_XDP sockets May 3, 2018
xdpsock_kern.c samples/bpf: xdpsock, minor fixes Aug 31, 2018
xdpsock_user.c samples/bpf: xdpsock, minor fixes Aug 31, 2018

README.rst

eBPF sample programs

This directory contains a test stubs, verifier test-suite and examples for using eBPF. The examples use libbpf from tools/lib/bpf.

Build dependencies

Compiling requires having installed:
  • clang >= version 3.4.0
  • llvm >= version 3.7.1

Note that LLVM's tool 'llc' must support target 'bpf', list version and supported targets with command: llc --version

Kernel headers

There are usually dependencies to header files of the current kernel. To avoid installing devel kernel headers system wide, as a normal user, simply call:

make headers_install

This will creates a local "usr/include" directory in the git/build top level directory, that the make system automatically pickup first.

Compiling

For building the BPF samples, issue the below command from the kernel top level directory:

make samples/bpf/

Do notice the "/" slash after the directory name.

It is also possible to call make from this directory. This will just hide the the invocation of make as above with the appended "/".

Manually compiling LLVM with 'bpf' support

Since version 3.7.0, LLVM adds a proper LLVM backend target for the BPF bytecode architecture.

By default llvm will build all non-experimental backends including bpf. To generate a smaller llc binary one can use:

-DLLVM_TARGETS_TO_BUILD="BPF"

Quick sniplet for manually compiling LLVM and clang (build dependencies are cmake and gcc-c++):

$ git clone http://llvm.org/git/llvm.git
$ cd llvm/tools
$ git clone --depth 1 http://llvm.org/git/clang.git
$ cd ..; mkdir build; cd build
$ cmake .. -DLLVM_TARGETS_TO_BUILD="BPF;X86"
$ make -j $(getconf _NPROCESSORS_ONLN)

It is also possible to point make to the newly compiled 'llc' or 'clang' command via redefining LLC or CLANG on the make command line:

make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang

Cross compiling samples

In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH environment variables before calling make. This will direct make to build samples for the cross target.

export ARCH=arm64 export CROSS_COMPILE="aarch64-linux-gnu-" make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang