bpftool-cgroup.rst 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. .. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
  2. ================
  3. bpftool-cgroup
  4. ================
  5. -------------------------------------------------------------------------------
  6. tool for inspection and simple manipulation of eBPF progs
  7. -------------------------------------------------------------------------------
  8. :Manual section: 8
  9. .. include:: substitutions.rst
  10. SYNOPSIS
  11. ========
  12. **bpftool** [*OPTIONS*] **cgroup** *COMMAND*
  13. *OPTIONS* := { |COMMON_OPTIONS| | { **-f** | **--bpffs** } }
  14. *COMMANDS* :=
  15. { **show** | **list** | **tree** | **attach** | **detach** | **help** }
  16. CGROUP COMMANDS
  17. ===============
  18. | **bpftool** **cgroup** { **show** | **list** } *CGROUP* [**effective**]
  19. | **bpftool** **cgroup tree** [*CGROUP_ROOT*] [**effective**]
  20. | **bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
  21. | **bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
  22. | **bpftool** **cgroup help**
  23. |
  24. | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* }
  25. | *ATTACH_TYPE* := { **cgroup_inet_ingress** | **cgroup_inet_egress** |
  26. | **cgroup_inet_sock_create** | **cgroup_sock_ops** |
  27. | **cgroup_device** | **cgroup_inet4_bind** | **cgroup_inet6_bind** |
  28. | **cgroup_inet4_post_bind** | **cgroup_inet6_post_bind** |
  29. | **cgroup_inet4_connect** | **cgroup_inet6_connect** |
  30. | **cgroup_unix_connect** | **cgroup_inet4_getpeername** |
  31. | **cgroup_inet6_getpeername** | **cgroup_unix_getpeername** |
  32. | **cgroup_inet4_getsockname** | **cgroup_inet6_getsockname** |
  33. | **cgroup_unix_getsockname** | **cgroup_udp4_sendmsg** |
  34. | **cgroup_udp6_sendmsg** | **cgroup_unix_sendmsg** |
  35. | **cgroup_udp4_recvmsg** | **cgroup_udp6_recvmsg** |
  36. | **cgroup_unix_recvmsg** | **cgroup_sysctl** |
  37. | **cgroup_getsockopt** | **cgroup_setsockopt** |
  38. | **cgroup_inet_sock_release** }
  39. | *ATTACH_FLAGS* := { **multi** | **override** }
  40. DESCRIPTION
  41. ===========
  42. bpftool cgroup { show | list } *CGROUP* [effective]
  43. List all programs attached to the cgroup *CGROUP*.
  44. Output will start with program ID followed by attach type, attach flags and
  45. program name.
  46. If **effective** is specified retrieve effective programs that will execute
  47. for events within a cgroup. This includes inherited along with attached
  48. ones.
  49. bpftool cgroup tree [*CGROUP_ROOT*] [effective]
  50. Iterate over all cgroups in *CGROUP_ROOT* and list all attached programs.
  51. If *CGROUP_ROOT* is not specified, bpftool uses cgroup v2 mountpoint.
  52. The output is similar to the output of cgroup show/list commands: it starts
  53. with absolute cgroup path, followed by program ID, attach type, attach
  54. flags and program name.
  55. If **effective** is specified retrieve effective programs that will execute
  56. for events within a cgroup. This includes inherited along with attached
  57. ones.
  58. bpftool cgroup attach *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
  59. Attach program *PROG* to the cgroup *CGROUP* with attach type *ATTACH_TYPE*
  60. and optional *ATTACH_FLAGS*.
  61. *ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs some
  62. bpf program, the program in this cgroup yields to sub-cgroup program;
  63. **multi** if a sub-cgroup installs some bpf program, that cgroup program
  64. gets run in addition to the program in this cgroup.
  65. Only one program is allowed to be attached to a cgroup with no attach flags
  66. or the **override** flag. Attaching another program will release old
  67. program and attach the new one.
  68. Multiple programs are allowed to be attached to a cgroup with **multi**.
  69. They are executed in FIFO order (those that were attached first, run
  70. first).
  71. Non-default *ATTACH_FLAGS* are supported by kernel version 4.14 and later.
  72. *ATTACH_TYPE* can be one of:
  73. - **ingress** ingress path of the inet socket (since 4.10)
  74. - **egress** egress path of the inet socket (since 4.10)
  75. - **sock_create** opening of an inet socket (since 4.10)
  76. - **sock_ops** various socket operations (since 4.12)
  77. - **device** device access (since 4.15)
  78. - **bind4** call to bind(2) for an inet4 socket (since 4.17)
  79. - **bind6** call to bind(2) for an inet6 socket (since 4.17)
  80. - **post_bind4** return from bind(2) for an inet4 socket (since 4.17)
  81. - **post_bind6** return from bind(2) for an inet6 socket (since 4.17)
  82. - **connect4** call to connect(2) for an inet4 socket (since 4.17)
  83. - **connect6** call to connect(2) for an inet6 socket (since 4.17)
  84. - **connect_unix** call to connect(2) for a unix socket (since 6.7)
  85. - **sendmsg4** call to sendto(2), sendmsg(2), sendmmsg(2) for an unconnected udp4 socket (since 4.18)
  86. - **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an unconnected udp6 socket (since 4.18)
  87. - **sendmsg_unix** call to sendto(2), sendmsg(2), sendmmsg(2) for an unconnected unix socket (since 6.7)
  88. - **recvmsg4** call to recvfrom(2), recvmsg(2), recvmmsg(2) for an unconnected udp4 socket (since 5.2)
  89. - **recvmsg6** call to recvfrom(2), recvmsg(2), recvmmsg(2) for an unconnected udp6 socket (since 5.2)
  90. - **recvmsg_unix** call to recvfrom(2), recvmsg(2), recvmmsg(2) for an unconnected unix socket (since 6.7)
  91. - **sysctl** sysctl access (since 5.2)
  92. - **getsockopt** call to getsockopt (since 5.3)
  93. - **setsockopt** call to setsockopt (since 5.3)
  94. - **getpeername4** call to getpeername(2) for an inet4 socket (since 5.8)
  95. - **getpeername6** call to getpeername(2) for an inet6 socket (since 5.8)
  96. - **getpeername_unix** call to getpeername(2) for a unix socket (since 6.7)
  97. - **getsockname4** call to getsockname(2) for an inet4 socket (since 5.8)
  98. - **getsockname6** call to getsockname(2) for an inet6 socket (since 5.8)
  99. - **getsockname_unix** call to getsockname(2) for a unix socket (since 6.7)
  100. - **sock_release** closing a userspace inet socket (since 5.9)
  101. bpftool cgroup detach *CGROUP* *ATTACH_TYPE* *PROG*
  102. Detach *PROG* from the cgroup *CGROUP* and attach type *ATTACH_TYPE*.
  103. bpftool prog help
  104. Print short help message.
  105. OPTIONS
  106. =======
  107. .. include:: common_options.rst
  108. -f, --bpffs
  109. Show file names of pinned programs.
  110. EXAMPLES
  111. ========
  112. |
  113. | **# mount -t bpf none /sys/fs/bpf/**
  114. | **# mkdir /sys/fs/cgroup/test.slice**
  115. | **# bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog**
  116. | **# bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi**
  117. **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
  118. ::
  119. ID AttachType AttachFlags Name
  120. 1 device allow_multi bpf_prog1
  121. |
  122. | **# bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1**
  123. | **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
  124. ::
  125. ID AttachType AttachFlags Name