bpftool-cgroup.rst 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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* }
  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_inet4_getpeername** | **cgroup_inet6_getpeername** |
  31. | **cgroup_inet4_getsockname** | **cgroup_inet6_getsockname** |
  32. | **cgroup_udp4_sendmsg** | **cgroup_udp6_sendmsg** |
  33. | **cgroup_udp4_recvmsg** | **cgroup_udp6_recvmsg** |
  34. | **cgroup_sysctl** | **cgroup_getsockopt** | **cgroup_setsockopt** |
  35. | **cgroup_inet_sock_release** }
  36. | *ATTACH_FLAGS* := { **multi** | **override** }
  37. DESCRIPTION
  38. ===========
  39. **bpftool cgroup { show | list }** *CGROUP* [**effective**]
  40. List all programs attached to the cgroup *CGROUP*.
  41. Output will start with program ID followed by attach type,
  42. attach flags and program name.
  43. If **effective** is specified retrieve effective programs that
  44. will execute for events within a cgroup. This includes
  45. inherited along with attached ones.
  46. **bpftool cgroup tree** [*CGROUP_ROOT*] [**effective**]
  47. Iterate over all cgroups in *CGROUP_ROOT* and list all
  48. attached programs. If *CGROUP_ROOT* is not specified,
  49. bpftool uses cgroup v2 mountpoint.
  50. The output is similar to the output of cgroup show/list
  51. commands: it starts with absolute cgroup path, followed by
  52. program ID, attach type, attach flags and program name.
  53. If **effective** is specified retrieve effective programs that
  54. will execute for events within a cgroup. This includes
  55. inherited along with attached ones.
  56. **bpftool cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
  57. Attach program *PROG* to the cgroup *CGROUP* with attach type
  58. *ATTACH_TYPE* and optional *ATTACH_FLAGS*.
  59. *ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs
  60. some bpf program, the program in this cgroup yields to sub-cgroup
  61. program; **multi** if a sub-cgroup installs some bpf program,
  62. that cgroup program gets run in addition to the program in this
  63. cgroup.
  64. Only one program is allowed to be attached to a cgroup with
  65. no attach flags or the **override** flag. Attaching another
  66. program will release old program and attach the new one.
  67. Multiple programs are allowed to be attached to a cgroup with
  68. **multi**. They are executed in FIFO order (those that were
  69. attached first, run first).
  70. Non-default *ATTACH_FLAGS* are supported by kernel version 4.14
  71. and later.
  72. *ATTACH_TYPE* can be on 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. **sendmsg4** call to sendto(2), sendmsg(2), sendmmsg(2) for an
  85. unconnected udp4 socket (since 4.18);
  86. **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an
  87. unconnected udp6 socket (since 4.18);
  88. **recvmsg4** call to recvfrom(2), recvmsg(2), recvmmsg(2) for
  89. an unconnected udp4 socket (since 5.2);
  90. **recvmsg6** call to recvfrom(2), recvmsg(2), recvmmsg(2) for
  91. an unconnected udp6 socket (since 5.2);
  92. **sysctl** sysctl access (since 5.2);
  93. **getsockopt** call to getsockopt (since 5.3);
  94. **setsockopt** call to setsockopt (since 5.3);
  95. **getpeername4** call to getpeername(2) for an inet4 socket (since 5.8);
  96. **getpeername6** call to getpeername(2) for an inet6 socket (since 5.8);
  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. **sock_release** closing an userspace inet socket (since 5.9).
  100. **bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
  101. Detach *PROG* from the cgroup *CGROUP* and attach type
  102. *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