drm/bridge: adv7511: Switch to atomic operations
[drm/drm-misc.git] / tools / testing / selftests / net / cmsg_so_mark.sh
blob772ad0cc2630454e853057f6db6409d135a86bc9
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
4 source lib.sh
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
12 cleanup()
14 cleanup_ns $NS
17 trap cleanup EXIT
19 # Namespaces
20 setup_ns NS
22 ip netns exec $NS sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null
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
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
35 # Test
36 BAD=0
37 TOTAL=0
39 check_result() {
40 ((TOTAL++))
41 if [ $1 -ne $2 ]; then
42 echo " Case $3 returned $1, expected $2"
43 ((BAD++))
47 for ovr in setsock cmsg both; do
48 for i in 4 6; do
49 [ $i == 4 ] && TGT=$TGT4 || TGT=$TGT6
51 for p in u i r; do
52 [ $p == "u" ] && prot=UDP
53 [ $p == "i" ] && prot=ICMP
54 [ $p == "r" ] && prot=RAW
56 [ $ovr == "setsock" ] && m="-M"
57 [ $ovr == "cmsg" ] && m="-m"
58 [ $ovr == "both" ] && m="-M $MARK -m"
60 ip netns exec $NS ./cmsg_sender -$i -p $p $m $((MARK + 1)) $TGT 1234
61 check_result $? 0 "$prot $ovr - pass"
63 [ $ovr == "diff" ] && m="-M $((MARK + 1)) -m"
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
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