1================
2bpftool-link
3================
4-------------------------------------------------------------------------------
5tool for inspection and simple manipulation of eBPF links
6-------------------------------------------------------------------------------
7
8:Manual section: 8
9
10SYNOPSIS
11========
12
13	**bpftool** [*OPTIONS*] **link** *COMMAND*
14
15	*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-d** | **--debug** } |
16		{ **-f** | **--bpffs** } | { **-n** | **--nomount** } }
17
18	*COMMANDS* := { **show** | **list** | **pin** | **help** }
19
20LINK COMMANDS
21=============
22
23|	**bpftool** **link { show | list }** [*LINK*]
24|	**bpftool** **link pin** *LINK* *FILE*
25|	**bpftool** **link detach** *LINK*
26|	**bpftool** **link help**
27|
28|	*LINK* := { **id** *LINK_ID* | **pinned** *FILE* }
29
30
31DESCRIPTION
32===========
33	**bpftool link { show | list }** [*LINK*]
34		  Show information about active links. If *LINK* is
35		  specified show information only about given link,
36		  otherwise list all links currently active on the system.
37
38		  Output will start with link ID followed by link type and
39		  zero or more named attributes, some of which depend on type
40		  of link.
41
42		  Since Linux 5.8 bpftool is able to discover information about
43		  processes that hold open file descriptors (FDs) against BPF
44		  links. On such kernels bpftool will automatically emit this
45		  information as well.
46
47	**bpftool link pin** *LINK* *FILE*
48		  Pin link *LINK* as *FILE*.
49
50		  Note: *FILE* must be located in *bpffs* mount. It must not
51		  contain a dot character ('.'), which is reserved for future
52		  extensions of *bpffs*.
53
54	**bpftool link detach** *LINK*
55		  Force-detach link *LINK*. BPF link and its underlying BPF
56		  program will stay valid, but they will be detached from the
57		  respective BPF hook and BPF link will transition into
58		  a defunct state until last open file descriptor for that
59		  link is closed.
60
61	**bpftool link help**
62		  Print short help message.
63
64OPTIONS
65=======
66	.. include:: common_options.rst
67
68	-f, --bpffs
69		  When showing BPF links, show file names of pinned
70		  links.
71
72	-n, --nomount
73		  Do not automatically attempt to mount any virtual file system
74		  (such as tracefs or BPF virtual file system) when necessary.
75
76EXAMPLES
77========
78**# bpftool link show**
79
80::
81
82    10: cgroup  prog 25
83            cgroup_id 614  attach_type egress
84            pids test_progs(223)
85
86**# bpftool --json --pretty link show**
87
88::
89
90    [{
91            "type": "cgroup",
92            "prog_id": 25,
93            "cgroup_id": 614,
94            "attach_type": "egress",
95            "pids": [{
96                    "pid": 223,
97                    "comm": "test_progs"
98                }
99            ]
100        }
101    ]
102
103|
104| **# bpftool link pin id 10 /sys/fs/bpf/link**
105| **# ls -l /sys/fs/bpf/**
106
107::
108
109    -rw------- 1 root root 0 Apr 23 21:39 link
110