Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
gnu/ | 22-Nov-2024 | - | 2 | 0 | ||
.gitignore | D | 22-Nov-2024 | 655 | 52 | 51 | |
Makefile | D | 22-Nov-2024 | 14.3 KiB | 417 | 330 | |
Makefile.target | D | 22-Nov-2024 | 2.5 KiB | 76 | 33 | |
README.rst | D | 22-Nov-2024 | 3.9 KiB | 122 | 86 | |
asm_goto_workaround.h | D | 22-Nov-2024 | 715 | 29 | 13 | |
bpf_insn.h | D | 22-Nov-2024 | 6.3 KiB | 234 | 158 | |
cookie_uid_helper_example.c | D | 22-Nov-2024 | 9.4 KiB | 333 | 244 | |
cpustat_kern.c | D | 22-Nov-2024 | 6.9 KiB | 281 | 140 | |
cpustat_user.c | D | 22-Nov-2024 | 5.7 KiB | 252 | 179 | |
do_hbm_test.sh | D | 22-Nov-2024 | 12 KiB | 439 | 392 | |
fds_example.c | D | 22-Nov-2024 | 4.3 KiB | 196 | 165 | |
hash_func01.h | D | 22-Nov-2024 | 1.3 KiB | 56 | 39 | |
hbm.c | D | 22-Nov-2024 | 13.6 KiB | 516 | 410 | |
hbm.h | D | 22-Nov-2024 | 1.2 KiB | 39 | 26 | |
hbm_edt_kern.c | D | 22-Nov-2024 | 5.3 KiB | 169 | 84 | |
hbm_kern.h | D | 22-Nov-2024 | 5.7 KiB | 216 | 182 | |
hbm_out_kern.c | D | 22-Nov-2024 | 5.5 KiB | 180 | 94 | |
ibumad_kern.c | D | 22-Nov-2024 | 2.9 KiB | 139 | 100 | |
ibumad_user.c | D | 22-Nov-2024 | 3.4 KiB | 159 | 122 | |
lathist_kern.c | D | 22-Nov-2024 | 2.1 KiB | 100 | 68 | |
lathist_user.c | D | 22-Nov-2024 | 2.6 KiB | 131 | 101 | |
lwt_len_hist.bpf.c | D | 22-Nov-2024 | 1.5 KiB | 63 | 41 | |
lwt_len_hist.sh | D | 22-Nov-2024 | 1 KiB | 41 | 31 | |
lwt_len_hist_user.c | D | 22-Nov-2024 | 1.6 KiB | 78 | 60 | |
map_perf_test.bpf.c | D | 22-Nov-2024 | 6.4 KiB | 298 | 247 | |
map_perf_test_user.c | D | 22-Nov-2024 | 11.6 KiB | 504 | 406 | |
net_shared.h | D | 22-Nov-2024 | 843 | 35 | 27 | |
offwaketime.bpf.c | D | 22-Nov-2024 | 3.3 KiB | 142 | 109 | |
offwaketime_user.c | D | 22-Nov-2024 | 3.2 KiB | 154 | 125 | |
parse_ldabs.c | D | 22-Nov-2024 | 1.2 KiB | 44 | 33 | |
parse_simple.c | D | 22-Nov-2024 | 1.3 KiB | 50 | 36 | |
parse_varlen.c | D | 22-Nov-2024 | 3.4 KiB | 151 | 122 | |
run_cookie_uid_helper_example.sh | D | 22-Nov-2024 | 341 | 16 | 11 | |
sampleip_kern.c | D | 22-Nov-2024 | 915 | 39 | 26 | |
sampleip_user.c | D | 22-Nov-2024 | 5 KiB | 235 | 185 | |
sock_example.c | D | 22-Nov-2024 | 2.9 KiB | 112 | 79 | |
sock_example.h | D | 22-Nov-2024 | 814 | 36 | 30 | |
sock_flags.bpf.c | D | 22-Nov-2024 | 1.1 KiB | 48 | 31 | |
sockex1_kern.c | D | 22-Nov-2024 | 661 | 31 | 25 | |
sockex1_user.c | D | 22-Nov-2024 | 1.4 KiB | 64 | 47 | |
sockex2_kern.c | D | 22-Nov-2024 | 4.8 KiB | 224 | 190 | |
sockex2_user.c | D | 22-Nov-2024 | 1.3 KiB | 63 | 50 | |
sockex3_kern.c | D | 22-Nov-2024 | 6.5 KiB | 305 | 238 | |
sockex3_user.c | D | 22-Nov-2024 | 2.2 KiB | 101 | 80 | |
spintest.bpf.c | D | 22-Nov-2024 | 1.7 KiB | 61 | 45 | |
spintest_user.c | D | 22-Nov-2024 | 1.8 KiB | 85 | 72 | |
syscall_nrs.c | D | 22-Nov-2024 | 337 | 20 | 15 | |
syscall_tp_kern.c | D | 22-Nov-2024 | 1.9 KiB | 103 | 86 | |
syscall_tp_user.c | D | 22-Nov-2024 | 3.4 KiB | 156 | 116 | |
task_fd_query_kern.c | D | 22-Nov-2024 | 412 | 20 | 16 | |
task_fd_query_user.c | D | 22-Nov-2024 | 11.3 KiB | 424 | 360 | |
tc_l2_redirect.sh | D | 22-Nov-2024 | 5.1 KiB | 178 | 138 | |
tc_l2_redirect_kern.c | D | 22-Nov-2024 | 6 KiB | 238 | 182 | |
tc_l2_redirect_user.c | D | 22-Nov-2024 | 1.3 KiB | 71 | 56 | |
tcbpf1_kern.c | D | 22-Nov-2024 | 2.6 KiB | 92 | 76 | |
tcp_basertt_kern.c | D | 22-Nov-2024 | 1.7 KiB | 72 | 49 | |
tcp_bpf.readme | D | 22-Nov-2024 | 1.1 KiB | 29 | 21 | |
tcp_bufs_kern.c | D | 22-Nov-2024 | 2.1 KiB | 82 | 52 | |
tcp_clamp_kern.c | D | 22-Nov-2024 | 2.7 KiB | 98 | 68 | |
tcp_cong_kern.c | D | 22-Nov-2024 | 1.9 KiB | 79 | 53 | |
tcp_dumpstats_kern.c | D | 22-Nov-2024 | 1.3 KiB | 69 | 51 | |
tcp_iw_kern.c | D | 22-Nov-2024 | 2.2 KiB | 84 | 55 | |
tcp_rwnd_kern.c | D | 22-Nov-2024 | 1.7 KiB | 65 | 36 | |
tcp_synrto_kern.c | D | 22-Nov-2024 | 1.7 KiB | 65 | 36 | |
tcp_tos_reflect_kern.c | D | 22-Nov-2024 | 1.8 KiB | 81 | 67 | |
test_cgrp2_array_pin.c | D | 22-Nov-2024 | 2.1 KiB | 107 | 91 | |
test_cgrp2_attach.c | D | 22-Nov-2024 | 4.6 KiB | 178 | 130 | |
test_cgrp2_sock.c | D | 22-Nov-2024 | 6.3 KiB | 295 | 228 | |
test_cgrp2_sock.sh | D | 22-Nov-2024 | 2.9 KiB | 138 | 88 | |
test_cgrp2_sock2.c | D | 22-Nov-2024 | 2 KiB | 96 | 70 | |
test_cgrp2_sock2.sh | D | 22-Nov-2024 | 1.9 KiB | 104 | 81 | |
test_cgrp2_tc.bpf.c | D | 22-Nov-2024 | 1.5 KiB | 57 | 42 | |
test_cgrp2_tc.sh | D | 22-Nov-2024 | 4.3 KiB | 188 | 160 | |
test_cls_bpf.sh | D | 22-Nov-2024 | 915 | 39 | 31 | |
test_current_task_under_cgroup.bpf.c | D | 22-Nov-2024 | 1.1 KiB | 44 | 29 | |
test_current_task_under_cgroup_user.c | D | 22-Nov-2024 | 2.4 KiB | 116 | 82 | |
test_lru_dist.c | D | 22-Nov-2024 | 11.8 KiB | 535 | 417 | |
test_lwt_bpf.c | D | 22-Nov-2024 | 5.8 KiB | 246 | 186 | |
test_lwt_bpf.sh | D | 22-Nov-2024 | 9.2 KiB | 406 | 353 | |
test_map_in_map.bpf.c | D | 22-Nov-2024 | 3.8 KiB | 173 | 127 | |
test_map_in_map_user.c | D | 22-Nov-2024 | 4.3 KiB | 169 | 131 | |
test_overhead_kprobe.bpf.c | D | 22-Nov-2024 | 1 KiB | 42 | 30 | |
test_overhead_raw_tp.bpf.c | D | 22-Nov-2024 | 358 | 18 | 13 | |
test_overhead_tp.bpf.c | D | 22-Nov-2024 | 658 | 24 | 13 | |
test_overhead_user.c | D | 22-Nov-2024 | 4.5 KiB | 226 | 188 | |
test_override_return.sh | D | 22-Nov-2024 | 276 | 17 | 14 | |
test_probe_write_user.bpf.c | D | 22-Nov-2024 | 1.6 KiB | 53 | 32 | |
test_probe_write_user_user.c | D | 22-Nov-2024 | 3.3 KiB | 109 | 85 | |
trace_event_kern.c | D | 22-Nov-2024 | 2.3 KiB | 80 | 62 | |
trace_event_user.c | D | 22-Nov-2024 | 7.8 KiB | 353 | 288 | |
trace_output.bpf.c | D | 22-Nov-2024 | 589 | 30 | 23 | |
trace_output_user.c | D | 22-Nov-2024 | 2.2 KiB | 106 | 85 | |
tracex1.bpf.c | D | 22-Nov-2024 | 1.4 KiB | 48 | 25 | |
tracex1_user.c | D | 22-Nov-2024 | 1.1 KiB | 51 | 40 | |
tracex3.bpf.c | D | 22-Nov-2024 | 2.2 KiB | 101 | 68 | |
tracex3_user.c | D | 22-Nov-2024 | 3.7 KiB | 184 | 156 | |
tracex4.bpf.c | D | 22-Nov-2024 | 1.2 KiB | 55 | 36 | |
tracex4_user.c | D | 22-Nov-2024 | 2 KiB | 97 | 76 | |
tracex5.bpf.c | D | 22-Nov-2024 | 2.2 KiB | 94 | 70 | |
tracex5_user.c | D | 22-Nov-2024 | 2.3 KiB | 99 | 78 | |
tracex6.bpf.c | D | 22-Nov-2024 | 1.9 KiB | 82 | 62 | |
tracex6_user.c | D | 22-Nov-2024 | 5.5 KiB | 223 | 188 | |
tracex7.bpf.c | D | 22-Nov-2024 | 301 | 16 | 12 | |
tracex7_user.c | D | 22-Nov-2024 | 1.2 KiB | 57 | 46 | |
xdp2skb_meta.sh | D | 22-Nov-2024 | 4.5 KiB | 221 | 168 | |
xdp2skb_meta_kern.c | D | 22-Nov-2024 | 3 KiB | 106 | 36 | |
xdp_adjust_tail_kern.c | D | 22-Nov-2024 | 3.8 KiB | 156 | 120 | |
xdp_adjust_tail_user.c | D | 22-Nov-2024 | 4.6 KiB | 199 | 157 | |
xdp_fwd_kern.c | D | 22-Nov-2024 | 4.5 KiB | 159 | 98 | |
xdp_fwd_user.c | D | 22-Nov-2024 | 5.2 KiB | 227 | 179 | |
xdp_router_ipv4.bpf.c | D | 22-Nov-2024 | 4 KiB | 190 | 143 | |
xdp_router_ipv4_user.c | D | 22-Nov-2024 | 17 KiB | 700 | 618 | |
xdp_sample.bpf.c | D | 22-Nov-2024 | 7.1 KiB | 267 | 207 | |
xdp_sample.bpf.h | D | 22-Nov-2024 | 3.3 KiB | 122 | 87 | |
xdp_sample_shared.h | D | 22-Nov-2024 | 295 | 18 | 14 | |
xdp_sample_user.c | D | 22-Nov-2024 | 42.4 KiB | 1,674 | 1,416 | |
xdp_sample_user.h | D | 22-Nov-2024 | 4.4 KiB | 111 | 96 | |
xdp_tx_iptunnel_common.h | D | 22-Nov-2024 | 485 | 35 | 26 | |
xdp_tx_iptunnel_kern.c | D | 22-Nov-2024 | 5.6 KiB | 238 | 180 | |
xdp_tx_iptunnel_user.c | D | 22-Nov-2024 | 7.4 KiB | 311 | 264 |
README.rst
1eBPF sample programs 2==================== 3 4This directory contains a test stubs, verifier test-suite and examples 5for using eBPF. The examples use libbpf from tools/lib/bpf. 6 7Note that the XDP-specific samples have been removed from this directory and 8moved to the xdp-tools repository: https://github.com/xdp-project/xdp-tools 9See the commit messages removing each tool from this directory for how to 10convert specific command invocations between the old samples and the utilities 11in xdp-tools. 12 13Build dependencies 14================== 15 16Compiling requires having installed: 17 * clang 18 * llvm 19 * pahole 20 21Consult :ref:`Documentation/process/changes.rst <changes>` for the minimum 22version numbers required and how to update them. Note that LLVM's tool 23'llc' must support target 'bpf', list version and supported targets with 24command: ``llc --version`` 25 26Clean and configuration 27----------------------- 28 29It can be needed to clean tools, samples or kernel before trying new arch or 30after some changes (on demand):: 31 32 make -C tools clean 33 make -C samples/bpf clean 34 make clean 35 36Configure kernel, defconfig for instance 37(see "tools/testing/selftests/bpf/config" for a reference config):: 38 39 make defconfig 40 41Kernel headers 42-------------- 43 44There are usually dependencies to header files of the current kernel. 45To avoid installing devel kernel headers system wide, as a normal 46user, simply call:: 47 48 make headers_install 49 50This will create a local "usr/include" directory in the git/build top 51level directory, that the make system will automatically pick up first. 52 53Compiling 54========= 55 56For building the BPF samples, issue the below command from the kernel 57top level directory:: 58 59 make M=samples/bpf 60 61It is also possible to call make from this directory. This will just 62hide the invocation of make as above. 63 64Manually compiling LLVM with 'bpf' support 65------------------------------------------ 66 67Since version 3.7.0, LLVM adds a proper LLVM backend target for the 68BPF bytecode architecture. 69 70By default llvm will build all non-experimental backends including bpf. 71To generate a smaller llc binary one can use:: 72 73 -DLLVM_TARGETS_TO_BUILD="BPF" 74 75We recommend that developers who want the fastest incremental builds 76use the Ninja build system, you can find it in your system's package 77manager, usually the package is ninja or ninja-build. 78 79Quick sniplet for manually compiling LLVM and clang 80(build dependencies are ninja, cmake and gcc-c++):: 81 82 $ git clone https://github.com/llvm/llvm-project.git 83 $ mkdir -p llvm-project/llvm/build 84 $ cd llvm-project/llvm/build 85 $ cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \ 86 -DLLVM_ENABLE_PROJECTS="clang" \ 87 -DCMAKE_BUILD_TYPE=Release \ 88 -DLLVM_BUILD_RUNTIME=OFF 89 $ ninja 90 91It is also possible to point make to the newly compiled 'llc' or 92'clang' command via redefining LLC or CLANG on the make command line:: 93 94 make M=samples/bpf LLC=~/git/llvm-project/llvm/build/bin/llc CLANG=~/git/llvm-project/llvm/build/bin/clang 95 96Cross compiling samples 97----------------------- 98In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH 99environment variables before calling make. But do this before clean, 100configuration and header install steps described above. This will direct make to 101build samples for the cross target:: 102 103 export ARCH=arm64 104 export CROSS_COMPILE="aarch64-linux-gnu-" 105 106Headers can be also installed on RFS of target board if need to keep them in 107sync (not necessarily and it creates a local "usr/include" directory also):: 108 109 make INSTALL_HDR_PATH=~/some_sysroot/usr headers_install 110 111Pointing LLC and CLANG is not necessarily if it's installed on HOST and have 112in its targets appropriate arm64 arch (usually it has several arches). 113Build samples:: 114 115 make M=samples/bpf 116 117Or build samples with SYSROOT if some header or library is absent in toolchain, 118say libelf, providing address to file system containing headers and libs, 119can be RFS of target board:: 120 121 make M=samples/bpf SYSROOT=~/some_sysroot 122
tcp_bpf.readme
1This file describes how to run the tcp_*_kern.o tcp_bpf (or socket_ops) 2programs. These programs attach to a cgroupv2. The following commands create 3a cgroupv2 and attach a bash shell to the group. 4 5 mkdir -p /tmp/cgroupv2 6 mount -t cgroup2 none /tmp/cgroupv2 7 mkdir -p /tmp/cgroupv2/foo 8 bash 9 echo $$ >> /tmp/cgroupv2/foo/cgroup.procs 10 11Anything that runs under this shell belongs to the foo cgroupv2. To load 12(attach) one of the tcp_*_kern.o programs: 13 14 bpftool prog load tcp_basertt_kern.o /sys/fs/bpf/tcp_prog 15 bpftool cgroup attach /tmp/cgroupv2/foo sock_ops pinned /sys/fs/bpf/tcp_prog 16 bpftool prog tracelog 17 18"bpftool prog tracelog" will continue to run printing the BPF log buffer. 19The tcp_*_kern.o programs use special print functions to print logging 20information (if enabled by the ifdef). 21 22If using netperf/netserver to create traffic, you need to run them under the 23cgroupv2 to which the BPF programs are attached (i.e. under bash shell 24attached to the cgroupv2). 25 26To remove (unattach) a socket_ops BPF program from a cgroupv2: 27 28 bpftool cgroup detach /tmp/cgroupv2/foo sock_ops pinned /sys/fs/bpf/tcp_prog 29