2 # SPDX-License-Identifier: GPL-2.0
4 # Test various socket options that can be set by attaching programs to cgroups.
6 CGRP_MNT
="/tmp/cgroupv2-test_cgrp2_sock"
8 ################################################################################
15 [ $rc -ne 0 ] && status
="FAIL"
17 printf "%-50s [%4s]\n" "$2" "$status"
22 out
=$
(test_cgrp2_sock
)
23 echo $out |
grep -q "$1"
25 print_result
1 "IPv4: $2"
30 print_result
0 "IPv4: $2"
36 out
=$
(test_cgrp2_sock
-6)
37 echo $out |
grep -q "$1"
39 print_result
1 "IPv6: $2"
44 print_result
0 "IPv6: $2"
48 ################################################################################
53 echo $$
>> ${CGRP_MNT}/cgroup.procs
54 rmdir ${CGRP_MNT}/sockopts
62 [ -n "$msg" ] && echo "ERROR: $msg"
71 ################################################################################
76 ip li add cgrp2_sock
type dummy
2>/dev
/null
80 mount
-t cgroup2 none
${CGRP_MNT}
84 # make sure we have a known start point
87 mkdir
-p ${CGRP_MNT}/sockopts
88 [ $?
-ne 0 ] && cleanup_and_exit
1 "Failed to create cgroup hierarchy"
92 echo $$
> ${CGRP_MNT}/sockopts
/cgroup.procs
94 # no bpf program attached, so socket should show no settings
95 check_sock
"dev , mark 0, priority 0" "No programs attached"
96 check_sock6
"dev , mark 0, priority 0" "No programs attached"
98 # verify device is set
100 test_cgrp2_sock
-b cgrp2_sock
${CGRP_MNT}/sockopts
101 if [ $?
-ne 0 ]; then
102 cleanup_and_exit
1 "Failed to install program to set device"
104 check_sock
"dev cgrp2_sock, mark 0, priority 0" "Device set"
105 check_sock6
"dev cgrp2_sock, mark 0, priority 0" "Device set"
109 test_cgrp2_sock
-m 666 ${CGRP_MNT}/sockopts
110 if [ $?
-ne 0 ]; then
111 cleanup_and_exit
1 "Failed to install program to set mark"
113 check_sock
"dev , mark 666, priority 0" "Mark set"
114 check_sock6
"dev , mark 666, priority 0" "Mark set"
116 # verify priority is set
118 test_cgrp2_sock
-p 123 ${CGRP_MNT}/sockopts
119 if [ $?
-ne 0 ]; then
120 cleanup_and_exit
1 "Failed to install program to set priority"
122 check_sock
"dev , mark 0, priority 123" "Priority set"
123 check_sock6
"dev , mark 0, priority 123" "Priority set"
127 test_cgrp2_sock
-b cgrp2_sock
-m 666 -p 123 ${CGRP_MNT}/sockopts
128 if [ $?
-ne 0 ]; then
129 cleanup_and_exit
1 "Failed to install program to set device, mark and priority"
131 check_sock
"dev cgrp2_sock, mark 666, priority 123" "Priority set"
132 check_sock6
"dev cgrp2_sock, mark 666, priority 123" "Priority set"