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