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