bpftool-link.rst 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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
  27. specified show information only about given link,
  28. otherwise list all links currently active on the system.
  29. Output will start with link ID followed by link type and
  30. zero or more named attributes, some of which depend on type
  31. of link.
  32. Since Linux 5.8 bpftool is able to discover information about
  33. processes that hold open file descriptors (FDs) against BPF
  34. links. On such kernels bpftool will automatically emit this
  35. information as well.
  36. **bpftool link pin** *LINK* *FILE*
  37. Pin link *LINK* as *FILE*.
  38. Note: *FILE* must be located in *bpffs* mount. It must not
  39. contain a dot character ('.'), which is reserved for future
  40. extensions of *bpffs*.
  41. **bpftool link detach** *LINK*
  42. Force-detach link *LINK*. BPF link and its underlying BPF
  43. program will stay valid, but they will be detached from the
  44. respective BPF hook and BPF link will transition into
  45. a defunct state until last open file descriptor for that
  46. link is closed.
  47. **bpftool link help**
  48. Print short help message.
  49. OPTIONS
  50. =======
  51. .. include:: common_options.rst
  52. -f, --bpffs
  53. When showing BPF links, show file names of pinned
  54. links.
  55. -n, --nomount
  56. Do not automatically attempt to mount any virtual file system
  57. (such as tracefs or BPF virtual file system) when necessary.
  58. EXAMPLES
  59. ========
  60. **# bpftool link show**
  61. ::
  62. 10: cgroup prog 25
  63. cgroup_id 614 attach_type egress
  64. pids test_progs(223)
  65. **# bpftool --json --pretty link show**
  66. ::
  67. [{
  68. "type": "cgroup",
  69. "prog_id": 25,
  70. "cgroup_id": 614,
  71. "attach_type": "egress",
  72. "pids": [{
  73. "pid": 223,
  74. "comm": "test_progs"
  75. }
  76. ]
  77. }
  78. ]
  79. |
  80. | **# bpftool link pin id 10 /sys/fs/bpf/link**
  81. | **# ls -l /sys/fs/bpf/**
  82. ::
  83. -rw------- 1 root root 0 Apr 23 21:39 link