Bo YU 20cdeb5408 bpf, tracex3_user: erase "ARRAY_SIZE" redefined 6 years ago
..
.gitignore c48424d993 samples/bpf: add .gitignore file 7 years ago
Makefile acb4ea9564 bpf: add TCP_SAVE_SYN/TCP_SAVED_SYN sample program 7 years ago
README.rst 8bf2ac25a9 samples/bpf: Add documentation on cross compilation 7 years ago
bpf_insn.h 8d93045077 samples: bpf: rename libbpf.h to bpf_insn.h 7 years ago
bpf_load.c 664e787845 samples/bpf: remove duplicated includes 6 years ago
bpf_load.h 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
cookie_uid_helper_example.c 8d93045077 samples: bpf: rename libbpf.h to bpf_insn.h 7 years ago
cpustat_kern.c c535077789 samples/bpf: Add program for CPU state statistics 7 years ago
cpustat_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
fds_example.c 8d93045077 samples: bpf: rename libbpf.h to bpf_insn.h 7 years ago
hash_func01.h 1139568658 samples/bpf: add Paul Hsieh's (LGPL 2.1) hash function SuperFastHash 7 years ago
lathist_kern.c 0fb1170ee6 bpf: BPF based latency tracing 10 years ago
lathist_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
load_sock_ops.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
lwt_len_hist.sh b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license 7 years ago
lwt_len_hist_kern.c f74599f7c5 bpf: Add tests and samples for LWT-BPF 8 years ago
lwt_len_hist_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
map_perf_test_kern.c 95ec669685 samples/bpf: Use getppid instead of getpgrp for array map stress 7 years ago
map_perf_test_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
offwaketime_kern.c 02413cabd6 bpf, samples: don't zero data when not needed 9 years ago
offwaketime_user.c 28dbf861de samples/bpf: move common-purpose trace functions to selftests 7 years ago
parse_ldabs.c 96a8eb1eee bpf: fix samples to add fake KBUILD_MODNAME 8 years ago
parse_simple.c 96a8eb1eee bpf: fix samples to add fake KBUILD_MODNAME 8 years ago
parse_varlen.c 4d5d33a085 samples/bpf: add missing <linux/if_vlan.h> 7 years ago
run_cookie_uid_helper_example.sh b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license 7 years ago
sampleip_kern.c 2dbb4c05d0 bpf/samples: Fix PT_REGS_IP on s390x and use it 8 years ago
sampleip_user.c 664e787845 samples/bpf: remove duplicated includes 6 years ago
sock_example.c 8d93045077 samples: bpf: rename libbpf.h to bpf_insn.h 7 years ago
sock_example.h 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
sock_flags_kern.c 0adc3dd900 samples/bpf: Update cgroup socket examples to use uid gid helper 8 years ago
sockex1_kern.c 614cd3bd37 samples: bpf: add skb->field examples and tests 10 years ago
sockex1_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
sockex2_kern.c 32c0097983 samples/bpf: fix compilation failure 6 years ago
sockex2_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
sockex3_kern.c 32c0097983 samples/bpf: fix compilation failure 6 years ago
sockex3_user.c 32c0097983 samples/bpf: fix compilation failure 6 years ago
spintest_kern.c 138d6153a1 samples/bpf: Enable powerpc support 9 years ago
spintest_user.c 28dbf861de samples/bpf: move common-purpose trace functions to selftests 7 years ago
syscall_nrs.c b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license 7 years ago
syscall_tp_kern.c 1da236b6be bpf: add a test case for syscalls/sys_{enter|exit}_* tracepoints 8 years ago
syscall_tp_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
task_fd_query_kern.c ecb96f7fe1 samples/bpf: add a samples/bpf test for BPF_TASK_FD_QUERY 7 years ago
task_fd_query_user.c ecb96f7fe1 samples/bpf: add a samples/bpf test for BPF_TASK_FD_QUERY 7 years ago
tc_l2_redirect.sh b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license 7 years ago
tc_l2_redirect_kern.c cdb749cef1 bpf: fix samples xdp_tx_iptunnel and tc_l2_redirect with fake KBUILD_MODNAME 8 years ago
tc_l2_redirect_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
tcbpf1_kern.c 96a8eb1eee bpf: fix samples to add fake KBUILD_MODNAME 8 years ago
tcp_basertt_kern.c c890063e44 bpf: sample BPF_SOCKET_OPS_BASE_RTT program 7 years ago
tcp_bpf.readme aaf151b9e6 bpf: Rename tcp_bbf.readme to tcp_bpf.readme 7 years ago
tcp_bufs_kern.c a4174f0560 bpf: Fix tcp_bufs_kern.c sample program 7 years ago
tcp_clamp_kern.c 03e982eed4 bpf: Fix tcp_clamp_kern.c sample program 7 years ago
tcp_cong_kern.c 2ff969fbe2 bpf: Fix tcp_cong_kern.c sample program 7 years ago
tcp_iw_kern.c e1853319fc bpf: Fix tcp_iw_kern.c sample program 7 years ago
tcp_rwnd_kern.c 016e661bb0 bpf: Fix tcp_rwnd_kern.c sample program 7 years ago
tcp_synrto_kern.c 7863f46bac bpf: Fix tcp_synrto_kern.c sample program 7 years ago
tcp_tos_reflect_kern.c acb4ea9564 bpf: add TCP_SAVE_SYN/TCP_SAVED_SYN sample program 7 years ago
test_cgrp2_array_pin.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
test_cgrp2_attach.c 8d93045077 samples: bpf: rename libbpf.h to bpf_insn.h 7 years ago
test_cgrp2_attach2.c 5fcbd29b37 samples/bpf: extend test_cgrp2_attach2 test to use per-cpu cgroup storage 6 years ago
test_cgrp2_sock.c 8d93045077 samples: bpf: rename libbpf.h to bpf_insn.h 7 years ago
test_cgrp2_sock.sh c8745e07d5 samples/bpf: detach prog from cgroup 7 years ago
test_cgrp2_sock2.c ee583014a9 samples/bpf: test_cgrp2_sock2: fix an off by one 7 years ago
test_cgrp2_sock2.sh c8745e07d5 samples/bpf: detach prog from cgroup 7 years ago
test_cgrp2_tc.sh b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license 7 years ago
test_cgrp2_tc_kern.c 96a8eb1eee bpf: fix samples to add fake KBUILD_MODNAME 8 years ago
test_cls_bpf.sh b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license 7 years ago
test_current_task_under_cgroup_kern.c 9e6e60ecbd samples/bpf: Add test_current_task_under_cgroup test 9 years ago
test_current_task_under_cgroup_user.c 664e787845 samples/bpf: remove duplicated includes 6 years ago
test_ipip.sh b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license 7 years ago
test_lru_dist.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
test_lwt_bpf.c f74599f7c5 bpf: Add tests and samples for LWT-BPF 8 years ago
test_lwt_bpf.sh b24413180f License cleanup: add SPDX GPL-2.0 license identifier to files with no license 7 years ago
test_map_in_map_kern.c fb30d4b712 bpf: Add tests for map-in-map 8 years ago
test_map_in_map_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
test_overhead_kprobe_kern.c e3edfdec04 samples/bpf: add tracepoint vs kprobe performance tests 9 years ago
test_overhead_raw_tp_kern.c 4662a4e538 samples/bpf: raw tracepoint test 7 years ago
test_overhead_tp_kern.c e3edfdec04 samples/bpf: add tracepoint vs kprobe performance tests 9 years ago
test_overhead_user.c 02a2f000a3 samples/bpf: Check the error of write() and read() 7 years ago
test_override_return.sh 965de87e54 samples/bpf: add a test for bpf_override_return 7 years ago
test_probe_write_user_kern.c cf9b1199de samples/bpf: Add test/example of using bpf_probe_write_user bpf helper 9 years ago
test_probe_write_user_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
trace_event_kern.c 12fe12253c samples/bpf: add example to test reading address 7 years ago
trace_event_user.c 492b7e8945 samples/bpf: Check the result of system() 7 years ago
trace_output_kern.c 569cc39d39 samples/bpf: fix trace_output example 9 years ago
trace_output_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
tracex1_kern.c 02413cabd6 bpf, samples: don't zero data when not needed 9 years ago
tracex1_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
tracex2_kern.c 02413cabd6 bpf, samples: don't zero data when not needed 9 years ago
tracex2_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
tracex3_kern.c 3059303f59 samples/bpf: update tracex[23] examples to use per-cpu maps 9 years ago
tracex3_user.c 20cdeb5408 bpf, tracex3_user: erase "ARRAY_SIZE" redefined 6 years ago
tracex4_kern.c 138d6153a1 samples/bpf: Enable powerpc support 9 years ago
tracex4_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
tracex5_kern.c 4b7190e841 samples/bpf: Fix tracex5 to work with MIPS syscalls. 8 years ago
tracex5_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
tracex6_kern.c 020a32d958 bpf: add a test case for helper bpf_perf_event_read_value 7 years ago
tracex6_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
tracex7_kern.c 965de87e54 samples/bpf: add a test for bpf_override_return 7 years ago
tracex7_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
xdp1_kern.c d9094bda5c bpf: make xdp sample variable names more meaningful 9 years ago
xdp1_user.c be5bca44aa samples: bpf: convert some XDP samples from bpf_load to libbpf 7 years ago
xdp2_kern.c d9094bda5c bpf: make xdp sample variable names more meaningful 9 years ago
xdp2skb_meta.sh b9626f45ab samples/bpf: Fix tc and ip paths in xdp2skb_meta.sh 7 years ago
xdp2skb_meta_kern.c e2e3224122 samples/bpf: xdp2skb_meta comment explain why pkt-data pointers are invalidated 7 years ago
xdp_adjust_tail_kern.c c6ffd1ff78 bpf: add bpf_xdp_adjust_tail sample prog 7 years ago
xdp_adjust_tail_user.c be5bca44aa samples: bpf: convert some XDP samples from bpf_load to libbpf 7 years ago
xdp_fwd_kern.c 4c79579b44 bpf: Change bpf_fib_lookup to return lookup status 7 years ago
xdp_fwd_user.c e1a40ef418 samples: bpf: convert xdp_fwd_user.c to libbpf 7 years ago
xdp_monitor_kern.c a570e48fee samples/bpf: xdp_monitor use err code from tracepoint xdp:xdp_devmap_xmit 7 years ago
xdp_monitor_user.c a570e48fee samples/bpf: xdp_monitor use err code from tracepoint xdp:xdp_devmap_xmit 7 years ago
xdp_redirect_cpu_kern.c c1617fb4c5 Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next 7 years ago
xdp_redirect_cpu_user.c 817b89beb9 samples/bpf: all XDP samples should unload xdp/bpf prog on SIGTERM 7 years ago
xdp_redirect_kern.c 3edcf18ec2 samples/bpf: Fix compilation issue in redirect dummy program 8 years ago
xdp_redirect_map_kern.c 3edcf18ec2 samples/bpf: Fix compilation issue in redirect dummy program 8 years ago
xdp_redirect_map_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
xdp_redirect_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
xdp_router_ipv4_kern.c 3e29cd0e65 xdp: Sample xdp program implementing ip forward 7 years ago
xdp_router_ipv4_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
xdp_rxq_info_kern.c 509fda105b samples/bpf: xdp_rxq_info action XDP_TX must adjust MAC-addrs 7 years ago
xdp_rxq_info_user.c 817b89beb9 samples/bpf: all XDP samples should unload xdp/bpf prog on SIGTERM 7 years ago
xdp_sample_pkts_kern.c 1e54ad251a samples/bpf: Add xdp_sample_pkts example 7 years ago
xdp_sample_pkts_user.c 1e54ad251a samples/bpf: Add xdp_sample_pkts example 7 years ago
xdp_tx_iptunnel_common.h 12d8bb64e3 bpf: xdp: Add XDP example for head adjustment 8 years ago
xdp_tx_iptunnel_kern.c cdb749cef1 bpf: fix samples xdp_tx_iptunnel and tc_l2_redirect with fake KBUILD_MODNAME 8 years ago
xdp_tx_iptunnel_user.c 2bf3e2ef42 samples: bpf: include bpf/bpf.h instead of local libbpf.h 7 years ago
xdpsock.h b4b8faa1de samples/bpf: sample application and documentation for AF_XDP sockets 7 years ago
xdpsock_kern.c 11c3f51136 samples/bpf: xdpsock, minor fixes 7 years ago
xdpsock_user.c 11c3f51136 samples/bpf: xdpsock, minor fixes 7 years ago

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