Loading...
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4ksft_skip=4
5
6NS=ns
7IP6=2001:db8:1::1/64
8TGT6=2001:db8:1::2
9TMPF=$(mktemp --suffix ".pcap")
10
11cleanup()
12{
13 rm -f $TMPF
14 ip netns del $NS
15}
16
17trap cleanup EXIT
18
19NSEXE="ip netns exec $NS"
20
21tcpdump -h | grep immediate-mode >> /dev/null
22if [ $? -ne 0 ]; then
23 echo "SKIP - tcpdump with --immediate-mode option required"
24 exit $ksft_skip
25fi
26
27# Namespaces
28ip netns add $NS
29
30$NSEXE sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null
31
32# Connectivity
33ip -netns $NS link add type dummy
34ip -netns $NS link set dev dummy0 up
35ip -netns $NS addr add $IP6 dev dummy0
36
37# Test
38BAD=0
39TOTAL=0
40
41check_result() {
42 ((TOTAL++))
43 if [ $1 -ne $2 ]; then
44 echo " Case $3 returned $1, expected $2"
45 ((BAD++))
46 fi
47}
48
49# IPV6_DONTFRAG
50for ovr in setsock cmsg both diff; do
51 for df in 0 1; do
52 for p in u i r; do
53 [ $p == "u" ] && prot=UDP
54 [ $p == "i" ] && prot=ICMP
55 [ $p == "r" ] && prot=RAW
56
57 [ $ovr == "setsock" ] && m="-F $df"
58 [ $ovr == "cmsg" ] && m="-f $df"
59 [ $ovr == "both" ] && m="-F $df -f $df"
60 [ $ovr == "diff" ] && m="-F $((1 - df)) -f $df"
61
62 $NSEXE ./cmsg_sender -s -S 2000 -6 -p $p $m $TGT6 1234
63 check_result $? $df "DONTFRAG $prot $ovr"
64 done
65 done
66done
67
68# IPV6_TCLASS
69TOS=0x10
70TOS2=0x20
71
72ip -6 -netns $NS rule add tos $TOS lookup 300
73ip -6 -netns $NS route add table 300 prohibit any
74
75for ovr in setsock cmsg both diff; do
76 for p in u i r; do
77 [ $p == "u" ] && prot=UDP
78 [ $p == "i" ] && prot=ICMP
79 [ $p == "r" ] && prot=RAW
80
81 [ $ovr == "setsock" ] && m="-C"
82 [ $ovr == "cmsg" ] && m="-c"
83 [ $ovr == "both" ] && m="-C $((TOS2)) -c"
84 [ $ovr == "diff" ] && m="-C $((TOS )) -c"
85
86 $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null &
87 BG=$!
88 sleep 0.05
89
90 $NSEXE ./cmsg_sender -6 -p $p $m $((TOS2)) $TGT6 1234
91 check_result $? 0 "TCLASS $prot $ovr - pass"
92
93 while [ -d /proc/$BG ]; do
94 $NSEXE ./cmsg_sender -6 -p u $TGT6 1234
95 done
96
97 tcpdump -r $TMPF -v 2>&1 | grep "class $TOS2" >> /dev/null
98 check_result $? 0 "TCLASS $prot $ovr - packet data"
99 rm $TMPF
100
101 [ $ovr == "both" ] && m="-C $((TOS )) -c"
102 [ $ovr == "diff" ] && m="-C $((TOS2)) -c"
103
104 $NSEXE ./cmsg_sender -6 -p $p $m $((TOS)) -s $TGT6 1234
105 check_result $? 1 "TCLASS $prot $ovr - rejection"
106 done
107done
108
109# IPV6_HOPLIMIT
110LIM=4
111
112for ovr in setsock cmsg both diff; do
113 for p in u i r; do
114 [ $p == "u" ] && prot=UDP
115 [ $p == "i" ] && prot=ICMP
116 [ $p == "r" ] && prot=RAW
117
118 [ $ovr == "setsock" ] && m="-L"
119 [ $ovr == "cmsg" ] && m="-l"
120 [ $ovr == "both" ] && m="-L $LIM -l"
121 [ $ovr == "diff" ] && m="-L $((LIM + 1)) -l"
122
123 $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null &
124 BG=$!
125 sleep 0.05
126
127 $NSEXE ./cmsg_sender -6 -p $p $m $LIM $TGT6 1234
128 check_result $? 0 "HOPLIMIT $prot $ovr - pass"
129
130 while [ -d /proc/$BG ]; do
131 $NSEXE ./cmsg_sender -6 -p u $TGT6 1234
132 done
133
134 tcpdump -r $TMPF -v 2>&1 | grep "hlim $LIM[^0-9]" >> /dev/null
135 check_result $? 0 "HOPLIMIT $prot $ovr - packet data"
136 rm $TMPF
137 done
138done
139
140# IPV6 exthdr
141for p in u i r; do
142 # Very basic "does it crash" test
143 for h in h d r; do
144 $NSEXE ./cmsg_sender -p $p -6 -H $h $TGT6 1234
145 check_result $? 0 "ExtHdr $prot $ovr - pass"
146 done
147done
148
149# Summary
150if [ $BAD -ne 0 ]; then
151 echo "FAIL - $BAD/$TOTAL cases failed"
152 exit 1
153else
154 echo "OK"
155 exit 0
156fi
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4source lib.sh
5
6IP6=2001:db8:1::1/64
7TGT6=2001:db8:1::2
8TMPF=$(mktemp --suffix ".pcap")
9
10cleanup()
11{
12 rm -f $TMPF
13 cleanup_ns $NS
14}
15
16trap cleanup EXIT
17
18tcpdump -h | grep immediate-mode >> /dev/null
19if [ $? -ne 0 ]; then
20 echo "SKIP - tcpdump with --immediate-mode option required"
21 exit $ksft_skip
22fi
23
24# Namespaces
25setup_ns NS
26NSEXE="ip netns exec $NS"
27
28$NSEXE sysctl -w net.ipv4.ping_group_range='0 2147483647' > /dev/null
29
30# Connectivity
31ip -netns $NS link add type dummy
32ip -netns $NS link set dev dummy0 up
33ip -netns $NS addr add $IP6 dev dummy0
34
35# Test
36BAD=0
37TOTAL=0
38
39check_result() {
40 ((TOTAL++))
41 if [ $1 -ne $2 ]; then
42 echo " Case $3 returned $1, expected $2"
43 ((BAD++))
44 fi
45}
46
47# IPV6_DONTFRAG
48for ovr in setsock cmsg both diff; do
49 for df in 0 1; do
50 for p in u i r; do
51 [ $p == "u" ] && prot=UDP
52 [ $p == "i" ] && prot=ICMP
53 [ $p == "r" ] && prot=RAW
54
55 [ $ovr == "setsock" ] && m="-F $df"
56 [ $ovr == "cmsg" ] && m="-f $df"
57 [ $ovr == "both" ] && m="-F $df -f $df"
58 [ $ovr == "diff" ] && m="-F $((1 - df)) -f $df"
59
60 $NSEXE ./cmsg_sender -s -S 2000 -6 -p $p $m $TGT6 1234
61 check_result $? $df "DONTFRAG $prot $ovr"
62 done
63 done
64done
65
66# IPV6_TCLASS
67TOS=0x10
68TOS2=0x20
69
70ip -6 -netns $NS rule add tos $TOS lookup 300
71ip -6 -netns $NS route add table 300 prohibit any
72
73for ovr in setsock cmsg both diff; do
74 for p in u i r; do
75 [ $p == "u" ] && prot=UDP
76 [ $p == "i" ] && prot=ICMP
77 [ $p == "r" ] && prot=RAW
78
79 [ $ovr == "setsock" ] && m="-C"
80 [ $ovr == "cmsg" ] && m="-c"
81 [ $ovr == "both" ] && m="-C $((TOS2)) -c"
82 [ $ovr == "diff" ] && m="-C $((TOS )) -c"
83
84 $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null &
85 BG=$!
86 sleep 0.05
87
88 $NSEXE ./cmsg_sender -6 -p $p $m $((TOS2)) $TGT6 1234
89 check_result $? 0 "TCLASS $prot $ovr - pass"
90
91 while [ -d /proc/$BG ]; do
92 $NSEXE ./cmsg_sender -6 -p $p $m $((TOS2)) $TGT6 1234
93 done
94
95 tcpdump -r $TMPF -v 2>&1 | grep "class $TOS2" >> /dev/null
96 check_result $? 0 "TCLASS $prot $ovr - packet data"
97 rm $TMPF
98
99 [ $ovr == "both" ] && m="-C $((TOS )) -c"
100 [ $ovr == "diff" ] && m="-C $((TOS2)) -c"
101
102 $NSEXE ./cmsg_sender -6 -p $p $m $((TOS)) -s $TGT6 1234
103 check_result $? 1 "TCLASS $prot $ovr - rejection"
104 done
105done
106
107# IPV6_HOPLIMIT
108LIM=4
109
110for ovr in setsock cmsg both diff; do
111 for p in u i r; do
112 [ $p == "u" ] && prot=UDP
113 [ $p == "i" ] && prot=ICMP
114 [ $p == "r" ] && prot=RAW
115
116 [ $ovr == "setsock" ] && m="-L"
117 [ $ovr == "cmsg" ] && m="-l"
118 [ $ovr == "both" ] && m="-L $LIM -l"
119 [ $ovr == "diff" ] && m="-L $((LIM + 1)) -l"
120
121 $NSEXE nohup tcpdump --immediate-mode -p -ni dummy0 -w $TMPF -c 4 2> /dev/null &
122 BG=$!
123 sleep 0.05
124
125 $NSEXE ./cmsg_sender -6 -p $p $m $LIM $TGT6 1234
126 check_result $? 0 "HOPLIMIT $prot $ovr - pass"
127
128 while [ -d /proc/$BG ]; do
129 $NSEXE ./cmsg_sender -6 -p $p $m $LIM $TGT6 1234
130 done
131
132 tcpdump -r $TMPF -v 2>&1 | grep "hlim $LIM[^0-9]" >> /dev/null
133 check_result $? 0 "HOPLIMIT $prot $ovr - packet data"
134 rm $TMPF
135 done
136done
137
138# IPV6 exthdr
139for p in u i r; do
140 # Very basic "does it crash" test
141 for h in h d r; do
142 $NSEXE ./cmsg_sender -p $p -6 -H $h $TGT6 1234
143 check_result $? 0 "ExtHdr $prot $ovr - pass"
144 done
145done
146
147# Summary
148if [ $BAD -ne 0 ]; then
149 echo "FAIL - $BAD/$TOTAL cases failed"
150 exit 1
151else
152 echo "OK"
153 exit 0
154fi