Name Date Size #Lines LOC

..05-Apr-2024-

gnu/H05-Apr-2024-20

.gitignoreH A D05-Apr-2024655 5251

MakefileH A D05-Apr-202413.8 KiB405322

Makefile.targetH A D07-Mar-20212.5 KiB7633

README.rstH A D05-Apr-20243.9 KiB12286

asm_goto_workaround.hH A D05-Apr-2024715 2913

bpf_insn.hH A D24-May-20226.3 KiB234158

cookie_uid_helper_example.cH A D05-Apr-20249.4 KiB333244

cpustat_kern.cH A D05-Apr-20247 KiB282141

cpustat_user.cH A D05-Apr-20245.7 KiB252179

do_hbm_test.shH A D24-May-202212 KiB439392

fds_example.cH A D05-Apr-20244.3 KiB196165

hash_func01.hH A D07-Mar-20211.3 KiB5639

hbm.cH A D05-Apr-202413.6 KiB516410

hbm.hH A D07-Mar-20211.2 KiB3926

hbm_edt_kern.cH A D05-Apr-20245.3 KiB16984

hbm_kern.hH A D24-May-20225.7 KiB216182

hbm_out_kern.cH A D07-Mar-20215.5 KiB18094

ibumad_kern.cH A D05-Apr-20242.9 KiB139100

ibumad_user.cH A D05-Apr-20243.4 KiB159122

lathist_kern.cH A D08-Mar-20212.1 KiB10068

lathist_user.cH A D08-Mar-20212.6 KiB131101

lwt_len_hist.bpf.cH A D05-Apr-20241.5 KiB6341

lwt_len_hist.shH A D05-Apr-20241 KiB4131

lwt_len_hist_user.cH A D07-Mar-20211.6 KiB7860

map_perf_test.bpf.cH A D05-Apr-20246.4 KiB298247

map_perf_test_user.cH A D05-Apr-202411.5 KiB504406

net_shared.hH A D05-Apr-2024843 3527

offwaketime.bpf.cH A D05-Apr-20243.3 KiB142109

offwaketime_user.cH A D05-Apr-20243.2 KiB154125

parse_ldabs.cH A D07-Mar-20211.2 KiB4433

parse_simple.cH A D07-Mar-20211.3 KiB5036

parse_varlen.cH A D07-Mar-20213.4 KiB151122

run_cookie_uid_helper_example.shH A D07-Mar-2021341 1611

sampleip_kern.cH A D24-May-2022915 3926

sampleip_user.cH A D05-Apr-20245 KiB235185

sock_example.cH A D05-Apr-20242.9 KiB11279

sock_example.hH A D07-Mar-2021814 3630

sock_flags.bpf.cH A D05-Apr-20241.1 KiB4831

sockex1_kern.cH A D07-Mar-2021661 3125

sockex1_user.cH A D05-Apr-20241.4 KiB6447

sockex2_kern.cH A D07-Mar-20214.8 KiB224190

sockex2_user.cH A D05-Apr-20241.3 KiB6350

sockex3_kern.cH A D05-Apr-20246.5 KiB305238

sockex3_user.cH A D05-Apr-20242.2 KiB10180

spintest.bpf.cH A D05-Apr-20241.7 KiB6145

spintest_user.cH A D05-Apr-20241.8 KiB8572

syscall_nrs.cH A D07-Mar-2021337 2015

syscall_tp_kern.cH A D05-Apr-20241.8 KiB9276

syscall_tp_user.cH A D05-Apr-20243.4 KiB156116

task_fd_query_kern.cH A D05-Apr-2024412 2016

task_fd_query_user.cH A D05-Apr-202411.3 KiB424360

tc_l2_redirect.shH A D05-Apr-20245.1 KiB178138

tc_l2_redirect_kern.cH A D07-Mar-20216 KiB238182

tc_l2_redirect_user.cH A D07-Mar-20211.3 KiB7156

tcbpf1_kern.cH A D07-Mar-20212.6 KiB9276

tcp_basertt_kern.cH A D05-Apr-20241.7 KiB7249

tcp_bpf.readmeH A D07-Mar-20211.1 KiB2921

tcp_bufs_kern.cH A D07-Mar-20212.1 KiB8252

tcp_clamp_kern.cH A D07-Mar-20212.7 KiB9868

tcp_cong_kern.cH A D07-Mar-20211.9 KiB7953

tcp_dumpstats_kern.cH A D07-Mar-20211.3 KiB6951

tcp_iw_kern.cH A D07-Mar-20212.2 KiB8455

tcp_rwnd_kern.cH A D07-Mar-20211.7 KiB6536

