^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) This file describes how to run the tcp_*_kern.o tcp_bpf (or socket_ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) programs. These programs attach to a cgroupv2. The following commands create
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) a cgroupv2 and attach a bash shell to the group.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) mkdir -p /tmp/cgroupv2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) mount -t cgroup2 none /tmp/cgroupv2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) mkdir -p /tmp/cgroupv2/foo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) bash
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) echo $$ >> /tmp/cgroupv2/foo/cgroup.procs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) Anything that runs under this shell belongs to the foo cgroupv2. To load
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) (attach) one of the tcp_*_kern.o programs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) bpftool prog load tcp_basertt_kern.o /sys/fs/bpf/tcp_prog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) bpftool cgroup attach /tmp/cgroupv2/foo sock_ops pinned /sys/fs/bpf/tcp_prog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) bpftool prog tracelog
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) "bpftool prog tracelog" will continue to run printing the BPF log buffer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) The tcp_*_kern.o programs use special print functions to print logging
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) information (if enabled by the ifdef).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) If using netperf/netserver to create traffic, you need to run them under the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) cgroupv2 to which the BPF programs are attached (i.e. under bash shell
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) attached to the cgroupv2).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) To remove (unattach) a socket_ops BPF program from a cgroupv2:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) bpftool cgroup detach /tmp/cgroupv2/foo sock_ops pinned /sys/fs/bpf/tcp_prog