fib_rule_tests.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # This test is for checking IPv4 and IPv6 FIB rules API
  4. source lib.sh
  5. ret=0
  6. PAUSE_ON_FAIL=${PAUSE_ON_FAIL:=no}
  7. RTABLE=100
  8. RTABLE_PEER=101
  9. RTABLE_VRF=102
  10. GW_IP4=192.51.100.2
  11. SRC_IP=192.51.100.3
  12. GW_IP6=2001:db8:1::2
  13. SRC_IP6=2001:db8:1::3
  14. DEV_ADDR=192.51.100.1
  15. DEV_ADDR6=2001:db8:1::1
  16. DEV=dummy0
  17. TESTS="
  18. fib_rule6
  19. fib_rule4
  20. fib_rule6_connect
  21. fib_rule4_connect
  22. fib_rule6_vrf
  23. fib_rule4_vrf
  24. "
  25. SELFTEST_PATH=""
  26. log_test()
  27. {
  28. local rc=$1
  29. local expected=$2
  30. local msg="$3"
  31. if [ ${rc} -eq ${expected} ]; then
  32. nsuccess=$((nsuccess+1))
  33. printf " TEST: %-60s [ OK ]\n" "${msg}"
  34. else
  35. ret=1
  36. nfail=$((nfail+1))
  37. printf " TEST: %-60s [FAIL]\n" "${msg}"
  38. if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
  39. echo
  40. echo "hit enter to continue, 'q' to quit"
  41. read a
  42. [ "$a" = "q" ] && exit 1
  43. fi
  44. fi
  45. }
  46. setup()
  47. {
  48. set -e
  49. setup_ns testns
  50. IP="ip -netns $testns"
  51. $IP link add dummy0 type dummy
  52. $IP link set dev dummy0 up
  53. $IP address add $DEV_ADDR/24 dev dummy0
  54. $IP -6 address add $DEV_ADDR6/64 dev dummy0
  55. set +e
  56. }
  57. cleanup()
  58. {
  59. $IP link del dev dummy0 &> /dev/null
  60. cleanup_ns $testns
  61. }
  62. setup_peer()
  63. {
  64. set -e
  65. setup_ns peerns
  66. IP_PEER="ip -netns $peerns"
  67. $IP_PEER link set dev lo up
  68. ip link add name veth0 netns $testns type veth \
  69. peer name veth1 netns $peerns
  70. $IP link set dev veth0 up
  71. $IP_PEER link set dev veth1 up
  72. $IP address add 192.0.2.10 peer 192.0.2.11/32 dev veth0
  73. $IP_PEER address add 192.0.2.11 peer 192.0.2.10/32 dev veth1
  74. $IP address add 2001:db8::10 peer 2001:db8::11/128 dev veth0 nodad
  75. $IP_PEER address add 2001:db8::11 peer 2001:db8::10/128 dev veth1 nodad
  76. $IP_PEER address add 198.51.100.11/32 dev lo
  77. $IP route add table $RTABLE_PEER 198.51.100.11/32 via 192.0.2.11
  78. $IP_PEER address add 2001:db8::1:11/128 dev lo
  79. $IP route add table $RTABLE_PEER 2001:db8::1:11/128 via 2001:db8::11
  80. set +e
  81. }
  82. cleanup_peer()
  83. {
  84. $IP link del dev veth0
  85. ip netns del $peerns
  86. }
  87. setup_vrf()
  88. {
  89. $IP link add name vrf0 up type vrf table $RTABLE_VRF
  90. $IP link set dev $DEV master vrf0
  91. }
  92. cleanup_vrf()
  93. {
  94. $IP link del dev vrf0
  95. }
  96. fib_check_iproute_support()
  97. {
  98. ip rule help 2>&1 | grep -q $1
  99. if [ $? -ne 0 ]; then
  100. echo "SKIP: iproute2 iprule too old, missing $1 match"
  101. return 1
  102. fi
  103. ip route get help 2>&1 | grep -q $2
  104. if [ $? -ne 0 ]; then
  105. echo "SKIP: iproute2 get route too old, missing $2 match"
  106. return 1
  107. fi
  108. return 0
  109. }
  110. fib_rule6_del()
  111. {
  112. $IP -6 rule del $1
  113. log_test $? 0 "rule6 del $1"
  114. }
  115. fib_rule6_del_by_pref()
  116. {
  117. pref=$($IP -6 rule show $1 table $RTABLE | cut -d ":" -f 1)
  118. $IP -6 rule del pref $pref
  119. }
  120. fib_rule6_test_match_n_redirect()
  121. {
  122. local match="$1"
  123. local getmatch="$2"
  124. local getnomatch="$3"
  125. local description="$4"
  126. local nomatch_description="$5"
  127. $IP -6 rule add $match table $RTABLE
  128. $IP -6 route get $GW_IP6 $getmatch | grep -q "table $RTABLE"
  129. log_test $? 0 "rule6 check: $description"
  130. $IP -6 route get $GW_IP6 $getnomatch 2>&1 | grep -q "table $RTABLE"
  131. log_test $? 1 "rule6 check: $nomatch_description"
  132. fib_rule6_del_by_pref "$match"
  133. log_test $? 0 "rule6 del by pref: $description"
  134. }
  135. fib_rule6_test_reject()
  136. {
  137. local match="$1"
  138. local rc
  139. $IP -6 rule add $match table $RTABLE 2>/dev/null
  140. rc=$?
  141. log_test $rc 2 "rule6 check: $match"
  142. if [ $rc -eq 0 ]; then
  143. $IP -6 rule del $match table $RTABLE
  144. fi
  145. }
  146. fib_rule6_test()
  147. {
  148. local ext_name=$1; shift
  149. local getnomatch
  150. local getmatch
  151. local match
  152. local cnt
  153. echo
  154. echo "IPv6 FIB rule tests $ext_name"
  155. # setup the fib rule redirect route
  156. $IP -6 route add table $RTABLE default via $GW_IP6 dev $DEV onlink
  157. match="oif $DEV"
  158. getnomatch="oif lo"
  159. fib_rule6_test_match_n_redirect "$match" "$match" "$getnomatch" \
  160. "oif redirect to table" "oif no redirect to table"
  161. match="from $SRC_IP6 iif $DEV"
  162. getnomatch="from $SRC_IP6 iif lo"
  163. fib_rule6_test_match_n_redirect "$match" "$match" "$getnomatch" \
  164. "iif redirect to table" "iif no redirect to table"
  165. # Reject dsfield (tos) options which have ECN bits set
  166. for cnt in $(seq 1 3); do
  167. match="dsfield $cnt"
  168. fib_rule6_test_reject "$match"
  169. done
  170. # Don't take ECN bits into account when matching on dsfield
  171. match="tos 0x10"
  172. for cnt in "0x10" "0x11" "0x12" "0x13"; do
  173. # Using option 'tos' instead of 'dsfield' as old iproute2
  174. # versions don't support 'dsfield' in ip rule show.
  175. getmatch="tos $cnt"
  176. getnomatch="tos 0x20"
  177. fib_rule6_test_match_n_redirect "$match" "$getmatch" \
  178. "$getnomatch" "$getmatch redirect to table" \
  179. "$getnomatch no redirect to table"
  180. done
  181. # Re-test TOS matching, but with input routes since they are handled
  182. # differently from output routes.
  183. match="tos 0x10"
  184. for cnt in "0x10" "0x11" "0x12" "0x13"; do
  185. getmatch="tos $cnt"
  186. getnomatch="tos 0x20"
  187. fib_rule6_test_match_n_redirect "$match" \
  188. "from $SRC_IP6 iif $DEV $getmatch" \
  189. "from $SRC_IP6 iif $DEV $getnomatch" \
  190. "iif $getmatch redirect to table" \
  191. "iif $getnomatch no redirect to table"
  192. done
  193. match="fwmark 0x64"
  194. getmatch="mark 0x64"
  195. getnomatch="mark 0x63"
  196. fib_rule6_test_match_n_redirect "$match" "$getmatch" "$getnomatch" \
  197. "fwmark redirect to table" "fwmark no redirect to table"
  198. fib_check_iproute_support "uidrange" "uid"
  199. if [ $? -eq 0 ]; then
  200. match="uidrange 100-100"
  201. getmatch="uid 100"
  202. getnomatch="uid 101"
  203. fib_rule6_test_match_n_redirect "$match" "$getmatch" \
  204. "$getnomatch" "uid redirect to table" \
  205. "uid no redirect to table"
  206. fi
  207. fib_check_iproute_support "sport" "sport"
  208. if [ $? -eq 0 ]; then
  209. match="sport 666 dport 777"
  210. getnomatch="sport 667 dport 778"
  211. fib_rule6_test_match_n_redirect "$match" "$match" \
  212. "$getnomatch" "sport and dport redirect to table" \
  213. "sport and dport no redirect to table"
  214. fi
  215. fib_check_iproute_support "ipproto" "ipproto"
  216. if [ $? -eq 0 ]; then
  217. match="ipproto tcp"
  218. getnomatch="ipproto udp"
  219. fib_rule6_test_match_n_redirect "$match" "$match" \
  220. "$getnomatch" "ipproto tcp match" "ipproto udp no match"
  221. fi
  222. fib_check_iproute_support "ipproto" "ipproto"
  223. if [ $? -eq 0 ]; then
  224. match="ipproto ipv6-icmp"
  225. getnomatch="ipproto tcp"
  226. fib_rule6_test_match_n_redirect "$match" "$match" \
  227. "$getnomatch" "ipproto ipv6-icmp match" \
  228. "ipproto ipv6-tcp no match"
  229. fi
  230. fib_check_iproute_support "dscp" "tos"
  231. if [ $? -eq 0 ]; then
  232. match="dscp 0x3f"
  233. getmatch="tos 0xfc"
  234. getnomatch="tos 0xf4"
  235. fib_rule6_test_match_n_redirect "$match" "$getmatch" \
  236. "$getnomatch" "dscp redirect to table" \
  237. "dscp no redirect to table"
  238. match="dscp 0x3f"
  239. getmatch="from $SRC_IP6 iif $DEV tos 0xfc"
  240. getnomatch="from $SRC_IP6 iif $DEV tos 0xf4"
  241. fib_rule6_test_match_n_redirect "$match" "$getmatch" \
  242. "$getnomatch" "iif dscp redirect to table" \
  243. "iif dscp no redirect to table"
  244. fi
  245. }
  246. fib_rule6_vrf_test()
  247. {
  248. setup_vrf
  249. fib_rule6_test "- with VRF"
  250. cleanup_vrf
  251. }
  252. # Verify that the IPV6_TCLASS option of UDPv6 and TCPv6 sockets is properly
  253. # taken into account when connecting the socket and when sending packets.
  254. fib_rule6_connect_test()
  255. {
  256. local dsfield
  257. echo
  258. echo "IPv6 FIB rule connect tests"
  259. setup_peer
  260. $IP -6 rule add dsfield 0x04 table $RTABLE_PEER
  261. # Combine the base DS Field value (0x04) with all possible ECN values
  262. # (Not-ECT: 0, ECT(1): 1, ECT(0): 2, CE: 3).
  263. # The ECN bits shouldn't influence the result of the test.
  264. for dsfield in 0x04 0x05 0x06 0x07; do
  265. nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D \
  266. -Q "${dsfield}" -l 2001:db8::1:11 -r 2001:db8::1:11
  267. log_test $? 0 "rule6 dsfield udp connect (dsfield ${dsfield})"
  268. nettest -q -6 -B -t 5 -N $testns -O $peerns -Q "${dsfield}" \
  269. -l 2001:db8::1:11 -r 2001:db8::1:11
  270. log_test $? 0 "rule6 dsfield tcp connect (dsfield ${dsfield})"
  271. done
  272. # Check that UDP and TCP connections fail when using a DS Field that
  273. # does not match the previously configured FIB rule.
  274. nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D \
  275. -Q 0x20 -l 2001:db8::1:11 -r 2001:db8::1:11
  276. log_test $? 1 "rule6 dsfield udp no connect (dsfield 0x20)"
  277. nettest -q -6 -B -t 5 -N $testns -O $peerns -Q 0x20 \
  278. -l 2001:db8::1:11 -r 2001:db8::1:11
  279. log_test $? 1 "rule6 dsfield tcp no connect (dsfield 0x20)"
  280. $IP -6 rule del dsfield 0x04 table $RTABLE_PEER
  281. ip rule help 2>&1 | grep -q dscp
  282. if [ $? -ne 0 ]; then
  283. echo "SKIP: iproute2 iprule too old, missing dscp match"
  284. cleanup_peer
  285. return
  286. fi
  287. $IP -6 rule add dscp 0x3f table $RTABLE_PEER
  288. nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D -Q 0xfc \
  289. -l 2001:db8::1:11 -r 2001:db8::1:11
  290. log_test $? 0 "rule6 dscp udp connect"
  291. nettest -q -6 -B -t 5 -N $testns -O $peerns -Q 0xfc \
  292. -l 2001:db8::1:11 -r 2001:db8::1:11
  293. log_test $? 0 "rule6 dscp tcp connect"
  294. nettest -q -6 -B -t 5 -N $testns -O $peerns -U -D -Q 0xf4 \
  295. -l 2001:db8::1:11 -r 2001:db8::1:11
  296. log_test $? 1 "rule6 dscp udp no connect"
  297. nettest -q -6 -B -t 5 -N $testns -O $peerns -Q 0xf4 \
  298. -l 2001:db8::1:11 -r 2001:db8::1:11
  299. log_test $? 1 "rule6 dscp tcp no connect"
  300. $IP -6 rule del dscp 0x3f table $RTABLE_PEER
  301. cleanup_peer
  302. }
  303. fib_rule4_del()
  304. {
  305. $IP rule del $1
  306. log_test $? 0 "del $1"
  307. }
  308. fib_rule4_del_by_pref()
  309. {
  310. pref=$($IP rule show $1 table $RTABLE | cut -d ":" -f 1)
  311. $IP rule del pref $pref
  312. }
  313. fib_rule4_test_match_n_redirect()
  314. {
  315. local match="$1"
  316. local getmatch="$2"
  317. local getnomatch="$3"
  318. local description="$4"
  319. local nomatch_description="$5"
  320. $IP rule add $match table $RTABLE
  321. $IP route get $GW_IP4 $getmatch | grep -q "table $RTABLE"
  322. log_test $? 0 "rule4 check: $description"
  323. $IP route get $GW_IP4 $getnomatch 2>&1 | grep -q "table $RTABLE"
  324. log_test $? 1 "rule4 check: $nomatch_description"
  325. fib_rule4_del_by_pref "$match"
  326. log_test $? 0 "rule4 del by pref: $description"
  327. }
  328. fib_rule4_test_reject()
  329. {
  330. local match="$1"
  331. local rc
  332. $IP rule add $match table $RTABLE 2>/dev/null
  333. rc=$?
  334. log_test $rc 2 "rule4 check: $match"
  335. if [ $rc -eq 0 ]; then
  336. $IP rule del $match table $RTABLE
  337. fi
  338. }
  339. fib_rule4_test()
  340. {
  341. local ext_name=$1; shift
  342. local getnomatch
  343. local getmatch
  344. local match
  345. local cnt
  346. echo
  347. echo "IPv4 FIB rule tests $ext_name"
  348. # setup the fib rule redirect route
  349. $IP route add table $RTABLE default via $GW_IP4 dev $DEV onlink
  350. match="oif $DEV"
  351. getnomatch="oif lo"
  352. fib_rule4_test_match_n_redirect "$match" "$match" "$getnomatch" \
  353. "oif redirect to table" "oif no redirect to table"
  354. # Enable forwarding and disable rp_filter as all the addresses are in
  355. # the same subnet and egress device == ingress device.
  356. ip netns exec $testns sysctl -qw net.ipv4.ip_forward=1
  357. ip netns exec $testns sysctl -qw net.ipv4.conf.$DEV.rp_filter=0
  358. match="from $SRC_IP iif $DEV"
  359. getnomatch="from $SRC_IP iif lo"
  360. fib_rule4_test_match_n_redirect "$match" "$match" "$getnomatch" \
  361. "iif redirect to table" "iif no redirect to table"
  362. # Reject dsfield (tos) options which have ECN bits set
  363. for cnt in $(seq 1 3); do
  364. match="dsfield $cnt"
  365. fib_rule4_test_reject "$match"
  366. done
  367. # Don't take ECN bits into account when matching on dsfield
  368. match="tos 0x10"
  369. for cnt in "0x10" "0x11" "0x12" "0x13"; do
  370. # Using option 'tos' instead of 'dsfield' as old iproute2
  371. # versions don't support 'dsfield' in ip rule show.
  372. getmatch="tos $cnt"
  373. getnomatch="tos 0x20"
  374. fib_rule4_test_match_n_redirect "$match" "$getmatch" \
  375. "$getnomatch" "$getmatch redirect to table" \
  376. "$getnomatch no redirect to table"
  377. done
  378. # Re-test TOS matching, but with input routes since they are handled
  379. # differently from output routes.
  380. match="tos 0x10"
  381. for cnt in "0x10" "0x11" "0x12" "0x13"; do
  382. getmatch="tos $cnt"
  383. getnomatch="tos 0x20"
  384. fib_rule4_test_match_n_redirect "$match" \
  385. "from $SRC_IP iif $DEV $getmatch" \
  386. "from $SRC_IP iif $DEV $getnomatch" \
  387. "iif $getmatch redirect to table" \
  388. "iif $getnomatch no redirect to table"
  389. done
  390. match="fwmark 0x64"
  391. getmatch="mark 0x64"
  392. getnomatch="mark 0x63"
  393. fib_rule4_test_match_n_redirect "$match" "$getmatch" "$getnomatch" \
  394. "fwmark redirect to table" "fwmark no redirect to table"
  395. fib_check_iproute_support "uidrange" "uid"
  396. if [ $? -eq 0 ]; then
  397. match="uidrange 100-100"
  398. getmatch="uid 100"
  399. getnomatch="uid 101"
  400. fib_rule4_test_match_n_redirect "$match" "$getmatch" \
  401. "$getnomatch" "uid redirect to table" \
  402. "uid no redirect to table"
  403. fi
  404. fib_check_iproute_support "sport" "sport"
  405. if [ $? -eq 0 ]; then
  406. match="sport 666 dport 777"
  407. getnomatch="sport 667 dport 778"
  408. fib_rule4_test_match_n_redirect "$match" "$match" \
  409. "$getnomatch" "sport and dport redirect to table" \
  410. "sport and dport no redirect to table"
  411. fi
  412. fib_check_iproute_support "ipproto" "ipproto"
  413. if [ $? -eq 0 ]; then
  414. match="ipproto tcp"
  415. getnomatch="ipproto udp"
  416. fib_rule4_test_match_n_redirect "$match" "$match" \
  417. "$getnomatch" "ipproto tcp match" \
  418. "ipproto udp no match"
  419. fi
  420. fib_check_iproute_support "ipproto" "ipproto"
  421. if [ $? -eq 0 ]; then
  422. match="ipproto icmp"
  423. getnomatch="ipproto tcp"
  424. fib_rule4_test_match_n_redirect "$match" "$match" \
  425. "$getnomatch" "ipproto icmp match" \
  426. "ipproto tcp no match"
  427. fi
  428. fib_check_iproute_support "dscp" "tos"
  429. if [ $? -eq 0 ]; then
  430. match="dscp 0x3f"
  431. getmatch="tos 0xfc"
  432. getnomatch="tos 0xf4"
  433. fib_rule4_test_match_n_redirect "$match" "$getmatch" \
  434. "$getnomatch" "dscp redirect to table" \
  435. "dscp no redirect to table"
  436. match="dscp 0x3f"
  437. getmatch="from $SRC_IP iif $DEV tos 0xfc"
  438. getnomatch="from $SRC_IP iif $DEV tos 0xf4"
  439. fib_rule4_test_match_n_redirect "$match" "$getmatch" \
  440. "$getnomatch" "iif dscp redirect to table" \
  441. "iif dscp no redirect to table"
  442. fi
  443. }
  444. fib_rule4_vrf_test()
  445. {
  446. setup_vrf
  447. fib_rule4_test "- with VRF"
  448. cleanup_vrf
  449. }
  450. # Verify that the IP_TOS option of UDPv4 and TCPv4 sockets is properly taken
  451. # into account when connecting the socket and when sending packets.
  452. fib_rule4_connect_test()
  453. {
  454. local dsfield
  455. echo
  456. echo "IPv4 FIB rule connect tests"
  457. setup_peer
  458. $IP -4 rule add dsfield 0x04 table $RTABLE_PEER
  459. # Combine the base DS Field value (0x04) with all possible ECN values
  460. # (Not-ECT: 0, ECT(1): 1, ECT(0): 2, CE: 3).
  461. # The ECN bits shouldn't influence the result of the test.
  462. for dsfield in 0x04 0x05 0x06 0x07; do
  463. nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q "${dsfield}" \
  464. -l 198.51.100.11 -r 198.51.100.11
  465. log_test $? 0 "rule4 dsfield udp connect (dsfield ${dsfield})"
  466. nettest -q -B -t 5 -N $testns -O $peerns -Q "${dsfield}" \
  467. -l 198.51.100.11 -r 198.51.100.11
  468. log_test $? 0 "rule4 dsfield tcp connect (dsfield ${dsfield})"
  469. done
  470. # Check that UDP and TCP connections fail when using a DS Field that
  471. # does not match the previously configured FIB rule.
  472. nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q 0x20 \
  473. -l 198.51.100.11 -r 198.51.100.11
  474. log_test $? 1 "rule4 dsfield udp no connect (dsfield 0x20)"
  475. nettest -q -B -t 5 -N $testns -O $peerns -Q 0x20 \
  476. -l 198.51.100.11 -r 198.51.100.11
  477. log_test $? 1 "rule4 dsfield tcp no connect (dsfield 0x20)"
  478. $IP -4 rule del dsfield 0x04 table $RTABLE_PEER
  479. ip rule help 2>&1 | grep -q dscp
  480. if [ $? -ne 0 ]; then
  481. echo "SKIP: iproute2 iprule too old, missing dscp match"
  482. cleanup_peer
  483. return
  484. fi
  485. $IP -4 rule add dscp 0x3f table $RTABLE_PEER
  486. nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q 0xfc \
  487. -l 198.51.100.11 -r 198.51.100.11
  488. log_test $? 0 "rule4 dscp udp connect"
  489. nettest -q -B -t 5 -N $testns -O $peerns -Q 0xfc \
  490. -l 198.51.100.11 -r 198.51.100.11
  491. log_test $? 0 "rule4 dscp tcp connect"
  492. nettest -q -B -t 5 -N $testns -O $peerns -D -U -Q 0xf4 \
  493. -l 198.51.100.11 -r 198.51.100.11
  494. log_test $? 1 "rule4 dscp udp no connect"
  495. nettest -q -B -t 5 -N $testns -O $peerns -Q 0xf4 \
  496. -l 198.51.100.11 -r 198.51.100.11
  497. log_test $? 1 "rule4 dscp tcp no connect"
  498. $IP -4 rule del dscp 0x3f table $RTABLE_PEER
  499. cleanup_peer
  500. }
  501. ################################################################################
  502. # usage
  503. usage()
  504. {
  505. cat <<EOF
  506. usage: ${0##*/} OPTS
  507. -t <test> Test(s) to run (default: all)
  508. (options: $TESTS)
  509. EOF
  510. }
  511. ################################################################################
  512. # main
  513. while getopts ":t:h" opt; do
  514. case $opt in
  515. t) TESTS=$OPTARG;;
  516. h) usage; exit 0;;
  517. *) usage; exit 1;;
  518. esac
  519. done
  520. if [ "$(id -u)" -ne 0 ];then
  521. echo "SKIP: Need root privileges"
  522. exit $ksft_skip
  523. fi
  524. if [ ! -x "$(command -v ip)" ]; then
  525. echo "SKIP: Could not run test without ip tool"
  526. exit $ksft_skip
  527. fi
  528. check_gen_prog "nettest"
  529. # start clean
  530. cleanup &> /dev/null
  531. setup
  532. for t in $TESTS
  533. do
  534. case $t in
  535. fib_rule6_test|fib_rule6) fib_rule6_test;;
  536. fib_rule4_test|fib_rule4) fib_rule4_test;;
  537. fib_rule6_connect_test|fib_rule6_connect) fib_rule6_connect_test;;
  538. fib_rule4_connect_test|fib_rule4_connect) fib_rule4_connect_test;;
  539. fib_rule6_vrf_test|fib_rule6_vrf) fib_rule6_vrf_test;;
  540. fib_rule4_vrf_test|fib_rule4_vrf) fib_rule4_vrf_test;;
  541. help) echo "Test names: $TESTS"; exit 0;;
  542. esac
  543. done
  544. cleanup
  545. if [ "$TESTS" != "none" ]; then
  546. printf "\nTests passed: %3d\n" ${nsuccess}
  547. printf "Tests failed: %3d\n" ${nfail}
  548. fi
  549. exit $ret