tcp_synrto_kern.cH A D07-Mar-20211.7 KiB6536

tcp_tos_reflect_kern.cH A D07-Mar-20211.8 KiB8167

test_cgrp2_array_pin.cH A D05-Apr-20242.1 KiB10791

test_cgrp2_attach.cH A D05-Apr-20244.6 KiB178130

test_cgrp2_sock.cH A D05-Apr-20246.3 KiB295228

test_cgrp2_sock.shH A D05-Apr-20242.9 KiB13888

test_cgrp2_sock2.cH A D24-May-20222 KiB9670

test_cgrp2_sock2.shH A D05-Apr-20241.9 KiB10481

test_cgrp2_tc.bpf.cH A D05-Apr-20241.5 KiB5742

test_cgrp2_tc.shH A D05-Apr-20244.3 KiB188160

test_cls_bpf.shH A D07-Mar-2021915 3931

test_current_task_under_cgroup.bpf.cH A D05-Apr-20241.1 KiB4429

test_current_task_under_cgroup_user.cH A D05-Apr-20242.4 KiB11682

test_lru_dist.cH A D05-Apr-202411.8 KiB535417

test_lwt_bpf.cH A D05-Apr-20245.8 KiB246186

test_lwt_bpf.shH A D05-Apr-20249.2 KiB406353

test_map_in_map.bpf.cH A D05-Apr-20243.8 KiB173127

test_map_in_map_user.cH A D05-Apr-20244.3 KiB169131

test_overhead_kprobe.bpf.cH A D05-Apr-20241 KiB4230

test_overhead_raw_tp.bpf.cH A D05-Apr-2024358 1813

test_overhead_tp.bpf.cH A D05-Apr-2024658 2413

test_overhead_user.cH A D05-Apr-20244.5 KiB226188

test_override_return.shH A D20-Sep-2021276 1714

test_probe_write_user.bpf.cH A D05-Apr-20241.6 KiB5332

test_probe_write_user_user.cH A D05-Apr-20243.3 KiB10985

trace_event_kern.cH A D24-May-20222.3 KiB8062

trace_event_user.cH A D24-May-20227.8 KiB353288

trace_output.bpf.cH A D05-Apr-2024589 3023

trace_output_user.cH A D05-Apr-20242.2 KiB10685

tracex1.bpf.cH A D05-Apr-20241.4 KiB4825

tracex1_user.cH A D05-Apr-20241.1 KiB5140

tracex2.bpf.cH A D05-Apr-20242.3 KiB10075

tracex2_user.cH A D05-Apr-20244 KiB188153

tracex3.bpf.cH A D05-Apr-20242.2 KiB10168

tracex3_user.cH A D05-Apr-20243.7 KiB184156

tracex4.bpf.cH A D05-Apr-20241.2 KiB5536

tracex4_user.cH A D05-Apr-20242 KiB9776

tracex5.bpf.cH A D05-Apr-20242.2 KiB9470

tracex5_user.cH A D05-Apr-20242.3 KiB9978

tracex6.bpf.cH A D05-Apr-20241.9 KiB8262

tracex6_user.cH A D05-Apr-20245.5 KiB223188

tracex7.bpf.cH A D05-Apr-2024301 1612

tracex7_user.cH A D05-Apr-20241.2 KiB5746

xdp2skb_meta.shH A D07-Mar-20214.5 KiB221168

xdp2skb_meta_kern.cH A D24-May-20223 KiB10636

xdp_adjust_tail_kern.cH A D07-Mar-20213.8 KiB156120

xdp_adjust_tail_user.cH A D05-Apr-20244.6 KiB199157

xdp_fwd_kern.cH A D07-Mar-20214.5 KiB15998

xdp_fwd_user.cH A D05-Apr-20245.2 KiB227179

xdp_router_ipv4.bpf.cH A D05-Apr-20244 KiB190143

xdp_router_ipv4_user.cH A D05-Apr-202417 KiB700618

xdp_sample.bpf.cH A D24-May-20227.1 KiB267207

xdp_sample.bpf.hH A D05-Apr-20243.3 KiB12287

xdp_sample_shared.hH A D24-May-2022295 1814

xdp_sample_user.cH A D05-Apr-202442.4 KiB1,6741,416

xdp_sample_user.hH A D05-Apr-20244.4 KiB11196

xdp_tx_iptunnel_common.hH A D07-Mar-2021485 3526

xdp_tx_iptunnel_kern.cH A D05-Apr-20245.6 KiB238180

xdp_tx_iptunnel_user.cH A D05-Apr-20247.4 KiB311264

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