pmtu.sh 79 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. #
  4. # Check that route PMTU values match expectations, and that initial device MTU
  5. # values are assigned correctly
  6. #
  7. # Tests currently implemented:
  8. #
  9. # - pmtu_ipv4
  10. # Set up two namespaces, A and B, with two paths between them over routers
  11. # R1 and R2 (also implemented with namespaces), with different MTUs:
  12. #
  13. # segment a_r1 segment b_r1 a_r1: 2000
  14. # .--------------R1--------------. b_r1: 1400
  15. # A B a_r2: 2000
  16. # '--------------R2--------------' b_r2: 1500
  17. # segment a_r2 segment b_r2
  18. #
  19. # Check that PMTU exceptions with the correct PMTU are created. Then
  20. # decrease and increase the MTU of the local link for one of the paths,
  21. # A to R1, checking that route exception PMTU changes accordingly over
  22. # this path. Also check that locked exceptions are created when an ICMP
  23. # message advertising a PMTU smaller than net.ipv4.route.min_pmtu is
  24. # received
  25. #
  26. # - pmtu_ipv6
  27. # Same as pmtu_ipv4, except for locked PMTU tests, using IPv6
  28. #
  29. # - pmtu_ipv4_dscp_icmp_exception
  30. # Set up the same network topology as pmtu_ipv4, but use non-default
  31. # routing table in A. A fib-rule is used to jump to this routing table
  32. # based on DSCP. Send ICMPv4 packets with the expected DSCP value and
  33. # verify that ECN doesn't interfere with the creation of PMTU exceptions.
  34. #
  35. # - pmtu_ipv4_dscp_udp_exception
  36. # Same as pmtu_ipv4_dscp_icmp_exception, but use UDP instead of ICMP.
  37. #
  38. # - pmtu_ipv4_vxlan4_exception
  39. # Set up the same network topology as pmtu_ipv4, create a VXLAN tunnel
  40. # over IPv4 between A and B, routed via R1. On the link between R1 and B,
  41. # set a MTU lower than the VXLAN MTU and the MTU on the link between A and
  42. # R1. Send IPv4 packets, exceeding the MTU between R1 and B, over VXLAN
  43. # from A to B and check that the PMTU exception is created with the right
  44. # value on A
  45. #
  46. # - pmtu_ipv6_vxlan4_exception
  47. # Same as pmtu_ipv4_vxlan4_exception, but send IPv6 packets from A to B
  48. #
  49. # - pmtu_ipv4_vxlan6_exception
  50. # Same as pmtu_ipv4_vxlan4_exception, but use IPv6 transport from A to B
  51. #
  52. # - pmtu_ipv6_vxlan6_exception
  53. # Same as pmtu_ipv4_vxlan6_exception, but send IPv6 packets from A to B
  54. #
  55. # - pmtu_ipv4_geneve4_exception
  56. # Same as pmtu_ipv4_vxlan4_exception, but using a GENEVE tunnel instead of
  57. # VXLAN
  58. #
  59. # - pmtu_ipv6_geneve4_exception
  60. # Same as pmtu_ipv6_vxlan4_exception, but using a GENEVE tunnel instead of
  61. # VXLAN
  62. #
  63. # - pmtu_ipv4_geneve6_exception
  64. # Same as pmtu_ipv4_vxlan6_exception, but using a GENEVE tunnel instead of
  65. # VXLAN
  66. #
  67. # - pmtu_ipv6_geneve6_exception
  68. # Same as pmtu_ipv6_vxlan6_exception, but using a GENEVE tunnel instead of
  69. # VXLAN
  70. #
  71. # - pmtu_ipv{4,6}_br_vxlan{4,6}_exception
  72. # Set up three namespaces, A, B, and C, with routing between A and B over
  73. # R1. R2 is unused in these tests. A has a veth connection to C, and is
  74. # connected to B via a VXLAN endpoint, which is directly bridged to C.
  75. # MTU on the B-R1 link is lower than other MTUs.
  76. #
  77. # Check that both C and A are able to communicate with B over the VXLAN
  78. # tunnel, and that PMTU exceptions with the correct values are created.
  79. #
  80. # segment a_r1 segment b_r1 b_r1: 4000
  81. # .--------------R1--------------. everything
  82. # C---veth A B else: 5000
  83. # ' bridge |
  84. # '---- - - - - - VXLAN - - - - - - - '
  85. #
  86. # - pmtu_ipv{4,6}_br_geneve{4,6}_exception
  87. # Same as pmtu_ipv{4,6}_br_vxlan{4,6}_exception, with a GENEVE tunnel
  88. # instead.
  89. #
  90. # - pmtu_ipv{4,6}_ovs_vxlan{4,6}_exception
  91. # Set up two namespaces, B, and C, with routing between the init namespace
  92. # and B over R1. A and R2 are unused in these tests. The init namespace
  93. # has a veth connection to C, and is connected to B via a VXLAN endpoint,
  94. # which is handled by Open vSwitch and bridged to C. MTU on the B-R1 link
  95. # is lower than other MTUs.
  96. #
  97. # Check that C is able to communicate with B over the VXLAN tunnel, and
  98. # that PMTU exceptions with the correct values are created.
  99. #
  100. # segment a_r1 segment b_r1 b_r1: 4000
  101. # .--------------R1--------------. everything
  102. # C---veth init B else: 5000
  103. # '- ovs |
  104. # '---- - - - - - VXLAN - - - - - - - '
  105. #
  106. # - pmtu_ipv{4,6}_ovs_geneve{4,6}_exception
  107. # Same as pmtu_ipv{4,6}_ovs_vxlan{4,6}_exception, with a GENEVE tunnel
  108. # instead.
  109. #
  110. # - pmtu_ipv{4,6}_fou{4,6}_exception
  111. # Same as pmtu_ipv4_vxlan4, but using a direct IPv4/IPv6 encapsulation
  112. # (FoU) over IPv4/IPv6, instead of VXLAN
  113. #
  114. # - pmtu_ipv{4,6}_fou{4,6}_exception
  115. # Same as pmtu_ipv4_vxlan4, but using a generic UDP IPv4/IPv6
  116. # encapsulation (GUE) over IPv4/IPv6, instead of VXLAN
  117. #
  118. # - pmtu_ipv{4,6}_ipv{4,6}_exception
  119. # Same as pmtu_ipv4_vxlan4, but using a IPv4/IPv6 tunnel over IPv4/IPv6,
  120. # instead of VXLAN
  121. #
  122. # - pmtu_vti4_exception
  123. # Set up vti tunnel on top of veth, with xfrm states and policies, in two
  124. # namespaces with matching endpoints. Check that route exception is not
  125. # created if link layer MTU is not exceeded, then exceed it and check that
  126. # exception is created with the expected PMTU. The approach described
  127. # below for IPv6 doesn't apply here, because, on IPv4, administrative MTU
  128. # changes alone won't affect PMTU
  129. #
  130. # - pmtu_vti4_udp_exception
  131. # Same as pmtu_vti4_exception, but using ESP-in-UDP
  132. #
  133. # - pmtu_vti4_udp_routed_exception
  134. # Set up vti tunnel on top of veth connected through routing namespace and
  135. # add xfrm states and policies with ESP-in-UDP encapsulation. Check that
  136. # route exception is not created if link layer MTU is not exceeded, then
  137. # lower MTU on second part of routed environment and check that exception
  138. # is created with the expected PMTU.
  139. #
  140. # - pmtu_vti6_exception
  141. # Set up vti6 tunnel on top of veth, with xfrm states and policies, in two
  142. # namespaces with matching endpoints. Check that route exception is
  143. # created by exceeding link layer MTU with ping to other endpoint. Then
  144. # decrease and increase MTU of tunnel, checking that route exception PMTU
  145. # changes accordingly
  146. #
  147. # - pmtu_vti6_udp_exception
  148. # Same as pmtu_vti6_exception, but using ESP-in-UDP
  149. #
  150. # - pmtu_vti6_udp_routed_exception
  151. # Same as pmtu_vti6_udp_routed_exception but with routing between vti
  152. # endpoints
  153. #
  154. # - pmtu_vti4_default_mtu
  155. # Set up vti4 tunnel on top of veth, in two namespaces with matching
  156. # endpoints. Check that MTU assigned to vti interface is the MTU of the
  157. # lower layer (veth) minus additional lower layer headers (zero, for veth)
  158. # minus IPv4 header length
  159. #
  160. # - pmtu_vti6_default_mtu
  161. # Same as above, for IPv6
  162. #
  163. # - pmtu_vti4_link_add_mtu
  164. # Set up vti4 interface passing MTU value at link creation, check MTU is
  165. # configured, and that link is not created with invalid MTU values
  166. #
  167. # - pmtu_vti6_link_add_mtu
  168. # Same as above, for IPv6
  169. #
  170. # - pmtu_vti6_link_change_mtu
  171. # Set up two dummy interfaces with different MTUs, create a vti6 tunnel
  172. # and check that configured MTU is used on link creation and changes, and
  173. # that MTU is properly calculated instead when MTU is not configured from
  174. # userspace
  175. #
  176. # - cleanup_ipv4_exception
  177. # Similar to pmtu_ipv4_vxlan4_exception, but explicitly generate PMTU
  178. # exceptions on multiple CPUs and check that the veth device tear-down
  179. # happens in a timely manner
  180. #
  181. # - cleanup_ipv6_exception
  182. # Same as above, but use IPv6 transport from A to B
  183. #
  184. # - list_flush_ipv4_exception
  185. # Using the same topology as in pmtu_ipv4, create exceptions, and check
  186. # they are shown when listing exception caches, gone after flushing them
  187. #
  188. # - list_flush_ipv6_exception
  189. # Using the same topology as in pmtu_ipv6, create exceptions, and check
  190. # they are shown when listing exception caches, gone after flushing them
  191. #
  192. # - pmtu_ipv4_route_change
  193. # Use the same topology as in pmtu_ipv4, but issue a route replacement
  194. # command and delete the corresponding device afterward. This tests for
  195. # proper cleanup of the PMTU exceptions by the route replacement path.
  196. # Device unregistration should complete successfully
  197. #
  198. # - pmtu_ipv6_route_change
  199. # Same as above but with IPv6
  200. #
  201. # - pmtu_ipv4_mp_exceptions
  202. # Use the same topology as in pmtu_ipv4, but add routeable addresses
  203. # on host A and B on lo reachable via both routers. Host A and B
  204. # addresses have multipath routes to each other, b_r1 mtu = 1500.
  205. # Check that PMTU exceptions are created for both paths.
  206. source lib.sh
  207. PAUSE_ON_FAIL=no
  208. VERBOSE=0
  209. TRACING=0
  210. # Some systems don't have a ping6 binary anymore
  211. which ping6 > /dev/null 2>&1 && ping6=$(which ping6) || ping6=$(which ping)
  212. # Name Description re-run with nh
  213. tests="
  214. pmtu_ipv4_exception ipv4: PMTU exceptions 1
  215. pmtu_ipv6_exception ipv6: PMTU exceptions 1
  216. pmtu_ipv4_dscp_icmp_exception ICMPv4 with DSCP and ECN: PMTU exceptions 1
  217. pmtu_ipv4_dscp_udp_exception UDPv4 with DSCP and ECN: PMTU exceptions 1
  218. pmtu_ipv4_vxlan4_exception IPv4 over vxlan4: PMTU exceptions 1
  219. pmtu_ipv6_vxlan4_exception IPv6 over vxlan4: PMTU exceptions 1
  220. pmtu_ipv4_vxlan6_exception IPv4 over vxlan6: PMTU exceptions 1
  221. pmtu_ipv6_vxlan6_exception IPv6 over vxlan6: PMTU exceptions 1
  222. pmtu_ipv4_geneve4_exception IPv4 over geneve4: PMTU exceptions 1
  223. pmtu_ipv6_geneve4_exception IPv6 over geneve4: PMTU exceptions 1
  224. pmtu_ipv4_geneve6_exception IPv4 over geneve6: PMTU exceptions 1
  225. pmtu_ipv6_geneve6_exception IPv6 over geneve6: PMTU exceptions 1
  226. pmtu_ipv4_br_vxlan4_exception IPv4, bridged vxlan4: PMTU exceptions 1
  227. pmtu_ipv6_br_vxlan4_exception IPv6, bridged vxlan4: PMTU exceptions 1
  228. pmtu_ipv4_br_vxlan6_exception IPv4, bridged vxlan6: PMTU exceptions 1
  229. pmtu_ipv6_br_vxlan6_exception IPv6, bridged vxlan6: PMTU exceptions 1
  230. pmtu_ipv4_br_geneve4_exception IPv4, bridged geneve4: PMTU exceptions 1
  231. pmtu_ipv6_br_geneve4_exception IPv6, bridged geneve4: PMTU exceptions 1
  232. pmtu_ipv4_br_geneve6_exception IPv4, bridged geneve6: PMTU exceptions 1
  233. pmtu_ipv6_br_geneve6_exception IPv6, bridged geneve6: PMTU exceptions 1
  234. pmtu_ipv4_ovs_vxlan4_exception IPv4, OVS vxlan4: PMTU exceptions 1
  235. pmtu_ipv6_ovs_vxlan4_exception IPv6, OVS vxlan4: PMTU exceptions 1
  236. pmtu_ipv4_ovs_vxlan6_exception IPv4, OVS vxlan6: PMTU exceptions 1
  237. pmtu_ipv6_ovs_vxlan6_exception IPv6, OVS vxlan6: PMTU exceptions 1
  238. pmtu_ipv4_ovs_geneve4_exception IPv4, OVS geneve4: PMTU exceptions 1
  239. pmtu_ipv6_ovs_geneve4_exception IPv6, OVS geneve4: PMTU exceptions 1
  240. pmtu_ipv4_ovs_geneve6_exception IPv4, OVS geneve6: PMTU exceptions 1
  241. pmtu_ipv6_ovs_geneve6_exception IPv6, OVS geneve6: PMTU exceptions 1
  242. pmtu_ipv4_fou4_exception IPv4 over fou4: PMTU exceptions 1
  243. pmtu_ipv6_fou4_exception IPv6 over fou4: PMTU exceptions 1
  244. pmtu_ipv4_fou6_exception IPv4 over fou6: PMTU exceptions 1
  245. pmtu_ipv6_fou6_exception IPv6 over fou6: PMTU exceptions 1
  246. pmtu_ipv4_gue4_exception IPv4 over gue4: PMTU exceptions 1
  247. pmtu_ipv6_gue4_exception IPv6 over gue4: PMTU exceptions 1
  248. pmtu_ipv4_gue6_exception IPv4 over gue6: PMTU exceptions 1
  249. pmtu_ipv6_gue6_exception IPv6 over gue6: PMTU exceptions 1
  250. pmtu_ipv4_ipv4_exception IPv4 over IPv4: PMTU exceptions 1
  251. pmtu_ipv6_ipv4_exception IPv6 over IPv4: PMTU exceptions 1
  252. pmtu_ipv4_ipv6_exception IPv4 over IPv6: PMTU exceptions 1
  253. pmtu_ipv6_ipv6_exception IPv6 over IPv6: PMTU exceptions 1
  254. pmtu_vti6_exception vti6: PMTU exceptions 0
  255. pmtu_vti4_exception vti4: PMTU exceptions 0
  256. pmtu_vti6_udp_exception vti6: PMTU exceptions (ESP-in-UDP) 0
  257. pmtu_vti4_udp_exception vti4: PMTU exceptions (ESP-in-UDP) 0
  258. pmtu_vti6_udp_routed_exception vti6: PMTU exceptions, routed (ESP-in-UDP) 0
  259. pmtu_vti4_udp_routed_exception vti4: PMTU exceptions, routed (ESP-in-UDP) 0
  260. pmtu_vti4_default_mtu vti4: default MTU assignment 0
  261. pmtu_vti6_default_mtu vti6: default MTU assignment 0
  262. pmtu_vti4_link_add_mtu vti4: MTU setting on link creation 0
  263. pmtu_vti6_link_add_mtu vti6: MTU setting on link creation 0
  264. pmtu_vti6_link_change_mtu vti6: MTU changes on link changes 0
  265. cleanup_ipv4_exception ipv4: cleanup of cached exceptions 1
  266. cleanup_ipv6_exception ipv6: cleanup of cached exceptions 1
  267. list_flush_ipv4_exception ipv4: list and flush cached exceptions 1
  268. list_flush_ipv6_exception ipv6: list and flush cached exceptions 1
  269. pmtu_ipv4_route_change ipv4: PMTU exception w/route replace 1
  270. pmtu_ipv6_route_change ipv6: PMTU exception w/route replace 1
  271. pmtu_ipv4_mp_exceptions ipv4: PMTU multipath nh exceptions 1"
  272. # Addressing and routing for tests with routers: four network segments, with
  273. # index SEGMENT between 1 and 4, a common prefix (PREFIX4 or PREFIX6) and an
  274. # identifier ID, which is 1 for hosts (A and B), 2 for routers (R1 and R2).
  275. # Addresses are:
  276. # - IPv4: PREFIX4.SEGMENT.ID (/24)
  277. # - IPv6: PREFIX6:SEGMENT::ID (/64)
  278. prefix4="10.0"
  279. prefix6="fc00"
  280. a_r1=1
  281. a_r2=2
  282. b_r1=3
  283. b_r2=4
  284. # ns peer segment
  285. routing_addrs="
  286. A R1 ${a_r1}
  287. A R2 ${a_r2}
  288. B R1 ${b_r1}
  289. B R2 ${b_r2}
  290. "
  291. # Traffic from A to B goes through R1 by default, and through R2, if destined to
  292. # B's address on the b_r2 segment.
  293. # Traffic from B to A goes through R1.
  294. # ns destination gateway
  295. routes="
  296. A default ${prefix4}.${a_r1}.2
  297. A ${prefix4}.${b_r2}.1 ${prefix4}.${a_r2}.2
  298. B default ${prefix4}.${b_r1}.2
  299. A default ${prefix6}:${a_r1}::2
  300. A ${prefix6}:${b_r2}::1 ${prefix6}:${a_r2}::2
  301. B default ${prefix6}:${b_r1}::2
  302. "
  303. USE_NH="no"
  304. # ns family nh id destination gateway
  305. nexthops="
  306. A 4 41 ${prefix4}.${a_r1}.2 veth_A-R1
  307. A 4 42 ${prefix4}.${a_r2}.2 veth_A-R2
  308. B 4 41 ${prefix4}.${b_r1}.2 veth_B-R1
  309. A 6 61 ${prefix6}:${a_r1}::2 veth_A-R1
  310. A 6 62 ${prefix6}:${a_r2}::2 veth_A-R2
  311. B 6 61 ${prefix6}:${b_r1}::2 veth_B-R1
  312. "
  313. # nexthop id correlates to id in nexthops config above
  314. # ns family prefix nh id
  315. routes_nh="
  316. A 4 default 41
  317. A 4 ${prefix4}.${b_r2}.1 42
  318. B 4 default 41
  319. A 6 default 61
  320. A 6 ${prefix6}:${b_r2}::1 62
  321. B 6 default 61
  322. "
  323. policy_mark=0x04
  324. rt_table=main
  325. veth4_a_addr="192.168.1.1"
  326. veth4_b_addr="192.168.1.2"
  327. veth4_c_addr="192.168.2.10"
  328. veth4_mask="24"
  329. veth6_a_addr="fd00:1::a"
  330. veth6_b_addr="fd00:1::b"
  331. veth6_c_addr="fd00:2::c"
  332. veth6_mask="64"
  333. tunnel4_a_addr="192.168.2.1"
  334. tunnel4_b_addr="192.168.2.2"
  335. tunnel4_mask="24"
  336. tunnel6_a_addr="fd00:2::a"
  337. tunnel6_b_addr="fd00:2::b"
  338. tunnel6_mask="64"
  339. host4_a_addr="192.168.99.99"
  340. host4_b_addr="192.168.88.88"
  341. dummy6_0_prefix="fc00:1000::"
  342. dummy6_1_prefix="fc00:1001::"
  343. dummy6_mask="64"
  344. err_buf=
  345. tcpdump_pids=
  346. nettest_pids=
  347. socat_pids=
  348. tmpoutfile=
  349. err() {
  350. err_buf="${err_buf}${1}
  351. "
  352. }
  353. err_flush() {
  354. echo -n "${err_buf}"
  355. err_buf=
  356. }
  357. run_cmd() {
  358. cmd="$*"
  359. if [ "$VERBOSE" = "1" ]; then
  360. printf " COMMAND: $cmd\n"
  361. fi
  362. out="$($cmd 2>&1)"
  363. rc=$?
  364. if [ "$VERBOSE" = "1" -a -n "$out" ]; then
  365. echo " $out"
  366. echo
  367. fi
  368. return $rc
  369. }
  370. run_cmd_bg() {
  371. cmd="$*"
  372. if [ "$VERBOSE" = "1" ]; then
  373. printf " COMMAND: %s &\n" "${cmd}"
  374. fi
  375. $cmd 2>&1 &
  376. }
  377. # Find the auto-generated name for this namespace
  378. nsname() {
  379. eval echo \$NS_$1
  380. }
  381. setup_fou_or_gue() {
  382. outer="${1}"
  383. inner="${2}"
  384. encap="${3}"
  385. if [ "${outer}" = "4" ]; then
  386. modprobe fou || return $ksft_skip
  387. a_addr="${prefix4}.${a_r1}.1"
  388. b_addr="${prefix4}.${b_r1}.1"
  389. if [ "${inner}" = "4" ]; then
  390. type="ipip"
  391. ipproto="4"
  392. else
  393. type="sit"
  394. ipproto="41"
  395. fi
  396. else
  397. modprobe fou6 || return $ksft_skip
  398. a_addr="${prefix6}:${a_r1}::1"
  399. b_addr="${prefix6}:${b_r1}::1"
  400. if [ "${inner}" = "4" ]; then
  401. type="ip6tnl"
  402. mode="mode ipip6"
  403. ipproto="4 -6"
  404. else
  405. type="ip6tnl"
  406. mode="mode ip6ip6"
  407. ipproto="41 -6"
  408. fi
  409. fi
  410. run_cmd ${ns_a} ip fou add port 5555 ipproto ${ipproto} || return $ksft_skip
  411. run_cmd ${ns_a} ip link add ${encap}_a type ${type} ${mode} local ${a_addr} remote ${b_addr} encap ${encap} encap-sport auto encap-dport 5556 || return $ksft_skip
  412. run_cmd ${ns_b} ip fou add port 5556 ipproto ${ipproto}
  413. run_cmd ${ns_b} ip link add ${encap}_b type ${type} ${mode} local ${b_addr} remote ${a_addr} encap ${encap} encap-sport auto encap-dport 5555
  414. if [ "${inner}" = "4" ]; then
  415. run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${encap}_a
  416. run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${encap}_b
  417. else
  418. run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${encap}_a
  419. run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${encap}_b
  420. fi
  421. run_cmd ${ns_a} ip link set ${encap}_a up
  422. run_cmd ${ns_b} ip link set ${encap}_b up
  423. }
  424. setup_fou44() {
  425. setup_fou_or_gue 4 4 fou
  426. }
  427. setup_fou46() {
  428. setup_fou_or_gue 4 6 fou
  429. }
  430. setup_fou64() {
  431. setup_fou_or_gue 6 4 fou
  432. }
  433. setup_fou66() {
  434. setup_fou_or_gue 6 6 fou
  435. }
  436. setup_gue44() {
  437. setup_fou_or_gue 4 4 gue
  438. }
  439. setup_gue46() {
  440. setup_fou_or_gue 4 6 gue
  441. }
  442. setup_gue64() {
  443. setup_fou_or_gue 6 4 gue
  444. }
  445. setup_gue66() {
  446. setup_fou_or_gue 6 6 gue
  447. }
  448. setup_ipvX_over_ipvY() {
  449. inner=${1}
  450. outer=${2}
  451. if [ "${outer}" -eq 4 ]; then
  452. a_addr="${prefix4}.${a_r1}.1"
  453. b_addr="${prefix4}.${b_r1}.1"
  454. if [ "${inner}" -eq 4 ]; then
  455. type="ipip"
  456. mode="ipip"
  457. else
  458. type="sit"
  459. mode="ip6ip"
  460. fi
  461. else
  462. a_addr="${prefix6}:${a_r1}::1"
  463. b_addr="${prefix6}:${b_r1}::1"
  464. type="ip6tnl"
  465. if [ "${inner}" -eq 4 ]; then
  466. mode="ipip6"
  467. else
  468. mode="ip6ip6"
  469. fi
  470. fi
  471. run_cmd ${ns_a} ip link add ip_a type ${type} local ${a_addr} remote ${b_addr} mode ${mode} || return $ksft_skip
  472. run_cmd ${ns_b} ip link add ip_b type ${type} local ${b_addr} remote ${a_addr} mode ${mode}
  473. run_cmd ${ns_a} ip link set ip_a up
  474. run_cmd ${ns_b} ip link set ip_b up
  475. if [ "${inner}" = "4" ]; then
  476. run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ip_a
  477. run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ip_b
  478. else
  479. run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ip_a
  480. run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ip_b
  481. fi
  482. }
  483. setup_ip4ip4() {
  484. setup_ipvX_over_ipvY 4 4
  485. }
  486. setup_ip6ip4() {
  487. setup_ipvX_over_ipvY 6 4
  488. }
  489. setup_ip4ip6() {
  490. setup_ipvX_over_ipvY 4 6
  491. }
  492. setup_ip6ip6() {
  493. setup_ipvX_over_ipvY 6 6
  494. }
  495. setup_namespaces() {
  496. setup_ns NS_A NS_B NS_C NS_R1 NS_R2
  497. for n in ${NS_A} ${NS_B} ${NS_C} ${NS_R1} ${NS_R2}; do
  498. # Disable DAD, so that we don't have to wait to use the
  499. # configured IPv6 addresses
  500. ip netns exec ${n} sysctl -q net/ipv6/conf/default/accept_dad=0
  501. done
  502. ns_a="ip netns exec ${NS_A}"
  503. ns_b="ip netns exec ${NS_B}"
  504. ns_c="ip netns exec ${NS_C}"
  505. ns_r1="ip netns exec ${NS_R1}"
  506. ns_r2="ip netns exec ${NS_R2}"
  507. }
  508. setup_veth() {
  509. run_cmd ${ns_a} ip link add veth_a type veth peer name veth_b || return 1
  510. run_cmd ${ns_a} ip link set veth_b netns ${NS_B}
  511. run_cmd ${ns_a} ip addr add ${veth4_a_addr}/${veth4_mask} dev veth_a
  512. run_cmd ${ns_b} ip addr add ${veth4_b_addr}/${veth4_mask} dev veth_b
  513. run_cmd ${ns_a} ip addr add ${veth6_a_addr}/${veth6_mask} dev veth_a
  514. run_cmd ${ns_b} ip addr add ${veth6_b_addr}/${veth6_mask} dev veth_b
  515. run_cmd ${ns_a} ip link set veth_a up
  516. run_cmd ${ns_b} ip link set veth_b up
  517. }
  518. setup_vti() {
  519. proto=${1}
  520. veth_a_addr="${2}"
  521. veth_b_addr="${3}"
  522. vti_a_addr="${4}"
  523. vti_b_addr="${5}"
  524. vti_mask=${6}
  525. [ ${proto} -eq 6 ] && vti_type="vti6" || vti_type="vti"
  526. run_cmd ${ns_a} ip link add vti${proto}_a type ${vti_type} local ${veth_a_addr} remote ${veth_b_addr} key 10 || return 1
  527. run_cmd ${ns_b} ip link add vti${proto}_b type ${vti_type} local ${veth_b_addr} remote ${veth_a_addr} key 10
  528. run_cmd ${ns_a} ip addr add ${vti_a_addr}/${vti_mask} dev vti${proto}_a
  529. run_cmd ${ns_b} ip addr add ${vti_b_addr}/${vti_mask} dev vti${proto}_b
  530. run_cmd ${ns_a} ip link set vti${proto}_a up
  531. run_cmd ${ns_b} ip link set vti${proto}_b up
  532. }
  533. setup_vti4() {
  534. setup_vti 4 ${veth4_a_addr} ${veth4_b_addr} ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask}
  535. }
  536. setup_vti6() {
  537. setup_vti 6 ${veth6_a_addr} ${veth6_b_addr} ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask}
  538. }
  539. setup_vti4routed() {
  540. setup_vti 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 ${tunnel4_a_addr} ${tunnel4_b_addr} ${tunnel4_mask}
  541. }
  542. setup_vti6routed() {
  543. setup_vti 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ${tunnel6_a_addr} ${tunnel6_b_addr} ${tunnel6_mask}
  544. }
  545. setup_vxlan_or_geneve() {
  546. type="${1}"
  547. a_addr="${2}"
  548. b_addr="${3}"
  549. opts="${4}"
  550. br_if_a="${5}"
  551. if [ "${type}" = "vxlan" ]; then
  552. opts="${opts} ttl 64 dstport 4789"
  553. opts_a="local ${a_addr}"
  554. opts_b="local ${b_addr}"
  555. else
  556. opts_a=""
  557. opts_b=""
  558. fi
  559. run_cmd ${ns_a} ip link add ${type}_a type ${type} id 1 ${opts_a} remote ${b_addr} ${opts} || return 1
  560. run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts}
  561. if [ -n "${br_if_a}" ]; then
  562. run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${br_if_a}
  563. run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${br_if_a}
  564. run_cmd ${ns_a} ip link set ${type}_a master ${br_if_a}
  565. else
  566. run_cmd ${ns_a} ip addr add ${tunnel4_a_addr}/${tunnel4_mask} dev ${type}_a
  567. run_cmd ${ns_a} ip addr add ${tunnel6_a_addr}/${tunnel6_mask} dev ${type}_a
  568. fi
  569. run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b
  570. run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b
  571. run_cmd ${ns_a} ip link set ${type}_a up
  572. run_cmd ${ns_b} ip link set ${type}_b up
  573. }
  574. setup_geneve4() {
  575. setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set"
  576. }
  577. setup_vxlan4() {
  578. setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set"
  579. }
  580. setup_geneve6() {
  581. setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ""
  582. }
  583. setup_vxlan6() {
  584. setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 ""
  585. }
  586. setup_bridged_geneve4() {
  587. setup_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0"
  588. }
  589. setup_bridged_vxlan4() {
  590. setup_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "df set" "br0"
  591. }
  592. setup_bridged_geneve6() {
  593. setup_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0"
  594. }
  595. setup_bridged_vxlan6() {
  596. setup_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "" "br0"
  597. }
  598. setup_xfrm() {
  599. proto=${1}
  600. veth_a_addr="${2}"
  601. veth_b_addr="${3}"
  602. encap=${4}
  603. run_cmd ${ns_a} ip -${proto} xfrm state add src ${veth_a_addr} dst ${veth_b_addr} spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode tunnel ${encap} || return 1
  604. run_cmd ${ns_a} ip -${proto} xfrm state add src ${veth_b_addr} dst ${veth_a_addr} spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode tunnel ${encap}
  605. run_cmd ${ns_a} ip -${proto} xfrm policy add dir out mark 10 tmpl src ${veth_a_addr} dst ${veth_b_addr} proto esp mode tunnel
  606. run_cmd ${ns_a} ip -${proto} xfrm policy add dir in mark 10 tmpl src ${veth_b_addr} dst ${veth_a_addr} proto esp mode tunnel
  607. run_cmd ${ns_b} ip -${proto} xfrm state add src ${veth_a_addr} dst ${veth_b_addr} spi 0x1000 proto esp aead 'rfc4106(gcm(aes))' 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode tunnel ${encap}
  608. run_cmd ${ns_b} ip -${proto} xfrm state add src ${veth_b_addr} dst ${veth_a_addr} spi 0x1001 proto esp aead 'rfc4106(gcm(aes))' 0x0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f0f 128 mode tunnel ${encap}
  609. run_cmd ${ns_b} ip -${proto} xfrm policy add dir out mark 10 tmpl src ${veth_b_addr} dst ${veth_a_addr} proto esp mode tunnel
  610. run_cmd ${ns_b} ip -${proto} xfrm policy add dir in mark 10 tmpl src ${veth_a_addr} dst ${veth_b_addr} proto esp mode tunnel
  611. }
  612. setup_nettest_xfrm() {
  613. check_gen_prog "nettest"
  614. [ ${1} -eq 6 ] && proto="-6" || proto=""
  615. port=${2}
  616. run_cmd_bg "${ns_a}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5
  617. nettest_pids="${nettest_pids} $!"
  618. run_cmd_bg "${ns_b}" nettest "${proto}" -q -D -s -x -p "${port}" -t 5
  619. nettest_pids="${nettest_pids} $!"
  620. }
  621. setup_xfrm4() {
  622. setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr}
  623. }
  624. setup_xfrm6() {
  625. setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr}
  626. }
  627. setup_xfrm4udp() {
  628. setup_xfrm 4 ${veth4_a_addr} ${veth4_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \
  629. setup_nettest_xfrm 4 4500
  630. }
  631. setup_xfrm6udp() {
  632. setup_xfrm 6 ${veth6_a_addr} ${veth6_b_addr} "encap espinudp 4500 4500 0.0.0.0" && \
  633. setup_nettest_xfrm 6 4500
  634. }
  635. setup_xfrm4udprouted() {
  636. setup_xfrm 4 ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1 "encap espinudp 4500 4500 0.0.0.0" && \
  637. setup_nettest_xfrm 4 4500
  638. }
  639. setup_xfrm6udprouted() {
  640. setup_xfrm 6 ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1 "encap espinudp 4500 4500 0.0.0.0" && \
  641. setup_nettest_xfrm 6 4500
  642. }
  643. setup_routing_old() {
  644. for i in ${routes}; do
  645. [ "${ns}" = "" ] && ns="${i}" && continue
  646. [ "${addr}" = "" ] && addr="${i}" && continue
  647. [ "${gw}" = "" ] && gw="${i}"
  648. ns_name="$(nsname ${ns})"
  649. ip -n "${ns_name}" route add "${addr}" table "${rt_table}" via "${gw}"
  650. ns=""; addr=""; gw=""
  651. done
  652. }
  653. setup_routing_new() {
  654. for i in ${nexthops}; do
  655. [ "${ns}" = "" ] && ns="${i}" && continue
  656. [ "${fam}" = "" ] && fam="${i}" && continue
  657. [ "${nhid}" = "" ] && nhid="${i}" && continue
  658. [ "${gw}" = "" ] && gw="${i}" && continue
  659. [ "${dev}" = "" ] && dev="${i}"
  660. ns_name="$(nsname ${ns})"
  661. ip -n ${ns_name} -${fam} nexthop add id ${nhid} via ${gw} dev ${dev}
  662. ns=""; fam=""; nhid=""; gw=""; dev=""
  663. done
  664. for i in ${routes_nh}; do
  665. [ "${ns}" = "" ] && ns="${i}" && continue
  666. [ "${fam}" = "" ] && fam="${i}" && continue
  667. [ "${addr}" = "" ] && addr="${i}" && continue
  668. [ "${nhid}" = "" ] && nhid="${i}"
  669. ns_name="$(nsname ${ns})"
  670. ip -n "${ns_name}" -"${fam}" route add "${addr}" table "${rt_table}" nhid "${nhid}"
  671. ns=""; fam=""; addr=""; nhid=""
  672. done
  673. }
  674. setup_routing() {
  675. for i in ${NS_R1} ${NS_R2}; do
  676. ip netns exec ${i} sysctl -q net/ipv4/ip_forward=1
  677. ip netns exec ${i} sysctl -q net/ipv6/conf/all/forwarding=1
  678. done
  679. for i in ${routing_addrs}; do
  680. [ "${ns}" = "" ] && ns="${i}" && continue
  681. [ "${peer}" = "" ] && peer="${i}" && continue
  682. [ "${segment}" = "" ] && segment="${i}"
  683. ns_name="$(nsname ${ns})"
  684. peer_name="$(nsname ${peer})"
  685. if="veth_${ns}-${peer}"
  686. ifpeer="veth_${peer}-${ns}"
  687. # Create veth links
  688. ip link add ${if} up netns ${ns_name} type veth peer name ${ifpeer} netns ${peer_name} || return 1
  689. ip -n ${peer_name} link set dev ${ifpeer} up
  690. # Add addresses
  691. ip -n ${ns_name} addr add ${prefix4}.${segment}.1/24 dev ${if}
  692. ip -n ${ns_name} addr add ${prefix6}:${segment}::1/64 dev ${if}
  693. ip -n ${peer_name} addr add ${prefix4}.${segment}.2/24 dev ${ifpeer}
  694. ip -n ${peer_name} addr add ${prefix6}:${segment}::2/64 dev ${ifpeer}
  695. ns=""; peer=""; segment=""
  696. done
  697. if [ "$USE_NH" = "yes" ]; then
  698. setup_routing_new
  699. else
  700. setup_routing_old
  701. fi
  702. return 0
  703. }
  704. setup_policy_routing() {
  705. setup_routing
  706. ip -netns "${NS_A}" -4 rule add dsfield "${policy_mark}" \
  707. table "${rt_table}"
  708. # Set the IPv4 Don't Fragment bit with tc, since socat doesn't seem to
  709. # have an option do to it.
  710. tc -netns "${NS_A}" qdisc replace dev veth_A-R1 root prio
  711. tc -netns "${NS_A}" qdisc replace dev veth_A-R2 root prio
  712. tc -netns "${NS_A}" filter add dev veth_A-R1 \
  713. protocol ipv4 flower ip_proto udp \
  714. action pedit ex munge ip df set 0x40 pipe csum ip and udp
  715. tc -netns "${NS_A}" filter add dev veth_A-R2 \
  716. protocol ipv4 flower ip_proto udp \
  717. action pedit ex munge ip df set 0x40 pipe csum ip and udp
  718. }
  719. setup_bridge() {
  720. run_cmd ${ns_a} ip link add br0 type bridge || return $ksft_skip
  721. run_cmd ${ns_a} ip link set br0 up
  722. run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
  723. run_cmd ${ns_c} ip link set veth_A-C netns ${NS_A}
  724. run_cmd ${ns_a} ip link set veth_A-C up
  725. run_cmd ${ns_c} ip link set veth_C-A up
  726. run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A
  727. run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A
  728. run_cmd ${ns_a} ip link set veth_A-C master br0
  729. }
  730. setup_ovs_via_internal_utility() {
  731. type="${1}"
  732. a_addr="${2}"
  733. b_addr="${3}"
  734. dport="${4}"
  735. run_cmd python3 ./openvswitch/ovs-dpctl.py add-if ovs_br0 ${type}_a -t ${type} || return 1
  736. ports=$(python3 ./openvswitch/ovs-dpctl.py show)
  737. br0_port=$(echo "$ports" | grep -E "\sovs_br0" | sed -e 's@port @@' | cut -d: -f1 | xargs)
  738. type_a_port=$(echo "$ports" | grep ${type}_a | sed -e 's@port @@' | cut -d: -f1 | xargs)
  739. veth_a_port=$(echo "$ports" | grep veth_A | sed -e 's@port @@' | cut -d: -f1 | xargs)
  740. v4_a_tun="${prefix4}.${a_r1}.1"
  741. v4_b_tun="${prefix4}.${b_r1}.1"
  742. v6_a_tun="${prefix6}:${a_r1}::1"
  743. v6_b_tun="${prefix6}:${b_r1}::1"
  744. if [ "${v4_a_tun}" = "${a_addr}" ]; then
  745. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  746. "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0800),ipv4()" \
  747. "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"
  748. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  749. "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x86dd),ipv6()" \
  750. "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"
  751. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  752. "recirc_id(0),tunnel(tun_id=1,src=${v4_b_tun},dst=${v4_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x0800),ipv4()" \
  753. "${veth_a_port}"
  754. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  755. "recirc_id(0),tunnel(tun_id=1,src=${v4_b_tun},dst=${v4_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x86dd),ipv6()" \
  756. "${veth_a_port}"
  757. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  758. "recirc_id(0),tunnel(tun_id=1,src=${v4_b_tun},dst=${v4_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x0806),arp()" \
  759. "${veth_a_port}"
  760. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  761. "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0806),arp(sip=${veth4_c_addr},tip=${tunnel4_b_addr})" \
  762. "set(tunnel(tun_id=1,dst=${v4_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"
  763. else
  764. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  765. "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0800),ipv4()" \
  766. "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"
  767. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  768. "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x86dd),ipv6()" \
  769. "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"
  770. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  771. "recirc_id(0),tunnel(tun_id=1,ipv6_src=${v6_b_tun},ipv6_dst=${v6_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x0800),ipv4()" \
  772. "${veth_a_port}"
  773. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  774. "recirc_id(0),tunnel(tun_id=1,ipv6_src=${v6_b_tun},ipv6_dst=${v6_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x86dd),ipv6()" \
  775. "${veth_a_port}"
  776. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  777. "recirc_id(0),tunnel(tun_id=1,ipv6_src=${v6_b_tun},ipv6_dst=${v6_a_tun}),in_port(${type_a_port}),eth(),eth_type(0x0806),arp()" \
  778. "${veth_a_port}"
  779. run_cmd python3 ./openvswitch/ovs-dpctl.py add-flow ovs_br0 \
  780. "recirc_id(0),in_port(${veth_a_port}),eth(),eth_type(0x0806),arp(sip=${veth4_c_addr},tip=${tunnel4_b_addr})" \
  781. "set(tunnel(tun_id=1,ipv6_dst=${v6_b_tun},ttl=64,tp_dst=${dport},flags(df|csum))),${type_a_port}"
  782. fi
  783. }
  784. setup_ovs_via_vswitchd() {
  785. type="${1}"
  786. b_addr="${2}"
  787. run_cmd ovs-vsctl add-port ovs_br0 ${type}_a -- \
  788. set interface ${type}_a type=${type} \
  789. options:remote_ip=${b_addr} options:key=1 options:csum=true || return 1
  790. }
  791. setup_ovs_vxlan_or_geneve() {
  792. type="${1}"
  793. a_addr="${2}"
  794. b_addr="${3}"
  795. dport="6081"
  796. if [ "${type}" = "vxlan" ]; then
  797. dport="4789"
  798. opts="${opts} ttl 64 dstport 4789"
  799. opts_b="local ${b_addr}"
  800. fi
  801. setup_ovs_via_internal_utility "${type}" "${a_addr}" "${b_addr}" \
  802. "${dport}" || \
  803. setup_ovs_via_vswitchd "${type}" "${b_addr}" || return 1
  804. run_cmd ${ns_b} ip link add ${type}_b type ${type} id 1 ${opts_b} remote ${a_addr} ${opts} || return 1
  805. run_cmd ${ns_b} ip addr add ${tunnel4_b_addr}/${tunnel4_mask} dev ${type}_b
  806. run_cmd ${ns_b} ip addr add ${tunnel6_b_addr}/${tunnel6_mask} dev ${type}_b
  807. run_cmd ip link set ${type}_a up
  808. run_cmd ${ns_b} ip link set ${type}_b up
  809. }
  810. setup_ovs_geneve4() {
  811. setup_ovs_vxlan_or_geneve geneve ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1
  812. }
  813. setup_ovs_vxlan4() {
  814. setup_ovs_vxlan_or_geneve vxlan ${prefix4}.${a_r1}.1 ${prefix4}.${b_r1}.1
  815. }
  816. setup_ovs_geneve6() {
  817. setup_ovs_vxlan_or_geneve geneve ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1
  818. }
  819. setup_ovs_vxlan6() {
  820. setup_ovs_vxlan_or_geneve vxlan ${prefix6}:${a_r1}::1 ${prefix6}:${b_r1}::1
  821. }
  822. setup_ovs_br_internal() {
  823. run_cmd python3 ./openvswitch/ovs-dpctl.py add-dp ovs_br0 || \
  824. return 1
  825. }
  826. setup_ovs_br_vswitchd() {
  827. run_cmd ovs-vsctl add-br ovs_br0 || return 1
  828. }
  829. setup_ovs_add_if() {
  830. ifname="${1}"
  831. run_cmd python3 ./openvswitch/ovs-dpctl.py add-if ovs_br0 \
  832. "${ifname}" || \
  833. run_cmd ovs-vsctl add-port ovs_br0 "${ifname}"
  834. }
  835. setup_ovs_bridge() {
  836. setup_ovs_br_internal || setup_ovs_br_vswitchd || return $ksft_skip
  837. run_cmd ip link set ovs_br0 up
  838. run_cmd ${ns_c} ip link add veth_C-A type veth peer name veth_A-C
  839. run_cmd ${ns_c} ip link set veth_A-C netns 1
  840. run_cmd ip link set veth_A-C up
  841. run_cmd ${ns_c} ip link set veth_C-A up
  842. run_cmd ${ns_c} ip addr add ${veth4_c_addr}/${veth4_mask} dev veth_C-A
  843. run_cmd ${ns_c} ip addr add ${veth6_c_addr}/${veth6_mask} dev veth_C-A
  844. setup_ovs_add_if veth_A-C
  845. # Move veth_A-R1 to init
  846. run_cmd ${ns_a} ip link set veth_A-R1 netns 1
  847. run_cmd ip addr add ${prefix4}.${a_r1}.1/${veth4_mask} dev veth_A-R1
  848. run_cmd ip addr add ${prefix6}:${a_r1}::1/${veth6_mask} dev veth_A-R1
  849. run_cmd ip link set veth_A-R1 up
  850. run_cmd ip route add ${prefix4}.${b_r1}.1 via ${prefix4}.${a_r1}.2
  851. run_cmd ip route add ${prefix6}:${b_r1}::1 via ${prefix6}:${a_r1}::2
  852. }
  853. setup_multipath_new() {
  854. # Set up host A with multipath routes to host B host4_b_addr
  855. run_cmd ${ns_a} ip addr add ${host4_a_addr} dev lo
  856. run_cmd ${ns_a} ip nexthop add id 401 via ${prefix4}.${a_r1}.2 dev veth_A-R1
  857. run_cmd ${ns_a} ip nexthop add id 402 via ${prefix4}.${a_r2}.2 dev veth_A-R2
  858. run_cmd ${ns_a} ip nexthop add id 403 group 401/402
  859. run_cmd ${ns_a} ip route add ${host4_b_addr} src ${host4_a_addr} nhid 403
  860. # Set up host B with multipath routes to host A host4_a_addr
  861. run_cmd ${ns_b} ip addr add ${host4_b_addr} dev lo
  862. run_cmd ${ns_b} ip nexthop add id 401 via ${prefix4}.${b_r1}.2 dev veth_B-R1
  863. run_cmd ${ns_b} ip nexthop add id 402 via ${prefix4}.${b_r2}.2 dev veth_B-R2
  864. run_cmd ${ns_b} ip nexthop add id 403 group 401/402
  865. run_cmd ${ns_b} ip route add ${host4_a_addr} src ${host4_b_addr} nhid 403
  866. }
  867. setup_multipath_old() {
  868. # Set up host A with multipath routes to host B host4_b_addr
  869. run_cmd ${ns_a} ip addr add ${host4_a_addr} dev lo
  870. run_cmd ${ns_a} ip route add ${host4_b_addr} \
  871. src ${host4_a_addr} \
  872. nexthop via ${prefix4}.${a_r1}.2 weight 1 \
  873. nexthop via ${prefix4}.${a_r2}.2 weight 1
  874. # Set up host B with multipath routes to host A host4_a_addr
  875. run_cmd ${ns_b} ip addr add ${host4_b_addr} dev lo
  876. run_cmd ${ns_b} ip route add ${host4_a_addr} \
  877. src ${host4_b_addr} \
  878. nexthop via ${prefix4}.${b_r1}.2 weight 1 \
  879. nexthop via ${prefix4}.${b_r2}.2 weight 1
  880. }
  881. setup_multipath() {
  882. if [ "$USE_NH" = "yes" ]; then
  883. setup_multipath_new
  884. else
  885. setup_multipath_old
  886. fi
  887. # Set up routers with routes to dummies
  888. run_cmd ${ns_r1} ip route add ${host4_a_addr} via ${prefix4}.${a_r1}.1
  889. run_cmd ${ns_r2} ip route add ${host4_a_addr} via ${prefix4}.${a_r2}.1
  890. run_cmd ${ns_r1} ip route add ${host4_b_addr} via ${prefix4}.${b_r1}.1
  891. run_cmd ${ns_r2} ip route add ${host4_b_addr} via ${prefix4}.${b_r2}.1
  892. }
  893. setup() {
  894. [ "$(id -u)" -ne 0 ] && echo " need to run as root" && return $ksft_skip
  895. for arg do
  896. eval setup_${arg} || { echo " ${arg} not supported"; return 1; }
  897. done
  898. }
  899. trace() {
  900. [ $TRACING -eq 0 ] && return
  901. for arg do
  902. [ "${ns_cmd}" = "" ] && ns_cmd="${arg}" && continue
  903. ${ns_cmd} tcpdump --immediate-mode -s 0 -i "${arg}" -w "${name}_${arg}.pcap" 2> /dev/null &
  904. tcpdump_pids="${tcpdump_pids} $!"
  905. ns_cmd=
  906. done
  907. sleep 1
  908. }
  909. cleanup_del_ovs_internal() {
  910. # squelch the output of the del-if commands since it can be wordy
  911. python3 ./openvswitch/ovs-dpctl.py del-if ovs_br0 -d true vxlan_a >/dev/null 2>&1
  912. python3 ./openvswitch/ovs-dpctl.py del-if ovs_br0 -d true geneve_a >/dev/null 2>&1
  913. python3 ./openvswitch/ovs-dpctl.py del-dp ovs_br0 >/dev/null 2>&1
  914. }
  915. cleanup_del_ovs_vswitchd() {
  916. ovs-vsctl --if-exists del-port vxlan_a 2>/dev/null
  917. ovs-vsctl --if-exists del-br ovs_br0 2>/dev/null
  918. }
  919. cleanup() {
  920. for pid in ${tcpdump_pids}; do
  921. kill ${pid}
  922. done
  923. tcpdump_pids=
  924. for pid in ${nettest_pids}; do
  925. kill ${pid}
  926. done
  927. nettest_pids=
  928. for pid in ${socat_pids}; do
  929. kill "${pid}"
  930. done
  931. socat_pids=
  932. cleanup_all_ns
  933. [ -e "/sys/class/net/veth_A-C" ] && ip link del veth_A-C
  934. [ -e "/sys/class/net/veth_A-R1" ] && ip link del veth_A-R1
  935. [ -e "/sys/class/net/ovs_br0" ] && cleanup_del_ovs_internal
  936. [ -e "/sys/class/net/ovs_br0" ] && cleanup_del_ovs_vswitchd
  937. rm -f "$tmpoutfile"
  938. }
  939. mtu() {
  940. ns_cmd="${1}"
  941. dev="${2}"
  942. mtu="${3}"
  943. ${ns_cmd} ip link set dev ${dev} mtu ${mtu}
  944. }
  945. mtu_parse() {
  946. input="${1}"
  947. next=0
  948. for i in ${input}; do
  949. [ ${next} -eq 1 -a "${i}" = "lock" ] && next=2 && continue
  950. [ ${next} -eq 1 ] && echo "${i}" && return
  951. [ ${next} -eq 2 ] && echo "lock ${i}" && return
  952. [ "${i}" = "mtu" ] && next=1
  953. done
  954. }
  955. link_get() {
  956. ns_cmd="${1}"
  957. name="${2}"
  958. ${ns_cmd} ip link show dev "${name}"
  959. }
  960. link_get_mtu() {
  961. ns_cmd="${1}"
  962. name="${2}"
  963. mtu_parse "$(link_get "${ns_cmd}" ${name})"
  964. }
  965. route_get_dst_exception() {
  966. ns_cmd="${1}"; shift
  967. ${ns_cmd} ip route get "$@"
  968. }
  969. route_get_dst_pmtu_from_exception() {
  970. ns_cmd="${1}"; shift
  971. mtu_parse "$(route_get_dst_exception "${ns_cmd}" "$@")"
  972. }
  973. check_pmtu_value() {
  974. expected="${1}"
  975. value="${2}"
  976. event="${3}"
  977. [ "${expected}" = "any" ] && [ -n "${value}" ] && return 0
  978. [ "${value}" = "${expected}" ] && return 0
  979. [ -z "${value}" ] && err " PMTU exception wasn't created after ${event}" && return 1
  980. [ -z "${expected}" ] && err " PMTU exception shouldn't exist after ${event}" && return 1
  981. err " found PMTU exception with incorrect MTU ${value}, expected ${expected}, after ${event}"
  982. return 1
  983. }
  984. test_pmtu_ipvX() {
  985. family=${1}
  986. setup namespaces routing || return $ksft_skip
  987. trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  988. "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
  989. "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
  990. "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
  991. if [ ${family} -eq 4 ]; then
  992. ping=ping
  993. dst1="${prefix4}.${b_r1}.1"
  994. dst2="${prefix4}.${b_r2}.1"
  995. else
  996. ping=${ping6}
  997. dst1="${prefix6}:${b_r1}::1"
  998. dst2="${prefix6}:${b_r2}::1"
  999. fi
  1000. # Set up initial MTU values
  1001. mtu "${ns_a}" veth_A-R1 2000
  1002. mtu "${ns_r1}" veth_R1-A 2000
  1003. mtu "${ns_r1}" veth_R1-B 1400
  1004. mtu "${ns_b}" veth_B-R1 1400
  1005. mtu "${ns_a}" veth_A-R2 2000
  1006. mtu "${ns_r2}" veth_R2-A 2000
  1007. mtu "${ns_r2}" veth_R2-B 1500
  1008. mtu "${ns_b}" veth_B-R2 1500
  1009. # Create route exceptions
  1010. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1}
  1011. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2}
  1012. # Check that exceptions have been created with the correct PMTU
  1013. pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"
  1014. check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
  1015. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1016. check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
  1017. # Decrease local MTU below PMTU, check for PMTU decrease in route exception
  1018. mtu "${ns_a}" veth_A-R1 1300
  1019. mtu "${ns_r1}" veth_R1-A 1300
  1020. pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"
  1021. check_pmtu_value "1300" "${pmtu_1}" "decreasing local MTU" || return 1
  1022. # Second exception shouldn't be modified
  1023. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1024. check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1
  1025. # Increase MTU, check for PMTU increase in route exception
  1026. mtu "${ns_a}" veth_A-R1 1700
  1027. mtu "${ns_r1}" veth_R1-A 1700
  1028. pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"
  1029. check_pmtu_value "1700" "${pmtu_1}" "increasing local MTU" || return 1
  1030. # Second exception shouldn't be modified
  1031. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1032. check_pmtu_value "1500" "${pmtu_2}" "changing local MTU on a link not on this path" || return 1
  1033. # Skip PMTU locking tests for IPv6
  1034. [ $family -eq 6 ] && return 0
  1035. # Decrease remote MTU on path via R2, get new exception
  1036. mtu "${ns_r2}" veth_R2-B 400
  1037. mtu "${ns_b}" veth_B-R2 400
  1038. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2}
  1039. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1040. check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1
  1041. # Decrease local MTU below PMTU
  1042. mtu "${ns_a}" veth_A-R2 500
  1043. mtu "${ns_r2}" veth_R2-A 500
  1044. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1045. check_pmtu_value "500" "${pmtu_2}" "decreasing local MTU" || return 1
  1046. # Increase local MTU
  1047. mtu "${ns_a}" veth_A-R2 1500
  1048. mtu "${ns_r2}" veth_R2-A 1500
  1049. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1050. check_pmtu_value "1500" "${pmtu_2}" "increasing local MTU" || return 1
  1051. # Get new exception
  1052. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1400 ${dst2}
  1053. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1054. check_pmtu_value "lock 552" "${pmtu_2}" "exceeding MTU, with MTU < min_pmtu" || return 1
  1055. }
  1056. test_pmtu_ipv4_exception() {
  1057. test_pmtu_ipvX 4
  1058. }
  1059. test_pmtu_ipv6_exception() {
  1060. test_pmtu_ipvX 6
  1061. }
  1062. test_pmtu_ipv4_dscp_icmp_exception() {
  1063. rt_table=100
  1064. setup namespaces policy_routing || return $ksft_skip
  1065. trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1066. "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
  1067. "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
  1068. "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
  1069. # Set up initial MTU values
  1070. mtu "${ns_a}" veth_A-R1 2000
  1071. mtu "${ns_r1}" veth_R1-A 2000
  1072. mtu "${ns_r1}" veth_R1-B 1400
  1073. mtu "${ns_b}" veth_B-R1 1400
  1074. mtu "${ns_a}" veth_A-R2 2000
  1075. mtu "${ns_r2}" veth_R2-A 2000
  1076. mtu "${ns_r2}" veth_R2-B 1500
  1077. mtu "${ns_b}" veth_B-R2 1500
  1078. len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R1
  1079. dst1="${prefix4}.${b_r1}.1"
  1080. dst2="${prefix4}.${b_r2}.1"
  1081. # Create route exceptions
  1082. dsfield=${policy_mark} # No ECN bit set (Not-ECT)
  1083. run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst1}"
  1084. dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0))
  1085. run_cmd "${ns_a}" ping -q -M want -Q "${dsfield}" -c 1 -w 1 -s "${len}" "${dst2}"
  1086. # Check that exceptions have been created with the correct PMTU
  1087. pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" dsfield "${policy_mark}")"
  1088. check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
  1089. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" dsfield "${policy_mark}")"
  1090. check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
  1091. }
  1092. test_pmtu_ipv4_dscp_udp_exception() {
  1093. rt_table=100
  1094. if ! which socat > /dev/null 2>&1; then
  1095. echo "'socat' command not found; skipping tests"
  1096. return $ksft_skip
  1097. fi
  1098. setup namespaces policy_routing || return $ksft_skip
  1099. trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1100. "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
  1101. "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
  1102. "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
  1103. # Set up initial MTU values
  1104. mtu "${ns_a}" veth_A-R1 2000
  1105. mtu "${ns_r1}" veth_R1-A 2000
  1106. mtu "${ns_r1}" veth_R1-B 1400
  1107. mtu "${ns_b}" veth_B-R1 1400
  1108. mtu "${ns_a}" veth_A-R2 2000
  1109. mtu "${ns_r2}" veth_R2-A 2000
  1110. mtu "${ns_r2}" veth_R2-B 1500
  1111. mtu "${ns_b}" veth_B-R2 1500
  1112. len=$((2000 - 20 - 8)) # Fills MTU of veth_A-R1
  1113. dst1="${prefix4}.${b_r1}.1"
  1114. dst2="${prefix4}.${b_r2}.1"
  1115. # Create route exceptions
  1116. run_cmd_bg "${ns_b}" socat UDP-LISTEN:50000 OPEN:/dev/null,wronly=1
  1117. socat_pids="${socat_pids} $!"
  1118. dsfield=${policy_mark} # No ECN bit set (Not-ECT)
  1119. run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \
  1120. UDP:"${dst1}":50000,tos="${dsfield}"
  1121. dsfield=$(printf "%#x" $((policy_mark + 0x02))) # ECN=2 (ECT(0))
  1122. run_cmd "${ns_a}" socat OPEN:/dev/zero,rdonly=1,readbytes="${len}" \
  1123. UDP:"${dst2}":50000,tos="${dsfield}"
  1124. # Check that exceptions have been created with the correct PMTU
  1125. pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst1}" dsfield "${policy_mark}")"
  1126. check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
  1127. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst2}" dsfield "${policy_mark}")"
  1128. check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
  1129. }
  1130. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception() {
  1131. type=${1}
  1132. family=${2}
  1133. outer_family=${3}
  1134. ll_mtu=4000
  1135. if [ ${outer_family} -eq 4 ]; then
  1136. setup namespaces routing ${type}4 || return $ksft_skip
  1137. # IPv4 header UDP header VXLAN/GENEVE header Ethernet header
  1138. exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))
  1139. else
  1140. setup namespaces routing ${type}6 || return $ksft_skip
  1141. # IPv6 header UDP header VXLAN/GENEVE header Ethernet header
  1142. exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))
  1143. fi
  1144. trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \
  1145. "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1146. "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B
  1147. if [ ${family} -eq 4 ]; then
  1148. ping=ping
  1149. dst=${tunnel4_b_addr}
  1150. else
  1151. ping=${ping6}
  1152. dst=${tunnel6_b_addr}
  1153. fi
  1154. # Create route exception by exceeding link layer MTU
  1155. mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
  1156. mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
  1157. mtu "${ns_b}" veth_B-R1 ${ll_mtu}
  1158. mtu "${ns_r1}" veth_R1-B ${ll_mtu}
  1159. mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000))
  1160. mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))
  1161. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}
  1162. # Check that exception was created
  1163. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
  1164. check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${type} interface"
  1165. }
  1166. test_pmtu_ipv4_vxlan4_exception() {
  1167. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 4
  1168. }
  1169. test_pmtu_ipv6_vxlan4_exception() {
  1170. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 4
  1171. }
  1172. test_pmtu_ipv4_geneve4_exception() {
  1173. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 4
  1174. }
  1175. test_pmtu_ipv6_geneve4_exception() {
  1176. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 4
  1177. }
  1178. test_pmtu_ipv4_vxlan6_exception() {
  1179. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 4 6
  1180. }
  1181. test_pmtu_ipv6_vxlan6_exception() {
  1182. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception vxlan 6 6
  1183. }
  1184. test_pmtu_ipv4_geneve6_exception() {
  1185. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 4 6
  1186. }
  1187. test_pmtu_ipv6_geneve6_exception() {
  1188. test_pmtu_ipvX_over_vxlanY_or_geneveY_exception geneve 6 6
  1189. }
  1190. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception() {
  1191. type=${1}
  1192. family=${2}
  1193. outer_family=${3}
  1194. ll_mtu=4000
  1195. if [ ${outer_family} -eq 4 ]; then
  1196. setup namespaces routing bridge bridged_${type}4 || return $ksft_skip
  1197. # IPv4 header UDP header VXLAN/GENEVE header Ethernet header
  1198. exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))
  1199. else
  1200. setup namespaces routing bridge bridged_${type}6 || return $ksft_skip
  1201. # IPv6 header UDP header VXLAN/GENEVE header Ethernet header
  1202. exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))
  1203. fi
  1204. trace "${ns_a}" ${type}_a "${ns_b}" ${type}_b \
  1205. "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1206. "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \
  1207. "${ns_a}" br0 "${ns_a}" veth-A-C \
  1208. "${ns_c}" veth_C-A
  1209. if [ ${family} -eq 4 ]; then
  1210. ping=ping
  1211. dst=${tunnel4_b_addr}
  1212. else
  1213. ping=${ping6}
  1214. dst=${tunnel6_b_addr}
  1215. fi
  1216. # Create route exception by exceeding link layer MTU
  1217. mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
  1218. mtu "${ns_a}" br0 $((${ll_mtu} + 1000))
  1219. mtu "${ns_a}" veth_A-C $((${ll_mtu} + 1000))
  1220. mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000))
  1221. mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
  1222. mtu "${ns_b}" veth_B-R1 ${ll_mtu}
  1223. mtu "${ns_r1}" veth_R1-B ${ll_mtu}
  1224. mtu "${ns_a}" ${type}_a $((${ll_mtu} + 1000))
  1225. mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))
  1226. run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 10 -s $((${ll_mtu} + 500)) ${dst} || return 1
  1227. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst} || return 1
  1228. # Check that exceptions were created
  1229. pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"
  1230. check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on bridged ${type} interface"
  1231. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
  1232. check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on locally bridged ${type} interface"
  1233. tmpoutfile=$(mktemp)
  1234. # Flush Exceptions, retry with TCP
  1235. run_cmd ${ns_a} ip route flush cached ${dst}
  1236. run_cmd ${ns_b} ip route flush cached ${dst}
  1237. run_cmd ${ns_c} ip route flush cached ${dst}
  1238. for target in "${ns_a}" "${ns_c}" ; do
  1239. if [ ${family} -eq 4 ]; then
  1240. TCPDST=TCP:${dst}:50000
  1241. else
  1242. TCPDST="TCP:[${dst}]:50000"
  1243. fi
  1244. ${ns_b} socat -T 3 -u -6 TCP-LISTEN:50000,reuseaddr STDOUT > $tmpoutfile &
  1245. local socat_pid=$!
  1246. wait_local_port_listen ${NS_B} 50000 tcp
  1247. dd if=/dev/zero status=none bs=1M count=1 | ${target} socat -T 3 -u STDIN $TCPDST,connect-timeout=3
  1248. wait ${socat_pid}
  1249. size=$(du -sb $tmpoutfile)
  1250. size=${size%%/tmp/*}
  1251. [ $size -ne 1048576 ] && err "File size $size mismatches expected value in locally bridged vxlan test" && return 1
  1252. done
  1253. rm -f "$tmpoutfile"
  1254. # Check that exceptions were created
  1255. pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"
  1256. check_pmtu_value ${exp_mtu} "${pmtu}" "tcp: exceeding link layer MTU on bridged ${type} interface"
  1257. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
  1258. check_pmtu_value ${exp_mtu} "${pmtu}" "tcp exceeding link layer MTU on locally bridged ${type} interface"
  1259. }
  1260. test_pmtu_ipv4_br_vxlan4_exception() {
  1261. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 4
  1262. }
  1263. test_pmtu_ipv6_br_vxlan4_exception() {
  1264. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 4
  1265. }
  1266. test_pmtu_ipv4_br_geneve4_exception() {
  1267. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 4
  1268. }
  1269. test_pmtu_ipv6_br_geneve4_exception() {
  1270. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 4
  1271. }
  1272. test_pmtu_ipv4_br_vxlan6_exception() {
  1273. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 4 6
  1274. }
  1275. test_pmtu_ipv6_br_vxlan6_exception() {
  1276. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception vxlan 6 6
  1277. }
  1278. test_pmtu_ipv4_br_geneve6_exception() {
  1279. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 4 6
  1280. }
  1281. test_pmtu_ipv6_br_geneve6_exception() {
  1282. test_pmtu_ipvX_over_bridged_vxlanY_or_geneveY_exception geneve 6 6
  1283. }
  1284. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception() {
  1285. type=${1}
  1286. family=${2}
  1287. outer_family=${3}
  1288. ll_mtu=4000
  1289. if [ "${type}" = "vxlan" ]; then
  1290. tun_a="vxlan_sys_4789"
  1291. elif [ "${type}" = "geneve" ]; then
  1292. tun_a="genev_sys_6081"
  1293. fi
  1294. if [ ${outer_family} -eq 4 ]; then
  1295. setup namespaces routing ovs_bridge ovs_${type}4 || return $ksft_skip
  1296. # IPv4 header UDP header VXLAN/GENEVE header Ethernet header
  1297. exp_mtu=$((${ll_mtu} - 20 - 8 - 8 - 14))
  1298. else
  1299. setup namespaces routing ovs_bridge ovs_${type}6 || return $ksft_skip
  1300. # IPv6 header UDP header VXLAN/GENEVE header Ethernet header
  1301. exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - 14))
  1302. fi
  1303. trace "" ${type}_a "${ns_b}" ${type}_b \
  1304. "" veth_A-R1 "${ns_r1}" veth_R1-A \
  1305. "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B \
  1306. "" ovs_br0 "" veth-A_C \
  1307. "${ns_c}" veth_C-A "" "${tun_a}"
  1308. if [ ${family} -eq 4 ]; then
  1309. ping=ping
  1310. dst=${tunnel4_b_addr}
  1311. else
  1312. ping=${ping6}
  1313. dst=${tunnel6_b_addr}
  1314. fi
  1315. # Create route exception by exceeding link layer MTU
  1316. mtu "" veth_A-R1 $((${ll_mtu} + 1000))
  1317. mtu "" ovs_br0 $((${ll_mtu} + 1000))
  1318. mtu "" veth_A-C $((${ll_mtu} + 1000))
  1319. mtu "${ns_c}" veth_C-A $((${ll_mtu} + 1000))
  1320. mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
  1321. mtu "${ns_b}" veth_B-R1 ${ll_mtu}
  1322. mtu "${ns_r1}" veth_R1-B ${ll_mtu}
  1323. mtu "" ${tun_a} $((${ll_mtu} + 1000)) 2>/dev/null || \
  1324. mtu "" ${type}_a $((${ll_mtu} + 1000)) 2>/dev/null
  1325. mtu "${ns_b}" ${type}_b $((${ll_mtu} + 1000))
  1326. run_cmd ${ns_c} ${ping} -q -M want -i 0.1 -c 20 -s $((${ll_mtu} + 500)) ${dst} || return 1
  1327. # Check that exceptions were created
  1328. pmtu="$(route_get_dst_pmtu_from_exception "${ns_c}" ${dst})"
  1329. check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on Open vSwitch ${type} interface"
  1330. }
  1331. test_pmtu_ipv4_ovs_vxlan4_exception() {
  1332. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 4
  1333. }
  1334. test_pmtu_ipv6_ovs_vxlan4_exception() {
  1335. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 4
  1336. }
  1337. test_pmtu_ipv4_ovs_geneve4_exception() {
  1338. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 4
  1339. }
  1340. test_pmtu_ipv6_ovs_geneve4_exception() {
  1341. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 4
  1342. }
  1343. test_pmtu_ipv4_ovs_vxlan6_exception() {
  1344. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 4 6
  1345. }
  1346. test_pmtu_ipv6_ovs_vxlan6_exception() {
  1347. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception vxlan 6 6
  1348. }
  1349. test_pmtu_ipv4_ovs_geneve6_exception() {
  1350. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 4 6
  1351. }
  1352. test_pmtu_ipv6_ovs_geneve6_exception() {
  1353. test_pmtu_ipvX_over_ovs_vxlanY_or_geneveY_exception geneve 6 6
  1354. }
  1355. test_pmtu_ipvX_over_fouY_or_gueY() {
  1356. inner_family=${1}
  1357. outer_family=${2}
  1358. encap=${3}
  1359. ll_mtu=4000
  1360. setup namespaces routing ${encap}${outer_family}${inner_family} || return $ksft_skip
  1361. trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \
  1362. "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1363. "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B
  1364. if [ ${inner_family} -eq 4 ]; then
  1365. ping=ping
  1366. dst=${tunnel4_b_addr}
  1367. else
  1368. ping=${ping6}
  1369. dst=${tunnel6_b_addr}
  1370. fi
  1371. if [ "${encap}" = "gue" ]; then
  1372. encap_overhead=4
  1373. else
  1374. encap_overhead=0
  1375. fi
  1376. if [ ${outer_family} -eq 4 ]; then
  1377. # IPv4 header UDP header
  1378. exp_mtu=$((${ll_mtu} - 20 - 8 - ${encap_overhead}))
  1379. else
  1380. # IPv6 header Option 4 UDP header
  1381. exp_mtu=$((${ll_mtu} - 40 - 8 - 8 - ${encap_overhead}))
  1382. fi
  1383. # Create route exception by exceeding link layer MTU
  1384. mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
  1385. mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
  1386. mtu "${ns_b}" veth_B-R1 ${ll_mtu}
  1387. mtu "${ns_r1}" veth_R1-B ${ll_mtu}
  1388. mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000))
  1389. mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000))
  1390. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}
  1391. # Check that exception was created
  1392. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
  1393. check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ${encap} interface"
  1394. }
  1395. test_pmtu_ipv4_fou4_exception() {
  1396. test_pmtu_ipvX_over_fouY_or_gueY 4 4 fou
  1397. }
  1398. test_pmtu_ipv6_fou4_exception() {
  1399. test_pmtu_ipvX_over_fouY_or_gueY 6 4 fou
  1400. }
  1401. test_pmtu_ipv4_fou6_exception() {
  1402. test_pmtu_ipvX_over_fouY_or_gueY 4 6 fou
  1403. }
  1404. test_pmtu_ipv6_fou6_exception() {
  1405. test_pmtu_ipvX_over_fouY_or_gueY 6 6 fou
  1406. }
  1407. test_pmtu_ipv4_gue4_exception() {
  1408. test_pmtu_ipvX_over_fouY_or_gueY 4 4 gue
  1409. }
  1410. test_pmtu_ipv6_gue4_exception() {
  1411. test_pmtu_ipvX_over_fouY_or_gueY 6 4 gue
  1412. }
  1413. test_pmtu_ipv4_gue6_exception() {
  1414. test_pmtu_ipvX_over_fouY_or_gueY 4 6 gue
  1415. }
  1416. test_pmtu_ipv6_gue6_exception() {
  1417. test_pmtu_ipvX_over_fouY_or_gueY 6 6 gue
  1418. }
  1419. test_pmtu_ipvX_over_ipvY_exception() {
  1420. inner=${1}
  1421. outer=${2}
  1422. ll_mtu=4000
  1423. setup namespaces routing ip${inner}ip${outer} || return $ksft_skip
  1424. trace "${ns_a}" ip_a "${ns_b}" ip_b \
  1425. "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1426. "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B
  1427. if [ ${inner} -eq 4 ]; then
  1428. ping=ping
  1429. dst=${tunnel4_b_addr}
  1430. else
  1431. ping=${ping6}
  1432. dst=${tunnel6_b_addr}
  1433. fi
  1434. if [ ${outer} -eq 4 ]; then
  1435. # IPv4 header
  1436. exp_mtu=$((${ll_mtu} - 20))
  1437. else
  1438. # IPv6 header Option 4
  1439. exp_mtu=$((${ll_mtu} - 40 - 8))
  1440. fi
  1441. # Create route exception by exceeding link layer MTU
  1442. mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
  1443. mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
  1444. mtu "${ns_b}" veth_B-R1 ${ll_mtu}
  1445. mtu "${ns_r1}" veth_R1-B ${ll_mtu}
  1446. mtu "${ns_a}" ip_a $((${ll_mtu} + 1000)) || return
  1447. mtu "${ns_b}" ip_b $((${ll_mtu} + 1000)) || return
  1448. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${dst}
  1449. # Check that exception was created
  1450. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst})"
  1451. check_pmtu_value ${exp_mtu} "${pmtu}" "exceeding link layer MTU on ip${inner}ip${outer} interface"
  1452. }
  1453. test_pmtu_ipv4_ipv4_exception() {
  1454. test_pmtu_ipvX_over_ipvY_exception 4 4
  1455. }
  1456. test_pmtu_ipv6_ipv4_exception() {
  1457. test_pmtu_ipvX_over_ipvY_exception 6 4
  1458. }
  1459. test_pmtu_ipv4_ipv6_exception() {
  1460. test_pmtu_ipvX_over_ipvY_exception 4 6
  1461. }
  1462. test_pmtu_ipv6_ipv6_exception() {
  1463. test_pmtu_ipvX_over_ipvY_exception 6 6
  1464. }
  1465. test_pmtu_vti4_exception() {
  1466. setup namespaces veth vti4 xfrm4 || return $ksft_skip
  1467. trace "${ns_a}" veth_a "${ns_b}" veth_b \
  1468. "${ns_a}" vti4_a "${ns_b}" vti4_b
  1469. veth_mtu=1500
  1470. vti_mtu=$((veth_mtu - 20))
  1471. # SPI SN IV ICV pad length next header
  1472. esp_payload_rfc4106=$((vti_mtu - 4 - 4 - 8 - 16 - 1 - 1))
  1473. ping_payload=$((esp_payload_rfc4106 - 28))
  1474. mtu "${ns_a}" veth_a ${veth_mtu}
  1475. mtu "${ns_b}" veth_b ${veth_mtu}
  1476. mtu "${ns_a}" vti4_a ${vti_mtu}
  1477. mtu "${ns_b}" vti4_b ${vti_mtu}
  1478. # Send DF packet without exceeding link layer MTU, check that no
  1479. # exception is created
  1480. run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}
  1481. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
  1482. check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1
  1483. # Now exceed link layer MTU by one byte, check that exception is created
  1484. # with the right PMTU value
  1485. run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr}
  1486. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
  1487. check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))"
  1488. }
  1489. test_pmtu_vti6_exception() {
  1490. setup namespaces veth vti6 xfrm6 || return $ksft_skip
  1491. trace "${ns_a}" veth_a "${ns_b}" veth_b \
  1492. "${ns_a}" vti6_a "${ns_b}" vti6_b
  1493. fail=0
  1494. # Create route exception by exceeding link layer MTU
  1495. mtu "${ns_a}" veth_a 4000
  1496. mtu "${ns_b}" veth_b 4000
  1497. mtu "${ns_a}" vti6_a 5000
  1498. mtu "${ns_b}" vti6_b 5000
  1499. run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr}
  1500. # Check that exception was created
  1501. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
  1502. check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1
  1503. # Decrease tunnel MTU, check for PMTU decrease in route exception
  1504. mtu "${ns_a}" vti6_a 3000
  1505. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
  1506. check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1
  1507. # Increase tunnel MTU, check for PMTU increase in route exception
  1508. mtu "${ns_a}" vti6_a 9000
  1509. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
  1510. check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1
  1511. return ${fail}
  1512. }
  1513. test_pmtu_vti4_udp_exception() {
  1514. setup namespaces veth vti4 xfrm4udp || return $ksft_skip
  1515. trace "${ns_a}" veth_a "${ns_b}" veth_b \
  1516. "${ns_a}" vti4_a "${ns_b}" vti4_b
  1517. veth_mtu=1500
  1518. vti_mtu=$((veth_mtu - 20))
  1519. # UDP SPI SN IV ICV pad length next header
  1520. esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))
  1521. ping_payload=$((esp_payload_rfc4106 - 28))
  1522. mtu "${ns_a}" veth_a ${veth_mtu}
  1523. mtu "${ns_b}" veth_b ${veth_mtu}
  1524. mtu "${ns_a}" vti4_a ${vti_mtu}
  1525. mtu "${ns_b}" vti4_b ${vti_mtu}
  1526. # Send DF packet without exceeding link layer MTU, check that no
  1527. # exception is created
  1528. run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}
  1529. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
  1530. check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1
  1531. # Now exceed link layer MTU by one byte, check that exception is created
  1532. # with the right PMTU value
  1533. run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload + 1)) ${tunnel4_b_addr}
  1534. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
  1535. check_pmtu_value "${esp_payload_rfc4106}" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106 + 1)))"
  1536. }
  1537. test_pmtu_vti6_udp_exception() {
  1538. setup namespaces veth vti6 xfrm6udp || return $ksft_skip
  1539. trace "${ns_a}" veth_a "${ns_b}" veth_b \
  1540. "${ns_a}" vti6_a "${ns_b}" vti6_b
  1541. fail=0
  1542. # Create route exception by exceeding link layer MTU
  1543. mtu "${ns_a}" veth_a 4000
  1544. mtu "${ns_b}" veth_b 4000
  1545. mtu "${ns_a}" vti6_a 5000
  1546. mtu "${ns_b}" vti6_b 5000
  1547. run_cmd ${ns_a} ${ping6} -q -i 0.1 -w 1 -s 60000 ${tunnel6_b_addr}
  1548. # Check that exception was created
  1549. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
  1550. check_pmtu_value any "${pmtu}" "creating tunnel exceeding link layer MTU" || return 1
  1551. # Decrease tunnel MTU, check for PMTU decrease in route exception
  1552. mtu "${ns_a}" vti6_a 3000
  1553. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
  1554. check_pmtu_value "3000" "${pmtu}" "decreasing tunnel MTU" || fail=1
  1555. # Increase tunnel MTU, check for PMTU increase in route exception
  1556. mtu "${ns_a}" vti6_a 9000
  1557. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
  1558. check_pmtu_value "9000" "${pmtu}" "increasing tunnel MTU" || fail=1
  1559. return ${fail}
  1560. }
  1561. test_pmtu_vti4_udp_routed_exception() {
  1562. setup namespaces routing vti4routed xfrm4udprouted || return $ksft_skip
  1563. trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \
  1564. "${ns_a}" vti4_a "${ns_b}" vti4_b
  1565. veth_mtu=1500
  1566. vti_mtu=$((veth_mtu - 20))
  1567. # UDP SPI SN IV ICV pad length next header
  1568. esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))
  1569. ping_payload=$((esp_payload_rfc4106 - 28))
  1570. mtu "${ns_a}" veth_A-R1 ${veth_mtu}
  1571. mtu "${ns_r1}" veth_R1-A ${veth_mtu}
  1572. mtu "${ns_b}" veth_B-R1 ${veth_mtu}
  1573. mtu "${ns_r1}" veth_R1-B ${veth_mtu}
  1574. mtu "${ns_a}" vti4_a ${vti_mtu}
  1575. mtu "${ns_b}" vti4_b ${vti_mtu}
  1576. # Send DF packet without exceeding link layer MTU, check that no
  1577. # exception is created
  1578. run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel4_b_addr}
  1579. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
  1580. check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1
  1581. # Now decrease link layer MTU by 8 bytes on R1, check that exception is created
  1582. # with the right PMTU value
  1583. mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8))
  1584. run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel4_b_addr}
  1585. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel4_b_addr})"
  1586. check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))"
  1587. }
  1588. test_pmtu_vti6_udp_routed_exception() {
  1589. setup namespaces routing vti6routed xfrm6udprouted || return $ksft_skip
  1590. trace "${ns_a}" veth_A-R1 "${ns_b}" veth_B-R1 \
  1591. "${ns_a}" vti6_a "${ns_b}" vti6_b
  1592. veth_mtu=1500
  1593. vti_mtu=$((veth_mtu - 40))
  1594. # UDP SPI SN IV ICV pad length next header
  1595. esp_payload_rfc4106=$((vti_mtu - 8 - 4 - 4 - 8 - 16 - 1 - 1))
  1596. ping_payload=$((esp_payload_rfc4106 - 48))
  1597. mtu "${ns_a}" veth_A-R1 ${veth_mtu}
  1598. mtu "${ns_r1}" veth_R1-A ${veth_mtu}
  1599. mtu "${ns_b}" veth_B-R1 ${veth_mtu}
  1600. mtu "${ns_r1}" veth_R1-B ${veth_mtu}
  1601. # mtu "${ns_a}" vti6_a ${vti_mtu}
  1602. # mtu "${ns_b}" vti6_b ${vti_mtu}
  1603. run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s ${ping_payload} ${tunnel6_b_addr}
  1604. # Check that exception was not created
  1605. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
  1606. check_pmtu_value "" "${pmtu}" "sending packet smaller than PMTU (IP payload length ${esp_payload_rfc4106})" || return 1
  1607. # Now decrease link layer MTU by 8 bytes on R1, check that exception is created
  1608. # with the right PMTU value
  1609. mtu "${ns_r1}" veth_R1-B $((veth_mtu - 8))
  1610. run_cmd ${ns_a} ${ping6} -q -M want -i 0.1 -w 1 -s $((ping_payload)) ${tunnel6_b_addr}
  1611. pmtu="$(route_get_dst_pmtu_from_exception "${ns_a}" ${tunnel6_b_addr})"
  1612. check_pmtu_value "$((esp_payload_rfc4106 - 8))" "${pmtu}" "exceeding PMTU (IP payload length $((esp_payload_rfc4106)))"
  1613. }
  1614. test_pmtu_vti4_default_mtu() {
  1615. setup namespaces veth vti4 || return $ksft_skip
  1616. # Check that MTU of vti device is MTU of veth minus IPv4 header length
  1617. veth_mtu="$(link_get_mtu "${ns_a}" veth_a)"
  1618. vti4_mtu="$(link_get_mtu "${ns_a}" vti4_a)"
  1619. if [ $((veth_mtu - vti4_mtu)) -ne 20 ]; then
  1620. err " vti MTU ${vti4_mtu} is not veth MTU ${veth_mtu} minus IPv4 header length"
  1621. return 1
  1622. fi
  1623. }
  1624. test_pmtu_vti6_default_mtu() {
  1625. setup namespaces veth vti6 || return $ksft_skip
  1626. # Check that MTU of vti device is MTU of veth minus IPv6 header length
  1627. veth_mtu="$(link_get_mtu "${ns_a}" veth_a)"
  1628. vti6_mtu="$(link_get_mtu "${ns_a}" vti6_a)"
  1629. if [ $((veth_mtu - vti6_mtu)) -ne 40 ]; then
  1630. err " vti MTU ${vti6_mtu} is not veth MTU ${veth_mtu} minus IPv6 header length"
  1631. return 1
  1632. fi
  1633. }
  1634. test_pmtu_vti4_link_add_mtu() {
  1635. setup namespaces || return $ksft_skip
  1636. run_cmd ${ns_a} ip link add vti4_a type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10
  1637. [ $? -ne 0 ] && err " vti not supported" && return $ksft_skip
  1638. run_cmd ${ns_a} ip link del vti4_a
  1639. fail=0
  1640. min=68
  1641. max=$((65535 - 20))
  1642. # Check invalid values first
  1643. for v in $((min - 1)) $((max + 1)); do
  1644. run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10
  1645. # This can fail, or MTU can be adjusted to a proper value
  1646. [ $? -ne 0 ] && continue
  1647. mtu="$(link_get_mtu "${ns_a}" vti4_a)"
  1648. if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then
  1649. err " vti tunnel created with invalid MTU ${mtu}"
  1650. fail=1
  1651. fi
  1652. run_cmd ${ns_a} ip link del vti4_a
  1653. done
  1654. # Now check valid values
  1655. for v in ${min} 1300 ${max}; do
  1656. run_cmd ${ns_a} ip link add vti4_a mtu ${v} type vti local ${veth4_a_addr} remote ${veth4_b_addr} key 10
  1657. mtu="$(link_get_mtu "${ns_a}" vti4_a)"
  1658. run_cmd ${ns_a} ip link del vti4_a
  1659. if [ "${mtu}" != "${v}" ]; then
  1660. err " vti MTU ${mtu} doesn't match configured value ${v}"
  1661. fail=1
  1662. fi
  1663. done
  1664. return ${fail}
  1665. }
  1666. test_pmtu_vti6_link_add_mtu() {
  1667. setup namespaces || return $ksft_skip
  1668. run_cmd ${ns_a} ip link add vti6_a type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10
  1669. [ $? -ne 0 ] && err " vti6 not supported" && return $ksft_skip
  1670. run_cmd ${ns_a} ip link del vti6_a
  1671. fail=0
  1672. min=68 # vti6 can carry IPv4 packets too
  1673. max=$((65535 - 40))
  1674. # Check invalid values first
  1675. for v in $((min - 1)) $((max + 1)); do
  1676. run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10
  1677. # This can fail, or MTU can be adjusted to a proper value
  1678. [ $? -ne 0 ] && continue
  1679. mtu="$(link_get_mtu "${ns_a}" vti6_a)"
  1680. if [ ${mtu} -lt ${min} -o ${mtu} -gt ${max} ]; then
  1681. err " vti6 tunnel created with invalid MTU ${v}"
  1682. fail=1
  1683. fi
  1684. run_cmd ${ns_a} ip link del vti6_a
  1685. done
  1686. # Now check valid values
  1687. for v in 68 1280 1300 $((65535 - 40)); do
  1688. run_cmd ${ns_a} ip link add vti6_a mtu ${v} type vti6 local ${veth6_a_addr} remote ${veth6_b_addr} key 10
  1689. mtu="$(link_get_mtu "${ns_a}" vti6_a)"
  1690. run_cmd ${ns_a} ip link del vti6_a
  1691. if [ "${mtu}" != "${v}" ]; then
  1692. err " vti6 MTU ${mtu} doesn't match configured value ${v}"
  1693. fail=1
  1694. fi
  1695. done
  1696. return ${fail}
  1697. }
  1698. test_pmtu_vti6_link_change_mtu() {
  1699. setup namespaces || return $ksft_skip
  1700. run_cmd ${ns_a} ip link add dummy0 mtu 1500 type dummy
  1701. [ $? -ne 0 ] && err " dummy not supported" && return $ksft_skip
  1702. run_cmd ${ns_a} ip link add dummy1 mtu 3000 type dummy
  1703. run_cmd ${ns_a} ip link set dummy0 up
  1704. run_cmd ${ns_a} ip link set dummy1 up
  1705. run_cmd ${ns_a} ip addr add ${dummy6_0_prefix}1/${dummy6_mask} dev dummy0
  1706. run_cmd ${ns_a} ip addr add ${dummy6_1_prefix}1/${dummy6_mask} dev dummy1
  1707. fail=0
  1708. # Create vti6 interface bound to device, passing MTU, check it
  1709. run_cmd ${ns_a} ip link add vti6_a mtu 1300 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1
  1710. mtu="$(link_get_mtu "${ns_a}" vti6_a)"
  1711. if [ ${mtu} -ne 1300 ]; then
  1712. err " vti6 MTU ${mtu} doesn't match configured value 1300"
  1713. fail=1
  1714. fi
  1715. # Move to another device with different MTU, without passing MTU, check
  1716. # MTU is adjusted
  1717. run_cmd ${ns_a} ip link set vti6_a type vti6 remote ${dummy6_1_prefix}2 local ${dummy6_1_prefix}1
  1718. mtu="$(link_get_mtu "${ns_a}" vti6_a)"
  1719. if [ ${mtu} -ne $((3000 - 40)) ]; then
  1720. err " vti MTU ${mtu} is not dummy MTU 3000 minus IPv6 header length"
  1721. fail=1
  1722. fi
  1723. # Move it back, passing MTU, check MTU is not overridden
  1724. run_cmd ${ns_a} ip link set vti6_a mtu 1280 type vti6 remote ${dummy6_0_prefix}2 local ${dummy6_0_prefix}1
  1725. mtu="$(link_get_mtu "${ns_a}" vti6_a)"
  1726. if [ ${mtu} -ne 1280 ]; then
  1727. err " vti6 MTU ${mtu} doesn't match configured value 1280"
  1728. fail=1
  1729. fi
  1730. return ${fail}
  1731. }
  1732. check_command() {
  1733. cmd=${1}
  1734. if ! which ${cmd} > /dev/null 2>&1; then
  1735. err " missing required command: '${cmd}'"
  1736. return 1
  1737. fi
  1738. return 0
  1739. }
  1740. check_running() {
  1741. pid=${1}
  1742. cmd=${2}
  1743. [ "$(cat /proc/${pid}/cmdline 2>/dev/null | tr -d '\0')" = "${cmd}" ]
  1744. }
  1745. test_cleanup_vxlanX_exception() {
  1746. outer="${1}"
  1747. encap="vxlan"
  1748. ll_mtu=4000
  1749. check_command taskset || return $ksft_skip
  1750. cpu_list=$(grep -m 2 processor /proc/cpuinfo | cut -d ' ' -f 2)
  1751. setup namespaces routing ${encap}${outer} || return $ksft_skip
  1752. trace "${ns_a}" ${encap}_a "${ns_b}" ${encap}_b \
  1753. "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1754. "${ns_b}" veth_B-R1 "${ns_r1}" veth_R1-B
  1755. # Create route exception by exceeding link layer MTU
  1756. mtu "${ns_a}" veth_A-R1 $((${ll_mtu} + 1000))
  1757. mtu "${ns_r1}" veth_R1-A $((${ll_mtu} + 1000))
  1758. mtu "${ns_b}" veth_B-R1 ${ll_mtu}
  1759. mtu "${ns_r1}" veth_R1-B ${ll_mtu}
  1760. mtu "${ns_a}" ${encap}_a $((${ll_mtu} + 1000))
  1761. mtu "${ns_b}" ${encap}_b $((${ll_mtu} + 1000))
  1762. # Fill exception cache for multiple CPUs (2)
  1763. # we can always use inner IPv4 for that
  1764. for cpu in ${cpu_list}; do
  1765. run_cmd taskset --cpu-list ${cpu} ${ns_a} ping -q -M want -i 0.1 -w 1 -s $((${ll_mtu} + 500)) ${tunnel4_b_addr}
  1766. done
  1767. ${ns_a} ip link del dev veth_A-R1 &
  1768. iplink_pid=$!
  1769. for i in $(seq 1 20); do
  1770. check_running ${iplink_pid} "iplinkdeldevveth_A-R1" || return 0
  1771. sleep 0.1
  1772. done
  1773. err " can't delete veth device in a timely manner, PMTU dst likely leaked"
  1774. return 1
  1775. }
  1776. test_cleanup_ipv6_exception() {
  1777. test_cleanup_vxlanX_exception 6
  1778. }
  1779. test_cleanup_ipv4_exception() {
  1780. test_cleanup_vxlanX_exception 4
  1781. }
  1782. run_test() {
  1783. (
  1784. tname="$1"
  1785. tdesc="$2"
  1786. unset IFS
  1787. # Since cleanup() relies on variables modified by this subshell, it
  1788. # has to run in this context.
  1789. trap cleanup EXIT
  1790. if [ "$VERBOSE" = "1" ]; then
  1791. printf "\n##########################################################################\n\n"
  1792. fi
  1793. eval test_${tname}
  1794. ret=$?
  1795. if [ $ret -eq 0 ]; then
  1796. printf "TEST: %-60s [ OK ]\n" "${tdesc}"
  1797. elif [ $ret -eq 1 ]; then
  1798. printf "TEST: %-60s [FAIL]\n" "${tdesc}"
  1799. if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
  1800. echo
  1801. echo "Pausing. Hit enter to continue"
  1802. read a
  1803. fi
  1804. err_flush
  1805. exit 1
  1806. elif [ $ret -eq $ksft_skip ]; then
  1807. printf "TEST: %-60s [SKIP]\n" "${tdesc}"
  1808. err_flush
  1809. fi
  1810. return $ret
  1811. )
  1812. ret=$?
  1813. case $ret in
  1814. 0)
  1815. all_skipped=false
  1816. [ $exitcode -eq $ksft_skip ] && exitcode=0
  1817. ;;
  1818. $ksft_skip)
  1819. [ $all_skipped = true ] && exitcode=$ksft_skip
  1820. ;;
  1821. *)
  1822. all_skipped=false
  1823. exitcode=1
  1824. ;;
  1825. esac
  1826. return $ret
  1827. }
  1828. run_test_nh() {
  1829. tname="$1"
  1830. tdesc="$2"
  1831. USE_NH=yes
  1832. run_test "${tname}" "${tdesc} - nexthop objects"
  1833. USE_NH=no
  1834. }
  1835. test_list_flush_ipv4_exception() {
  1836. setup namespaces routing || return $ksft_skip
  1837. trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1838. "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
  1839. "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
  1840. "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
  1841. dst_prefix1="${prefix4}.${b_r1}."
  1842. dst2="${prefix4}.${b_r2}.1"
  1843. # Set up initial MTU values
  1844. mtu "${ns_a}" veth_A-R1 2000
  1845. mtu "${ns_r1}" veth_R1-A 2000
  1846. mtu "${ns_r1}" veth_R1-B 1500
  1847. mtu "${ns_b}" veth_B-R1 1500
  1848. mtu "${ns_a}" veth_A-R2 2000
  1849. mtu "${ns_r2}" veth_R2-A 2000
  1850. mtu "${ns_r2}" veth_R2-B 1500
  1851. mtu "${ns_b}" veth_B-R2 1500
  1852. fail=0
  1853. # Add 100 addresses for veth endpoint on B reached by default A route
  1854. for i in $(seq 100 199); do
  1855. run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1
  1856. done
  1857. # Create 100 cached route exceptions for path via R1, one via R2. Note
  1858. # that with IPv4 we need to actually cause a route lookup that matches
  1859. # the exception caused by ICMP, in order to actually have a cached
  1860. # route, so we need to ping each destination twice
  1861. for i in $(seq 100 199); do
  1862. run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst_prefix1}${i}"
  1863. done
  1864. run_cmd ${ns_a} ping -q -M want -i 0.1 -c 2 -s 1800 "${dst2}"
  1865. if [ "$(${ns_a} ip -oneline route list cache | wc -l)" -ne 101 ]; then
  1866. err " can't list cached exceptions"
  1867. fail=1
  1868. fi
  1869. run_cmd ${ns_a} ip route flush cache
  1870. pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}1)"
  1871. pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst_prefix}2)"
  1872. if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \
  1873. [ -n "$(${ns_a} ip route list cache)" ]; then
  1874. err " can't flush cached exceptions"
  1875. fail=1
  1876. fi
  1877. return ${fail}
  1878. }
  1879. test_list_flush_ipv6_exception() {
  1880. setup namespaces routing || return $ksft_skip
  1881. trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1882. "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
  1883. "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
  1884. "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
  1885. dst_prefix1="${prefix6}:${b_r1}::"
  1886. dst2="${prefix6}:${b_r2}::1"
  1887. # Set up initial MTU values
  1888. mtu "${ns_a}" veth_A-R1 2000
  1889. mtu "${ns_r1}" veth_R1-A 2000
  1890. mtu "${ns_r1}" veth_R1-B 1500
  1891. mtu "${ns_b}" veth_B-R1 1500
  1892. mtu "${ns_a}" veth_A-R2 2000
  1893. mtu "${ns_r2}" veth_R2-A 2000
  1894. mtu "${ns_r2}" veth_R2-B 1500
  1895. mtu "${ns_b}" veth_B-R2 1500
  1896. fail=0
  1897. # Add 100 addresses for veth endpoint on B reached by default A route
  1898. for i in $(seq 100 199); do
  1899. run_cmd ${ns_b} ip addr add "${dst_prefix1}${i}" dev veth_B-R1
  1900. done
  1901. # Create 100 cached route exceptions for path via R1, one via R2
  1902. for i in $(seq 100 199); do
  1903. run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst_prefix1}${i}"
  1904. done
  1905. run_cmd ${ns_a} ping -q -M want -i 0.1 -w 1 -s 1800 "${dst2}"
  1906. if [ "$(${ns_a} ip -oneline -6 route list cache | wc -l)" -ne 101 ]; then
  1907. err " can't list cached exceptions"
  1908. fail=1
  1909. fi
  1910. run_cmd ${ns_a} ip -6 route flush cache
  1911. pmtu1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${dst_prefix1}100")"
  1912. pmtu2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1913. if [ -n "${pmtu1}" ] || [ -n "${pmtu2}" ] || \
  1914. [ -n "$(${ns_a} ip -6 route list cache)" ]; then
  1915. err " can't flush cached exceptions"
  1916. fail=1
  1917. fi
  1918. return ${fail}
  1919. }
  1920. test_pmtu_ipvX_route_change() {
  1921. family=${1}
  1922. setup namespaces routing || return 2
  1923. trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1924. "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
  1925. "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
  1926. "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
  1927. if [ ${family} -eq 4 ]; then
  1928. ping=ping
  1929. dst1="${prefix4}.${b_r1}.1"
  1930. dst2="${prefix4}.${b_r2}.1"
  1931. gw="${prefix4}.${a_r1}.2"
  1932. else
  1933. ping=${ping6}
  1934. dst1="${prefix6}:${b_r1}::1"
  1935. dst2="${prefix6}:${b_r2}::1"
  1936. gw="${prefix6}:${a_r1}::2"
  1937. fi
  1938. # Set up initial MTU values
  1939. mtu "${ns_a}" veth_A-R1 2000
  1940. mtu "${ns_r1}" veth_R1-A 2000
  1941. mtu "${ns_r1}" veth_R1-B 1400
  1942. mtu "${ns_b}" veth_B-R1 1400
  1943. mtu "${ns_a}" veth_A-R2 2000
  1944. mtu "${ns_r2}" veth_R2-A 2000
  1945. mtu "${ns_r2}" veth_R2-B 1500
  1946. mtu "${ns_b}" veth_B-R2 1500
  1947. # Create route exceptions
  1948. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst1}
  1949. run_cmd ${ns_a} ${ping} -q -M want -i 0.1 -w 1 -s 1800 ${dst2}
  1950. # Check that exceptions have been created with the correct PMTU
  1951. pmtu_1="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst1})"
  1952. check_pmtu_value "1400" "${pmtu_1}" "exceeding MTU" || return 1
  1953. pmtu_2="$(route_get_dst_pmtu_from_exception "${ns_a}" ${dst2})"
  1954. check_pmtu_value "1500" "${pmtu_2}" "exceeding MTU" || return 1
  1955. # Replace the route from A to R1
  1956. run_cmd ${ns_a} ip route change default via ${gw}
  1957. # Delete the device in A
  1958. run_cmd ${ns_a} ip link del "veth_A-R1"
  1959. }
  1960. test_pmtu_ipv4_route_change() {
  1961. test_pmtu_ipvX_route_change 4
  1962. }
  1963. test_pmtu_ipv6_route_change() {
  1964. test_pmtu_ipvX_route_change 6
  1965. }
  1966. test_pmtu_ipv4_mp_exceptions() {
  1967. setup namespaces routing multipath || return $ksft_skip
  1968. trace "${ns_a}" veth_A-R1 "${ns_r1}" veth_R1-A \
  1969. "${ns_r1}" veth_R1-B "${ns_b}" veth_B-R1 \
  1970. "${ns_a}" veth_A-R2 "${ns_r2}" veth_R2-A \
  1971. "${ns_r2}" veth_R2-B "${ns_b}" veth_B-R2
  1972. # Set up initial MTU values
  1973. mtu "${ns_a}" veth_A-R1 2000
  1974. mtu "${ns_r1}" veth_R1-A 2000
  1975. mtu "${ns_r1}" veth_R1-B 1500
  1976. mtu "${ns_b}" veth_B-R1 1500
  1977. mtu "${ns_a}" veth_A-R2 2000
  1978. mtu "${ns_r2}" veth_R2-A 2000
  1979. mtu "${ns_r2}" veth_R2-B 1500
  1980. mtu "${ns_b}" veth_B-R2 1500
  1981. # Ping and expect two nexthop exceptions for two routes
  1982. run_cmd ${ns_a} ping -q -M want -i 0.1 -c 1 -s 1800 "${host4_b_addr}"
  1983. # Check that exceptions have been created with the correct PMTU
  1984. pmtu_a_R1="$(route_get_dst_pmtu_from_exception "${ns_a}" "${host4_b_addr}" oif veth_A-R1)"
  1985. pmtu_a_R2="$(route_get_dst_pmtu_from_exception "${ns_a}" "${host4_b_addr}" oif veth_A-R2)"
  1986. check_pmtu_value "1500" "${pmtu_a_R1}" "exceeding MTU (veth_A-R1)" || return 1
  1987. check_pmtu_value "1500" "${pmtu_a_R2}" "exceeding MTU (veth_A-R2)" || return 1
  1988. }
  1989. usage() {
  1990. echo
  1991. echo "$0 [OPTIONS] [TEST]..."
  1992. echo "If no TEST argument is given, all tests will be run."
  1993. echo
  1994. echo "Options"
  1995. echo " --trace: capture traffic to TEST_INTERFACE.pcap"
  1996. echo
  1997. echo "Available tests${tests}"
  1998. exit 1
  1999. }
  2000. ################################################################################
  2001. #
  2002. exitcode=0
  2003. desc=0
  2004. all_skipped=true
  2005. while getopts :ptv o
  2006. do
  2007. case $o in
  2008. p) PAUSE_ON_FAIL=yes;;
  2009. v) VERBOSE=1;;
  2010. t) if which tcpdump > /dev/null 2>&1; then
  2011. TRACING=1
  2012. else
  2013. echo "=== tcpdump not available, tracing disabled"
  2014. fi
  2015. ;;
  2016. *) usage;;
  2017. esac
  2018. done
  2019. shift $(($OPTIND-1))
  2020. IFS="
  2021. "
  2022. for arg do
  2023. # Check first that all requested tests are available before running any
  2024. command -v > /dev/null "test_${arg}" || { echo "=== Test ${arg} not found"; usage; }
  2025. done
  2026. trap cleanup EXIT
  2027. # start clean
  2028. cleanup
  2029. HAVE_NH=no
  2030. ip nexthop ls >/dev/null 2>&1
  2031. [ $? -eq 0 ] && HAVE_NH=yes
  2032. name=""
  2033. desc=""
  2034. rerun_nh=0
  2035. for t in ${tests}; do
  2036. [ "${name}" = "" ] && name="${t}" && continue
  2037. [ "${desc}" = "" ] && desc="${t}" && continue
  2038. if [ "${HAVE_NH}" = "yes" ]; then
  2039. rerun_nh="${t}"
  2040. fi
  2041. run_this=1
  2042. for arg do
  2043. [ "${arg}" != "${arg#--*}" ] && continue
  2044. [ "${arg}" = "${name}" ] && run_this=1 && break
  2045. run_this=0
  2046. done
  2047. if [ $run_this -eq 1 ]; then
  2048. run_test "${name}" "${desc}"
  2049. # if test was skipped no need to retry with nexthop objects
  2050. [ $? -eq $ksft_skip ] && rerun_nh=0
  2051. if [ "${rerun_nh}" = "1" ]; then
  2052. run_test_nh "${name}" "${desc}"
  2053. fi
  2054. fi
  2055. name=""
  2056. desc=""
  2057. rerun_nh=0
  2058. done
  2059. exit ${exitcode}