bpftool-link.rst 2.8 KB

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