]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - samples/bpf/test_cgrp2_sock2.sh
fc4e64d00cb3063a065cc07ec6c02c7184d19626
[mirror_ubuntu-bionic-kernel.git] / samples / bpf / test_cgrp2_sock2.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
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
14 }
15
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
22 }
23
24
25 function attach_bpf {
26 test_cgrp2_sock2 /tmp/cgroupv2/foo sock_flags_kern.o $1
27 [ $? -ne 0 ] && exit 1
28 }
29
30 function cleanup {
31 ip link del veth0b
32 ip netns delete at_ns0
33 umount /tmp/cgroupv2
34 rm -rf /tmp/cgroupv2
35 }
36
37 cleanup 2>/dev/null
38
39 set -e
40 config_device
41 config_cgroup
42 set +e
43
44 #
45 # Test 1 - fail ping6
46 #
47 attach_bpf 0
48 ping -c1 -w1 172.16.1.100
49 if [ $? -ne 0 ]; then
50 echo "ping failed when it should succeed"
51 cleanup
52 exit 1
53 fi
54
55 ping6 -c1 -w1 2401:db00::1
56 if [ $? -eq 0 ]; then
57 echo "ping6 succeeded when it should not"
58 cleanup
59 exit 1
60 fi
61
62 #
63 # Test 2 - fail ping
64 #
65 attach_bpf 1
66 ping6 -c1 -w1 2401:db00::1
67 if [ $? -ne 0 ]; then
68 echo "ping6 failed when it should succeed"
69 cleanup
70 exit 1
71 fi
72
73 ping -c1 -w1 172.16.1.100
74 if [ $? -eq 0 ]; then
75 echo "ping succeeded when it should not"
76 cleanup
77 exit 1
78 fi
79
80 cleanup
81 echo
82 echo "*** PASS ***"