btrfs: use file:line format for assertion report
[linux/fpc-iii.git] / samples / bpf / test_cgrp2_sock2.sh
blob0f396a86e0cbebd68e9ddf2d5c8557ce40028f38
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 function config_device {
5 ip netns add at_ns0
6 ip link add veth0 type veth peer name veth0b
7 ip link set veth0b up
8 ip link set veth0 netns at_ns0
9 ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0
10 ip netns exec at_ns0 ip addr add 2401:db00::1/64 dev veth0 nodad
11 ip netns exec at_ns0 ip link set dev veth0 up
12 ip addr add 172.16.1.101/24 dev veth0b
13 ip addr add 2401:db00::2/64 dev veth0b nodad
16 function config_cgroup {
17 rm -rf /tmp/cgroupv2
18 mkdir -p /tmp/cgroupv2
19 mount -t cgroup2 none /tmp/cgroupv2
20 mkdir -p /tmp/cgroupv2/foo
21 echo $$ >> /tmp/cgroupv2/foo/cgroup.procs
25 function attach_bpf {
26 test_cgrp2_sock2 /tmp/cgroupv2/foo sock_flags_kern.o $1
27 [ $? -ne 0 ] && exit 1
30 function cleanup {
31 if [ -d /tmp/cgroupv2/foo ]; then
32 test_cgrp2_sock -d /tmp/cgroupv2/foo
34 ip link del veth0b
35 ip netns delete at_ns0
36 umount /tmp/cgroupv2
37 rm -rf /tmp/cgroupv2
40 cleanup 2>/dev/null
42 set -e
43 config_device
44 config_cgroup
45 set +e
48 # Test 1 - fail ping6
50 attach_bpf 0
51 ping -c1 -w1 172.16.1.100
52 if [ $? -ne 0 ]; then
53 echo "ping failed when it should succeed"
54 cleanup
55 exit 1
58 ping6 -c1 -w1 2401:db00::1
59 if [ $? -eq 0 ]; then
60 echo "ping6 succeeded when it should not"
61 cleanup
62 exit 1
66 # Test 2 - fail ping
68 attach_bpf 1
69 ping6 -c1 -w1 2401:db00::1
70 if [ $? -ne 0 ]; then
71 echo "ping6 failed when it should succeed"
72 cleanup
73 exit 1
76 ping -c1 -w1 172.16.1.100
77 if [ $? -eq 0 ]; then
78 echo "ping succeeded when it should not"
79 cleanup
80 exit 1
83 cleanup
84 echo
85 echo "*** PASS ***"