vrf_route_leaking.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Copyright (c) 2019 David Ahern <dsahern@gmail.com>. All rights reserved.
  5. # Copyright (c) 2020 Michael Jeanson <mjeanson@efficios.com>. All rights reserved.
  6. #
  7. # Requires CONFIG_NET_VRF, CONFIG_VETH, CONFIG_BRIDGE and CONFIG_NET_NS.
  8. #
  9. #
  10. # Symmetric routing topology
  11. #
  12. # blue red
  13. # +----+ .253 +----+ .253 +----+
  14. # | h1 |-------------------| r1 |-------------------| h2 |
  15. # +----+ .1 +----+ .2 +----+
  16. # 172.16.1/24 172.16.2/24
  17. # 2001:db8:16:1/64 2001:db8:16:2/64
  18. #
  19. #
  20. # Route from h1 to h2 and back goes through r1, incoming vrf blue has a route
  21. # to the outgoing vrf red for the n2 network and red has a route back to n1.
  22. # The red VRF interface has a MTU of 1400.
  23. #
  24. # The first test sends a ping with a ttl of 1 from h1 to h2 and parses the
  25. # output of the command to check that a ttl expired error is received.
  26. #
  27. # The second test runs traceroute from h1 to h2 and parses the output to check
  28. # for a hop on r1.
  29. #
  30. # The third test sends a ping with a packet size of 1450 from h1 to h2 and
  31. # parses the output of the command to check that a fragmentation error is
  32. # received.
  33. #
  34. #
  35. # Asymmetric routing topology
  36. #
  37. # This topology represents a customer setup where the issue with icmp errors
  38. # and VRF route leaking was initialy reported. The MTU test isn't done here
  39. # because of the lack of a return route in the red VRF.
  40. #
  41. # blue red
  42. # .253 +----+ .253
  43. # +----| r1 |----+
  44. # | +----+ |
  45. # +----+ | | +----+
  46. # | h1 |--------------+ +--------------| h2 |
  47. # +----+ .1 | | .2 +----+
  48. # 172.16.1/24 | +----+ | 172.16.2/24
  49. # 2001:db8:16:1/64 +----| r2 |----+ 2001:db8:16:2/64
  50. # .254 +----+ .254
  51. #
  52. #
  53. # Route from h1 to h2 goes through r1, incoming vrf blue has a route to the
  54. # outgoing vrf red for the n2 network but red doesn't have a route back to n1.
  55. # Route from h2 to h1 goes through r2.
  56. #
  57. # The objective is to check that the incoming vrf routing table is selected
  58. # to send an ICMP error back to the source when the ttl of a packet reaches 1
  59. # while it is forwarded between different vrfs.
  60. source lib.sh
  61. VERBOSE=0
  62. PAUSE_ON_FAIL=no
  63. DEFAULT_TTYPE=sym
  64. H1_N1=172.16.1.0/24
  65. H1_N1_6=2001:db8:16:1::/64
  66. H1_N1_IP=172.16.1.1
  67. R1_N1_IP=172.16.1.253
  68. R2_N1_IP=172.16.1.254
  69. H1_N1_IP6=2001:db8:16:1::1
  70. R1_N1_IP6=2001:db8:16:1::253
  71. R2_N1_IP6=2001:db8:16:1::254
  72. H2_N2=172.16.2.0/24
  73. H2_N2_6=2001:db8:16:2::/64
  74. H2_N2_IP=172.16.2.2
  75. R1_N2_IP=172.16.2.253
  76. R2_N2_IP=172.16.2.254
  77. H2_N2_IP6=2001:db8:16:2::2
  78. R1_N2_IP6=2001:db8:16:2::253
  79. R2_N2_IP6=2001:db8:16:2::254
  80. ################################################################################
  81. # helpers
  82. log_section()
  83. {
  84. echo
  85. echo "###########################################################################"
  86. echo "$*"
  87. echo "###########################################################################"
  88. echo
  89. }
  90. log_test()
  91. {
  92. local rc=$1
  93. local expected=$2
  94. local msg="$3"
  95. if [ "${rc}" -eq "${expected}" ]; then
  96. printf "TEST: %-60s [ OK ]\n" "${msg}"
  97. nsuccess=$((nsuccess+1))
  98. else
  99. ret=1
  100. nfail=$((nfail+1))
  101. printf "TEST: %-60s [FAIL]\n" "${msg}"
  102. if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
  103. echo
  104. echo "hit enter to continue, 'q' to quit"
  105. read -r a
  106. [ "$a" = "q" ] && exit 1
  107. fi
  108. fi
  109. }
  110. run_cmd()
  111. {
  112. local cmd="$*"
  113. local out
  114. local rc
  115. if [ "$VERBOSE" = "1" ]; then
  116. echo "COMMAND: $cmd"
  117. fi
  118. # shellcheck disable=SC2086
  119. out=$(eval $cmd 2>&1)
  120. rc=$?
  121. if [ "$VERBOSE" = "1" ] && [ -n "$out" ]; then
  122. echo "$out"
  123. fi
  124. [ "$VERBOSE" = "1" ] && echo
  125. return $rc
  126. }
  127. run_cmd_grep()
  128. {
  129. local grep_pattern="$1"
  130. shift
  131. local cmd="$*"
  132. local out
  133. local rc
  134. if [ "$VERBOSE" = "1" ]; then
  135. echo "COMMAND: $cmd"
  136. fi
  137. # shellcheck disable=SC2086
  138. out=$(eval $cmd 2>&1)
  139. if [ "$VERBOSE" = "1" ] && [ -n "$out" ]; then
  140. echo "$out"
  141. fi
  142. echo "$out" | grep -q "$grep_pattern"
  143. rc=$?
  144. [ "$VERBOSE" = "1" ] && echo
  145. return $rc
  146. }
  147. ################################################################################
  148. # setup and teardown
  149. cleanup()
  150. {
  151. cleanup_ns $h1 $h2 $r1 $r2
  152. }
  153. setup_vrf()
  154. {
  155. local ns=$1
  156. ip -netns "${ns}" rule del pref 0
  157. ip -netns "${ns}" rule add pref 32765 from all lookup local
  158. ip -netns "${ns}" -6 rule del pref 0
  159. ip -netns "${ns}" -6 rule add pref 32765 from all lookup local
  160. }
  161. create_vrf()
  162. {
  163. local ns=$1
  164. local vrf=$2
  165. local table=$3
  166. ip -netns "${ns}" link add "${vrf}" type vrf table "${table}"
  167. ip -netns "${ns}" link set "${vrf}" up
  168. ip -netns "${ns}" route add vrf "${vrf}" unreachable default metric 8192
  169. ip -netns "${ns}" -6 route add vrf "${vrf}" unreachable default metric 8192
  170. ip -netns "${ns}" addr add 127.0.0.1/8 dev "${vrf}"
  171. ip -netns "${ns}" -6 addr add ::1 dev "${vrf}" nodad
  172. }
  173. setup_sym()
  174. {
  175. local ns
  176. # make sure we are starting with a clean slate
  177. cleanup
  178. #
  179. # create nodes as namespaces
  180. setup_ns h1 h2 r1
  181. for ns in $h1 $h2 $r1; do
  182. if echo $ns | grep -q h[12]-; then
  183. ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=0
  184. ip netns exec $ns sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1
  185. else
  186. ip netns exec $ns sysctl -q -w net.ipv4.ip_forward=1
  187. ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=1
  188. fi
  189. done
  190. #
  191. # create interconnects
  192. #
  193. ip -netns $h1 link add eth0 type veth peer name r1h1
  194. ip -netns $h1 link set r1h1 netns $r1 name eth0 up
  195. ip -netns $h2 link add eth0 type veth peer name r1h2
  196. ip -netns $h2 link set r1h2 netns $r1 name eth1 up
  197. #
  198. # h1
  199. #
  200. ip -netns $h1 addr add dev eth0 ${H1_N1_IP}/24
  201. ip -netns $h1 -6 addr add dev eth0 ${H1_N1_IP6}/64 nodad
  202. ip -netns $h1 link set eth0 up
  203. # h1 to h2 via r1
  204. ip -netns $h1 route add ${H2_N2} via ${R1_N1_IP} dev eth0
  205. ip -netns $h1 -6 route add ${H2_N2_6} via "${R1_N1_IP6}" dev eth0
  206. #
  207. # h2
  208. #
  209. ip -netns $h2 addr add dev eth0 ${H2_N2_IP}/24
  210. ip -netns $h2 -6 addr add dev eth0 ${H2_N2_IP6}/64 nodad
  211. ip -netns $h2 link set eth0 up
  212. # h2 to h1 via r1
  213. ip -netns $h2 route add default via ${R1_N2_IP} dev eth0
  214. ip -netns $h2 -6 route add default via ${R1_N2_IP6} dev eth0
  215. #
  216. # r1
  217. #
  218. setup_vrf $r1
  219. create_vrf $r1 blue 1101
  220. create_vrf $r1 red 1102
  221. ip -netns $r1 link set mtu 1400 dev eth1
  222. ip -netns $r1 link set eth0 vrf blue up
  223. ip -netns $r1 link set eth1 vrf red up
  224. ip -netns $r1 addr add dev eth0 ${R1_N1_IP}/24
  225. ip -netns $r1 -6 addr add dev eth0 ${R1_N1_IP6}/64 nodad
  226. ip -netns $r1 addr add dev eth1 ${R1_N2_IP}/24
  227. ip -netns $r1 -6 addr add dev eth1 ${R1_N2_IP6}/64 nodad
  228. # Route leak from blue to red
  229. ip -netns $r1 route add vrf blue ${H2_N2} dev red
  230. ip -netns $r1 -6 route add vrf blue ${H2_N2_6} dev red
  231. # Route leak from red to blue
  232. ip -netns $r1 route add vrf red ${H1_N1} dev blue
  233. ip -netns $r1 -6 route add vrf red ${H1_N1_6} dev blue
  234. # Wait for ip config to settle
  235. slowwait 5 ip netns exec $h1 "${ping6}" -c1 -w1 ${H2_N2_IP6} >/dev/null 2>&1
  236. }
  237. setup_asym()
  238. {
  239. local ns
  240. # make sure we are starting with a clean slate
  241. cleanup
  242. #
  243. # create nodes as namespaces
  244. setup_ns h1 h2 r1 r2
  245. for ns in $h1 $h2 $r1 $r2; do
  246. if echo $ns | grep -q h[12]-; then
  247. ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=0
  248. ip netns exec $ns sysctl -q -w net.ipv6.conf.all.keep_addr_on_down=1
  249. else
  250. ip netns exec $ns sysctl -q -w net.ipv4.ip_forward=1
  251. ip netns exec $ns sysctl -q -w net.ipv6.conf.all.forwarding=1
  252. fi
  253. done
  254. #
  255. # create interconnects
  256. #
  257. ip -netns $h1 link add eth0 type veth peer name r1h1
  258. ip -netns $h1 link set r1h1 netns $r1 name eth0 up
  259. ip -netns $h1 link add eth1 type veth peer name r2h1
  260. ip -netns $h1 link set r2h1 netns $r2 name eth0 up
  261. ip -netns $h2 link add eth0 type veth peer name r1h2
  262. ip -netns $h2 link set r1h2 netns $r1 name eth1 up
  263. ip -netns $h2 link add eth1 type veth peer name r2h2
  264. ip -netns $h2 link set r2h2 netns $r2 name eth1 up
  265. #
  266. # h1
  267. #
  268. ip -netns $h1 link add br0 type bridge
  269. ip -netns $h1 link set br0 up
  270. ip -netns $h1 addr add dev br0 ${H1_N1_IP}/24
  271. ip -netns $h1 -6 addr add dev br0 ${H1_N1_IP6}/64 nodad
  272. ip -netns $h1 link set eth0 master br0 up
  273. ip -netns $h1 link set eth1 master br0 up
  274. # h1 to h2 via r1
  275. ip -netns $h1 route add ${H2_N2} via ${R1_N1_IP} dev br0
  276. ip -netns $h1 -6 route add ${H2_N2_6} via "${R1_N1_IP6}" dev br0
  277. #
  278. # h2
  279. #
  280. ip -netns $h2 link add br0 type bridge
  281. ip -netns $h2 link set br0 up
  282. ip -netns $h2 addr add dev br0 ${H2_N2_IP}/24
  283. ip -netns $h2 -6 addr add dev br0 ${H2_N2_IP6}/64 nodad
  284. ip -netns $h2 link set eth0 master br0 up
  285. ip -netns $h2 link set eth1 master br0 up
  286. # h2 to h1 via r2
  287. ip -netns $h2 route add default via ${R2_N2_IP} dev br0
  288. ip -netns $h2 -6 route add default via ${R2_N2_IP6} dev br0
  289. #
  290. # r1
  291. #
  292. setup_vrf $r1
  293. create_vrf $r1 blue 1101
  294. create_vrf $r1 red 1102
  295. ip -netns $r1 link set mtu 1400 dev eth1
  296. ip -netns $r1 link set eth0 vrf blue up
  297. ip -netns $r1 link set eth1 vrf red up
  298. ip -netns $r1 addr add dev eth0 ${R1_N1_IP}/24
  299. ip -netns $r1 -6 addr add dev eth0 ${R1_N1_IP6}/64 nodad
  300. ip -netns $r1 addr add dev eth1 ${R1_N2_IP}/24
  301. ip -netns $r1 -6 addr add dev eth1 ${R1_N2_IP6}/64 nodad
  302. # Route leak from blue to red
  303. ip -netns $r1 route add vrf blue ${H2_N2} dev red
  304. ip -netns $r1 -6 route add vrf blue ${H2_N2_6} dev red
  305. # No route leak from red to blue
  306. #
  307. # r2
  308. #
  309. ip -netns $r2 addr add dev eth0 ${R2_N1_IP}/24
  310. ip -netns $r2 -6 addr add dev eth0 ${R2_N1_IP6}/64 nodad
  311. ip -netns $r2 addr add dev eth1 ${R2_N2_IP}/24
  312. ip -netns $r2 -6 addr add dev eth1 ${R2_N2_IP6}/64 nodad
  313. # Wait for ip config to settle
  314. slowwait 5 ip netns exec $h1 "${ping6}" -c1 -w1 ${H2_N2_IP6} >/dev/null 2>&1
  315. }
  316. check_connectivity()
  317. {
  318. ip netns exec $h1 ping -c1 -w1 ${H2_N2_IP} >/dev/null 2>&1
  319. log_test $? 0 "Basic IPv4 connectivity"
  320. return $?
  321. }
  322. check_connectivity6()
  323. {
  324. ip netns exec $h1 "${ping6}" -c1 -w1 ${H2_N2_IP6} >/dev/null 2>&1
  325. log_test $? 0 "Basic IPv6 connectivity"
  326. return $?
  327. }
  328. check_traceroute()
  329. {
  330. if [ ! -x "$(command -v traceroute)" ]; then
  331. echo "SKIP: Could not run IPV4 test without traceroute"
  332. return 1
  333. fi
  334. }
  335. check_traceroute6()
  336. {
  337. if [ ! -x "$(command -v traceroute6)" ]; then
  338. echo "SKIP: Could not run IPV6 test without traceroute6"
  339. return 1
  340. fi
  341. }
  342. ipv4_traceroute()
  343. {
  344. local ttype="$1"
  345. [ "x$ttype" = "x" ] && ttype="$DEFAULT_TTYPE"
  346. log_section "IPv4 ($ttype route): VRF ICMP error route lookup traceroute"
  347. check_traceroute || return
  348. setup_"$ttype"
  349. check_connectivity || return
  350. run_cmd_grep "${R1_N1_IP}" ip netns exec $h1 traceroute ${H2_N2_IP}
  351. log_test $? 0 "Traceroute reports a hop on r1"
  352. }
  353. ipv4_traceroute_asym()
  354. {
  355. ipv4_traceroute asym
  356. }
  357. ipv6_traceroute()
  358. {
  359. local ttype="$1"
  360. [ "x$ttype" = "x" ] && ttype="$DEFAULT_TTYPE"
  361. log_section "IPv6 ($ttype route): VRF ICMP error route lookup traceroute"
  362. check_traceroute6 || return
  363. setup_"$ttype"
  364. check_connectivity6 || return
  365. run_cmd_grep "${R1_N1_IP6}" ip netns exec $h1 traceroute6 ${H2_N2_IP6}
  366. log_test $? 0 "Traceroute6 reports a hop on r1"
  367. }
  368. ipv6_traceroute_asym()
  369. {
  370. ipv6_traceroute asym
  371. }
  372. ipv4_ping_ttl()
  373. {
  374. local ttype="$1"
  375. [ "x$ttype" = "x" ] && ttype="$DEFAULT_TTYPE"
  376. log_section "IPv4 ($ttype route): VRF ICMP ttl error route lookup ping"
  377. setup_"$ttype"
  378. check_connectivity || return
  379. run_cmd_grep "Time to live exceeded" ip netns exec $h1 ping -t1 -c1 -W2 ${H2_N2_IP}
  380. log_test $? 0 "Ping received ICMP ttl exceeded"
  381. }
  382. ipv4_ping_ttl_asym()
  383. {
  384. ipv4_ping_ttl asym
  385. }
  386. ipv4_ping_frag()
  387. {
  388. local ttype="$1"
  389. [ "x$ttype" = "x" ] && ttype="$DEFAULT_TTYPE"
  390. log_section "IPv4 ($ttype route): VRF ICMP fragmentation error route lookup ping"
  391. setup_"$ttype"
  392. check_connectivity || return
  393. run_cmd_grep "Frag needed" ip netns exec $h1 ping -s 1450 -Mdo -c1 -W2 ${H2_N2_IP}
  394. log_test $? 0 "Ping received ICMP Frag needed"
  395. }
  396. ipv4_ping_frag_asym()
  397. {
  398. ipv4_ping_frag asym
  399. }
  400. ipv6_ping_ttl()
  401. {
  402. local ttype="$1"
  403. [ "x$ttype" = "x" ] && ttype="$DEFAULT_TTYPE"
  404. log_section "IPv6 ($ttype route): VRF ICMP ttl error route lookup ping"
  405. setup_"$ttype"
  406. check_connectivity6 || return
  407. run_cmd_grep "Time exceeded: Hop limit" ip netns exec $h1 "${ping6}" -t1 -c1 -W2 ${H2_N2_IP6}
  408. log_test $? 0 "Ping received ICMP Hop limit"
  409. }
  410. ipv6_ping_ttl_asym()
  411. {
  412. ipv6_ping_ttl asym
  413. }
  414. ipv6_ping_frag()
  415. {
  416. local ttype="$1"
  417. [ "x$ttype" = "x" ] && ttype="$DEFAULT_TTYPE"
  418. log_section "IPv6 ($ttype route): VRF ICMP fragmentation error route lookup ping"
  419. setup_"$ttype"
  420. check_connectivity6 || return
  421. run_cmd_grep "Packet too big" ip netns exec $h1 "${ping6}" -s 1450 -Mdo -c1 -W2 ${H2_N2_IP6}
  422. log_test $? 0 "Ping received ICMP Packet too big"
  423. }
  424. ipv6_ping_frag_asym()
  425. {
  426. ipv6_ping_frag asym
  427. }
  428. ipv4_ping_local()
  429. {
  430. log_section "IPv4 (sym route): VRF ICMP local error route lookup ping"
  431. setup_sym
  432. check_connectivity || return
  433. run_cmd ip netns exec $r1 ip vrf exec blue ping -c1 -w1 ${H2_N2_IP}
  434. log_test $? 0 "VRF ICMP local IPv4"
  435. }
  436. ipv4_tcp_local()
  437. {
  438. log_section "IPv4 (sym route): VRF tcp local connection"
  439. setup_sym
  440. check_connectivity || return
  441. run_cmd nettest -s -O "$h2" -l ${H2_N2_IP} -I eth0 -3 eth0 &
  442. sleep 1
  443. run_cmd nettest -N "$r1" -d blue -r ${H2_N2_IP}
  444. log_test $? 0 "VRF tcp local connection IPv4"
  445. }
  446. ipv4_udp_local()
  447. {
  448. log_section "IPv4 (sym route): VRF udp local connection"
  449. setup_sym
  450. check_connectivity || return
  451. run_cmd nettest -s -D -O "$h2" -l ${H2_N2_IP} -I eth0 -3 eth0 &
  452. sleep 1
  453. run_cmd nettest -D -N "$r1" -d blue -r ${H2_N2_IP}
  454. log_test $? 0 "VRF udp local connection IPv4"
  455. }
  456. ipv6_ping_local()
  457. {
  458. log_section "IPv6 (sym route): VRF ICMP local error route lookup ping"
  459. setup_sym
  460. check_connectivity6 || return
  461. run_cmd ip netns exec $r1 ip vrf exec blue ${ping6} -c1 -w1 ${H2_N2_IP6}
  462. log_test $? 0 "VRF ICMP local IPv6"
  463. }
  464. ipv6_tcp_local()
  465. {
  466. log_section "IPv6 (sym route): VRF tcp local connection"
  467. setup_sym
  468. check_connectivity6 || return
  469. run_cmd nettest -s -6 -O "$h2" -l ${H2_N2_IP6} -I eth0 -3 eth0 &
  470. sleep 1
  471. run_cmd nettest -6 -N "$r1" -d blue -r ${H2_N2_IP6}
  472. log_test $? 0 "VRF tcp local connection IPv6"
  473. }
  474. ipv6_udp_local()
  475. {
  476. log_section "IPv6 (sym route): VRF udp local connection"
  477. setup_sym
  478. check_connectivity6 || return
  479. run_cmd nettest -s -6 -D -O "$h2" -l ${H2_N2_IP6} -I eth0 -3 eth0 &
  480. sleep 1
  481. run_cmd nettest -6 -D -N "$r1" -d blue -r ${H2_N2_IP6}
  482. log_test $? 0 "VRF udp local connection IPv6"
  483. }
  484. ################################################################################
  485. # usage
  486. usage()
  487. {
  488. cat <<EOF
  489. usage: ${0##*/} OPTS
  490. -4 Run IPv4 tests only
  491. -6 Run IPv6 tests only
  492. -t TEST Run only TEST
  493. -p Pause on fail
  494. -v verbose mode (show commands and output)
  495. EOF
  496. }
  497. ################################################################################
  498. # main
  499. # Some systems don't have a ping6 binary anymore
  500. command -v ping6 > /dev/null 2>&1 && ping6=$(command -v ping6) || ping6=$(command -v ping)
  501. check_gen_prog "nettest"
  502. TESTS_IPV4="ipv4_ping_ttl ipv4_traceroute ipv4_ping_frag ipv4_ping_local ipv4_tcp_local
  503. ipv4_udp_local ipv4_ping_ttl_asym ipv4_traceroute_asym"
  504. TESTS_IPV6="ipv6_ping_ttl ipv6_traceroute ipv6_ping_local ipv6_tcp_local ipv6_udp_local
  505. ipv6_ping_ttl_asym ipv6_traceroute_asym"
  506. ret=0
  507. nsuccess=0
  508. nfail=0
  509. while getopts :46t:pvh o
  510. do
  511. case $o in
  512. 4) TESTS=ipv4;;
  513. 6) TESTS=ipv6;;
  514. t) TESTS=$OPTARG;;
  515. p) PAUSE_ON_FAIL=yes;;
  516. v) VERBOSE=1;;
  517. h) usage; exit 0;;
  518. *) usage; exit 1;;
  519. esac
  520. done
  521. #
  522. # show user test config
  523. #
  524. if [ -z "$TESTS" ]; then
  525. TESTS="$TESTS_IPV4 $TESTS_IPV6"
  526. elif [ "$TESTS" = "ipv4" ]; then
  527. TESTS="$TESTS_IPV4"
  528. elif [ "$TESTS" = "ipv6" ]; then
  529. TESTS="$TESTS_IPV6"
  530. fi
  531. for t in $TESTS
  532. do
  533. case $t in
  534. ipv4_ping_ttl|ping) ipv4_ping_ttl;;&
  535. ipv4_ping_ttl_asym|ping) ipv4_ping_ttl_asym;;&
  536. ipv4_traceroute|traceroute) ipv4_traceroute;;&
  537. ipv4_traceroute_asym|traceroute) ipv4_traceroute_asym;;&
  538. ipv4_ping_frag|ping) ipv4_ping_frag;;&
  539. ipv4_ping_local|ping) ipv4_ping_local;;&
  540. ipv4_tcp_local) ipv4_tcp_local;;&
  541. ipv4_udp_local) ipv4_udp_local;;&
  542. ipv6_ping_ttl|ping) ipv6_ping_ttl;;&
  543. ipv6_ping_ttl_asym|ping) ipv6_ping_ttl_asym;;&
  544. ipv6_traceroute|traceroute) ipv6_traceroute;;&
  545. ipv6_traceroute_asym|traceroute) ipv6_traceroute_asym;;&
  546. ipv6_ping_frag|ping) ipv6_ping_frag;;&
  547. ipv6_ping_local|ping) ipv6_ping_local;;&
  548. ipv6_tcp_local) ipv6_tcp_local;;&
  549. ipv6_udp_local) ipv6_udp_local;;&
  550. # setup namespaces and config, but do not run any tests
  551. setup_sym|setup) setup_sym; exit 0;;
  552. setup_asym) setup_asym; exit 0;;
  553. help) echo "Test names: $TESTS"; exit 0;;
  554. esac
  555. done
  556. cleanup
  557. printf "\nTests passed: %3d\n" ${nsuccess}
  558. printf "Tests failed: %3d\n" ${nfail}
  559. exit $ret