bareudp.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. # Test various bareudp tunnel configurations.
  4. #
  5. # The bareudp module allows to tunnel network protocols like IP or MPLS over
  6. # UDP, without adding any intermediate header. This scripts tests several
  7. # configurations of bareudp (using IPv4 or IPv6 as underlay and transporting
  8. # IPv4, IPv6 or MPLS packets on the overlay).
  9. #
  10. # Network topology:
  11. #
  12. # * A chain of 4 network namespaces, connected with veth pairs. Each veth
  13. # is assigned an IPv4 and an IPv6 address. A host-route allows a veth to
  14. # join its peer.
  15. #
  16. # * NS0 and NS3 are at the extremities of the chain. They have additional
  17. # IPv4 and IPv6 addresses on their loopback device. Routes are added in NS0
  18. # and NS3, so that they can communicate using these overlay IP addresses.
  19. # For IPv4 and IPv6 reachability tests, the route simply sets the peer's
  20. # veth address as gateway. For MPLS reachability tests, an MPLS header is
  21. # also pushed before the IP header.
  22. #
  23. # * NS1 and NS2 are the intermediate namespaces. They use a bareudp device to
  24. # encapsulate the traffic into UDP.
  25. #
  26. # +-----------------------------------------------------------------------+
  27. # | NS0 |
  28. # | |
  29. # | lo: |
  30. # | * IPv4 address: 192.0.2.100/32 |
  31. # | * IPv6 address: 2001:db8::100/128 |
  32. # | * IPv6 address: 2001:db8::200/128 |
  33. # | * IPv4 route: 192.0.2.103/32 reachable via 192.0.2.11 |
  34. # | * IPv6 route: 2001:db8::103/128 reachable via 2001:db8::11 |
  35. # | * IPv6 route: 2001:db8::203/128 reachable via 2001:db8::11 |
  36. # | (encapsulated with MPLS label 203) |
  37. # | |
  38. # | veth01: |
  39. # | ^ * IPv4 address: 192.0.2.10, peer 192.0.2.11/32 |
  40. # | | * IPv6 address: 2001:db8::10, peer 2001:db8::11/128 |
  41. # | | |
  42. # +---+-------------------------------------------------------------------+
  43. # |
  44. # | Traffic type: IP or MPLS (depending on test)
  45. # |
  46. # +---+-------------------------------------------------------------------+
  47. # | | NS1 |
  48. # | | |
  49. # | v |
  50. # | veth10: |
  51. # | * IPv4 address: 192.0.2.11, peer 192.0.2.10/32 |
  52. # | * IPv6 address: 2001:db8::11, peer 2001:db8::10/128 |
  53. # | |
  54. # | bareudp_ns1: |
  55. # | * Encapsulate IP or MPLS packets received on veth10 into UDP |
  56. # | and send the resulting packets through veth12. |
  57. # | * Decapsulate bareudp packets (either IP or MPLS, over UDP) |
  58. # | received on veth12 and send the inner packets through veth10. |
  59. # | |
  60. # | veth12: |
  61. # | ^ * IPv4 address: 192.0.2.21, peer 192.0.2.22/32 |
  62. # | | * IPv6 address: 2001:db8::21, peer 2001:db8::22/128 |
  63. # | | |
  64. # +---+-------------------------------------------------------------------+
  65. # |
  66. # | Traffic type: IP or MPLS (depending on test), over UDP
  67. # |
  68. # +---+-------------------------------------------------------------------+
  69. # | | NS2 |
  70. # | | |
  71. # | v |
  72. # | veth21: |
  73. # | * IPv4 address: 192.0.2.22, peer 192.0.2.21/32 |
  74. # | * IPv6 address: 2001:db8::22, peer 2001:db8::21/128 |
  75. # | |
  76. # | bareudp_ns2: |
  77. # | * Decapsulate bareudp packets (either IP or MPLS, over UDP) |
  78. # | received on veth21 and send the inner packets through veth23. |
  79. # | * Encapsulate IP or MPLS packets received on veth23 into UDP |
  80. # | and send the resulting packets through veth21. |
  81. # | |
  82. # | veth23: |
  83. # | ^ * IPv4 address: 192.0.2.32, peer 192.0.2.33/32 |
  84. # | | * IPv6 address: 2001:db8::32, peer 2001:db8::33/128 |
  85. # | | |
  86. # +---+-------------------------------------------------------------------+
  87. # |
  88. # | Traffic type: IP or MPLS (depending on test)
  89. # |
  90. # +---+-------------------------------------------------------------------+
  91. # | | NS3 |
  92. # | v |
  93. # | veth32: |
  94. # | * IPv4 address: 192.0.2.33, peer 192.0.2.32/32 |
  95. # | * IPv6 address: 2001:db8::33, peer 2001:db8::32/128 |
  96. # | |
  97. # | lo: |
  98. # | * IPv4 address: 192.0.2.103/32 |
  99. # | * IPv6 address: 2001:db8::103/128 |
  100. # | * IPv6 address: 2001:db8::203/128 |
  101. # | * IPv4 route: 192.0.2.100/32 reachable via 192.0.2.32 |
  102. # | * IPv6 route: 2001:db8::100/128 reachable via 2001:db8::32 |
  103. # | * IPv6 route: 2001:db8::200/128 reachable via 2001:db8::32 |
  104. # | (encapsulated with MPLS label 200) |
  105. # | |
  106. # +-----------------------------------------------------------------------+
  107. ERR=4 # Return 4 by default, which is the SKIP code for kselftest
  108. PING6="ping"
  109. PAUSE_ON_FAIL="no"
  110. readonly NS0=$(mktemp -u ns0-XXXXXXXX)
  111. readonly NS1=$(mktemp -u ns1-XXXXXXXX)
  112. readonly NS2=$(mktemp -u ns2-XXXXXXXX)
  113. readonly NS3=$(mktemp -u ns3-XXXXXXXX)
  114. # Exit the script after having removed the network namespaces it created
  115. #
  116. # Parameters:
  117. #
  118. # * The list of network namespaces to delete before exiting.
  119. #
  120. exit_cleanup()
  121. {
  122. for ns in "$@"; do
  123. ip netns delete "${ns}" 2>/dev/null || true
  124. done
  125. if [ "${ERR}" -eq 4 ]; then
  126. echo "Error: Setting up the testing environment failed." >&2
  127. fi
  128. exit "${ERR}"
  129. }
  130. # Create the four network namespaces used by the script (NS0, NS1, NS2 and NS3)
  131. #
  132. # New namespaces are cleaned up manually in case of error, to ensure that only
  133. # namespaces created by this script are deleted.
  134. create_namespaces()
  135. {
  136. ip netns add "${NS0}" || exit_cleanup
  137. ip netns add "${NS1}" || exit_cleanup "${NS0}"
  138. ip netns add "${NS2}" || exit_cleanup "${NS0}" "${NS1}"
  139. ip netns add "${NS3}" || exit_cleanup "${NS0}" "${NS1}" "${NS2}"
  140. }
  141. # The trap function handler
  142. #
  143. exit_cleanup_all()
  144. {
  145. exit_cleanup "${NS0}" "${NS1}" "${NS2}" "${NS3}"
  146. }
  147. # Configure a network interface using a host route
  148. #
  149. # Parameters
  150. #
  151. # * $1: the netns the network interface resides in,
  152. # * $2: the network interface name,
  153. # * $3: the local IPv4 address to assign to this interface,
  154. # * $4: the IPv4 address of the remote network interface,
  155. # * $5: the local IPv6 address to assign to this interface,
  156. # * $6: the IPv6 address of the remote network interface.
  157. #
  158. iface_config()
  159. {
  160. local NS="${1}"; readonly NS
  161. local DEV="${2}"; readonly DEV
  162. local LOCAL_IP4="${3}"; readonly LOCAL_IP4
  163. local PEER_IP4="${4}"; readonly PEER_IP4
  164. local LOCAL_IP6="${5}"; readonly LOCAL_IP6
  165. local PEER_IP6="${6}"; readonly PEER_IP6
  166. ip -netns "${NS}" link set dev "${DEV}" up
  167. ip -netns "${NS}" address add dev "${DEV}" "${LOCAL_IP4}" peer "${PEER_IP4}"
  168. ip -netns "${NS}" address add dev "${DEV}" "${LOCAL_IP6}" peer "${PEER_IP6}" nodad
  169. }
  170. # Create base networking topology:
  171. #
  172. # * set up the loopback device in all network namespaces (NS0..NS3),
  173. # * set up a veth pair to connect each netns in sequence (NS0 with NS1,
  174. # NS1 with NS2, etc.),
  175. # * add and IPv4 and an IPv6 address on each veth interface,
  176. # * prepare the ingress qdiscs in the intermediate namespaces.
  177. #
  178. setup_underlay()
  179. {
  180. for ns in "${NS0}" "${NS1}" "${NS2}" "${NS3}"; do
  181. ip -netns "${ns}" link set dev lo up
  182. done;
  183. ip link add name veth01 netns "${NS0}" type veth peer name veth10 netns "${NS1}"
  184. ip link add name veth12 netns "${NS1}" type veth peer name veth21 netns "${NS2}"
  185. ip link add name veth23 netns "${NS2}" type veth peer name veth32 netns "${NS3}"
  186. iface_config "${NS0}" veth01 192.0.2.10 192.0.2.11/32 2001:db8::10 2001:db8::11/128
  187. iface_config "${NS1}" veth10 192.0.2.11 192.0.2.10/32 2001:db8::11 2001:db8::10/128
  188. iface_config "${NS1}" veth12 192.0.2.21 192.0.2.22/32 2001:db8::21 2001:db8::22/128
  189. iface_config "${NS2}" veth21 192.0.2.22 192.0.2.21/32 2001:db8::22 2001:db8::21/128
  190. iface_config "${NS2}" veth23 192.0.2.32 192.0.2.33/32 2001:db8::32 2001:db8::33/128
  191. iface_config "${NS3}" veth32 192.0.2.33 192.0.2.32/32 2001:db8::33 2001:db8::32/128
  192. tc -netns "${NS1}" qdisc add dev veth10 ingress
  193. tc -netns "${NS2}" qdisc add dev veth23 ingress
  194. }
  195. # Set up the IPv4, IPv6 and MPLS overlays.
  196. #
  197. # Configuration is similar for all protocols:
  198. #
  199. # * add an overlay IP address on the loopback interface of each edge
  200. # namespace,
  201. # * route these IP addresses via the intermediate namespaces (for the MPLS
  202. # tests, this is also where MPLS encapsulation is done),
  203. # * add routes for these IP addresses (or MPLS labels) in the intermediate
  204. # namespaces.
  205. #
  206. # The bareudp encapsulation isn't configured in setup_overlay_*(). That will be
  207. # done just before running the reachability tests.
  208. setup_overlay_ipv4()
  209. {
  210. # Add the overlay IP addresses and route them through the veth devices
  211. ip -netns "${NS0}" address add 192.0.2.100/32 dev lo
  212. ip -netns "${NS3}" address add 192.0.2.103/32 dev lo
  213. ip -netns "${NS0}" route add 192.0.2.103/32 src 192.0.2.100 via 192.0.2.11
  214. ip -netns "${NS3}" route add 192.0.2.100/32 src 192.0.2.103 via 192.0.2.32
  215. # Route the overlay addresses in the intermediate namespaces
  216. # (used after bareudp decapsulation)
  217. ip netns exec "${NS1}" sysctl -qw net.ipv4.ip_forward=1
  218. ip netns exec "${NS2}" sysctl -qw net.ipv4.ip_forward=1
  219. ip -netns "${NS1}" route add 192.0.2.100/32 via 192.0.2.10
  220. ip -netns "${NS2}" route add 192.0.2.103/32 via 192.0.2.33
  221. # The intermediate namespaces don't have routes for the reverse path,
  222. # as it will be handled by tc. So we need to ensure that rp_filter is
  223. # not going to block the traffic.
  224. ip netns exec "${NS1}" sysctl -qw net.ipv4.conf.all.rp_filter=0
  225. ip netns exec "${NS2}" sysctl -qw net.ipv4.conf.all.rp_filter=0
  226. ip netns exec "${NS1}" sysctl -qw net.ipv4.conf.default.rp_filter=0
  227. ip netns exec "${NS2}" sysctl -qw net.ipv4.conf.default.rp_filter=0
  228. }
  229. setup_overlay_ipv6()
  230. {
  231. # Add the overlay IP addresses and route them through the veth devices
  232. ip -netns "${NS0}" address add 2001:db8::100/128 dev lo
  233. ip -netns "${NS3}" address add 2001:db8::103/128 dev lo
  234. ip -netns "${NS0}" route add 2001:db8::103/128 src 2001:db8::100 via 2001:db8::11
  235. ip -netns "${NS3}" route add 2001:db8::100/128 src 2001:db8::103 via 2001:db8::32
  236. # Route the overlay addresses in the intermediate namespaces
  237. # (used after bareudp decapsulation)
  238. ip netns exec "${NS1}" sysctl -qw net.ipv6.conf.all.forwarding=1
  239. ip netns exec "${NS2}" sysctl -qw net.ipv6.conf.all.forwarding=1
  240. ip -netns "${NS1}" route add 2001:db8::100/128 via 2001:db8::10
  241. ip -netns "${NS2}" route add 2001:db8::103/128 via 2001:db8::33
  242. }
  243. setup_overlay_mpls()
  244. {
  245. # Add specific overlay IP addresses, routed over MPLS
  246. ip -netns "${NS0}" address add 2001:db8::200/128 dev lo
  247. ip -netns "${NS3}" address add 2001:db8::203/128 dev lo
  248. ip -netns "${NS0}" route add 2001:db8::203/128 src 2001:db8::200 encap mpls 203 via 2001:db8::11
  249. ip -netns "${NS3}" route add 2001:db8::200/128 src 2001:db8::203 encap mpls 200 via 2001:db8::32
  250. # Route the MPLS packets in the intermediate namespaces
  251. # (used after bareudp decapsulation)
  252. ip netns exec "${NS1}" sysctl -qw net.mpls.platform_labels=256
  253. ip netns exec "${NS2}" sysctl -qw net.mpls.platform_labels=256
  254. ip -netns "${NS1}" -family mpls route add 200 via inet6 2001:db8::10
  255. ip -netns "${NS2}" -family mpls route add 203 via inet6 2001:db8::33
  256. }
  257. # Run "ping" from NS0 and print the result
  258. #
  259. # Parameters:
  260. #
  261. # * $1: the variant of ping to use (normally either "ping" or "ping6"),
  262. # * $2: the IP address to ping,
  263. # * $3: a human readable description of the purpose of the test.
  264. #
  265. # If the test fails and PAUSE_ON_FAIL is active, the user is given the
  266. # possibility to continue with the next test or to quit immediately.
  267. #
  268. ping_test_one()
  269. {
  270. local PING="$1"; readonly PING
  271. local IP="$2"; readonly IP
  272. local MSG="$3"; readonly MSG
  273. local RET
  274. printf "TEST: %-60s " "${MSG}"
  275. set +e
  276. ip netns exec "${NS0}" "${PING}" -w 5 -c 1 "${IP}" > /dev/null 2>&1
  277. RET=$?
  278. set -e
  279. if [ "${RET}" -eq 0 ]; then
  280. printf "[ OK ]\n"
  281. else
  282. ERR=1
  283. printf "[FAIL]\n"
  284. if [ "${PAUSE_ON_FAIL}" = "yes" ]; then
  285. printf "\nHit enter to continue, 'q' to quit\n"
  286. read a
  287. if [ "$a" = "q" ]; then
  288. exit 1
  289. fi
  290. fi
  291. fi
  292. }
  293. # Run reachability tests
  294. #
  295. # Parameters:
  296. #
  297. # * $1: human readable string describing the underlay protocol.
  298. #
  299. # $IPV4, $IPV6, $MPLS_UC and $MULTIPROTO are inherited from the calling
  300. # function.
  301. #
  302. ping_test()
  303. {
  304. local UNDERLAY="$1"; readonly UNDERLAY
  305. local MODE
  306. local MSG
  307. if [ "${MULTIPROTO}" = "multiproto" ]; then
  308. MODE=" (multiproto mode)"
  309. else
  310. MODE=""
  311. fi
  312. if [ $IPV4 ]; then
  313. ping_test_one "ping" "192.0.2.103" "IPv4 packets over ${UNDERLAY}${MODE}"
  314. fi
  315. if [ $IPV6 ]; then
  316. ping_test_one "${PING6}" "2001:db8::103" "IPv6 packets over ${UNDERLAY}${MODE}"
  317. fi
  318. if [ $MPLS_UC ]; then
  319. ping_test_one "${PING6}" "2001:db8::203" "Unicast MPLS packets over ${UNDERLAY}${MODE}"
  320. fi
  321. }
  322. # Set up a bareudp overlay and run reachability tests over IPv4 and IPv6
  323. #
  324. # Parameters:
  325. #
  326. # * $1: the packet type (protocol) to be handled by bareudp,
  327. # * $2: a flag to activate or deactivate bareudp's "multiproto" mode.
  328. #
  329. test_overlay()
  330. {
  331. local ETHERTYPE="$1"; readonly ETHERTYPE
  332. local MULTIPROTO="$2"; readonly MULTIPROTO
  333. local IPV4
  334. local IPV6
  335. local MPLS_UC
  336. case "${ETHERTYPE}" in
  337. "ipv4")
  338. IPV4="ipv4"
  339. if [ "${MULTIPROTO}" = "multiproto" ]; then
  340. IPV6="ipv6"
  341. else
  342. IPV6=""
  343. fi
  344. MPLS_UC=""
  345. ;;
  346. "ipv6")
  347. IPV6="ipv6"
  348. IPV4=""
  349. MPLS_UC=""
  350. ;;
  351. "mpls_uc")
  352. MPLS_UC="mpls_uc"
  353. IPV4=""
  354. IPV6=""
  355. ;;
  356. *)
  357. exit 1
  358. ;;
  359. esac
  360. readonly IPV4
  361. readonly IPV6
  362. readonly MPLS_UC
  363. # Create the bareudp devices in the intermediate namespaces
  364. ip -netns "${NS1}" link add name bareudp_ns1 up type bareudp dstport 6635 ethertype "${ETHERTYPE}" "${MULTIPROTO}"
  365. ip -netns "${NS2}" link add name bareudp_ns2 up type bareudp dstport 6635 ethertype "${ETHERTYPE}" "${MULTIPROTO}"
  366. # IPv4 over UDPv4
  367. if [ $IPV4 ]; then
  368. # Encapsulation instructions for bareudp over IPv4
  369. tc -netns "${NS1}" filter add dev veth10 ingress protocol ipv4 \
  370. flower dst_ip 192.0.2.103/32 \
  371. action tunnel_key set src_ip 192.0.2.21 dst_ip 192.0.2.22 id 0 \
  372. action mirred egress redirect dev bareudp_ns1
  373. tc -netns "${NS2}" filter add dev veth23 ingress protocol ipv4 \
  374. flower dst_ip 192.0.2.100/32 \
  375. action tunnel_key set src_ip 192.0.2.22 dst_ip 192.0.2.21 id 0 \
  376. action mirred egress redirect dev bareudp_ns2
  377. fi
  378. # IPv6 over UDPv4
  379. if [ $IPV6 ]; then
  380. # Encapsulation instructions for bareudp over IPv4
  381. tc -netns "${NS1}" filter add dev veth10 ingress protocol ipv6 \
  382. flower dst_ip 2001:db8::103/128 \
  383. action tunnel_key set src_ip 192.0.2.21 dst_ip 192.0.2.22 id 0 \
  384. action mirred egress redirect dev bareudp_ns1
  385. tc -netns "${NS2}" filter add dev veth23 ingress protocol ipv6 \
  386. flower dst_ip 2001:db8::100/128 \
  387. action tunnel_key set src_ip 192.0.2.22 dst_ip 192.0.2.21 id 0 \
  388. action mirred egress redirect dev bareudp_ns2
  389. fi
  390. # MPLS (unicast) over UDPv4
  391. if [ $MPLS_UC ]; then
  392. ip netns exec "${NS1}" sysctl -qw net.mpls.conf.bareudp_ns1.input=1
  393. ip netns exec "${NS2}" sysctl -qw net.mpls.conf.bareudp_ns2.input=1
  394. # Encapsulation instructions for bareudp over IPv4
  395. tc -netns "${NS1}" filter add dev veth10 ingress protocol mpls_uc \
  396. flower mpls_label 203 \
  397. action tunnel_key set src_ip 192.0.2.21 dst_ip 192.0.2.22 id 0 \
  398. action mirred egress redirect dev bareudp_ns1
  399. tc -netns "${NS2}" filter add dev veth23 ingress protocol mpls_uc \
  400. flower mpls_label 200 \
  401. action tunnel_key set src_ip 192.0.2.22 dst_ip 192.0.2.21 id 0 \
  402. action mirred egress redirect dev bareudp_ns2
  403. fi
  404. # Test IPv4 underlay
  405. ping_test "UDPv4"
  406. # Cleanup bareudp encapsulation instructions, as they were specific to
  407. # the IPv4 underlay, before setting up and testing the IPv6 underlay
  408. tc -netns "${NS1}" filter delete dev veth10 ingress
  409. tc -netns "${NS2}" filter delete dev veth23 ingress
  410. # IPv4 over UDPv6
  411. if [ $IPV4 ]; then
  412. # New encapsulation instructions for bareudp over IPv6
  413. tc -netns "${NS1}" filter add dev veth10 ingress protocol ipv4 \
  414. flower dst_ip 192.0.2.103/32 \
  415. action tunnel_key set src_ip 2001:db8::21 dst_ip 2001:db8::22 id 0 \
  416. action mirred egress redirect dev bareudp_ns1
  417. tc -netns "${NS2}" filter add dev veth23 ingress protocol ipv4 \
  418. flower dst_ip 192.0.2.100/32 \
  419. action tunnel_key set src_ip 2001:db8::22 dst_ip 2001:db8::21 id 0 \
  420. action mirred egress redirect dev bareudp_ns2
  421. fi
  422. # IPv6 over UDPv6
  423. if [ $IPV6 ]; then
  424. # New encapsulation instructions for bareudp over IPv6
  425. tc -netns "${NS1}" filter add dev veth10 ingress protocol ipv6 \
  426. flower dst_ip 2001:db8::103/128 \
  427. action tunnel_key set src_ip 2001:db8::21 dst_ip 2001:db8::22 id 0 \
  428. action mirred egress redirect dev bareudp_ns1
  429. tc -netns "${NS2}" filter add dev veth23 ingress protocol ipv6 \
  430. flower dst_ip 2001:db8::100/128 \
  431. action tunnel_key set src_ip 2001:db8::22 dst_ip 2001:db8::21 id 0 \
  432. action mirred egress redirect dev bareudp_ns2
  433. fi
  434. # MPLS (unicast) over UDPv6
  435. if [ $MPLS_UC ]; then
  436. # New encapsulation instructions for bareudp over IPv6
  437. tc -netns "${NS1}" filter add dev veth10 ingress protocol mpls_uc \
  438. flower mpls_label 203 \
  439. action tunnel_key set src_ip 2001:db8::21 dst_ip 2001:db8::22 id 0 \
  440. action mirred egress redirect dev bareudp_ns1
  441. tc -netns "${NS2}" filter add dev veth23 ingress protocol mpls_uc \
  442. flower mpls_label 200 \
  443. action tunnel_key set src_ip 2001:db8::22 dst_ip 2001:db8::21 id 0 \
  444. action mirred egress redirect dev bareudp_ns2
  445. fi
  446. # Test IPv6 underlay
  447. ping_test "UDPv6"
  448. tc -netns "${NS1}" filter delete dev veth10 ingress
  449. tc -netns "${NS2}" filter delete dev veth23 ingress
  450. ip -netns "${NS1}" link delete bareudp_ns1
  451. ip -netns "${NS2}" link delete bareudp_ns2
  452. }
  453. check_features()
  454. {
  455. ip link help 2>&1 | grep -q bareudp
  456. if [ $? -ne 0 ]; then
  457. echo "Missing bareudp support in iproute2" >&2
  458. exit_cleanup
  459. fi
  460. # Use ping6 on systems where ping doesn't handle IPv6
  461. ping -w 1 -c 1 ::1 > /dev/null 2>&1 || PING6="ping6"
  462. }
  463. usage()
  464. {
  465. echo "Usage: $0 [-p]"
  466. exit 1
  467. }
  468. while getopts :p o
  469. do
  470. case $o in
  471. p) PAUSE_ON_FAIL="yes";;
  472. *) usage;;
  473. esac
  474. done
  475. check_features
  476. # Create namespaces before setting up the exit trap.
  477. # Otherwise, exit_cleanup_all() could delete namespaces that were not created
  478. # by this script.
  479. create_namespaces
  480. set -e
  481. trap exit_cleanup_all EXIT
  482. setup_underlay
  483. setup_overlay_ipv4
  484. setup_overlay_ipv6
  485. setup_overlay_mpls
  486. test_overlay ipv4 nomultiproto
  487. test_overlay ipv6 nomultiproto
  488. test_overlay ipv4 multiproto
  489. test_overlay mpls_uc nomultiproto
  490. if [ "${ERR}" -eq 1 ]; then
  491. echo "Some tests failed." >&2
  492. else
  493. ERR=0
  494. fi