1 #!/bin/bash 2 # SPDX-License-Identifier: GPL-2.0 3 4 source lib.sh 5 6 IP4=172.16.0.1/24 7 TGT4=172.16.0.2 8 IP6=2001:db8:1::1/64 9 TGT6=2001:db8:1::2 10 MARK=1000 11 12 cleanup() 13 { 14 cleanup_ns $NS 15 } 16 17 trap cleanup EXIT 18 19 # Namespaces 20 setup_ns NS 21 22 ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null 23 24 # Connectivity 25 ip -netns $NS link add type dummy 26 ip -netns $NS link set dev dummy0 up 27 ip -netns $NS addr add $IP4 dev dummy0 28 ip -netns $NS addr add $IP6 dev dummy0 29 30 ip -netns $NS rule add fwmark $MARK lookup 300 31 ip -6 -netns $NS rule add fwmark $MARK lookup 300 32 ip -netns $NS route add prohibit any table 300 33 ip -6 -netns $NS route add prohibit any table 300 34 35 # Test 36 BAD=0 37 TOTAL=0 38 39 check_result() { 40 ((TOTAL++)) 41 if [ $1 -ne $2 ]; then 42 echo " Case $3 returned $1, expected $2" 43 ((BAD++)) 44 fi 45 } 46 47 for ovr in setsock cmsg both; do 48 for i in 4 6; do 49 [ $i == 4 ] && TGT=$TGT4 || TGT=$TGT6 50 51 for p in u i r; do 52 [ $p == "u" ] && prot=UDP 53 [ $p == "i" ] && prot=ICMP 54 [ $p == "r" ] && prot=RAW 55 56 [ $ovr == "setsock" ] && m="-M" 57 [ $ovr == "cmsg" ] && m="-m" 58 [ $ovr == "both" ] && m="-M $MARK -m" 59 60 ip netns exec $NS ./cmsg_sender -$i -p $p $m $((MARK + 1)) $TGT 1234 61 check_result $? 0 "$prot $ovr - pass" 62 63 [ $ovr == "diff" ] && m="-M $((MARK + 1)) -m" 64 65 ip netns exec $NS ./cmsg_sender -$i -p $p $m $MARK -s $TGT 1234 66 check_result $? 1 "$prot $ovr - rejection" 67 done 68 done 69 done 70 71 # Summary 72 if [ $BAD -ne 0 ]; then 73 echo "FAIL - $BAD/$TOTAL cases failed" 74 exit 1 75 else 76 echo "OK" 77 exit 0 78 fi
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.