2 # SPDX-License-Identifier: GPL-2.0
4 # Test various socket options that can be set by attaching programs to cgroups.
7 TEST=$MY_DIR/test_cgrp2_sock
8 CGRP_MNT="/tmp/cgroupv2-test_cgrp2_sock"
10 ################################################################################
17 [ $rc -ne 0 ] && status="FAIL"
19 printf "%-50s [%4s]\n" "$2" "$status"
25 echo $out | grep -q "$1"
27 print_result 1 "IPv4: $2"
32 print_result 0 "IPv4: $2"
39 echo $out | grep -q "$1"
41 print_result 1 "IPv6: $2"
46 print_result 0 "IPv6: $2"
50 ################################################################################
55 echo $$ >> ${CGRP_MNT}/cgroup.procs
56 rmdir ${CGRP_MNT}/sockopts
64 [ -n "$msg" ] && echo "ERROR: $msg"
66 $TEST -d ${CGRP_MNT}/sockopts
74 ################################################################################
79 ip li add cgrp2_sock type dummy 2>/dev/null
83 mount -t cgroup2 none ${CGRP_MNT}
87 # make sure we have a known start point
90 mkdir -p ${CGRP_MNT}/sockopts
91 [ $? -ne 0 ] && cleanup_and_exit 1 "Failed to create cgroup hierarchy"
95 echo $$ > ${CGRP_MNT}/sockopts/cgroup.procs
97 # no bpf program attached, so socket should show no settings
98 check_sock "dev , mark 0, priority 0" "No programs attached"
99 check_sock6 "dev , mark 0, priority 0" "No programs attached"
101 # verify device is set
103 $TEST -b cgrp2_sock ${CGRP_MNT}/sockopts
104 if [ $? -ne 0 ]; then
105 cleanup_and_exit 1 "Failed to install program to set device"
107 check_sock "dev cgrp2_sock, mark 0, priority 0" "Device set"
108 check_sock6 "dev cgrp2_sock, mark 0, priority 0" "Device set"
112 $TEST -m 666 ${CGRP_MNT}/sockopts
113 if [ $? -ne 0 ]; then
114 cleanup_and_exit 1 "Failed to install program to set mark"
116 check_sock "dev , mark 666, priority 0" "Mark set"
117 check_sock6 "dev , mark 666, priority 0" "Mark set"
119 # verify priority is set
121 $TEST -p 123 ${CGRP_MNT}/sockopts
122 if [ $? -ne 0 ]; then
123 cleanup_and_exit 1 "Failed to install program to set priority"
125 check_sock "dev , mark 0, priority 123" "Priority set"
126 check_sock6 "dev , mark 0, priority 123" "Priority set"
130 $TEST -b cgrp2_sock -m 666 -p 123 ${CGRP_MNT}/sockopts
131 if [ $? -ne 0 ]; then
132 cleanup_and_exit 1 "Failed to install program to set device, mark and priority"
134 check_sock "dev cgrp2_sock, mark 666, priority 123" "Priority set"
135 check_sock6 "dev cgrp2_sock, mark 666, priority 123" "Priority set"