fib_tests.sh 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # This test is for checking IPv4 and IPv6 FIB behavior in response to
  4. # different events.
  5. source lib.sh
  6. ret=0
  7. # all tests in this script. Can be overridden with -t option
  8. TESTS="unregister down carrier nexthop suppress ipv6_notify ipv4_notify \
  9. ipv6_rt ipv4_rt ipv6_addr_metric ipv4_addr_metric ipv6_route_metrics \
  10. ipv4_route_metrics ipv4_route_v6_gw rp_filter ipv4_del_addr \
  11. ipv6_del_addr ipv4_mangle ipv6_mangle ipv4_bcast_neigh fib6_gc_test \
  12. ipv4_mpath_list ipv6_mpath_list"
  13. VERBOSE=0
  14. PAUSE_ON_FAIL=no
  15. PAUSE=no
  16. which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
  17. log_test()
  18. {
  19. local rc=$1
  20. local expected=$2
  21. local msg="$3"
  22. if [ ${rc} -eq ${expected} ]; then
  23. printf " TEST: %-60s [ OK ]\n" "${msg}"
  24. nsuccess=$((nsuccess+1))
  25. else
  26. ret=1
  27. nfail=$((nfail+1))
  28. printf " TEST: %-60s [FAIL]\n" "${msg}"
  29. if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
  30. echo
  31. echo "hit enter to continue, 'q' to quit"
  32. read a
  33. [ "$a" = "q" ] && exit 1
  34. fi
  35. fi
  36. if [ "${PAUSE}" = "yes" ]; then
  37. echo
  38. echo "hit enter to continue, 'q' to quit"
  39. read a
  40. [ "$a" = "q" ] && exit 1
  41. fi
  42. }
  43. setup()
  44. {
  45. set -e
  46. setup_ns ns1
  47. IP="$(which ip) -netns $ns1"
  48. NS_EXEC="$(which ip) netns exec $ns1"
  49. ip netns exec $ns1 sysctl -qw net.ipv4.ip_forward=1
  50. ip netns exec $ns1 sysctl -qw net.ipv6.conf.all.forwarding=1
  51. $IP link add dummy0 type dummy
  52. $IP link set dev dummy0 up
  53. $IP address add 198.51.100.1/24 dev dummy0
  54. $IP -6 address add 2001:db8:1::1/64 dev dummy0
  55. set +e
  56. }
  57. cleanup()
  58. {
  59. $IP link del dev dummy0 &> /dev/null
  60. cleanup_ns $ns1 $ns2
  61. }
  62. get_linklocal()
  63. {
  64. local dev=$1
  65. local addr
  66. addr=$($IP -6 -br addr show dev ${dev} | \
  67. awk '{
  68. for (i = 3; i <= NF; ++i) {
  69. if ($i ~ /^fe80/)
  70. print $i
  71. }
  72. }'
  73. )
  74. addr=${addr/\/*}
  75. [ -z "$addr" ] && return 1
  76. echo $addr
  77. return 0
  78. }
  79. fib_unreg_unicast_test()
  80. {
  81. echo
  82. echo "Single path route test"
  83. setup
  84. echo " Start point"
  85. $IP route get fibmatch 198.51.100.2 &> /dev/null
  86. log_test $? 0 "IPv4 fibmatch"
  87. $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
  88. log_test $? 0 "IPv6 fibmatch"
  89. set -e
  90. $IP link del dev dummy0
  91. set +e
  92. echo " Nexthop device deleted"
  93. $IP route get fibmatch 198.51.100.2 &> /dev/null
  94. log_test $? 2 "IPv4 fibmatch - no route"
  95. $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
  96. log_test $? 2 "IPv6 fibmatch - no route"
  97. cleanup
  98. }
  99. fib_unreg_multipath_test()
  100. {
  101. echo
  102. echo "Multipath route test"
  103. setup
  104. set -e
  105. $IP link add dummy1 type dummy
  106. $IP link set dev dummy1 up
  107. $IP address add 192.0.2.1/24 dev dummy1
  108. $IP -6 address add 2001:db8:2::1/64 dev dummy1
  109. $IP route add 203.0.113.0/24 \
  110. nexthop via 198.51.100.2 dev dummy0 \
  111. nexthop via 192.0.2.2 dev dummy1
  112. $IP -6 route add 2001:db8:3::/64 \
  113. nexthop via 2001:db8:1::2 dev dummy0 \
  114. nexthop via 2001:db8:2::2 dev dummy1
  115. set +e
  116. echo " Start point"
  117. $IP route get fibmatch 203.0.113.1 &> /dev/null
  118. log_test $? 0 "IPv4 fibmatch"
  119. $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
  120. log_test $? 0 "IPv6 fibmatch"
  121. set -e
  122. $IP link del dev dummy0
  123. set +e
  124. echo " One nexthop device deleted"
  125. $IP route get fibmatch 203.0.113.1 &> /dev/null
  126. log_test $? 2 "IPv4 - multipath route removed on delete"
  127. $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
  128. # In IPv6 we do not flush the entire multipath route.
  129. log_test $? 0 "IPv6 - multipath down to single path"
  130. set -e
  131. $IP link del dev dummy1
  132. set +e
  133. echo " Second nexthop device deleted"
  134. $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
  135. log_test $? 2 "IPv6 - no route"
  136. cleanup
  137. }
  138. fib_unreg_test()
  139. {
  140. fib_unreg_unicast_test
  141. fib_unreg_multipath_test
  142. }
  143. fib_down_unicast_test()
  144. {
  145. echo
  146. echo "Single path, admin down"
  147. setup
  148. echo " Start point"
  149. $IP route get fibmatch 198.51.100.2 &> /dev/null
  150. log_test $? 0 "IPv4 fibmatch"
  151. $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
  152. log_test $? 0 "IPv6 fibmatch"
  153. set -e
  154. $IP link set dev dummy0 down
  155. set +e
  156. echo " Route deleted on down"
  157. $IP route get fibmatch 198.51.100.2 &> /dev/null
  158. log_test $? 2 "IPv4 fibmatch"
  159. $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
  160. log_test $? 2 "IPv6 fibmatch"
  161. cleanup
  162. }
  163. fib_down_multipath_test_do()
  164. {
  165. local down_dev=$1
  166. local up_dev=$2
  167. $IP route get fibmatch 203.0.113.1 \
  168. oif $down_dev &> /dev/null
  169. log_test $? 2 "IPv4 fibmatch on down device"
  170. $IP -6 route get fibmatch 2001:db8:3::1 \
  171. oif $down_dev &> /dev/null
  172. log_test $? 2 "IPv6 fibmatch on down device"
  173. $IP route get fibmatch 203.0.113.1 \
  174. oif $up_dev &> /dev/null
  175. log_test $? 0 "IPv4 fibmatch on up device"
  176. $IP -6 route get fibmatch 2001:db8:3::1 \
  177. oif $up_dev &> /dev/null
  178. log_test $? 0 "IPv6 fibmatch on up device"
  179. $IP route get fibmatch 203.0.113.1 | \
  180. grep $down_dev | grep -q "dead linkdown"
  181. log_test $? 0 "IPv4 flags on down device"
  182. $IP -6 route get fibmatch 2001:db8:3::1 | \
  183. grep $down_dev | grep -q "dead linkdown"
  184. log_test $? 0 "IPv6 flags on down device"
  185. $IP route get fibmatch 203.0.113.1 | \
  186. grep $up_dev | grep -q "dead linkdown"
  187. log_test $? 1 "IPv4 flags on up device"
  188. $IP -6 route get fibmatch 2001:db8:3::1 | \
  189. grep $up_dev | grep -q "dead linkdown"
  190. log_test $? 1 "IPv6 flags on up device"
  191. }
  192. fib_down_multipath_test()
  193. {
  194. echo
  195. echo "Admin down multipath"
  196. setup
  197. set -e
  198. $IP link add dummy1 type dummy
  199. $IP link set dev dummy1 up
  200. $IP address add 192.0.2.1/24 dev dummy1
  201. $IP -6 address add 2001:db8:2::1/64 dev dummy1
  202. $IP route add 203.0.113.0/24 \
  203. nexthop via 198.51.100.2 dev dummy0 \
  204. nexthop via 192.0.2.2 dev dummy1
  205. $IP -6 route add 2001:db8:3::/64 \
  206. nexthop via 2001:db8:1::2 dev dummy0 \
  207. nexthop via 2001:db8:2::2 dev dummy1
  208. set +e
  209. echo " Verify start point"
  210. $IP route get fibmatch 203.0.113.1 &> /dev/null
  211. log_test $? 0 "IPv4 fibmatch"
  212. $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
  213. log_test $? 0 "IPv6 fibmatch"
  214. set -e
  215. $IP link set dev dummy0 down
  216. set +e
  217. echo " One device down, one up"
  218. fib_down_multipath_test_do "dummy0" "dummy1"
  219. set -e
  220. $IP link set dev dummy0 up
  221. $IP link set dev dummy1 down
  222. set +e
  223. echo " Other device down and up"
  224. fib_down_multipath_test_do "dummy1" "dummy0"
  225. set -e
  226. $IP link set dev dummy0 down
  227. set +e
  228. echo " Both devices down"
  229. $IP route get fibmatch 203.0.113.1 &> /dev/null
  230. log_test $? 2 "IPv4 fibmatch"
  231. $IP -6 route get fibmatch 2001:db8:3::1 &> /dev/null
  232. log_test $? 2 "IPv6 fibmatch"
  233. $IP link del dev dummy1
  234. cleanup
  235. }
  236. fib_down_test()
  237. {
  238. fib_down_unicast_test
  239. fib_down_multipath_test
  240. }
  241. # Local routes should not be affected when carrier changes.
  242. fib_carrier_local_test()
  243. {
  244. echo
  245. echo "Local carrier tests - single path"
  246. setup
  247. set -e
  248. $IP link set dev dummy0 carrier on
  249. set +e
  250. echo " Start point"
  251. $IP route get fibmatch 198.51.100.1 &> /dev/null
  252. log_test $? 0 "IPv4 fibmatch"
  253. $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
  254. log_test $? 0 "IPv6 fibmatch"
  255. $IP route get fibmatch 198.51.100.1 | \
  256. grep -q "linkdown"
  257. log_test $? 1 "IPv4 - no linkdown flag"
  258. $IP -6 route get fibmatch 2001:db8:1::1 | \
  259. grep -q "linkdown"
  260. log_test $? 1 "IPv6 - no linkdown flag"
  261. set -e
  262. $IP link set dev dummy0 carrier off
  263. sleep 1
  264. set +e
  265. echo " Carrier off on nexthop"
  266. $IP route get fibmatch 198.51.100.1 &> /dev/null
  267. log_test $? 0 "IPv4 fibmatch"
  268. $IP -6 route get fibmatch 2001:db8:1::1 &> /dev/null
  269. log_test $? 0 "IPv6 fibmatch"
  270. $IP route get fibmatch 198.51.100.1 | \
  271. grep -q "linkdown"
  272. log_test $? 1 "IPv4 - linkdown flag set"
  273. $IP -6 route get fibmatch 2001:db8:1::1 | \
  274. grep -q "linkdown"
  275. log_test $? 1 "IPv6 - linkdown flag set"
  276. set -e
  277. $IP address add 192.0.2.1/24 dev dummy0
  278. $IP -6 address add 2001:db8:2::1/64 dev dummy0
  279. set +e
  280. echo " Route to local address with carrier down"
  281. $IP route get fibmatch 192.0.2.1 &> /dev/null
  282. log_test $? 0 "IPv4 fibmatch"
  283. $IP -6 route get fibmatch 2001:db8:2::1 &> /dev/null
  284. log_test $? 0 "IPv6 fibmatch"
  285. $IP route get fibmatch 192.0.2.1 | \
  286. grep -q "linkdown"
  287. log_test $? 1 "IPv4 linkdown flag set"
  288. $IP -6 route get fibmatch 2001:db8:2::1 | \
  289. grep -q "linkdown"
  290. log_test $? 1 "IPv6 linkdown flag set"
  291. cleanup
  292. }
  293. fib_carrier_unicast_test()
  294. {
  295. ret=0
  296. echo
  297. echo "Single path route carrier test"
  298. setup
  299. set -e
  300. $IP link set dev dummy0 carrier on
  301. set +e
  302. echo " Start point"
  303. $IP route get fibmatch 198.51.100.2 &> /dev/null
  304. log_test $? 0 "IPv4 fibmatch"
  305. $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
  306. log_test $? 0 "IPv6 fibmatch"
  307. $IP route get fibmatch 198.51.100.2 | \
  308. grep -q "linkdown"
  309. log_test $? 1 "IPv4 no linkdown flag"
  310. $IP -6 route get fibmatch 2001:db8:1::2 | \
  311. grep -q "linkdown"
  312. log_test $? 1 "IPv6 no linkdown flag"
  313. set -e
  314. $IP link set dev dummy0 carrier off
  315. sleep 1
  316. set +e
  317. echo " Carrier down"
  318. $IP route get fibmatch 198.51.100.2 &> /dev/null
  319. log_test $? 0 "IPv4 fibmatch"
  320. $IP -6 route get fibmatch 2001:db8:1::2 &> /dev/null
  321. log_test $? 0 "IPv6 fibmatch"
  322. $IP route get fibmatch 198.51.100.2 | \
  323. grep -q "linkdown"
  324. log_test $? 0 "IPv4 linkdown flag set"
  325. $IP -6 route get fibmatch 2001:db8:1::2 | \
  326. grep -q "linkdown"
  327. log_test $? 0 "IPv6 linkdown flag set"
  328. set -e
  329. $IP address add 192.0.2.1/24 dev dummy0
  330. $IP -6 address add 2001:db8:2::1/64 dev dummy0
  331. set +e
  332. echo " Second address added with carrier down"
  333. $IP route get fibmatch 192.0.2.2 &> /dev/null
  334. log_test $? 0 "IPv4 fibmatch"
  335. $IP -6 route get fibmatch 2001:db8:2::2 &> /dev/null
  336. log_test $? 0 "IPv6 fibmatch"
  337. $IP route get fibmatch 192.0.2.2 | \
  338. grep -q "linkdown"
  339. log_test $? 0 "IPv4 linkdown flag set"
  340. $IP -6 route get fibmatch 2001:db8:2::2 | \
  341. grep -q "linkdown"
  342. log_test $? 0 "IPv6 linkdown flag set"
  343. cleanup
  344. }
  345. fib_carrier_test()
  346. {
  347. fib_carrier_local_test
  348. fib_carrier_unicast_test
  349. }
  350. fib_rp_filter_test()
  351. {
  352. echo
  353. echo "IPv4 rp_filter tests"
  354. setup
  355. set -e
  356. setup_ns ns2
  357. $IP link add name veth1 type veth peer name veth2
  358. $IP link set dev veth2 netns $ns2
  359. $IP address add 192.0.2.1/24 dev veth1
  360. ip -netns $ns2 address add 192.0.2.1/24 dev veth2
  361. $IP link set dev veth1 up
  362. ip -netns $ns2 link set dev veth2 up
  363. $IP link set dev lo address 52:54:00:6a:c7:5e
  364. $IP link set dev veth1 address 52:54:00:6a:c7:5e
  365. ip -netns $ns2 link set dev lo address 52:54:00:6a:c7:5e
  366. ip -netns $ns2 link set dev veth2 address 52:54:00:6a:c7:5e
  367. # 1. (ns2) redirect lo's egress to veth2's egress
  368. ip netns exec $ns2 tc qdisc add dev lo parent root handle 1: fq_codel
  369. ip netns exec $ns2 tc filter add dev lo parent 1: protocol arp basic \
  370. action mirred egress redirect dev veth2
  371. ip netns exec $ns2 tc filter add dev lo parent 1: protocol ip basic \
  372. action mirred egress redirect dev veth2
  373. # 2. (ns1) redirect veth1's ingress to lo's ingress
  374. $NS_EXEC tc qdisc add dev veth1 ingress
  375. $NS_EXEC tc filter add dev veth1 ingress protocol arp basic \
  376. action mirred ingress redirect dev lo
  377. $NS_EXEC tc filter add dev veth1 ingress protocol ip basic \
  378. action mirred ingress redirect dev lo
  379. # 3. (ns1) redirect lo's egress to veth1's egress
  380. $NS_EXEC tc qdisc add dev lo parent root handle 1: fq_codel
  381. $NS_EXEC tc filter add dev lo parent 1: protocol arp basic \
  382. action mirred egress redirect dev veth1
  383. $NS_EXEC tc filter add dev lo parent 1: protocol ip basic \
  384. action mirred egress redirect dev veth1
  385. # 4. (ns2) redirect veth2's ingress to lo's ingress
  386. ip netns exec $ns2 tc qdisc add dev veth2 ingress
  387. ip netns exec $ns2 tc filter add dev veth2 ingress protocol arp basic \
  388. action mirred ingress redirect dev lo
  389. ip netns exec $ns2 tc filter add dev veth2 ingress protocol ip basic \
  390. action mirred ingress redirect dev lo
  391. $NS_EXEC sysctl -qw net.ipv4.conf.all.rp_filter=1
  392. $NS_EXEC sysctl -qw net.ipv4.conf.all.accept_local=1
  393. $NS_EXEC sysctl -qw net.ipv4.conf.all.route_localnet=1
  394. ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.rp_filter=1
  395. ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.accept_local=1
  396. ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.route_localnet=1
  397. set +e
  398. run_cmd "ip netns exec $ns2 ping -w1 -c1 192.0.2.1"
  399. log_test $? 0 "rp_filter passes local packets"
  400. run_cmd "ip netns exec $ns2 ping -w1 -c1 127.0.0.1"
  401. log_test $? 0 "rp_filter passes loopback packets"
  402. cleanup
  403. }
  404. ################################################################################
  405. # Tests on nexthop spec
  406. # run 'ip route add' with given spec
  407. add_rt()
  408. {
  409. local desc="$1"
  410. local erc=$2
  411. local vrf=$3
  412. local pfx=$4
  413. local gw=$5
  414. local dev=$6
  415. local cmd out rc
  416. [ "$vrf" = "-" ] && vrf="default"
  417. [ -n "$gw" ] && gw="via $gw"
  418. [ -n "$dev" ] && dev="dev $dev"
  419. cmd="$IP route add vrf $vrf $pfx $gw $dev"
  420. if [ "$VERBOSE" = "1" ]; then
  421. printf "\n COMMAND: $cmd\n"
  422. fi
  423. out=$(eval $cmd 2>&1)
  424. rc=$?
  425. if [ "$VERBOSE" = "1" -a -n "$out" ]; then
  426. echo " $out"
  427. fi
  428. log_test $rc $erc "$desc"
  429. }
  430. fib4_nexthop()
  431. {
  432. echo
  433. echo "IPv4 nexthop tests"
  434. echo "<<< write me >>>"
  435. }
  436. fib6_nexthop()
  437. {
  438. local lldummy=$(get_linklocal dummy0)
  439. local llv1=$(get_linklocal dummy0)
  440. if [ -z "$lldummy" ]; then
  441. echo "Failed to get linklocal address for dummy0"
  442. return 1
  443. fi
  444. if [ -z "$llv1" ]; then
  445. echo "Failed to get linklocal address for veth1"
  446. return 1
  447. fi
  448. echo
  449. echo "IPv6 nexthop tests"
  450. add_rt "Directly connected nexthop, unicast address" 0 \
  451. - 2001:db8:101::/64 2001:db8:1::2
  452. add_rt "Directly connected nexthop, unicast address with device" 0 \
  453. - 2001:db8:102::/64 2001:db8:1::2 "dummy0"
  454. add_rt "Gateway is linklocal address" 0 \
  455. - 2001:db8:103::1/64 $llv1 "veth0"
  456. # fails because LL address requires a device
  457. add_rt "Gateway is linklocal address, no device" 2 \
  458. - 2001:db8:104::1/64 $llv1
  459. # local address can not be a gateway
  460. add_rt "Gateway can not be local unicast address" 2 \
  461. - 2001:db8:105::/64 2001:db8:1::1
  462. add_rt "Gateway can not be local unicast address, with device" 2 \
  463. - 2001:db8:106::/64 2001:db8:1::1 "dummy0"
  464. add_rt "Gateway can not be a local linklocal address" 2 \
  465. - 2001:db8:107::1/64 $lldummy "dummy0"
  466. # VRF tests
  467. add_rt "Gateway can be local address in a VRF" 0 \
  468. - 2001:db8:108::/64 2001:db8:51::2
  469. add_rt "Gateway can be local address in a VRF, with device" 0 \
  470. - 2001:db8:109::/64 2001:db8:51::2 "veth0"
  471. add_rt "Gateway can be local linklocal address in a VRF" 0 \
  472. - 2001:db8:110::1/64 $llv1 "veth0"
  473. add_rt "Redirect to VRF lookup" 0 \
  474. - 2001:db8:111::/64 "" "red"
  475. add_rt "VRF route, gateway can be local address in default VRF" 0 \
  476. red 2001:db8:112::/64 2001:db8:51::1
  477. # local address in same VRF fails
  478. add_rt "VRF route, gateway can not be a local address" 2 \
  479. red 2001:db8:113::1/64 2001:db8:2::1
  480. add_rt "VRF route, gateway can not be a local addr with device" 2 \
  481. red 2001:db8:114::1/64 2001:db8:2::1 "dummy1"
  482. }
  483. # Default VRF:
  484. # dummy0 - 198.51.100.1/24 2001:db8:1::1/64
  485. # veth0 - 192.0.2.1/24 2001:db8:51::1/64
  486. #
  487. # VRF red:
  488. # dummy1 - 192.168.2.1/24 2001:db8:2::1/64
  489. # veth1 - 192.0.2.2/24 2001:db8:51::2/64
  490. #
  491. # [ dummy0 veth0 ]--[ veth1 dummy1 ]
  492. fib_nexthop_test()
  493. {
  494. setup
  495. set -e
  496. $IP -4 rule add pref 32765 table local
  497. $IP -4 rule del pref 0
  498. $IP -6 rule add pref 32765 table local
  499. $IP -6 rule del pref 0
  500. $IP link add red type vrf table 1
  501. $IP link set red up
  502. $IP -4 route add vrf red unreachable default metric 4278198272
  503. $IP -6 route add vrf red unreachable default metric 4278198272
  504. $IP link add veth0 type veth peer name veth1
  505. $IP link set dev veth0 up
  506. $IP address add 192.0.2.1/24 dev veth0
  507. $IP -6 address add 2001:db8:51::1/64 dev veth0
  508. $IP link set dev veth1 vrf red up
  509. $IP address add 192.0.2.2/24 dev veth1
  510. $IP -6 address add 2001:db8:51::2/64 dev veth1
  511. $IP link add dummy1 type dummy
  512. $IP link set dev dummy1 vrf red up
  513. $IP address add 192.168.2.1/24 dev dummy1
  514. $IP -6 address add 2001:db8:2::1/64 dev dummy1
  515. set +e
  516. sleep 1
  517. fib4_nexthop
  518. fib6_nexthop
  519. (
  520. $IP link del dev dummy1
  521. $IP link del veth0
  522. $IP link del red
  523. ) 2>/dev/null
  524. cleanup
  525. }
  526. fib6_notify_test()
  527. {
  528. setup
  529. echo
  530. echo "Fib6 info length calculation in route notify test"
  531. set -e
  532. for i in 10 20 30 40 50 60 70;
  533. do
  534. $IP link add dummy_$i type dummy
  535. $IP link set dev dummy_$i up
  536. $IP -6 address add 2001:$i::1/64 dev dummy_$i
  537. done
  538. $NS_EXEC ip monitor route &> errors.txt &
  539. sleep 2
  540. $IP -6 route add 2001::/64 \
  541. nexthop via 2001:10::2 dev dummy_10 \
  542. nexthop encap ip6 dst 2002::20 via 2001:20::2 dev dummy_20 \
  543. nexthop encap ip6 dst 2002::30 via 2001:30::2 dev dummy_30 \
  544. nexthop encap ip6 dst 2002::40 via 2001:40::2 dev dummy_40 \
  545. nexthop encap ip6 dst 2002::50 via 2001:50::2 dev dummy_50 \
  546. nexthop encap ip6 dst 2002::60 via 2001:60::2 dev dummy_60 \
  547. nexthop encap ip6 dst 2002::70 via 2001:70::2 dev dummy_70
  548. set +e
  549. err=`cat errors.txt |grep "Message too long"`
  550. if [ -z "$err" ];then
  551. ret=0
  552. else
  553. ret=1
  554. fi
  555. log_test $ret 0 "ipv6 route add notify"
  556. { kill %% && wait %%; } 2>/dev/null
  557. #rm errors.txt
  558. cleanup &> /dev/null
  559. }
  560. fib_notify_test()
  561. {
  562. setup
  563. echo
  564. echo "Fib4 info length calculation in route notify test"
  565. set -e
  566. for i in 10 20 30 40 50 60 70;
  567. do
  568. $IP link add dummy_$i type dummy
  569. $IP link set dev dummy_$i up
  570. $IP address add 20.20.$i.2/24 dev dummy_$i
  571. done
  572. $NS_EXEC ip monitor route &> errors.txt &
  573. sleep 2
  574. $IP route add 10.0.0.0/24 \
  575. nexthop via 20.20.10.1 dev dummy_10 \
  576. nexthop encap ip dst 192.168.10.20 via 20.20.20.1 dev dummy_20 \
  577. nexthop encap ip dst 192.168.10.30 via 20.20.30.1 dev dummy_30 \
  578. nexthop encap ip dst 192.168.10.40 via 20.20.40.1 dev dummy_40 \
  579. nexthop encap ip dst 192.168.10.50 via 20.20.50.1 dev dummy_50 \
  580. nexthop encap ip dst 192.168.10.60 via 20.20.60.1 dev dummy_60 \
  581. nexthop encap ip dst 192.168.10.70 via 20.20.70.1 dev dummy_70
  582. set +e
  583. err=`cat errors.txt |grep "Message too long"`
  584. if [ -z "$err" ];then
  585. ret=0
  586. else
  587. ret=1
  588. fi
  589. log_test $ret 0 "ipv4 route add notify"
  590. { kill %% && wait %%; } 2>/dev/null
  591. rm errors.txt
  592. cleanup &> /dev/null
  593. }
  594. # Create a new dummy_10 to remove all associated routes.
  595. reset_dummy_10()
  596. {
  597. $IP link del dev dummy_10
  598. $IP link add dummy_10 type dummy
  599. $IP link set dev dummy_10 up
  600. $IP -6 address add 2001:10::1/64 dev dummy_10
  601. }
  602. check_rt_num()
  603. {
  604. local expected=$1
  605. local num=$2
  606. if [ $num -ne $expected ]; then
  607. echo "FAIL: Expected $expected routes, got $num"
  608. ret=1
  609. else
  610. ret=0
  611. fi
  612. }
  613. check_rt_num_clean()
  614. {
  615. local expected=$1
  616. local num=$2
  617. if [ $num -ne $expected ]; then
  618. log_test 1 0 "expected $expected routes, got $num"
  619. set +e
  620. cleanup &> /dev/null
  621. return 1
  622. fi
  623. return 0
  624. }
  625. fib6_gc_test()
  626. {
  627. setup
  628. echo
  629. echo "Fib6 garbage collection test"
  630. set -e
  631. EXPIRE=5
  632. GC_WAIT_TIME=$((EXPIRE * 2 + 2))
  633. # Check expiration of routes every $EXPIRE seconds (GC)
  634. $NS_EXEC sysctl -wq net.ipv6.route.gc_interval=$EXPIRE
  635. $IP link add dummy_10 type dummy
  636. $IP link set dev dummy_10 up
  637. $IP -6 address add 2001:10::1/64 dev dummy_10
  638. $NS_EXEC sysctl -wq net.ipv6.route.flush=1
  639. # Temporary routes
  640. for i in $(seq 1 5); do
  641. # Expire route after $EXPIRE seconds
  642. $IP -6 route add 2001:20::$i \
  643. via 2001:10::2 dev dummy_10 expires $EXPIRE
  644. done
  645. sleep $GC_WAIT_TIME
  646. $NS_EXEC sysctl -wq net.ipv6.route.flush=1
  647. check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
  648. log_test $ret 0 "ipv6 route garbage collection"
  649. reset_dummy_10
  650. # Permanent routes
  651. for i in $(seq 1 5); do
  652. $IP -6 route add 2001:30::$i \
  653. via 2001:10::2 dev dummy_10
  654. done
  655. # Temporary routes
  656. for i in $(seq 1 5); do
  657. # Expire route after $EXPIRE seconds
  658. $IP -6 route add 2001:20::$i \
  659. via 2001:10::2 dev dummy_10 expires $EXPIRE
  660. done
  661. # Wait for GC
  662. sleep $GC_WAIT_TIME
  663. check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
  664. log_test $ret 0 "ipv6 route garbage collection (with permanent routes)"
  665. reset_dummy_10
  666. # Permanent routes
  667. for i in $(seq 1 5); do
  668. $IP -6 route add 2001:20::$i \
  669. via 2001:10::2 dev dummy_10
  670. done
  671. # Replace with temporary routes
  672. for i in $(seq 1 5); do
  673. # Expire route after $EXPIRE seconds
  674. $IP -6 route replace 2001:20::$i \
  675. via 2001:10::2 dev dummy_10 expires $EXPIRE
  676. done
  677. # Wait for GC
  678. sleep $GC_WAIT_TIME
  679. check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
  680. log_test $ret 0 "ipv6 route garbage collection (replace with expires)"
  681. reset_dummy_10
  682. # Temporary routes
  683. for i in $(seq 1 5); do
  684. # Expire route after $EXPIRE seconds
  685. $IP -6 route add 2001:20::$i \
  686. via 2001:10::2 dev dummy_10 expires $EXPIRE
  687. done
  688. # Replace with permanent routes
  689. for i in $(seq 1 5); do
  690. $IP -6 route replace 2001:20::$i \
  691. via 2001:10::2 dev dummy_10
  692. done
  693. check_rt_num_clean 0 $($IP -6 route list |grep expires|wc -l) || return
  694. # Wait for GC
  695. sleep $GC_WAIT_TIME
  696. check_rt_num 5 $($IP -6 route list |grep -v expires|grep 2001:20::|wc -l)
  697. log_test $ret 0 "ipv6 route garbage collection (replace with permanent)"
  698. # ra6 is required for the next test. (ipv6toolkit)
  699. if [ ! -x "$(command -v ra6)" ]; then
  700. echo "SKIP: ra6 not found."
  701. set +e
  702. cleanup &> /dev/null
  703. return
  704. fi
  705. # Delete dummy_10 and remove all routes
  706. $IP link del dev dummy_10
  707. # Create a pair of veth devices to send a RA message from one
  708. # device to another.
  709. $IP link add veth1 type veth peer name veth2
  710. $IP link set dev veth1 up
  711. $IP link set dev veth2 up
  712. $IP -6 address add 2001:10::1/64 dev veth1 nodad
  713. $IP -6 address add 2001:10::2/64 dev veth2 nodad
  714. # Make veth1 ready to receive RA messages.
  715. $NS_EXEC sysctl -wq net.ipv6.conf.veth1.accept_ra=2
  716. # Send a RA message with a route from veth2 to veth1.
  717. $NS_EXEC ra6 -i veth2 -d 2001:10::1 -t $EXPIRE
  718. # Wait for the RA message.
  719. sleep 1
  720. # systemd may mess up the test. You syould make sure that
  721. # systemd-networkd.service and systemd-networkd.socket are stopped.
  722. check_rt_num_clean 1 $($IP -6 route list|grep expires|wc -l) || return
  723. # Wait for GC
  724. sleep $GC_WAIT_TIME
  725. check_rt_num 0 $($IP -6 route list |grep expires|wc -l)
  726. log_test $ret 0 "ipv6 route garbage collection (RA message)"
  727. set +e
  728. cleanup &> /dev/null
  729. }
  730. fib_suppress_test()
  731. {
  732. echo
  733. echo "FIB rule with suppress_prefixlength"
  734. setup
  735. $IP link add dummy1 type dummy
  736. $IP link set dummy1 up
  737. $IP -6 route add default dev dummy1
  738. $IP -6 rule add table main suppress_prefixlength 0
  739. ping -f -c 1000 -W 1 1234::1 >/dev/null 2>&1
  740. $IP -6 rule del table main suppress_prefixlength 0
  741. $IP link del dummy1
  742. # If we got here without crashing, we're good.
  743. log_test 0 0 "FIB rule suppress test"
  744. cleanup
  745. }
  746. ################################################################################
  747. # Tests on route add and replace
  748. run_cmd()
  749. {
  750. local cmd="$1"
  751. local out
  752. local stderr="2>/dev/null"
  753. if [ "$VERBOSE" = "1" ]; then
  754. printf " COMMAND: $cmd\n"
  755. stderr=
  756. fi
  757. out=$(eval $cmd $stderr)
  758. rc=$?
  759. if [ "$VERBOSE" = "1" -a -n "$out" ]; then
  760. echo " $out"
  761. fi
  762. [ "$VERBOSE" = "1" ] && echo
  763. return $rc
  764. }
  765. check_expected()
  766. {
  767. local out="$1"
  768. local expected="$2"
  769. local rc=0
  770. [ "${out}" = "${expected}" ] && return 0
  771. if [ -z "${out}" ]; then
  772. if [ "$VERBOSE" = "1" ]; then
  773. printf "\nNo route entry found\n"
  774. printf "Expected:\n"
  775. printf " ${expected}\n"
  776. fi
  777. return 1
  778. fi
  779. # tricky way to convert output to 1-line without ip's
  780. # messy '\'; this drops all extra white space
  781. out=$(echo ${out})
  782. if [ "${out}" != "${expected}" ]; then
  783. rc=1
  784. if [ "${VERBOSE}" = "1" ]; then
  785. printf " Unexpected route entry. Have:\n"
  786. printf " ${out}\n"
  787. printf " Expected:\n"
  788. printf " ${expected}\n\n"
  789. fi
  790. fi
  791. return $rc
  792. }
  793. # add route for a prefix, flushing any existing routes first
  794. # expected to be the first step of a test
  795. add_route6()
  796. {
  797. local pfx="$1"
  798. local nh="$2"
  799. local out
  800. if [ "$VERBOSE" = "1" ]; then
  801. echo
  802. echo " ##################################################"
  803. echo
  804. fi
  805. run_cmd "$IP -6 ro flush ${pfx}"
  806. [ $? -ne 0 ] && exit 1
  807. out=$($IP -6 ro ls match ${pfx})
  808. if [ -n "$out" ]; then
  809. echo "Failed to flush routes for prefix used for tests."
  810. exit 1
  811. fi
  812. run_cmd "$IP -6 ro add ${pfx} ${nh}"
  813. if [ $? -ne 0 ]; then
  814. echo "Failed to add initial route for test."
  815. exit 1
  816. fi
  817. }
  818. # add initial route - used in replace route tests
  819. add_initial_route6()
  820. {
  821. add_route6 "2001:db8:104::/64" "$1"
  822. }
  823. check_route6()
  824. {
  825. local pfx
  826. local expected="$1"
  827. local out
  828. local rc=0
  829. set -- $expected
  830. pfx=$1
  831. out=$($IP -6 ro ls match ${pfx} | sed -e 's/ pref medium//')
  832. check_expected "${out}" "${expected}"
  833. }
  834. route_cleanup()
  835. {
  836. $IP li del red 2>/dev/null
  837. $IP li del dummy1 2>/dev/null
  838. $IP li del veth1 2>/dev/null
  839. $IP li del veth3 2>/dev/null
  840. cleanup &> /dev/null
  841. }
  842. route_setup()
  843. {
  844. route_cleanup
  845. setup
  846. [ "${VERBOSE}" = "1" ] && set -x
  847. set -e
  848. setup_ns ns2
  849. ip netns exec $ns2 sysctl -qw net.ipv4.ip_forward=1
  850. ip netns exec $ns2 sysctl -qw net.ipv6.conf.all.forwarding=1
  851. $IP li add veth1 type veth peer name veth2
  852. $IP li add veth3 type veth peer name veth4
  853. $IP li set veth1 up
  854. $IP li set veth3 up
  855. $IP li set veth2 netns $ns2 up
  856. $IP li set veth4 netns $ns2 up
  857. ip -netns $ns2 li add dummy1 type dummy
  858. ip -netns $ns2 li set dummy1 up
  859. $IP -6 addr add 2001:db8:101::1/64 dev veth1 nodad
  860. $IP -6 addr add 2001:db8:103::1/64 dev veth3 nodad
  861. $IP addr add 172.16.101.1/24 dev veth1
  862. $IP addr add 172.16.103.1/24 dev veth3
  863. ip -netns $ns2 -6 addr add 2001:db8:101::2/64 dev veth2 nodad
  864. ip -netns $ns2 -6 addr add 2001:db8:103::2/64 dev veth4 nodad
  865. ip -netns $ns2 -6 addr add 2001:db8:104::1/64 dev dummy1 nodad
  866. ip -netns $ns2 addr add 172.16.101.2/24 dev veth2
  867. ip -netns $ns2 addr add 172.16.103.2/24 dev veth4
  868. ip -netns $ns2 addr add 172.16.104.1/24 dev dummy1
  869. set +e
  870. }
  871. # assumption is that basic add of a single path route works
  872. # otherwise just adding an address on an interface is broken
  873. ipv6_rt_add()
  874. {
  875. local rc
  876. echo
  877. echo "IPv6 route add / append tests"
  878. # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
  879. add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
  880. run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2"
  881. log_test $? 2 "Attempt to add duplicate route - gw"
  882. # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
  883. add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
  884. run_cmd "$IP -6 ro add 2001:db8:104::/64 dev veth3"
  885. log_test $? 2 "Attempt to add duplicate route - dev only"
  886. # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
  887. add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
  888. run_cmd "$IP -6 ro add unreachable 2001:db8:104::/64"
  889. log_test $? 2 "Attempt to add duplicate route - reject route"
  890. # route append with same prefix adds a new route
  891. # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
  892. add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
  893. run_cmd "$IP -6 ro append 2001:db8:104::/64 via 2001:db8:103::2"
  894. check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
  895. log_test $? 0 "Append nexthop to existing route - gw"
  896. # insert mpath directly
  897. add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  898. check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
  899. log_test $? 0 "Add multipath route"
  900. add_route6 "2001:db8:104::/64" "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  901. run_cmd "$IP -6 ro add 2001:db8:104::/64 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  902. log_test $? 2 "Attempt to add duplicate multipath route"
  903. # insert of a second route without append but different metric
  904. add_route6 "2001:db8:104::/64" "via 2001:db8:101::2"
  905. run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::2 metric 512"
  906. rc=$?
  907. if [ $rc -eq 0 ]; then
  908. run_cmd "$IP -6 ro add 2001:db8:104::/64 via 2001:db8:103::3 metric 256"
  909. rc=$?
  910. fi
  911. log_test $rc 0 "Route add with different metrics"
  912. run_cmd "$IP -6 ro del 2001:db8:104::/64 metric 512"
  913. rc=$?
  914. if [ $rc -eq 0 ]; then
  915. check_route6 "2001:db8:104::/64 via 2001:db8:103::3 dev veth3 metric 256 2001:db8:104::/64 via 2001:db8:101::2 dev veth1 metric 1024"
  916. rc=$?
  917. fi
  918. log_test $rc 0 "Route delete with metric"
  919. }
  920. ipv6_rt_replace_single()
  921. {
  922. # single path with single path
  923. #
  924. add_initial_route6 "via 2001:db8:101::2"
  925. run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:103::2"
  926. check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024"
  927. log_test $? 0 "Single path with single path"
  928. # single path with multipath
  929. #
  930. add_initial_route6 "nexthop via 2001:db8:101::2"
  931. run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::2"
  932. check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::3 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
  933. log_test $? 0 "Single path with multipath"
  934. # single path with single path using MULTIPATH attribute
  935. #
  936. add_initial_route6 "via 2001:db8:101::2"
  937. run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:103::2"
  938. check_route6 "2001:db8:104::/64 via 2001:db8:103::2 dev veth3 metric 1024"
  939. log_test $? 0 "Single path with single path via multipath attribute"
  940. # route replace fails - invalid nexthop
  941. add_initial_route6 "via 2001:db8:101::2"
  942. run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:104::2"
  943. if [ $? -eq 0 ]; then
  944. # previous command is expected to fail so if it returns 0
  945. # that means the test failed.
  946. log_test 0 1 "Invalid nexthop"
  947. else
  948. check_route6 "2001:db8:104::/64 via 2001:db8:101::2 dev veth1 metric 1024"
  949. log_test $? 0 "Invalid nexthop"
  950. fi
  951. # replace non-existent route
  952. # - note use of change versus replace since ip adds NLM_F_CREATE
  953. # for replace
  954. add_initial_route6 "via 2001:db8:101::2"
  955. run_cmd "$IP -6 ro change 2001:db8:105::/64 via 2001:db8:101::2"
  956. log_test $? 2 "Single path - replace of non-existent route"
  957. }
  958. ipv6_rt_replace_mpath()
  959. {
  960. # multipath with multipath
  961. add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  962. run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3"
  963. check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::3 dev veth1 weight 1 nexthop via 2001:db8:103::3 dev veth3 weight 1"
  964. log_test $? 0 "Multipath with multipath"
  965. # multipath with single
  966. add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  967. run_cmd "$IP -6 ro replace 2001:db8:104::/64 via 2001:db8:101::3"
  968. check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
  969. log_test $? 0 "Multipath with single path"
  970. # multipath with single
  971. add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  972. run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3"
  973. check_route6 "2001:db8:104::/64 via 2001:db8:101::3 dev veth1 metric 1024"
  974. log_test $? 0 "Multipath with single path via multipath attribute"
  975. # multipath with dev-only
  976. add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  977. run_cmd "$IP -6 ro replace 2001:db8:104::/64 dev veth1"
  978. check_route6 "2001:db8:104::/64 dev veth1 metric 1024"
  979. log_test $? 0 "Multipath with dev-only"
  980. # route replace fails - invalid nexthop 1
  981. add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  982. run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:111::3 nexthop via 2001:db8:103::3"
  983. check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
  984. log_test $? 0 "Multipath - invalid first nexthop"
  985. # route replace fails - invalid nexthop 2
  986. add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  987. run_cmd "$IP -6 ro replace 2001:db8:104::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:113::3"
  988. check_route6 "2001:db8:104::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
  989. log_test $? 0 "Multipath - invalid second nexthop"
  990. # multipath non-existent route
  991. add_initial_route6 "nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  992. run_cmd "$IP -6 ro change 2001:db8:105::/64 nexthop via 2001:db8:101::3 nexthop via 2001:db8:103::3"
  993. log_test $? 2 "Multipath - replace of non-existent route"
  994. }
  995. ipv6_rt_replace()
  996. {
  997. echo
  998. echo "IPv6 route replace tests"
  999. ipv6_rt_replace_single
  1000. ipv6_rt_replace_mpath
  1001. }
  1002. ipv6_rt_dsfield()
  1003. {
  1004. echo
  1005. echo "IPv6 route with dsfield tests"
  1006. run_cmd "$IP -6 route flush 2001:db8:102::/64"
  1007. # IPv6 doesn't support routing based on dsfield
  1008. run_cmd "$IP -6 route add 2001:db8:102::/64 dsfield 0x04 via 2001:db8:101::2"
  1009. log_test $? 2 "Reject route with dsfield"
  1010. }
  1011. ipv6_route_test()
  1012. {
  1013. route_setup
  1014. ipv6_rt_add
  1015. ipv6_rt_replace
  1016. ipv6_rt_dsfield
  1017. route_cleanup
  1018. }
  1019. ip_addr_metric_check()
  1020. {
  1021. ip addr help 2>&1 | grep -q metric
  1022. if [ $? -ne 0 ]; then
  1023. echo "iproute2 command does not support metric for addresses. Skipping test"
  1024. return 1
  1025. fi
  1026. return 0
  1027. }
  1028. ipv6_addr_metric_test()
  1029. {
  1030. local rc
  1031. echo
  1032. echo "IPv6 prefix route tests"
  1033. ip_addr_metric_check || return 1
  1034. setup
  1035. set -e
  1036. $IP li add dummy1 type dummy
  1037. $IP li add dummy2 type dummy
  1038. $IP li set dummy1 up
  1039. $IP li set dummy2 up
  1040. # default entry is metric 256
  1041. run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64"
  1042. run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64"
  1043. set +e
  1044. check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 256 2001:db8:104::/64 dev dummy2 proto kernel metric 256"
  1045. log_test $? 0 "Default metric"
  1046. set -e
  1047. run_cmd "$IP -6 addr flush dev dummy1"
  1048. run_cmd "$IP -6 addr add dev dummy1 2001:db8:104::1/64 metric 257"
  1049. set +e
  1050. check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 256 2001:db8:104::/64 dev dummy1 proto kernel metric 257"
  1051. log_test $? 0 "User specified metric on first device"
  1052. set -e
  1053. run_cmd "$IP -6 addr flush dev dummy2"
  1054. run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::2/64 metric 258"
  1055. set +e
  1056. check_route6 "2001:db8:104::/64 dev dummy1 proto kernel metric 257 2001:db8:104::/64 dev dummy2 proto kernel metric 258"
  1057. log_test $? 0 "User specified metric on second device"
  1058. run_cmd "$IP -6 addr del dev dummy1 2001:db8:104::1/64 metric 257"
  1059. rc=$?
  1060. if [ $rc -eq 0 ]; then
  1061. check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 258"
  1062. rc=$?
  1063. fi
  1064. log_test $rc 0 "Delete of address on first device"
  1065. run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::2/64 metric 259"
  1066. rc=$?
  1067. if [ $rc -eq 0 ]; then
  1068. check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259"
  1069. rc=$?
  1070. fi
  1071. log_test $rc 0 "Modify metric of address"
  1072. # verify prefix route removed on down
  1073. run_cmd "ip netns exec $ns1 sysctl -qw net.ipv6.conf.all.keep_addr_on_down=1"
  1074. run_cmd "$IP li set dev dummy2 down"
  1075. rc=$?
  1076. if [ $rc -eq 0 ]; then
  1077. out=$($IP -6 ro ls match 2001:db8:104::/64)
  1078. check_expected "${out}" ""
  1079. rc=$?
  1080. fi
  1081. log_test $rc 0 "Prefix route removed on link down"
  1082. # verify prefix route re-inserted with assigned metric
  1083. run_cmd "$IP li set dev dummy2 up"
  1084. rc=$?
  1085. if [ $rc -eq 0 ]; then
  1086. check_route6 "2001:db8:104::/64 dev dummy2 proto kernel metric 259"
  1087. rc=$?
  1088. fi
  1089. log_test $rc 0 "Prefix route with metric on link up"
  1090. # verify peer metric added correctly
  1091. set -e
  1092. run_cmd "$IP -6 addr flush dev dummy2"
  1093. run_cmd "$IP -6 addr add dev dummy2 2001:db8:104::1 peer 2001:db8:104::2 metric 260"
  1094. set +e
  1095. check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 260"
  1096. log_test $? 0 "Set metric with peer route on local side"
  1097. check_route6 "2001:db8:104::2 dev dummy2 proto kernel metric 260"
  1098. log_test $? 0 "Set metric with peer route on peer side"
  1099. set -e
  1100. run_cmd "$IP -6 addr change dev dummy2 2001:db8:104::1 peer 2001:db8:104::3 metric 261"
  1101. set +e
  1102. check_route6 "2001:db8:104::1 dev dummy2 proto kernel metric 261"
  1103. log_test $? 0 "Modify metric and peer address on local side"
  1104. check_route6 "2001:db8:104::3 dev dummy2 proto kernel metric 261"
  1105. log_test $? 0 "Modify metric and peer address on peer side"
  1106. $IP li del dummy1
  1107. $IP li del dummy2
  1108. cleanup
  1109. }
  1110. ipv6_route_metrics_test()
  1111. {
  1112. local rc
  1113. echo
  1114. echo "IPv6 routes with metrics"
  1115. route_setup
  1116. #
  1117. # single path with metrics
  1118. #
  1119. run_cmd "$IP -6 ro add 2001:db8:111::/64 via 2001:db8:101::2 mtu 1400"
  1120. rc=$?
  1121. if [ $rc -eq 0 ]; then
  1122. check_route6 "2001:db8:111::/64 via 2001:db8:101::2 dev veth1 metric 1024 mtu 1400"
  1123. rc=$?
  1124. fi
  1125. log_test $rc 0 "Single path route with mtu metric"
  1126. #
  1127. # multipath via separate routes with metrics
  1128. #
  1129. run_cmd "$IP -6 ro add 2001:db8:112::/64 via 2001:db8:101::2 mtu 1400"
  1130. run_cmd "$IP -6 ro append 2001:db8:112::/64 via 2001:db8:103::2"
  1131. rc=$?
  1132. if [ $rc -eq 0 ]; then
  1133. check_route6 "2001:db8:112::/64 metric 1024 mtu 1400 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
  1134. rc=$?
  1135. fi
  1136. log_test $rc 0 "Multipath route via 2 single routes with mtu metric on first"
  1137. # second route is coalesced to first to make a multipath route.
  1138. # MTU of the second path is hidden from display!
  1139. run_cmd "$IP -6 ro add 2001:db8:113::/64 via 2001:db8:101::2"
  1140. run_cmd "$IP -6 ro append 2001:db8:113::/64 via 2001:db8:103::2 mtu 1400"
  1141. rc=$?
  1142. if [ $rc -eq 0 ]; then
  1143. check_route6 "2001:db8:113::/64 metric 1024 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
  1144. rc=$?
  1145. fi
  1146. log_test $rc 0 "Multipath route via 2 single routes with mtu metric on 2nd"
  1147. run_cmd "$IP -6 ro del 2001:db8:113::/64 via 2001:db8:101::2"
  1148. if [ $? -eq 0 ]; then
  1149. check_route6 "2001:db8:113::/64 via 2001:db8:103::2 dev veth3 metric 1024 mtu 1400"
  1150. log_test $? 0 " MTU of second leg"
  1151. fi
  1152. #
  1153. # multipath with metrics
  1154. #
  1155. run_cmd "$IP -6 ro add 2001:db8:115::/64 mtu 1400 nexthop via 2001:db8:101::2 nexthop via 2001:db8:103::2"
  1156. rc=$?
  1157. if [ $rc -eq 0 ]; then
  1158. check_route6 "2001:db8:115::/64 metric 1024 mtu 1400 nexthop via 2001:db8:101::2 dev veth1 weight 1 nexthop via 2001:db8:103::2 dev veth3 weight 1"
  1159. rc=$?
  1160. fi
  1161. log_test $rc 0 "Multipath route with mtu metric"
  1162. $IP -6 ro add 2001:db8:104::/64 via 2001:db8:101::2 mtu 1300
  1163. run_cmd "ip netns exec $ns1 ${ping6} -w1 -c1 -s 1500 2001:db8:104::1"
  1164. log_test $? 0 "Using route with mtu metric"
  1165. run_cmd "$IP -6 ro add 2001:db8:114::/64 via 2001:db8:101::2 congctl lock foo"
  1166. log_test $? 2 "Invalid metric (fails metric_convert)"
  1167. route_cleanup
  1168. }
  1169. # add route for a prefix, flushing any existing routes first
  1170. # expected to be the first step of a test
  1171. add_route()
  1172. {
  1173. local pfx="$1"
  1174. local nh="$2"
  1175. local out
  1176. if [ "$VERBOSE" = "1" ]; then
  1177. echo
  1178. echo " ##################################################"
  1179. echo
  1180. fi
  1181. run_cmd "$IP ro flush ${pfx}"
  1182. [ $? -ne 0 ] && exit 1
  1183. out=$($IP ro ls match ${pfx})
  1184. if [ -n "$out" ]; then
  1185. echo "Failed to flush routes for prefix used for tests."
  1186. exit 1
  1187. fi
  1188. run_cmd "$IP ro add ${pfx} ${nh}"
  1189. if [ $? -ne 0 ]; then
  1190. echo "Failed to add initial route for test."
  1191. exit 1
  1192. fi
  1193. }
  1194. # add initial route - used in replace route tests
  1195. add_initial_route()
  1196. {
  1197. add_route "172.16.104.0/24" "$1"
  1198. }
  1199. check_route()
  1200. {
  1201. local pfx
  1202. local expected="$1"
  1203. local out
  1204. set -- $expected
  1205. pfx=$1
  1206. [ "${pfx}" = "unreachable" ] && pfx=$2
  1207. out=$($IP ro ls match ${pfx})
  1208. check_expected "${out}" "${expected}"
  1209. }
  1210. # assumption is that basic add of a single path route works
  1211. # otherwise just adding an address on an interface is broken
  1212. ipv4_rt_add()
  1213. {
  1214. local rc
  1215. echo
  1216. echo "IPv4 route add / append tests"
  1217. # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
  1218. add_route "172.16.104.0/24" "via 172.16.101.2"
  1219. run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2"
  1220. log_test $? 2 "Attempt to add duplicate route - gw"
  1221. # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
  1222. add_route "172.16.104.0/24" "via 172.16.101.2"
  1223. run_cmd "$IP ro add 172.16.104.0/24 dev veth3"
  1224. log_test $? 2 "Attempt to add duplicate route - dev only"
  1225. # route add same prefix - fails with EEXISTS b/c ip adds NLM_F_EXCL
  1226. add_route "172.16.104.0/24" "via 172.16.101.2"
  1227. run_cmd "$IP ro add unreachable 172.16.104.0/24"
  1228. log_test $? 2 "Attempt to add duplicate route - reject route"
  1229. # iproute2 prepend only sets NLM_F_CREATE
  1230. # - adds a new route; does NOT convert existing route to ECMP
  1231. add_route "172.16.104.0/24" "via 172.16.101.2"
  1232. run_cmd "$IP ro prepend 172.16.104.0/24 via 172.16.103.2"
  1233. check_route "172.16.104.0/24 via 172.16.103.2 dev veth3 172.16.104.0/24 via 172.16.101.2 dev veth1"
  1234. log_test $? 0 "Add new nexthop for existing prefix"
  1235. # route append with same prefix adds a new route
  1236. # - iproute2 sets NLM_F_CREATE | NLM_F_APPEND
  1237. add_route "172.16.104.0/24" "via 172.16.101.2"
  1238. run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2"
  1239. check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 via 172.16.103.2 dev veth3"
  1240. log_test $? 0 "Append nexthop to existing route - gw"
  1241. add_route "172.16.104.0/24" "via 172.16.101.2"
  1242. run_cmd "$IP ro append 172.16.104.0/24 dev veth3"
  1243. check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 dev veth3 scope link"
  1244. log_test $? 0 "Append nexthop to existing route - dev only"
  1245. add_route "172.16.104.0/24" "via 172.16.101.2"
  1246. run_cmd "$IP ro append unreachable 172.16.104.0/24"
  1247. check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 unreachable 172.16.104.0/24"
  1248. log_test $? 0 "Append nexthop to existing route - reject route"
  1249. run_cmd "$IP ro flush 172.16.104.0/24"
  1250. run_cmd "$IP ro add unreachable 172.16.104.0/24"
  1251. run_cmd "$IP ro append 172.16.104.0/24 via 172.16.103.2"
  1252. check_route "unreachable 172.16.104.0/24 172.16.104.0/24 via 172.16.103.2 dev veth3"
  1253. log_test $? 0 "Append nexthop to existing reject route - gw"
  1254. run_cmd "$IP ro flush 172.16.104.0/24"
  1255. run_cmd "$IP ro add unreachable 172.16.104.0/24"
  1256. run_cmd "$IP ro append 172.16.104.0/24 dev veth3"
  1257. check_route "unreachable 172.16.104.0/24 172.16.104.0/24 dev veth3 scope link"
  1258. log_test $? 0 "Append nexthop to existing reject route - dev only"
  1259. # insert mpath directly
  1260. add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1261. check_route "172.16.104.0/24 nexthop via 172.16.101.2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
  1262. log_test $? 0 "add multipath route"
  1263. add_route "172.16.104.0/24" "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1264. run_cmd "$IP ro add 172.16.104.0/24 nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1265. log_test $? 2 "Attempt to add duplicate multipath route"
  1266. # insert of a second route without append but different metric
  1267. add_route "172.16.104.0/24" "via 172.16.101.2"
  1268. run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.2 metric 512"
  1269. rc=$?
  1270. if [ $rc -eq 0 ]; then
  1271. run_cmd "$IP ro add 172.16.104.0/24 via 172.16.103.3 metric 256"
  1272. rc=$?
  1273. fi
  1274. log_test $rc 0 "Route add with different metrics"
  1275. run_cmd "$IP ro del 172.16.104.0/24 metric 512"
  1276. rc=$?
  1277. if [ $rc -eq 0 ]; then
  1278. check_route "172.16.104.0/24 via 172.16.101.2 dev veth1 172.16.104.0/24 via 172.16.103.3 dev veth3 metric 256"
  1279. rc=$?
  1280. fi
  1281. log_test $rc 0 "Route delete with metric"
  1282. }
  1283. ipv4_rt_replace_single()
  1284. {
  1285. # single path with single path
  1286. #
  1287. add_initial_route "via 172.16.101.2"
  1288. run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.103.2"
  1289. check_route "172.16.104.0/24 via 172.16.103.2 dev veth3"
  1290. log_test $? 0 "Single path with single path"
  1291. # single path with multipath
  1292. #
  1293. add_initial_route "nexthop via 172.16.101.2"
  1294. run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.2"
  1295. check_route "172.16.104.0/24 nexthop via 172.16.101.3 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
  1296. log_test $? 0 "Single path with multipath"
  1297. # single path with reject
  1298. #
  1299. add_initial_route "nexthop via 172.16.101.2"
  1300. run_cmd "$IP ro replace unreachable 172.16.104.0/24"
  1301. check_route "unreachable 172.16.104.0/24"
  1302. log_test $? 0 "Single path with reject route"
  1303. # single path with single path using MULTIPATH attribute
  1304. #
  1305. add_initial_route "via 172.16.101.2"
  1306. run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.103.2"
  1307. check_route "172.16.104.0/24 via 172.16.103.2 dev veth3"
  1308. log_test $? 0 "Single path with single path via multipath attribute"
  1309. # route replace fails - invalid nexthop
  1310. add_initial_route "via 172.16.101.2"
  1311. run_cmd "$IP ro replace 172.16.104.0/24 via 2001:db8:104::2"
  1312. if [ $? -eq 0 ]; then
  1313. # previous command is expected to fail so if it returns 0
  1314. # that means the test failed.
  1315. log_test 0 1 "Invalid nexthop"
  1316. else
  1317. check_route "172.16.104.0/24 via 172.16.101.2 dev veth1"
  1318. log_test $? 0 "Invalid nexthop"
  1319. fi
  1320. # replace non-existent route
  1321. # - note use of change versus replace since ip adds NLM_F_CREATE
  1322. # for replace
  1323. add_initial_route "via 172.16.101.2"
  1324. run_cmd "$IP ro change 172.16.105.0/24 via 172.16.101.2"
  1325. log_test $? 2 "Single path - replace of non-existent route"
  1326. }
  1327. ipv4_rt_replace_mpath()
  1328. {
  1329. # multipath with multipath
  1330. add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1331. run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3"
  1332. check_route "172.16.104.0/24 nexthop via 172.16.101.3 dev veth1 weight 1 nexthop via 172.16.103.3 dev veth3 weight 1"
  1333. log_test $? 0 "Multipath with multipath"
  1334. # multipath with single
  1335. add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1336. run_cmd "$IP ro replace 172.16.104.0/24 via 172.16.101.3"
  1337. check_route "172.16.104.0/24 via 172.16.101.3 dev veth1"
  1338. log_test $? 0 "Multipath with single path"
  1339. # multipath with single
  1340. add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1341. run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3"
  1342. check_route "172.16.104.0/24 via 172.16.101.3 dev veth1"
  1343. log_test $? 0 "Multipath with single path via multipath attribute"
  1344. # multipath with reject
  1345. add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1346. run_cmd "$IP ro replace unreachable 172.16.104.0/24"
  1347. check_route "unreachable 172.16.104.0/24"
  1348. log_test $? 0 "Multipath with reject route"
  1349. # route replace fails - invalid nexthop 1
  1350. add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1351. run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.111.3 nexthop via 172.16.103.3"
  1352. check_route "172.16.104.0/24 nexthop via 172.16.101.2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
  1353. log_test $? 0 "Multipath - invalid first nexthop"
  1354. # route replace fails - invalid nexthop 2
  1355. add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1356. run_cmd "$IP ro replace 172.16.104.0/24 nexthop via 172.16.101.3 nexthop via 172.16.113.3"
  1357. check_route "172.16.104.0/24 nexthop via 172.16.101.2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
  1358. log_test $? 0 "Multipath - invalid second nexthop"
  1359. # multipath non-existent route
  1360. add_initial_route "nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1361. run_cmd "$IP ro change 172.16.105.0/24 nexthop via 172.16.101.3 nexthop via 172.16.103.3"
  1362. log_test $? 2 "Multipath - replace of non-existent route"
  1363. }
  1364. ipv4_rt_replace()
  1365. {
  1366. echo
  1367. echo "IPv4 route replace tests"
  1368. ipv4_rt_replace_single
  1369. ipv4_rt_replace_mpath
  1370. }
  1371. # checks that cached input route on VRF port is deleted
  1372. # when VRF is deleted
  1373. ipv4_local_rt_cache()
  1374. {
  1375. run_cmd "ip addr add 10.0.0.1/32 dev lo"
  1376. run_cmd "setup_ns test-ns"
  1377. run_cmd "ip link add veth-outside type veth peer name veth-inside"
  1378. run_cmd "ip link add vrf-100 type vrf table 1100"
  1379. run_cmd "ip link set veth-outside master vrf-100"
  1380. run_cmd "ip link set veth-inside netns $test-ns"
  1381. run_cmd "ip link set veth-outside up"
  1382. run_cmd "ip link set vrf-100 up"
  1383. run_cmd "ip route add 10.1.1.1/32 dev veth-outside table 1100"
  1384. run_cmd "ip netns exec $test-ns ip link set veth-inside up"
  1385. run_cmd "ip netns exec $test-ns ip addr add 10.1.1.1/32 dev veth-inside"
  1386. run_cmd "ip netns exec $test-ns ip route add 10.0.0.1/32 dev veth-inside"
  1387. run_cmd "ip netns exec $test-ns ip route add default via 10.0.0.1"
  1388. run_cmd "ip netns exec $test-ns ping 10.0.0.1 -c 1 -i 1"
  1389. run_cmd "ip link delete vrf-100"
  1390. # if we do not hang test is a success
  1391. log_test $? 0 "Cached route removed from VRF port device"
  1392. }
  1393. ipv4_rt_dsfield()
  1394. {
  1395. echo
  1396. echo "IPv4 route with dsfield tests"
  1397. run_cmd "$IP route flush 172.16.102.0/24"
  1398. # New routes should reject dsfield options that interfere with ECN
  1399. run_cmd "$IP route add 172.16.102.0/24 dsfield 0x01 via 172.16.101.2"
  1400. log_test $? 2 "Reject route with dsfield 0x01"
  1401. run_cmd "$IP route add 172.16.102.0/24 dsfield 0x02 via 172.16.101.2"
  1402. log_test $? 2 "Reject route with dsfield 0x02"
  1403. run_cmd "$IP route add 172.16.102.0/24 dsfield 0x03 via 172.16.101.2"
  1404. log_test $? 2 "Reject route with dsfield 0x03"
  1405. # A generic route that doesn't take DSCP into account
  1406. run_cmd "$IP route add 172.16.102.0/24 via 172.16.101.2"
  1407. # A more specific route for DSCP 0x10
  1408. run_cmd "$IP route add 172.16.102.0/24 dsfield 0x10 via 172.16.103.2"
  1409. # DSCP 0x10 should match the specific route, no matter the ECN bits
  1410. $IP route get fibmatch 172.16.102.1 dsfield 0x10 | \
  1411. grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
  1412. log_test $? 0 "IPv4 route with DSCP and ECN:Not-ECT"
  1413. $IP route get fibmatch 172.16.102.1 dsfield 0x11 | \
  1414. grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
  1415. log_test $? 0 "IPv4 route with DSCP and ECN:ECT(1)"
  1416. $IP route get fibmatch 172.16.102.1 dsfield 0x12 | \
  1417. grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
  1418. log_test $? 0 "IPv4 route with DSCP and ECN:ECT(0)"
  1419. $IP route get fibmatch 172.16.102.1 dsfield 0x13 | \
  1420. grep -q "172.16.102.0/24 tos 0x10 via 172.16.103.2"
  1421. log_test $? 0 "IPv4 route with DSCP and ECN:CE"
  1422. # Unknown DSCP should match the generic route, no matter the ECN bits
  1423. $IP route get fibmatch 172.16.102.1 dsfield 0x14 | \
  1424. grep -q "172.16.102.0/24 via 172.16.101.2"
  1425. log_test $? 0 "IPv4 route with unknown DSCP and ECN:Not-ECT"
  1426. $IP route get fibmatch 172.16.102.1 dsfield 0x15 | \
  1427. grep -q "172.16.102.0/24 via 172.16.101.2"
  1428. log_test $? 0 "IPv4 route with unknown DSCP and ECN:ECT(1)"
  1429. $IP route get fibmatch 172.16.102.1 dsfield 0x16 | \
  1430. grep -q "172.16.102.0/24 via 172.16.101.2"
  1431. log_test $? 0 "IPv4 route with unknown DSCP and ECN:ECT(0)"
  1432. $IP route get fibmatch 172.16.102.1 dsfield 0x17 | \
  1433. grep -q "172.16.102.0/24 via 172.16.101.2"
  1434. log_test $? 0 "IPv4 route with unknown DSCP and ECN:CE"
  1435. # Null DSCP should match the generic route, no matter the ECN bits
  1436. $IP route get fibmatch 172.16.102.1 dsfield 0x00 | \
  1437. grep -q "172.16.102.0/24 via 172.16.101.2"
  1438. log_test $? 0 "IPv4 route with no DSCP and ECN:Not-ECT"
  1439. $IP route get fibmatch 172.16.102.1 dsfield 0x01 | \
  1440. grep -q "172.16.102.0/24 via 172.16.101.2"
  1441. log_test $? 0 "IPv4 route with no DSCP and ECN:ECT(1)"
  1442. $IP route get fibmatch 172.16.102.1 dsfield 0x02 | \
  1443. grep -q "172.16.102.0/24 via 172.16.101.2"
  1444. log_test $? 0 "IPv4 route with no DSCP and ECN:ECT(0)"
  1445. $IP route get fibmatch 172.16.102.1 dsfield 0x03 | \
  1446. grep -q "172.16.102.0/24 via 172.16.101.2"
  1447. log_test $? 0 "IPv4 route with no DSCP and ECN:CE"
  1448. }
  1449. ipv4_route_test()
  1450. {
  1451. route_setup
  1452. ipv4_rt_add
  1453. ipv4_rt_replace
  1454. ipv4_local_rt_cache
  1455. ipv4_rt_dsfield
  1456. route_cleanup
  1457. }
  1458. ipv4_addr_metric_test()
  1459. {
  1460. local rc
  1461. echo
  1462. echo "IPv4 prefix route tests"
  1463. ip_addr_metric_check || return 1
  1464. setup
  1465. set -e
  1466. $IP li add dummy1 type dummy
  1467. $IP li add dummy2 type dummy
  1468. $IP li set dummy1 up
  1469. $IP li set dummy2 up
  1470. # default entry is metric 256
  1471. run_cmd "$IP addr add dev dummy1 172.16.104.1/24"
  1472. run_cmd "$IP addr add dev dummy2 172.16.104.2/24"
  1473. set +e
  1474. check_route "172.16.104.0/24 dev dummy1 proto kernel scope link src 172.16.104.1 172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2"
  1475. log_test $? 0 "Default metric"
  1476. set -e
  1477. run_cmd "$IP addr flush dev dummy1"
  1478. run_cmd "$IP addr add dev dummy1 172.16.104.1/24 metric 257"
  1479. set +e
  1480. check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 172.16.104.0/24 dev dummy1 proto kernel scope link src 172.16.104.1 metric 257"
  1481. log_test $? 0 "User specified metric on first device"
  1482. set -e
  1483. run_cmd "$IP addr flush dev dummy2"
  1484. run_cmd "$IP addr add dev dummy2 172.16.104.2/24 metric 258"
  1485. set +e
  1486. check_route "172.16.104.0/24 dev dummy1 proto kernel scope link src 172.16.104.1 metric 257 172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 258"
  1487. log_test $? 0 "User specified metric on second device"
  1488. run_cmd "$IP addr del dev dummy1 172.16.104.1/24 metric 257"
  1489. rc=$?
  1490. if [ $rc -eq 0 ]; then
  1491. check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 258"
  1492. rc=$?
  1493. fi
  1494. log_test $rc 0 "Delete of address on first device"
  1495. run_cmd "$IP addr change dev dummy2 172.16.104.2/24 metric 259"
  1496. rc=$?
  1497. if [ $rc -eq 0 ]; then
  1498. check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259"
  1499. rc=$?
  1500. fi
  1501. log_test $rc 0 "Modify metric of address"
  1502. # verify prefix route removed on down
  1503. run_cmd "$IP li set dev dummy2 down"
  1504. rc=$?
  1505. if [ $rc -eq 0 ]; then
  1506. out=$($IP ro ls match 172.16.104.0/24)
  1507. check_expected "${out}" ""
  1508. rc=$?
  1509. fi
  1510. log_test $rc 0 "Prefix route removed on link down"
  1511. # verify prefix route re-inserted with assigned metric
  1512. run_cmd "$IP li set dev dummy2 up"
  1513. rc=$?
  1514. if [ $rc -eq 0 ]; then
  1515. check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.2 metric 259"
  1516. rc=$?
  1517. fi
  1518. log_test $rc 0 "Prefix route with metric on link up"
  1519. # explicitly check for metric changes on edge scenarios
  1520. run_cmd "$IP addr flush dev dummy2"
  1521. run_cmd "$IP addr add dev dummy2 172.16.104.0/24 metric 259"
  1522. run_cmd "$IP addr change dev dummy2 172.16.104.0/24 metric 260"
  1523. rc=$?
  1524. if [ $rc -eq 0 ]; then
  1525. check_route "172.16.104.0/24 dev dummy2 proto kernel scope link src 172.16.104.0 metric 260"
  1526. rc=$?
  1527. fi
  1528. log_test $rc 0 "Modify metric of .0/24 address"
  1529. run_cmd "$IP addr flush dev dummy2"
  1530. run_cmd "$IP addr add dev dummy2 172.16.104.1/32 peer 172.16.104.2 metric 260"
  1531. rc=$?
  1532. if [ $rc -eq 0 ]; then
  1533. check_route "172.16.104.2 dev dummy2 proto kernel scope link src 172.16.104.1 metric 260"
  1534. rc=$?
  1535. fi
  1536. log_test $rc 0 "Set metric of address with peer route"
  1537. run_cmd "$IP addr change dev dummy2 172.16.104.1/32 peer 172.16.104.3 metric 261"
  1538. rc=$?
  1539. if [ $rc -eq 0 ]; then
  1540. check_route "172.16.104.3 dev dummy2 proto kernel scope link src 172.16.104.1 metric 261"
  1541. rc=$?
  1542. fi
  1543. log_test $rc 0 "Modify metric and peer address for peer route"
  1544. $IP li del dummy1
  1545. $IP li del dummy2
  1546. cleanup
  1547. }
  1548. ipv4_route_metrics_test()
  1549. {
  1550. local rc
  1551. echo
  1552. echo "IPv4 route add / append tests"
  1553. route_setup
  1554. run_cmd "$IP ro add 172.16.111.0/24 via 172.16.101.2 mtu 1400"
  1555. rc=$?
  1556. if [ $rc -eq 0 ]; then
  1557. check_route "172.16.111.0/24 via 172.16.101.2 dev veth1 mtu 1400"
  1558. rc=$?
  1559. fi
  1560. log_test $rc 0 "Single path route with mtu metric"
  1561. run_cmd "$IP ro add 172.16.112.0/24 mtu 1400 nexthop via 172.16.101.2 nexthop via 172.16.103.2"
  1562. rc=$?
  1563. if [ $rc -eq 0 ]; then
  1564. check_route "172.16.112.0/24 mtu 1400 nexthop via 172.16.101.2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
  1565. rc=$?
  1566. fi
  1567. log_test $rc 0 "Multipath route with mtu metric"
  1568. $IP ro add 172.16.104.0/24 via 172.16.101.2 mtu 1300
  1569. run_cmd "ip netns exec $ns1 ping -w1 -c1 -s 1500 172.16.104.1"
  1570. log_test $? 0 "Using route with mtu metric"
  1571. run_cmd "$IP ro add 172.16.111.0/24 via 172.16.101.2 congctl lock foo"
  1572. log_test $? 2 "Invalid metric (fails metric_convert)"
  1573. route_cleanup
  1574. }
  1575. ipv4_del_addr_test()
  1576. {
  1577. echo
  1578. echo "IPv4 delete address route tests"
  1579. setup
  1580. set -e
  1581. $IP li add dummy1 type dummy
  1582. $IP li set dummy1 up
  1583. $IP li add dummy2 type dummy
  1584. $IP li set dummy2 up
  1585. $IP li add red type vrf table 1111
  1586. $IP li set red up
  1587. $IP ro add vrf red unreachable default
  1588. $IP li set dummy2 vrf red
  1589. $IP addr add dev dummy1 172.16.104.1/24
  1590. $IP addr add dev dummy1 172.16.104.11/24
  1591. $IP addr add dev dummy1 172.16.104.12/24
  1592. $IP addr add dev dummy1 172.16.104.13/24
  1593. $IP addr add dev dummy2 172.16.104.1/24
  1594. $IP addr add dev dummy2 172.16.104.11/24
  1595. $IP addr add dev dummy2 172.16.104.12/24
  1596. $IP route add 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
  1597. $IP route add 172.16.106.0/24 dev lo src 172.16.104.12
  1598. $IP route add table 0 172.16.107.0/24 via 172.16.104.2 src 172.16.104.13
  1599. $IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
  1600. $IP route add vrf red 172.16.106.0/24 dev lo src 172.16.104.12
  1601. set +e
  1602. # removing address from device in vrf should only remove route from vrf table
  1603. echo " Regular FIB info"
  1604. $IP addr del dev dummy2 172.16.104.11/24
  1605. $IP ro ls vrf red | grep -q 172.16.105.0/24
  1606. log_test $? 1 "Route removed from VRF when source address deleted"
  1607. $IP ro ls | grep -q 172.16.105.0/24
  1608. log_test $? 0 "Route in default VRF not removed"
  1609. $IP addr add dev dummy2 172.16.104.11/24
  1610. $IP route add vrf red 172.16.105.0/24 via 172.16.104.2 src 172.16.104.11
  1611. $IP addr del dev dummy1 172.16.104.11/24
  1612. $IP ro ls | grep -q 172.16.105.0/24
  1613. log_test $? 1 "Route removed in default VRF when source address deleted"
  1614. $IP ro ls vrf red | grep -q 172.16.105.0/24
  1615. log_test $? 0 "Route in VRF is not removed by address delete"
  1616. # removing address from device in vrf should only remove route from vrf
  1617. # table even when the associated fib info only differs in table ID
  1618. echo " Identical FIB info with different table ID"
  1619. $IP addr del dev dummy2 172.16.104.12/24
  1620. $IP ro ls vrf red | grep -q 172.16.106.0/24
  1621. log_test $? 1 "Route removed from VRF when source address deleted"
  1622. $IP ro ls | grep -q 172.16.106.0/24
  1623. log_test $? 0 "Route in default VRF not removed"
  1624. $IP addr add dev dummy2 172.16.104.12/24
  1625. $IP route add vrf red 172.16.106.0/24 dev lo src 172.16.104.12
  1626. $IP addr del dev dummy1 172.16.104.12/24
  1627. $IP ro ls | grep -q 172.16.106.0/24
  1628. log_test $? 1 "Route removed in default VRF when source address deleted"
  1629. $IP ro ls vrf red | grep -q 172.16.106.0/24
  1630. log_test $? 0 "Route in VRF is not removed by address delete"
  1631. # removing address from device in default vrf should remove route from
  1632. # the default vrf even when route was inserted with a table ID of 0.
  1633. echo " Table ID 0"
  1634. $IP addr del dev dummy1 172.16.104.13/24
  1635. $IP ro ls | grep -q 172.16.107.0/24
  1636. log_test $? 1 "Route removed in default VRF when source address deleted"
  1637. $IP li del dummy1
  1638. $IP li del dummy2
  1639. cleanup
  1640. }
  1641. ipv6_del_addr_test()
  1642. {
  1643. echo
  1644. echo "IPv6 delete address route tests"
  1645. setup
  1646. set -e
  1647. for i in $(seq 6); do
  1648. $IP li add dummy${i} up type dummy
  1649. done
  1650. $IP li add red up type vrf table 1111
  1651. $IP ro add vrf red unreachable default
  1652. for i in $(seq 4 6); do
  1653. $IP li set dummy${i} vrf red
  1654. done
  1655. $IP addr add dev dummy1 fe80::1/128
  1656. $IP addr add dev dummy1 2001:db8:101::1/64
  1657. $IP addr add dev dummy1 2001:db8:101::10/64
  1658. $IP addr add dev dummy1 2001:db8:101::11/64
  1659. $IP addr add dev dummy1 2001:db8:101::12/64
  1660. $IP addr add dev dummy1 2001:db8:101::13/64
  1661. $IP addr add dev dummy1 2001:db8:101::14/64
  1662. $IP addr add dev dummy1 2001:db8:101::15/64
  1663. $IP addr add dev dummy2 fe80::1/128
  1664. $IP addr add dev dummy2 2001:db8:101::1/64
  1665. $IP addr add dev dummy2 2001:db8:101::11/64
  1666. $IP addr add dev dummy3 fe80::1/128
  1667. $IP addr add dev dummy4 2001:db8:101::1/64
  1668. $IP addr add dev dummy4 2001:db8:101::10/64
  1669. $IP addr add dev dummy4 2001:db8:101::11/64
  1670. $IP addr add dev dummy4 2001:db8:101::12/64
  1671. $IP addr add dev dummy4 2001:db8:101::13/64
  1672. $IP addr add dev dummy4 2001:db8:101::14/64
  1673. $IP addr add dev dummy5 2001:db8:101::1/64
  1674. $IP addr add dev dummy5 2001:db8:101::11/64
  1675. # Single device using src address
  1676. $IP route add 2001:db8:110::/64 dev dummy3 src 2001:db8:101::10
  1677. # Two devices with the same source address
  1678. $IP route add 2001:db8:111::/64 dev dummy3 src 2001:db8:101::11
  1679. # VRF with single device using src address
  1680. $IP route add vrf red 2001:db8:110::/64 dev dummy6 src 2001:db8:101::10
  1681. # VRF with two devices using src address
  1682. $IP route add vrf red 2001:db8:111::/64 dev dummy6 src 2001:db8:101::11
  1683. # src address and nexthop dev in same VRF
  1684. $IP route add 2001:db8:112::/64 dev dummy3 src 2001:db8:101::12
  1685. $IP route add vrf red 2001:db8:112::/64 dev dummy6 src 2001:db8:101::12
  1686. # src address and nexthop device in different VRF
  1687. $IP route add 2001:db8:113::/64 dev lo src 2001:db8:101::13
  1688. $IP route add vrf red 2001:db8:113::/64 dev lo src 2001:db8:101::13
  1689. # table ID 0
  1690. $IP route add table 0 2001:db8:115::/64 via 2001:db8:101::2 src 2001:db8:101::15
  1691. # Link local source route
  1692. $IP route add 2001:db8:116::/64 dev dummy2 src fe80::1
  1693. $IP route add 2001:db8:117::/64 dev dummy3 src fe80::1
  1694. set +e
  1695. echo " Single device using src address"
  1696. $IP addr del dev dummy1 2001:db8:101::10/64
  1697. $IP -6 route show | grep -q "src 2001:db8:101::10 "
  1698. log_test $? 1 "Prefsrc removed when src address removed on other device"
  1699. echo " Two devices with the same source address"
  1700. $IP addr del dev dummy1 2001:db8:101::11/64
  1701. $IP -6 route show | grep -q "src 2001:db8:101::11 "
  1702. log_test $? 0 "Prefsrc not removed when src address exist on other device"
  1703. $IP addr del dev dummy2 2001:db8:101::11/64
  1704. $IP -6 route show | grep -q "src 2001:db8:101::11 "
  1705. log_test $? 1 "Prefsrc removed when src address removed on all devices"
  1706. echo " VRF with single device using src address"
  1707. $IP addr del dev dummy4 2001:db8:101::10/64
  1708. $IP -6 route show vrf red | grep -q "src 2001:db8:101::10 "
  1709. log_test $? 1 "Prefsrc removed when src address removed on other device"
  1710. echo " VRF with two devices using src address"
  1711. $IP addr del dev dummy4 2001:db8:101::11/64
  1712. $IP -6 route show vrf red | grep -q "src 2001:db8:101::11 "
  1713. log_test $? 0 "Prefsrc not removed when src address exist on other device"
  1714. $IP addr del dev dummy5 2001:db8:101::11/64
  1715. $IP -6 route show vrf red | grep -q "src 2001:db8:101::11 "
  1716. log_test $? 1 "Prefsrc removed when src address removed on all devices"
  1717. echo " src address and nexthop dev in same VRF"
  1718. $IP addr del dev dummy4 2001:db8:101::12/64
  1719. $IP -6 route show vrf red | grep -q "src 2001:db8:101::12 "
  1720. log_test $? 1 "Prefsrc removed from VRF when source address deleted"
  1721. $IP -6 route show | grep -q " src 2001:db8:101::12 "
  1722. log_test $? 0 "Prefsrc in default VRF not removed"
  1723. $IP addr add dev dummy4 2001:db8:101::12/64
  1724. $IP route replace vrf red 2001:db8:112::/64 dev dummy6 src 2001:db8:101::12
  1725. $IP addr del dev dummy1 2001:db8:101::12/64
  1726. $IP -6 route show vrf red | grep -q "src 2001:db8:101::12 "
  1727. log_test $? 0 "Prefsrc not removed from VRF when source address exist"
  1728. $IP -6 route show | grep -q " src 2001:db8:101::12 "
  1729. log_test $? 1 "Prefsrc in default VRF removed"
  1730. echo " src address and nexthop device in different VRF"
  1731. $IP addr del dev dummy4 2001:db8:101::13/64
  1732. $IP -6 route show vrf red | grep -q "src 2001:db8:101::13 "
  1733. log_test $? 0 "Prefsrc not removed from VRF when nexthop dev in diff VRF"
  1734. $IP -6 route show | grep -q "src 2001:db8:101::13 "
  1735. log_test $? 0 "Prefsrc not removed in default VRF"
  1736. $IP addr add dev dummy4 2001:db8:101::13/64
  1737. $IP addr del dev dummy1 2001:db8:101::13/64
  1738. $IP -6 route show vrf red | grep -q "src 2001:db8:101::13 "
  1739. log_test $? 1 "Prefsrc removed from VRF when nexthop dev in diff VRF"
  1740. $IP -6 route show | grep -q "src 2001:db8:101::13 "
  1741. log_test $? 1 "Prefsrc removed in default VRF"
  1742. echo " Table ID 0"
  1743. $IP addr del dev dummy1 2001:db8:101::15/64
  1744. $IP -6 route show | grep -q "src 2001:db8:101::15"
  1745. log_test $? 1 "Prefsrc removed from default VRF when source address deleted"
  1746. echo " Link local source route"
  1747. $IP addr del dev dummy1 fe80::1/128
  1748. $IP -6 route show | grep -q "2001:db8:116::/64 dev dummy2 src fe80::1"
  1749. log_test $? 0 "Prefsrc not removed when delete ll addr from other dev"
  1750. $IP addr del dev dummy2 fe80::1/128
  1751. $IP -6 route show | grep -q "2001:db8:116::/64 dev dummy2 src fe80::1"
  1752. log_test $? 1 "Prefsrc removed when delete ll addr"
  1753. $IP -6 route show | grep -q "2001:db8:117::/64 dev dummy3 src fe80::1"
  1754. log_test $? 0 "Prefsrc not removed when delete ll addr from other dev"
  1755. $IP addr add dev dummy1 fe80::1/128
  1756. $IP addr del dev dummy3 fe80::1/128
  1757. $IP -6 route show | grep -q "2001:db8:117::/64 dev dummy3 src fe80::1"
  1758. log_test $? 1 "Prefsrc removed even ll addr still exist on other dev"
  1759. for i in $(seq 6); do
  1760. $IP li del dummy${i}
  1761. done
  1762. cleanup
  1763. }
  1764. ipv4_route_v6_gw_test()
  1765. {
  1766. local rc
  1767. echo
  1768. echo "IPv4 route with IPv6 gateway tests"
  1769. route_setup
  1770. sleep 2
  1771. #
  1772. # single path route
  1773. #
  1774. run_cmd "$IP ro add 172.16.104.0/24 via inet6 2001:db8:101::2"
  1775. rc=$?
  1776. log_test $rc 0 "Single path route with IPv6 gateway"
  1777. if [ $rc -eq 0 ]; then
  1778. check_route "172.16.104.0/24 via inet6 2001:db8:101::2 dev veth1"
  1779. fi
  1780. run_cmd "ip netns exec $ns1 ping -w1 -c1 172.16.104.1"
  1781. log_test $rc 0 "Single path route with IPv6 gateway - ping"
  1782. run_cmd "$IP ro del 172.16.104.0/24 via inet6 2001:db8:101::2"
  1783. rc=$?
  1784. log_test $rc 0 "Single path route delete"
  1785. if [ $rc -eq 0 ]; then
  1786. check_route "172.16.112.0/24"
  1787. fi
  1788. #
  1789. # multipath - v6 then v4
  1790. #
  1791. run_cmd "$IP ro add 172.16.104.0/24 nexthop via inet6 2001:db8:101::2 dev veth1 nexthop via 172.16.103.2 dev veth3"
  1792. rc=$?
  1793. log_test $rc 0 "Multipath route add - v6 nexthop then v4"
  1794. if [ $rc -eq 0 ]; then
  1795. check_route "172.16.104.0/24 nexthop via inet6 2001:db8:101::2 dev veth1 weight 1 nexthop via 172.16.103.2 dev veth3 weight 1"
  1796. fi
  1797. run_cmd "$IP ro del 172.16.104.0/24 nexthop via 172.16.103.2 dev veth3 nexthop via inet6 2001:db8:101::2 dev veth1"
  1798. log_test $? 2 " Multipath route delete - nexthops in wrong order"
  1799. run_cmd "$IP ro del 172.16.104.0/24 nexthop via inet6 2001:db8:101::2 dev veth1 nexthop via 172.16.103.2 dev veth3"
  1800. log_test $? 0 " Multipath route delete exact match"
  1801. #
  1802. # multipath - v4 then v6
  1803. #
  1804. run_cmd "$IP ro add 172.16.104.0/24 nexthop via 172.16.103.2 dev veth3 nexthop via inet6 2001:db8:101::2 dev veth1"
  1805. rc=$?
  1806. log_test $rc 0 "Multipath route add - v4 nexthop then v6"
  1807. if [ $rc -eq 0 ]; then
  1808. check_route "172.16.104.0/24 nexthop via 172.16.103.2 dev veth3 weight 1 nexthop via inet6 2001:db8:101::2 dev veth1 weight 1"
  1809. fi
  1810. run_cmd "$IP ro del 172.16.104.0/24 nexthop via inet6 2001:db8:101::2 dev veth1 nexthop via 172.16.103.2 dev veth3"
  1811. log_test $? 2 " Multipath route delete - nexthops in wrong order"
  1812. run_cmd "$IP ro del 172.16.104.0/24 nexthop via 172.16.103.2 dev veth3 nexthop via inet6 2001:db8:101::2 dev veth1"
  1813. log_test $? 0 " Multipath route delete exact match"
  1814. route_cleanup
  1815. }
  1816. socat_check()
  1817. {
  1818. if [ ! -x "$(command -v socat)" ]; then
  1819. echo "socat command not found. Skipping test"
  1820. return 1
  1821. fi
  1822. return 0
  1823. }
  1824. iptables_check()
  1825. {
  1826. iptables -t mangle -L OUTPUT &> /dev/null
  1827. if [ $? -ne 0 ]; then
  1828. echo "iptables configuration not supported. Skipping test"
  1829. return 1
  1830. fi
  1831. return 0
  1832. }
  1833. ip6tables_check()
  1834. {
  1835. ip6tables -t mangle -L OUTPUT &> /dev/null
  1836. if [ $? -ne 0 ]; then
  1837. echo "ip6tables configuration not supported. Skipping test"
  1838. return 1
  1839. fi
  1840. return 0
  1841. }
  1842. ipv4_mangle_test()
  1843. {
  1844. local rc
  1845. echo
  1846. echo "IPv4 mangling tests"
  1847. socat_check || return 1
  1848. iptables_check || return 1
  1849. route_setup
  1850. sleep 2
  1851. local tmp_file=$(mktemp)
  1852. ip netns exec $ns2 socat UDP4-LISTEN:54321,fork $tmp_file &
  1853. # Add a FIB rule and a route that will direct our connection to the
  1854. # listening server.
  1855. $IP rule add pref 100 ipproto udp sport 12345 dport 54321 table 123
  1856. $IP route add table 123 172.16.101.0/24 dev veth1
  1857. # Add an unreachable route to the main table that will block our
  1858. # connection in case the FIB rule is not hit.
  1859. $IP route add unreachable 172.16.101.2/32
  1860. run_cmd "echo a | $NS_EXEC socat STDIN UDP4:172.16.101.2:54321,sourceport=12345"
  1861. log_test $? 0 " Connection with correct parameters"
  1862. run_cmd "echo a | $NS_EXEC socat STDIN UDP4:172.16.101.2:54321,sourceport=11111"
  1863. log_test $? 1 " Connection with incorrect parameters"
  1864. # Add a mangling rule and make sure connection is still successful.
  1865. $NS_EXEC iptables -t mangle -A OUTPUT -j MARK --set-mark 1
  1866. run_cmd "echo a | $NS_EXEC socat STDIN UDP4:172.16.101.2:54321,sourceport=12345"
  1867. log_test $? 0 " Connection with correct parameters - mangling"
  1868. # Delete the mangling rule and make sure connection is still
  1869. # successful.
  1870. $NS_EXEC iptables -t mangle -D OUTPUT -j MARK --set-mark 1
  1871. run_cmd "echo a | $NS_EXEC socat STDIN UDP4:172.16.101.2:54321,sourceport=12345"
  1872. log_test $? 0 " Connection with correct parameters - no mangling"
  1873. # Verify connections were indeed successful on server side.
  1874. [[ $(cat $tmp_file | wc -l) -eq 3 ]]
  1875. log_test $? 0 " Connection check - server side"
  1876. $IP route del unreachable 172.16.101.2/32
  1877. $IP route del table 123 172.16.101.0/24 dev veth1
  1878. $IP rule del pref 100
  1879. { kill %% && wait %%; } 2>/dev/null
  1880. rm $tmp_file
  1881. route_cleanup
  1882. }
  1883. ipv6_mangle_test()
  1884. {
  1885. local rc
  1886. echo
  1887. echo "IPv6 mangling tests"
  1888. socat_check || return 1
  1889. ip6tables_check || return 1
  1890. route_setup
  1891. sleep 2
  1892. local tmp_file=$(mktemp)
  1893. ip netns exec $ns2 socat UDP6-LISTEN:54321,fork $tmp_file &
  1894. # Add a FIB rule and a route that will direct our connection to the
  1895. # listening server.
  1896. $IP -6 rule add pref 100 ipproto udp sport 12345 dport 54321 table 123
  1897. $IP -6 route add table 123 2001:db8:101::/64 dev veth1
  1898. # Add an unreachable route to the main table that will block our
  1899. # connection in case the FIB rule is not hit.
  1900. $IP -6 route add unreachable 2001:db8:101::2/128
  1901. run_cmd "echo a | $NS_EXEC socat STDIN UDP6:[2001:db8:101::2]:54321,sourceport=12345"
  1902. log_test $? 0 " Connection with correct parameters"
  1903. run_cmd "echo a | $NS_EXEC socat STDIN UDP6:[2001:db8:101::2]:54321,sourceport=11111"
  1904. log_test $? 1 " Connection with incorrect parameters"
  1905. # Add a mangling rule and make sure connection is still successful.
  1906. $NS_EXEC ip6tables -t mangle -A OUTPUT -j MARK --set-mark 1
  1907. run_cmd "echo a | $NS_EXEC socat STDIN UDP6:[2001:db8:101::2]:54321,sourceport=12345"
  1908. log_test $? 0 " Connection with correct parameters - mangling"
  1909. # Delete the mangling rule and make sure connection is still
  1910. # successful.
  1911. $NS_EXEC ip6tables -t mangle -D OUTPUT -j MARK --set-mark 1
  1912. run_cmd "echo a | $NS_EXEC socat STDIN UDP6:[2001:db8:101::2]:54321,sourceport=12345"
  1913. log_test $? 0 " Connection with correct parameters - no mangling"
  1914. # Verify connections were indeed successful on server side.
  1915. [[ $(cat $tmp_file | wc -l) -eq 3 ]]
  1916. log_test $? 0 " Connection check - server side"
  1917. $IP -6 route del unreachable 2001:db8:101::2/128
  1918. $IP -6 route del table 123 2001:db8:101::/64 dev veth1
  1919. $IP -6 rule del pref 100
  1920. { kill %% && wait %%; } 2>/dev/null
  1921. rm $tmp_file
  1922. route_cleanup
  1923. }
  1924. ip_neigh_get_check()
  1925. {
  1926. ip neigh help 2>&1 | grep -q 'ip neigh get'
  1927. if [ $? -ne 0 ]; then
  1928. echo "iproute2 command does not support neigh get. Skipping test"
  1929. return 1
  1930. fi
  1931. return 0
  1932. }
  1933. ipv4_bcast_neigh_test()
  1934. {
  1935. local rc
  1936. echo
  1937. echo "IPv4 broadcast neighbour tests"
  1938. ip_neigh_get_check || return 1
  1939. setup
  1940. set -e
  1941. run_cmd "$IP neigh add 192.0.2.111 lladdr 00:11:22:33:44:55 nud perm dev dummy0"
  1942. run_cmd "$IP neigh add 192.0.2.255 lladdr 00:11:22:33:44:55 nud perm dev dummy0"
  1943. run_cmd "$IP neigh get 192.0.2.111 dev dummy0"
  1944. run_cmd "$IP neigh get 192.0.2.255 dev dummy0"
  1945. run_cmd "$IP address add 192.0.2.1/24 broadcast 192.0.2.111 dev dummy0"
  1946. run_cmd "$IP neigh add 203.0.113.111 nud failed dev dummy0"
  1947. run_cmd "$IP neigh add 203.0.113.255 nud failed dev dummy0"
  1948. run_cmd "$IP neigh get 203.0.113.111 dev dummy0"
  1949. run_cmd "$IP neigh get 203.0.113.255 dev dummy0"
  1950. run_cmd "$IP address add 203.0.113.1/24 broadcast 203.0.113.111 dev dummy0"
  1951. set +e
  1952. run_cmd "$IP neigh get 192.0.2.111 dev dummy0"
  1953. log_test $? 0 "Resolved neighbour for broadcast address"
  1954. run_cmd "$IP neigh get 192.0.2.255 dev dummy0"
  1955. log_test $? 0 "Resolved neighbour for network broadcast address"
  1956. run_cmd "$IP neigh get 203.0.113.111 dev dummy0"
  1957. log_test $? 2 "Unresolved neighbour for broadcast address"
  1958. run_cmd "$IP neigh get 203.0.113.255 dev dummy0"
  1959. log_test $? 2 "Unresolved neighbour for network broadcast address"
  1960. cleanup
  1961. }
  1962. mpath_dep_check()
  1963. {
  1964. if [ ! -x "$(command -v mausezahn)" ]; then
  1965. echo "mausezahn command not found. Skipping test"
  1966. return 1
  1967. fi
  1968. if [ ! -x "$(command -v jq)" ]; then
  1969. echo "jq command not found. Skipping test"
  1970. return 1
  1971. fi
  1972. if [ ! -x "$(command -v bc)" ]; then
  1973. echo "bc command not found. Skipping test"
  1974. return 1
  1975. fi
  1976. if [ ! -x "$(command -v perf)" ]; then
  1977. echo "perf command not found. Skipping test"
  1978. return 1
  1979. fi
  1980. perf list fib:* | grep -q fib_table_lookup
  1981. if [ $? -ne 0 ]; then
  1982. echo "IPv4 FIB tracepoint not found. Skipping test"
  1983. return 1
  1984. fi
  1985. perf list fib6:* | grep -q fib6_table_lookup
  1986. if [ $? -ne 0 ]; then
  1987. echo "IPv6 FIB tracepoint not found. Skipping test"
  1988. return 1
  1989. fi
  1990. return 0
  1991. }
  1992. link_stats_get()
  1993. {
  1994. local ns=$1; shift
  1995. local dev=$1; shift
  1996. local dir=$1; shift
  1997. local stat=$1; shift
  1998. ip -n $ns -j -s link show dev $dev \
  1999. | jq '.[]["stats64"]["'$dir'"]["'$stat'"]'
  2000. }
  2001. list_rcv_eval()
  2002. {
  2003. local file=$1; shift
  2004. local expected=$1; shift
  2005. local count=$(tail -n 1 $file | jq '.["counter-value"] | tonumber | floor')
  2006. local ratio=$(echo "scale=2; $count / $expected" | bc -l)
  2007. local res=$(echo "$ratio >= 0.95" | bc)
  2008. [[ $res -eq 1 ]]
  2009. log_test $? 0 "Multipath route hit ratio ($ratio)"
  2010. }
  2011. ipv4_mpath_list_test()
  2012. {
  2013. echo
  2014. echo "IPv4 multipath list receive tests"
  2015. mpath_dep_check || return 1
  2016. route_setup
  2017. set -e
  2018. run_cmd "ip netns exec $ns1 ethtool -K veth1 tcp-segmentation-offload off"
  2019. run_cmd "ip netns exec $ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\""
  2020. run_cmd "ip netns exec $ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\""
  2021. run_cmd "ip netns exec $ns2 ethtool -K veth2 generic-receive-offload on"
  2022. run_cmd "ip -n $ns2 link add name nh1 up type dummy"
  2023. run_cmd "ip -n $ns2 link add name nh2 up type dummy"
  2024. run_cmd "ip -n $ns2 address add 172.16.201.1/24 dev nh1"
  2025. run_cmd "ip -n $ns2 address add 172.16.202.1/24 dev nh2"
  2026. run_cmd "ip -n $ns2 neigh add 172.16.201.2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
  2027. run_cmd "ip -n $ns2 neigh add 172.16.202.2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
  2028. run_cmd "ip -n $ns2 route add 203.0.113.0/24
  2029. nexthop via 172.16.201.2 nexthop via 172.16.202.2"
  2030. run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.fib_multipath_hash_policy=1"
  2031. run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.conf.veth2.rp_filter=0"
  2032. run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.conf.all.rp_filter=0"
  2033. run_cmd "ip netns exec $ns2 sysctl -qw net.ipv4.conf.default.rp_filter=0"
  2034. set +e
  2035. local dmac=$(ip -n $ns2 -j link show dev veth2 | jq -r '.[]["address"]')
  2036. local tmp_file=$(mktemp)
  2037. local cmd="ip netns exec $ns1 mausezahn veth1 -a own -b $dmac
  2038. -A 172.16.101.1 -B 203.0.113.1 -t udp 'sp=12345,dp=0-65535' -q"
  2039. # Packets forwarded in a list using a multipath route must not reuse a
  2040. # cached result so that a flow always hits the same nexthop. In other
  2041. # words, the FIB lookup tracepoint needs to be triggered for every
  2042. # packet.
  2043. local t0_rx_pkts=$(link_stats_get $ns2 veth2 rx packets)
  2044. run_cmd "perf stat -a -e fib:fib_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd"
  2045. local t1_rx_pkts=$(link_stats_get $ns2 veth2 rx packets)
  2046. local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
  2047. list_rcv_eval $tmp_file $diff
  2048. rm $tmp_file
  2049. route_cleanup
  2050. }
  2051. ipv6_mpath_list_test()
  2052. {
  2053. echo
  2054. echo "IPv6 multipath list receive tests"
  2055. mpath_dep_check || return 1
  2056. route_setup
  2057. set -e
  2058. run_cmd "ip netns exec $ns1 ethtool -K veth1 tcp-segmentation-offload off"
  2059. run_cmd "ip netns exec $ns2 bash -c \"echo 20000 > /sys/class/net/veth2/gro_flush_timeout\""
  2060. run_cmd "ip netns exec $ns2 bash -c \"echo 1 > /sys/class/net/veth2/napi_defer_hard_irqs\""
  2061. run_cmd "ip netns exec $ns2 ethtool -K veth2 generic-receive-offload on"
  2062. run_cmd "ip -n $ns2 link add name nh1 up type dummy"
  2063. run_cmd "ip -n $ns2 link add name nh2 up type dummy"
  2064. run_cmd "ip -n $ns2 -6 address add 2001:db8:201::1/64 dev nh1"
  2065. run_cmd "ip -n $ns2 -6 address add 2001:db8:202::1/64 dev nh2"
  2066. run_cmd "ip -n $ns2 -6 neigh add 2001:db8:201::2 lladdr 00:11:22:33:44:55 nud perm dev nh1"
  2067. run_cmd "ip -n $ns2 -6 neigh add 2001:db8:202::2 lladdr 00:aa:bb:cc:dd:ee nud perm dev nh2"
  2068. run_cmd "ip -n $ns2 -6 route add 2001:db8:301::/64
  2069. nexthop via 2001:db8:201::2 nexthop via 2001:db8:202::2"
  2070. run_cmd "ip netns exec $ns2 sysctl -qw net.ipv6.fib_multipath_hash_policy=1"
  2071. set +e
  2072. local dmac=$(ip -n $ns2 -j link show dev veth2 | jq -r '.[]["address"]')
  2073. local tmp_file=$(mktemp)
  2074. local cmd="ip netns exec $ns1 mausezahn -6 veth1 -a own -b $dmac
  2075. -A 2001:db8:101::1 -B 2001:db8:301::1 -t udp 'sp=12345,dp=0-65535' -q"
  2076. # Packets forwarded in a list using a multipath route must not reuse a
  2077. # cached result so that a flow always hits the same nexthop. In other
  2078. # words, the FIB lookup tracepoint needs to be triggered for every
  2079. # packet.
  2080. local t0_rx_pkts=$(link_stats_get $ns2 veth2 rx packets)
  2081. run_cmd "perf stat -a -e fib6:fib6_table_lookup --filter 'err == 0' -j -o $tmp_file -- $cmd"
  2082. local t1_rx_pkts=$(link_stats_get $ns2 veth2 rx packets)
  2083. local diff=$(echo $t1_rx_pkts - $t0_rx_pkts | bc -l)
  2084. list_rcv_eval $tmp_file $diff
  2085. rm $tmp_file
  2086. route_cleanup
  2087. }
  2088. ################################################################################
  2089. # usage
  2090. usage()
  2091. {
  2092. cat <<EOF
  2093. usage: ${0##*/} OPTS
  2094. -t <test> Test(s) to run (default: all)
  2095. (options: $TESTS)
  2096. -p Pause on fail
  2097. -P Pause after each test before cleanup
  2098. -v verbose mode (show commands and output)
  2099. EOF
  2100. }
  2101. ################################################################################
  2102. # main
  2103. trap cleanup EXIT
  2104. while getopts :t:pPhv o
  2105. do
  2106. case $o in
  2107. t) TESTS=$OPTARG;;
  2108. p) PAUSE_ON_FAIL=yes;;
  2109. P) PAUSE=yes;;
  2110. v) VERBOSE=$(($VERBOSE + 1));;
  2111. h) usage; exit 0;;
  2112. *) usage; exit 1;;
  2113. esac
  2114. done
  2115. PEER_CMD="ip netns exec ${PEER_NS}"
  2116. # make sure we don't pause twice
  2117. [ "${PAUSE}" = "yes" ] && PAUSE_ON_FAIL=no
  2118. if [ "$(id -u)" -ne 0 ];then
  2119. echo "SKIP: Need root privileges"
  2120. exit $ksft_skip;
  2121. fi
  2122. if [ ! -x "$(command -v ip)" ]; then
  2123. echo "SKIP: Could not run test without ip tool"
  2124. exit $ksft_skip
  2125. fi
  2126. ip route help 2>&1 | grep -q fibmatch
  2127. if [ $? -ne 0 ]; then
  2128. echo "SKIP: iproute2 too old, missing fibmatch"
  2129. exit $ksft_skip
  2130. fi
  2131. # start clean
  2132. cleanup &> /dev/null
  2133. for t in $TESTS
  2134. do
  2135. case $t in
  2136. fib_unreg_test|unregister) fib_unreg_test;;
  2137. fib_down_test|down) fib_down_test;;
  2138. fib_carrier_test|carrier) fib_carrier_test;;
  2139. fib_rp_filter_test|rp_filter) fib_rp_filter_test;;
  2140. fib_nexthop_test|nexthop) fib_nexthop_test;;
  2141. fib_notify_test|ipv4_notify) fib_notify_test;;
  2142. fib6_notify_test|ipv6_notify) fib6_notify_test;;
  2143. fib_suppress_test|suppress) fib_suppress_test;;
  2144. ipv6_route_test|ipv6_rt) ipv6_route_test;;
  2145. ipv4_route_test|ipv4_rt) ipv4_route_test;;
  2146. ipv6_addr_metric) ipv6_addr_metric_test;;
  2147. ipv4_addr_metric) ipv4_addr_metric_test;;
  2148. ipv4_del_addr) ipv4_del_addr_test;;
  2149. ipv6_del_addr) ipv6_del_addr_test;;
  2150. ipv6_route_metrics) ipv6_route_metrics_test;;
  2151. ipv4_route_metrics) ipv4_route_metrics_test;;
  2152. ipv4_route_v6_gw) ipv4_route_v6_gw_test;;
  2153. ipv4_mangle) ipv4_mangle_test;;
  2154. ipv6_mangle) ipv6_mangle_test;;
  2155. ipv4_bcast_neigh) ipv4_bcast_neigh_test;;
  2156. fib6_gc_test|ipv6_gc) fib6_gc_test;;
  2157. ipv4_mpath_list) ipv4_mpath_list_test;;
  2158. ipv6_mpath_list) ipv6_mpath_list_test;;
  2159. help) echo "Test names: $TESTS"; exit 0;;
  2160. esac
  2161. done
  2162. if [ "$TESTS" != "none" ]; then
  2163. printf "\nTests passed: %3d\n" ${nsuccess}
  2164. printf "Tests failed: %3d\n" ${nfail}
  2165. fi
  2166. exit $ret