~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/samples/bpf/test_cgrp2_sock2.sh

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #!/bin/bash
  2 # SPDX-License-Identifier: GPL-2.0
  3 
  4 BPFFS=/sys/fs/bpf
  5 MY_DIR=$(dirname $0)
  6 TEST=$MY_DIR/test_cgrp2_sock2
  7 LINK_PIN=$BPFFS/test_cgrp2_sock2
  8 BPF_PROG=$MY_DIR/sock_flags.bpf.o
  9 
 10 function config_device {
 11         ip netns add at_ns0
 12         ip link add veth0 type veth peer name veth0b
 13         ip link set veth0 netns at_ns0
 14         ip netns exec at_ns0 sysctl -q net.ipv6.conf.veth0.disable_ipv6=0
 15         ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0
 16         ip netns exec at_ns0 ip addr add 2401:db00::1/64 dev veth0 nodad
 17         ip netns exec at_ns0 ip link set dev veth0 up
 18         sysctl -q net.ipv6.conf.veth0b.disable_ipv6=0
 19         ip addr add 172.16.1.101/24 dev veth0b
 20         ip addr add 2401:db00::2/64 dev veth0b nodad
 21         ip link set veth0b up
 22 }
 23 
 24 function config_cgroup {
 25         rm -rf /tmp/cgroupv2
 26         mkdir -p /tmp/cgroupv2
 27         mount -t cgroup2 none /tmp/cgroupv2
 28         mkdir -p /tmp/cgroupv2/foo
 29         echo $$ >> /tmp/cgroupv2/foo/cgroup.procs
 30 }
 31 
 32 function config_bpffs {
 33         if mount | grep $BPFFS > /dev/null; then
 34                 echo "bpffs already mounted"
 35         else
 36                 echo "bpffs not mounted. Mounting..."
 37                 mount -t bpf none $BPFFS
 38         fi
 39 }
 40 
 41 function attach_bpf {
 42         $TEST /tmp/cgroupv2/foo $BPF_PROG $1
 43         [ $? -ne 0 ] && exit 1
 44 }
 45 
 46 function cleanup {
 47         rm -rf $LINK_PIN
 48         ip link del veth0b
 49         ip netns delete at_ns0
 50         umount /tmp/cgroupv2
 51         rm -rf /tmp/cgroupv2
 52 }
 53 
 54 cleanup 2>/dev/null
 55 
 56 set -e
 57 config_device
 58 config_cgroup
 59 config_bpffs
 60 set +e
 61 
 62 #
 63 # Test 1 - fail ping6
 64 #
 65 attach_bpf 0
 66 ping -c1 -w1 172.16.1.100
 67 if [ $? -ne 0 ]; then
 68         echo "ping failed when it should succeed"
 69         cleanup
 70         exit 1
 71 fi
 72 
 73 ping6 -c1 -w1 2401:db00::1
 74 if [ $? -eq 0 ]; then
 75         echo "ping6 succeeded when it should not"
 76         cleanup
 77         exit 1
 78 fi
 79 
 80 rm -rf $LINK_PIN
 81 sleep 1                 # Wait for link detach
 82 
 83 #
 84 # Test 2 - fail ping
 85 #
 86 attach_bpf 1
 87 ping6 -c1 -w1 2401:db00::1
 88 if [ $? -ne 0 ]; then
 89         echo "ping6 failed when it should succeed"
 90         cleanup
 91         exit 1
 92 fi
 93 
 94 ping -c1 -w1 172.16.1.100
 95 if [ $? -eq 0 ]; then
 96         echo "ping succeeded when it should not"
 97         cleanup
 98         exit 1
 99 fi
100 
101 cleanup
102 echo
103 echo "*** PASS ***"

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php