143448428SQuentin Monnet.. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 243448428SQuentin Monnet 37464d013SAndrii Nakryiko================ 47464d013SAndrii Nakryikobpftool-link 57464d013SAndrii Nakryiko================ 67464d013SAndrii Nakryiko------------------------------------------------------------------------------- 77464d013SAndrii Nakryikotool for inspection and simple manipulation of eBPF links 87464d013SAndrii Nakryiko------------------------------------------------------------------------------- 97464d013SAndrii Nakryiko 107464d013SAndrii Nakryiko:Manual section: 8 117464d013SAndrii Nakryiko 12*b6231815SQuentin Monnet.. include:: substitutions.rst 13*b6231815SQuentin Monnet 147464d013SAndrii NakryikoSYNOPSIS 157464d013SAndrii Nakryiko======== 167464d013SAndrii Nakryiko 177464d013SAndrii Nakryiko **bpftool** [*OPTIONS*] **link** *COMMAND* 187464d013SAndrii Nakryiko 19*b6231815SQuentin Monnet *OPTIONS* := { |COMMON_OPTIONS| | { **-f** | **--bpffs** } | { **-n** | **--nomount** } } 207464d013SAndrii Nakryiko 217464d013SAndrii Nakryiko *COMMANDS* := { **show** | **list** | **pin** | **help** } 227464d013SAndrii Nakryiko 237464d013SAndrii NakryikoLINK COMMANDS 247464d013SAndrii Nakryiko============= 257464d013SAndrii Nakryiko 267464d013SAndrii Nakryiko| **bpftool** **link { show | list }** [*LINK*] 277464d013SAndrii Nakryiko| **bpftool** **link pin** *LINK* *FILE* 281a7581b1SQuentin Monnet| **bpftool** **link detach** *LINK* 297464d013SAndrii Nakryiko| **bpftool** **link help** 307464d013SAndrii Nakryiko| 317464d013SAndrii Nakryiko| *LINK* := { **id** *LINK_ID* | **pinned** *FILE* } 327464d013SAndrii Nakryiko 337464d013SAndrii Nakryiko 347464d013SAndrii NakryikoDESCRIPTION 357464d013SAndrii Nakryiko=========== 367464d013SAndrii Nakryiko **bpftool link { show | list }** [*LINK*] 377464d013SAndrii Nakryiko Show information about active links. If *LINK* is 387464d013SAndrii Nakryiko specified show information only about given link, 397464d013SAndrii Nakryiko otherwise list all links currently active on the system. 407464d013SAndrii Nakryiko 417464d013SAndrii Nakryiko Output will start with link ID followed by link type and 427464d013SAndrii Nakryiko zero or more named attributes, some of which depend on type 437464d013SAndrii Nakryiko of link. 447464d013SAndrii Nakryiko 45075c7766SAndrii Nakryiko Since Linux 5.8 bpftool is able to discover information about 46075c7766SAndrii Nakryiko processes that hold open file descriptors (FDs) against BPF 47075c7766SAndrii Nakryiko links. On such kernels bpftool will automatically emit this 48075c7766SAndrii Nakryiko information as well. 49075c7766SAndrii Nakryiko 507464d013SAndrii Nakryiko **bpftool link pin** *LINK* *FILE* 517464d013SAndrii Nakryiko Pin link *LINK* as *FILE*. 527464d013SAndrii Nakryiko 537464d013SAndrii Nakryiko Note: *FILE* must be located in *bpffs* mount. It must not 547464d013SAndrii Nakryiko contain a dot character ('.'), which is reserved for future 557464d013SAndrii Nakryiko extensions of *bpffs*. 567464d013SAndrii Nakryiko 57e85f99aaSAndrii Nakryiko **bpftool link detach** *LINK* 58e85f99aaSAndrii Nakryiko Force-detach link *LINK*. BPF link and its underlying BPF 59e85f99aaSAndrii Nakryiko program will stay valid, but they will be detached from the 60e85f99aaSAndrii Nakryiko respective BPF hook and BPF link will transition into 61e85f99aaSAndrii Nakryiko a defunct state until last open file descriptor for that 62e85f99aaSAndrii Nakryiko link is closed. 63e85f99aaSAndrii Nakryiko 647464d013SAndrii Nakryiko **bpftool link help** 657464d013SAndrii Nakryiko Print short help message. 667464d013SAndrii Nakryiko 677464d013SAndrii NakryikoOPTIONS 687464d013SAndrii Nakryiko======= 69f28ef96dSQuentin Monnet .. include:: common_options.rst 707464d013SAndrii Nakryiko 717464d013SAndrii Nakryiko -f, --bpffs 727464d013SAndrii Nakryiko When showing BPF links, show file names of pinned 737464d013SAndrii Nakryiko links. 747464d013SAndrii Nakryiko 757464d013SAndrii Nakryiko -n, --nomount 767464d013SAndrii Nakryiko Do not automatically attempt to mount any virtual file system 777464d013SAndrii Nakryiko (such as tracefs or BPF virtual file system) when necessary. 787464d013SAndrii Nakryiko 797464d013SAndrii NakryikoEXAMPLES 807464d013SAndrii Nakryiko======== 817464d013SAndrii Nakryiko**# bpftool link show** 827464d013SAndrii Nakryiko 837464d013SAndrii Nakryiko:: 847464d013SAndrii Nakryiko 857464d013SAndrii Nakryiko 10: cgroup prog 25 867464d013SAndrii Nakryiko cgroup_id 614 attach_type egress 87075c7766SAndrii Nakryiko pids test_progs(223) 887464d013SAndrii Nakryiko 897464d013SAndrii Nakryiko**# bpftool --json --pretty link show** 907464d013SAndrii Nakryiko 917464d013SAndrii Nakryiko:: 927464d013SAndrii Nakryiko 937464d013SAndrii Nakryiko [{ 947464d013SAndrii Nakryiko "type": "cgroup", 957464d013SAndrii Nakryiko "prog_id": 25, 967464d013SAndrii Nakryiko "cgroup_id": 614, 97075c7766SAndrii Nakryiko "attach_type": "egress", 98075c7766SAndrii Nakryiko "pids": [{ 99075c7766SAndrii Nakryiko "pid": 223, 100075c7766SAndrii Nakryiko "comm": "test_progs" 101075c7766SAndrii Nakryiko } 102075c7766SAndrii Nakryiko ] 1037464d013SAndrii Nakryiko } 1047464d013SAndrii Nakryiko ] 1057464d013SAndrii Nakryiko 1067464d013SAndrii Nakryiko| 1077464d013SAndrii Nakryiko| **# bpftool link pin id 10 /sys/fs/bpf/link** 1087464d013SAndrii Nakryiko| **# ls -l /sys/fs/bpf/** 1097464d013SAndrii Nakryiko 1107464d013SAndrii Nakryiko:: 1117464d013SAndrii Nakryiko 1127464d013SAndrii Nakryiko -rw------- 1 root root 0 Apr 23 21:39 link 113