bpftool-cgroup.rst 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ================
  2. bpftool-cgroup
  3. ================
  4. -------------------------------------------------------------------------------
  5. tool for inspection and simple manipulation of eBPF progs
  6. -------------------------------------------------------------------------------
  7. :Manual section: 8
  8. SYNOPSIS
  9. ========
  10. **bpftool** [*OPTIONS*] **cgroup** *COMMAND*
  11. *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
  12. *COMMANDS* :=
  13. { **show** | **list** | **tree** | **attach** | **detach** | **help** }
  14. MAP COMMANDS
  15. =============
  16. | **bpftool** **cgroup { show | list }** *CGROUP*
  17. | **bpftool** **cgroup tree** [*CGROUP_ROOT*]
  18. | **bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
  19. | **bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
  20. | **bpftool** **cgroup help**
  21. |
  22. | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
  23. | *ATTACH_TYPE* := { **ingress** | **egress** | **sock_create** | **sock_ops** | **device** |
  24. | **bind4** | **bind6** | **post_bind4** | **post_bind6** | **connect4** | **connect6** |
  25. | **sendmsg4** | **sendmsg6** }
  26. | *ATTACH_FLAGS* := { **multi** | **override** }
  27. DESCRIPTION
  28. ===========
  29. **bpftool cgroup { show | list }** *CGROUP*
  30. List all programs attached to the cgroup *CGROUP*.
  31. Output will start with program ID followed by attach type,
  32. attach flags and program name.
  33. **bpftool cgroup tree** [*CGROUP_ROOT*]
  34. Iterate over all cgroups in *CGROUP_ROOT* and list all
  35. attached programs. If *CGROUP_ROOT* is not specified,
  36. bpftool uses cgroup v2 mountpoint.
  37. The output is similar to the output of cgroup show/list
  38. commands: it starts with absolute cgroup path, followed by
  39. program ID, attach type, attach flags and program name.
  40. **bpftool cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
  41. Attach program *PROG* to the cgroup *CGROUP* with attach type
  42. *ATTACH_TYPE* and optional *ATTACH_FLAGS*.
  43. *ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs
  44. some bpf program, the program in this cgroup yields to sub-cgroup
  45. program; **multi** if a sub-cgroup installs some bpf program,
  46. that cgroup program gets run in addition to the program in this
  47. cgroup.
  48. Only one program is allowed to be attached to a cgroup with
  49. no attach flags or the **override** flag. Attaching another
  50. program will release old program and attach the new one.
  51. Multiple programs are allowed to be attached to a cgroup with
  52. **multi**. They are executed in FIFO order (those that were
  53. attached first, run first).
  54. Non-default *ATTACH_FLAGS* are supported by kernel version 4.14
  55. and later.
  56. *ATTACH_TYPE* can be on of:
  57. **ingress** ingress path of the inet socket (since 4.10);
  58. **egress** egress path of the inet socket (since 4.10);
  59. **sock_create** opening of an inet socket (since 4.10);
  60. **sock_ops** various socket operations (since 4.12);
  61. **device** device access (since 4.15);
  62. **bind4** call to bind(2) for an inet4 socket (since 4.17);
  63. **bind6** call to bind(2) for an inet6 socket (since 4.17);
  64. **post_bind4** return from bind(2) for an inet4 socket (since 4.17);
  65. **post_bind6** return from bind(2) for an inet6 socket (since 4.17);
  66. **connect4** call to connect(2) for an inet4 socket (since 4.17);
  67. **connect6** call to connect(2) for an inet6 socket (since 4.17);
  68. **sendmsg4** call to sendto(2), sendmsg(2), sendmmsg(2) for an
  69. unconnected udp4 socket (since 4.18);
  70. **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an
  71. unconnected udp6 socket (since 4.18).
  72. **bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
  73. Detach *PROG* from the cgroup *CGROUP* and attach type
  74. *ATTACH_TYPE*.
  75. **bpftool prog help**
  76. Print short help message.
  77. OPTIONS
  78. =======
  79. -h, --help
  80. Print short generic help message (similar to **bpftool help**).
  81. -v, --version
  82. Print version number (similar to **bpftool version**).
  83. -j, --json
  84. Generate JSON output. For commands that cannot produce JSON, this
  85. option has no effect.
  86. -p, --pretty
  87. Generate human-readable JSON output. Implies **-j**.
  88. -f, --bpffs
  89. Show file names of pinned programs.
  90. EXAMPLES
  91. ========
  92. |
  93. | **# mount -t bpf none /sys/fs/bpf/**
  94. | **# mkdir /sys/fs/cgroup/test.slice**
  95. | **# bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog**
  96. | **# bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi**
  97. **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
  98. ::
  99. ID AttachType AttachFlags Name
  100. 1 device allow_multi bpf_prog1
  101. |
  102. | **# bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1**
  103. | **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
  104. ::
  105. ID AttachType AttachFlags Name
  106. SEE ALSO
  107. ========
  108. **bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-map**\ (8)