2 # SPDX-License-Identifier: GPL-2.0
4 # This test is for checking IPv4 and IPv6 FIB rules API
8 PAUSE_ON_FAIL
=${PAUSE_ON_FAIL:=no}
26 if [ ${rc} -eq ${expected} ]; then
27 nsuccess
=$
((nsuccess
+1))
28 printf "\n TEST: %-50s [ OK ]\n" "${msg}"
31 printf "\n TEST: %-50s [FAIL]\n" "${msg}"
32 if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
34 echo "hit enter to continue, 'q' to quit"
36 [ "$a" = "q" ] && exit 1
44 echo "######################################################################"
45 echo "TEST SECTION: $*"
46 echo "######################################################################"
53 $IP link
set dev lo up
55 $IP link add dummy0
type dummy
56 $IP link
set dev dummy0 up
57 $IP address add
198.51.100.1/24 dev dummy0
58 $IP -6 address add
2001:db8
:1::1/64 dev dummy0
65 $IP link del dev dummy0
&> /dev
/null
69 fib_check_iproute_support
()
71 ip rule
help 2>&1 |
grep -q $1
73 echo "SKIP: iproute2 iprule too old, missing $1 match"
77 ip route get
help 2>&1 |
grep -q $2
79 echo "SKIP: iproute2 get route too old, missing $2 match"
89 log_test $?
0 "rule6 del $1"
92 fib_rule6_del_by_pref
()
94 pref
=$
($IP -6 rule show |
grep "$1 lookup $TABLE" | cut
-d ":" -f 1)
95 $IP -6 rule del pref
$pref
98 fib_rule6_test_match_n_redirect
()
103 $IP -6 rule add
$match table
$RTABLE
104 $IP -6 route get
$GW_IP6 $getmatch |
grep -q "table $RTABLE"
105 log_test $?
0 "rule6 check: $1"
107 fib_rule6_del_by_pref
"$match"
108 log_test $?
0 "rule6 del by pref: $match"
113 # setup the fib rule redirect route
114 $IP -6 route add table
$RTABLE default via
$GW_IP6 dev
$DEV onlink
117 fib_rule6_test_match_n_redirect
"$match" "$match" "oif redirect to table"
119 match
="from $SRC_IP6 iif $DEV"
120 fib_rule6_test_match_n_redirect
"$match" "$match" "iif redirect to table"
123 fib_rule6_test_match_n_redirect
"$match" "$match" "tos redirect to table"
127 fib_rule6_test_match_n_redirect
"$match" "$getmatch" "fwmark redirect to table"
129 fib_check_iproute_support
"uidrange" "uid"
130 if [ $?
-eq 0 ]; then
131 match
="uidrange 100-100"
133 fib_rule6_test_match_n_redirect
"$match" "$getmatch" "uid redirect to table"
136 fib_check_iproute_support
"sport" "sport"
137 if [ $?
-eq 0 ]; then
138 match
="sport 666 dport 777"
139 fib_rule6_test_match_n_redirect
"$match" "$match" "sport and dport redirect to table"
142 fib_check_iproute_support
"ipproto" "ipproto"
143 if [ $?
-eq 0 ]; then
145 fib_rule6_test_match_n_redirect
"$match" "$match" "ipproto match"
148 fib_check_iproute_support
"ipproto" "ipproto"
149 if [ $?
-eq 0 ]; then
151 fib_rule6_test_match_n_redirect
"$match" "$match" "ipproto icmp match"
158 log_test $?
0 "del $1"
161 fib_rule4_del_by_pref
()
163 pref
=$
($IP rule show |
grep "$1 lookup $TABLE" | cut
-d ":" -f 1)
164 $IP rule del pref
$pref
167 fib_rule4_test_match_n_redirect
()
172 $IP rule add
$match table
$RTABLE
173 $IP route get
$GW_IP4 $getmatch |
grep -q "table $RTABLE"
174 log_test $?
0 "rule4 check: $1"
176 fib_rule4_del_by_pref
"$match"
177 log_test $?
0 "rule4 del by pref: $match"
182 # setup the fib rule redirect route
183 $IP route add table
$RTABLE default via
$GW_IP4 dev
$DEV onlink
186 fib_rule4_test_match_n_redirect
"$match" "$match" "oif redirect to table"
188 match
="from $SRC_IP iif $DEV"
189 fib_rule4_test_match_n_redirect
"$match" "$match" "iif redirect to table"
192 fib_rule4_test_match_n_redirect
"$match" "$match" "tos redirect to table"
196 fib_rule4_test_match_n_redirect
"$match" "$getmatch" "fwmark redirect to table"
198 fib_check_iproute_support
"uidrange" "uid"
199 if [ $?
-eq 0 ]; then
200 match
="uidrange 100-100"
202 fib_rule4_test_match_n_redirect
"$match" "$getmatch" "uid redirect to table"
205 fib_check_iproute_support
"sport" "sport"
206 if [ $?
-eq 0 ]; then
207 match
="sport 666 dport 777"
208 fib_rule4_test_match_n_redirect
"$match" "$match" "sport and dport redirect to table"
211 fib_check_iproute_support
"ipproto" "ipproto"
212 if [ $?
-eq 0 ]; then
214 fib_rule4_test_match_n_redirect
"$match" "$match" "ipproto tcp match"
217 fib_check_iproute_support
"ipproto" "ipproto"
218 if [ $?
-eq 0 ]; then
220 fib_rule4_test_match_n_redirect
"$match" "$match" "ipproto icmp match"
226 log_section
"IPv4 fib rule"
228 log_section
"IPv6 fib rule"
232 if [ "$(id -u)" -ne 0 ];then
233 echo "SKIP: Need root privileges"
237 if [ ! -x "$(command -v ip)" ]; then
238 echo "SKIP: Could not run test without ip tool"