test_tunnel.sh 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # End-to-end eBPF tunnel test suite
  4. # The script tests BPF network tunnel implementation.
  5. #
  6. # Topology:
  7. # ---------
  8. # root namespace | at_ns0 namespace
  9. # |
  10. # ----------- | -----------
  11. # | tnl dev | | | tnl dev | (overlay network)
  12. # ----------- | -----------
  13. # metadata-mode | native-mode
  14. # with bpf |
  15. # |
  16. # ---------- | ----------
  17. # | veth1 | --------- | veth0 | (underlay network)
  18. # ---------- peer ----------
  19. #
  20. #
  21. # Device Configuration
  22. # --------------------
  23. # Root namespace with metadata-mode tunnel + BPF
  24. # Device names and addresses:
  25. # veth1 IP: 172.16.1.200, IPv6: 00::22 (underlay)
  26. # tunnel dev <type>11, ex: gre11, IPv4: 10.1.1.200, IPv6: 1::22 (overlay)
  27. #
  28. # Namespace at_ns0 with native tunnel
  29. # Device names and addresses:
  30. # veth0 IPv4: 172.16.1.100, IPv6: 00::11 (underlay)
  31. # tunnel dev <type>00, ex: gre00, IPv4: 10.1.1.100, IPv6: 1::11 (overlay)
  32. #
  33. #
  34. # End-to-end ping packet flow
  35. # ---------------------------
  36. # Most of the tests start by namespace creation, device configuration,
  37. # then ping the underlay and overlay network. When doing 'ping 10.1.1.100'
  38. # from root namespace, the following operations happen:
  39. # 1) Route lookup shows 10.1.1.100/24 belongs to tnl dev, fwd to tnl dev.
  40. # 2) Tnl device's egress BPF program is triggered and set the tunnel metadata,
  41. # with remote_ip=172.16.1.100 and others.
  42. # 3) Outer tunnel header is prepended and route the packet to veth1's egress
  43. # 4) veth0's ingress queue receive the tunneled packet at namespace at_ns0
  44. # 5) Tunnel protocol handler, ex: vxlan_rcv, decap the packet
  45. # 6) Forward the packet to the overlay tnl dev
  46. BPF_FILE="test_tunnel_kern.bpf.o"
  47. BPF_PIN_TUNNEL_DIR="/sys/fs/bpf/tc/tunnel"
  48. PING_ARG="-c 3 -w 10 -q"
  49. ret=0
  50. GREEN='\033[0;92m'
  51. RED='\033[0;31m'
  52. NC='\033[0m' # No Color
  53. config_device()
  54. {
  55. ip netns add at_ns0
  56. ip link add veth0 type veth peer name veth1
  57. ip link set veth0 netns at_ns0
  58. ip netns exec at_ns0 ip addr add 172.16.1.100/24 dev veth0
  59. ip netns exec at_ns0 ip link set dev veth0 up
  60. ip link set dev veth1 up mtu 1500
  61. ip addr add dev veth1 172.16.1.200/24
  62. }
  63. add_gre_tunnel()
  64. {
  65. # at_ns0 namespace
  66. ip netns exec at_ns0 \
  67. ip link add dev $DEV_NS type $TYPE seq key 2 \
  68. local 172.16.1.100 remote 172.16.1.200
  69. ip netns exec at_ns0 ip link set dev $DEV_NS up
  70. ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
  71. # root namespace
  72. ip link add dev $DEV type $TYPE key 2 external
  73. ip link set dev $DEV up
  74. ip addr add dev $DEV 10.1.1.200/24
  75. }
  76. add_ip6gretap_tunnel()
  77. {
  78. # assign ipv6 address
  79. ip netns exec at_ns0 ip addr add ::11/96 dev veth0
  80. ip netns exec at_ns0 ip link set dev veth0 up
  81. ip addr add dev veth1 ::22/96
  82. ip link set dev veth1 up
  83. # at_ns0 namespace
  84. ip netns exec at_ns0 \
  85. ip link add dev $DEV_NS type $TYPE seq flowlabel 0xbcdef key 2 \
  86. local ::11 remote ::22
  87. ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
  88. ip netns exec at_ns0 ip addr add dev $DEV_NS fc80::100/96
  89. ip netns exec at_ns0 ip link set dev $DEV_NS up
  90. # root namespace
  91. ip link add dev $DEV type $TYPE external
  92. ip addr add dev $DEV 10.1.1.200/24
  93. ip addr add dev $DEV fc80::200/24
  94. ip link set dev $DEV up
  95. }
  96. add_erspan_tunnel()
  97. {
  98. # at_ns0 namespace
  99. if [ "$1" == "v1" ]; then
  100. ip netns exec at_ns0 \
  101. ip link add dev $DEV_NS type $TYPE seq key 2 \
  102. local 172.16.1.100 remote 172.16.1.200 \
  103. erspan_ver 1 erspan 123
  104. else
  105. ip netns exec at_ns0 \
  106. ip link add dev $DEV_NS type $TYPE seq key 2 \
  107. local 172.16.1.100 remote 172.16.1.200 \
  108. erspan_ver 2 erspan_dir egress erspan_hwid 3
  109. fi
  110. ip netns exec at_ns0 ip link set dev $DEV_NS up
  111. ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
  112. # root namespace
  113. ip link add dev $DEV type $TYPE external
  114. ip link set dev $DEV up
  115. ip addr add dev $DEV 10.1.1.200/24
  116. }
  117. add_ip6erspan_tunnel()
  118. {
  119. # assign ipv6 address
  120. ip netns exec at_ns0 ip addr add ::11/96 dev veth0
  121. ip netns exec at_ns0 ip link set dev veth0 up
  122. ip addr add dev veth1 ::22/96
  123. ip link set dev veth1 up
  124. # at_ns0 namespace
  125. if [ "$1" == "v1" ]; then
  126. ip netns exec at_ns0 \
  127. ip link add dev $DEV_NS type $TYPE seq key 2 \
  128. local ::11 remote ::22 \
  129. erspan_ver 1 erspan 123
  130. else
  131. ip netns exec at_ns0 \
  132. ip link add dev $DEV_NS type $TYPE seq key 2 \
  133. local ::11 remote ::22 \
  134. erspan_ver 2 erspan_dir egress erspan_hwid 7
  135. fi
  136. ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
  137. ip netns exec at_ns0 ip link set dev $DEV_NS up
  138. # root namespace
  139. ip link add dev $DEV type $TYPE external
  140. ip addr add dev $DEV 10.1.1.200/24
  141. ip link set dev $DEV up
  142. }
  143. add_geneve_tunnel()
  144. {
  145. # at_ns0 namespace
  146. ip netns exec at_ns0 \
  147. ip link add dev $DEV_NS type $TYPE \
  148. id 2 dstport 6081 remote 172.16.1.200
  149. ip netns exec at_ns0 ip link set dev $DEV_NS up
  150. ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
  151. # root namespace
  152. ip link add dev $DEV type $TYPE dstport 6081 external
  153. ip link set dev $DEV up
  154. ip addr add dev $DEV 10.1.1.200/24
  155. }
  156. add_ip6geneve_tunnel()
  157. {
  158. ip netns exec at_ns0 ip addr add ::11/96 dev veth0
  159. ip netns exec at_ns0 ip link set dev veth0 up
  160. ip addr add dev veth1 ::22/96
  161. ip link set dev veth1 up
  162. # at_ns0 namespace
  163. ip netns exec at_ns0 \
  164. ip link add dev $DEV_NS type $TYPE id 22 \
  165. remote ::22 # geneve has no local option
  166. ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
  167. ip netns exec at_ns0 ip link set dev $DEV_NS up
  168. # root namespace
  169. ip link add dev $DEV type $TYPE external
  170. ip addr add dev $DEV 10.1.1.200/24
  171. ip link set dev $DEV up
  172. }
  173. add_ipip_tunnel()
  174. {
  175. # at_ns0 namespace
  176. ip netns exec at_ns0 \
  177. ip link add dev $DEV_NS type $TYPE \
  178. local 172.16.1.100 remote 172.16.1.200
  179. ip netns exec at_ns0 ip link set dev $DEV_NS up
  180. ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
  181. # root namespace
  182. ip link add dev $DEV type $TYPE external
  183. ip link set dev $DEV up
  184. ip addr add dev $DEV 10.1.1.200/24
  185. }
  186. add_ip6tnl_tunnel()
  187. {
  188. ip netns exec at_ns0 ip addr add ::11/96 dev veth0
  189. ip netns exec at_ns0 ip link set dev veth0 up
  190. ip addr add dev veth1 ::22/96
  191. ip link set dev veth1 up
  192. # at_ns0 namespace
  193. ip netns exec at_ns0 \
  194. ip link add dev $DEV_NS type $TYPE \
  195. local ::11 remote ::22
  196. ip netns exec at_ns0 ip addr add dev $DEV_NS 10.1.1.100/24
  197. ip netns exec at_ns0 ip addr add dev $DEV_NS 1::11/96
  198. ip netns exec at_ns0 ip link set dev $DEV_NS up
  199. # root namespace
  200. ip link add dev $DEV type $TYPE external
  201. ip addr add dev $DEV 10.1.1.200/24
  202. ip addr add dev $DEV 1::22/96
  203. ip link set dev $DEV up
  204. }
  205. test_gre()
  206. {
  207. TYPE=gretap
  208. DEV_NS=gretap00
  209. DEV=gretap11
  210. ret=0
  211. check $TYPE
  212. config_device
  213. add_gre_tunnel
  214. attach_bpf $DEV gre_set_tunnel gre_get_tunnel
  215. ping $PING_ARG 10.1.1.100
  216. check_err $?
  217. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  218. check_err $?
  219. cleanup
  220. if [ $ret -ne 0 ]; then
  221. echo -e ${RED}"FAIL: $TYPE"${NC}
  222. return 1
  223. fi
  224. echo -e ${GREEN}"PASS: $TYPE"${NC}
  225. }
  226. test_ip6gre()
  227. {
  228. TYPE=ip6gre
  229. DEV_NS=ip6gre00
  230. DEV=ip6gre11
  231. ret=0
  232. check $TYPE
  233. config_device
  234. # reuse the ip6gretap function
  235. add_ip6gretap_tunnel
  236. attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
  237. # underlay
  238. ping6 $PING_ARG ::11
  239. # overlay: ipv4 over ipv6
  240. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  241. ping $PING_ARG 10.1.1.100
  242. check_err $?
  243. # overlay: ipv6 over ipv6
  244. ip netns exec at_ns0 ping6 $PING_ARG fc80::200
  245. check_err $?
  246. cleanup
  247. if [ $ret -ne 0 ]; then
  248. echo -e ${RED}"FAIL: $TYPE"${NC}
  249. return 1
  250. fi
  251. echo -e ${GREEN}"PASS: $TYPE"${NC}
  252. }
  253. test_ip6gretap()
  254. {
  255. TYPE=ip6gretap
  256. DEV_NS=ip6gretap00
  257. DEV=ip6gretap11
  258. ret=0
  259. check $TYPE
  260. config_device
  261. add_ip6gretap_tunnel
  262. attach_bpf $DEV ip6gretap_set_tunnel ip6gretap_get_tunnel
  263. # underlay
  264. ping6 $PING_ARG ::11
  265. # overlay: ipv4 over ipv6
  266. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  267. ping $PING_ARG 10.1.1.100
  268. check_err $?
  269. # overlay: ipv6 over ipv6
  270. ip netns exec at_ns0 ping6 $PING_ARG fc80::200
  271. check_err $?
  272. cleanup
  273. if [ $ret -ne 0 ]; then
  274. echo -e ${RED}"FAIL: $TYPE"${NC}
  275. return 1
  276. fi
  277. echo -e ${GREEN}"PASS: $TYPE"${NC}
  278. }
  279. test_erspan()
  280. {
  281. TYPE=erspan
  282. DEV_NS=erspan00
  283. DEV=erspan11
  284. ret=0
  285. check $TYPE
  286. config_device
  287. add_erspan_tunnel $1
  288. attach_bpf $DEV erspan_set_tunnel erspan_get_tunnel
  289. ping $PING_ARG 10.1.1.100
  290. check_err $?
  291. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  292. check_err $?
  293. cleanup
  294. if [ $ret -ne 0 ]; then
  295. echo -e ${RED}"FAIL: $TYPE"${NC}
  296. return 1
  297. fi
  298. echo -e ${GREEN}"PASS: $TYPE"${NC}
  299. }
  300. test_ip6erspan()
  301. {
  302. TYPE=ip6erspan
  303. DEV_NS=ip6erspan00
  304. DEV=ip6erspan11
  305. ret=0
  306. check $TYPE
  307. config_device
  308. add_ip6erspan_tunnel $1
  309. attach_bpf $DEV ip4ip6erspan_set_tunnel ip4ip6erspan_get_tunnel
  310. ping6 $PING_ARG ::11
  311. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  312. check_err $?
  313. cleanup
  314. if [ $ret -ne 0 ]; then
  315. echo -e ${RED}"FAIL: $TYPE"${NC}
  316. return 1
  317. fi
  318. echo -e ${GREEN}"PASS: $TYPE"${NC}
  319. }
  320. test_geneve()
  321. {
  322. TYPE=geneve
  323. DEV_NS=geneve00
  324. DEV=geneve11
  325. ret=0
  326. check $TYPE
  327. config_device
  328. add_geneve_tunnel
  329. attach_bpf $DEV geneve_set_tunnel geneve_get_tunnel
  330. ping $PING_ARG 10.1.1.100
  331. check_err $?
  332. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  333. check_err $?
  334. cleanup
  335. if [ $ret -ne 0 ]; then
  336. echo -e ${RED}"FAIL: $TYPE"${NC}
  337. return 1
  338. fi
  339. echo -e ${GREEN}"PASS: $TYPE"${NC}
  340. }
  341. test_ip6geneve()
  342. {
  343. TYPE=geneve
  344. DEV_NS=ip6geneve00
  345. DEV=ip6geneve11
  346. ret=0
  347. check $TYPE
  348. config_device
  349. add_ip6geneve_tunnel
  350. attach_bpf $DEV ip6geneve_set_tunnel ip6geneve_get_tunnel
  351. ping $PING_ARG 10.1.1.100
  352. check_err $?
  353. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  354. check_err $?
  355. cleanup
  356. if [ $ret -ne 0 ]; then
  357. echo -e ${RED}"FAIL: ip6$TYPE"${NC}
  358. return 1
  359. fi
  360. echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
  361. }
  362. test_ipip()
  363. {
  364. TYPE=ipip
  365. DEV_NS=ipip00
  366. DEV=ipip11
  367. ret=0
  368. check $TYPE
  369. config_device
  370. add_ipip_tunnel
  371. ip link set dev veth1 mtu 1500
  372. attach_bpf $DEV ipip_set_tunnel ipip_get_tunnel
  373. ping $PING_ARG 10.1.1.100
  374. check_err $?
  375. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  376. check_err $?
  377. cleanup
  378. if [ $ret -ne 0 ]; then
  379. echo -e ${RED}"FAIL: $TYPE"${NC}
  380. return 1
  381. fi
  382. echo -e ${GREEN}"PASS: $TYPE"${NC}
  383. }
  384. test_ipip6()
  385. {
  386. TYPE=ip6tnl
  387. DEV_NS=ipip6tnl00
  388. DEV=ipip6tnl11
  389. ret=0
  390. check $TYPE
  391. config_device
  392. add_ip6tnl_tunnel
  393. ip link set dev veth1 mtu 1500
  394. attach_bpf $DEV ipip6_set_tunnel ipip6_get_tunnel
  395. # underlay
  396. ping6 $PING_ARG ::11
  397. # ip4 over ip6
  398. ping $PING_ARG 10.1.1.100
  399. check_err $?
  400. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  401. check_err $?
  402. cleanup
  403. if [ $ret -ne 0 ]; then
  404. echo -e ${RED}"FAIL: $TYPE"${NC}
  405. return 1
  406. fi
  407. echo -e ${GREEN}"PASS: $TYPE"${NC}
  408. }
  409. test_ip6ip6()
  410. {
  411. TYPE=ip6tnl
  412. DEV_NS=ip6ip6tnl00
  413. DEV=ip6ip6tnl11
  414. ret=0
  415. check $TYPE
  416. config_device
  417. add_ip6tnl_tunnel
  418. ip link set dev veth1 mtu 1500
  419. attach_bpf $DEV ip6ip6_set_tunnel ip6ip6_get_tunnel
  420. # underlay
  421. ping6 $PING_ARG ::11
  422. # ip6 over ip6
  423. ping6 $PING_ARG 1::11
  424. check_err $?
  425. ip netns exec at_ns0 ping6 $PING_ARG 1::22
  426. check_err $?
  427. cleanup
  428. if [ $ret -ne 0 ]; then
  429. echo -e ${RED}"FAIL: ip6$TYPE"${NC}
  430. return 1
  431. fi
  432. echo -e ${GREEN}"PASS: ip6$TYPE"${NC}
  433. }
  434. setup_xfrm_tunnel()
  435. {
  436. auth=0x$(printf '1%.0s' {1..40})
  437. enc=0x$(printf '2%.0s' {1..32})
  438. spi_in_to_out=0x1
  439. spi_out_to_in=0x2
  440. # at_ns0 namespace
  441. # at_ns0 -> root
  442. ip netns exec at_ns0 \
  443. ip xfrm state add src 172.16.1.100 dst 172.16.1.200 proto esp \
  444. spi $spi_in_to_out reqid 1 mode tunnel \
  445. auth-trunc 'hmac(sha1)' $auth 96 enc 'cbc(aes)' $enc
  446. ip netns exec at_ns0 \
  447. ip xfrm policy add src 10.1.1.100/32 dst 10.1.1.200/32 dir out \
  448. tmpl src 172.16.1.100 dst 172.16.1.200 proto esp reqid 1 \
  449. mode tunnel
  450. # root -> at_ns0
  451. ip netns exec at_ns0 \
  452. ip xfrm state add src 172.16.1.200 dst 172.16.1.100 proto esp \
  453. spi $spi_out_to_in reqid 2 mode tunnel \
  454. auth-trunc 'hmac(sha1)' $auth 96 enc 'cbc(aes)' $enc
  455. ip netns exec at_ns0 \
  456. ip xfrm policy add src 10.1.1.200/32 dst 10.1.1.100/32 dir in \
  457. tmpl src 172.16.1.200 dst 172.16.1.100 proto esp reqid 2 \
  458. mode tunnel
  459. # address & route
  460. ip netns exec at_ns0 \
  461. ip addr add dev veth0 10.1.1.100/32
  462. ip netns exec at_ns0 \
  463. ip route add 10.1.1.200 dev veth0 via 172.16.1.200 \
  464. src 10.1.1.100
  465. # root namespace
  466. # at_ns0 -> root
  467. ip xfrm state add src 172.16.1.100 dst 172.16.1.200 proto esp \
  468. spi $spi_in_to_out reqid 1 mode tunnel \
  469. auth-trunc 'hmac(sha1)' $auth 96 enc 'cbc(aes)' $enc
  470. ip xfrm policy add src 10.1.1.100/32 dst 10.1.1.200/32 dir in \
  471. tmpl src 172.16.1.100 dst 172.16.1.200 proto esp reqid 1 \
  472. mode tunnel
  473. # root -> at_ns0
  474. ip xfrm state add src 172.16.1.200 dst 172.16.1.100 proto esp \
  475. spi $spi_out_to_in reqid 2 mode tunnel \
  476. auth-trunc 'hmac(sha1)' $auth 96 enc 'cbc(aes)' $enc
  477. ip xfrm policy add src 10.1.1.200/32 dst 10.1.1.100/32 dir out \
  478. tmpl src 172.16.1.200 dst 172.16.1.100 proto esp reqid 2 \
  479. mode tunnel
  480. # address & route
  481. ip addr add dev veth1 10.1.1.200/32
  482. ip route add 10.1.1.100 dev veth1 via 172.16.1.100 src 10.1.1.200
  483. }
  484. test_xfrm_tunnel()
  485. {
  486. config_device
  487. > /sys/kernel/debug/tracing/trace
  488. setup_xfrm_tunnel
  489. mkdir -p ${BPF_PIN_TUNNEL_DIR}
  490. bpftool prog loadall ${BPF_FILE} ${BPF_PIN_TUNNEL_DIR}
  491. tc qdisc add dev veth1 clsact
  492. tc filter add dev veth1 proto ip ingress bpf da object-pinned \
  493. ${BPF_PIN_TUNNEL_DIR}/xfrm_get_state
  494. ip netns exec at_ns0 ping $PING_ARG 10.1.1.200
  495. sleep 1
  496. grep "reqid 1" /sys/kernel/debug/tracing/trace
  497. check_err $?
  498. grep "spi 0x1" /sys/kernel/debug/tracing/trace
  499. check_err $?
  500. grep "remote ip 0xac100164" /sys/kernel/debug/tracing/trace
  501. check_err $?
  502. cleanup
  503. if [ $ret -ne 0 ]; then
  504. echo -e ${RED}"FAIL: xfrm tunnel"${NC}
  505. return 1
  506. fi
  507. echo -e ${GREEN}"PASS: xfrm tunnel"${NC}
  508. }
  509. attach_bpf()
  510. {
  511. DEV=$1
  512. SET=$2
  513. GET=$3
  514. mkdir -p ${BPF_PIN_TUNNEL_DIR}
  515. bpftool prog loadall ${BPF_FILE} ${BPF_PIN_TUNNEL_DIR}/
  516. tc qdisc add dev $DEV clsact
  517. tc filter add dev $DEV egress bpf da object-pinned ${BPF_PIN_TUNNEL_DIR}/$SET
  518. tc filter add dev $DEV ingress bpf da object-pinned ${BPF_PIN_TUNNEL_DIR}/$GET
  519. }
  520. cleanup()
  521. {
  522. rm -rf ${BPF_PIN_TUNNEL_DIR}
  523. ip netns delete at_ns0 2> /dev/null
  524. ip link del veth1 2> /dev/null
  525. ip link del ipip11 2> /dev/null
  526. ip link del ipip6tnl11 2> /dev/null
  527. ip link del ip6ip6tnl11 2> /dev/null
  528. ip link del gretap11 2> /dev/null
  529. ip link del ip6gre11 2> /dev/null
  530. ip link del ip6gretap11 2> /dev/null
  531. ip link del geneve11 2> /dev/null
  532. ip link del ip6geneve11 2> /dev/null
  533. ip link del erspan11 2> /dev/null
  534. ip link del ip6erspan11 2> /dev/null
  535. ip xfrm policy delete dir out src 10.1.1.200/32 dst 10.1.1.100/32 2> /dev/null
  536. ip xfrm policy delete dir in src 10.1.1.100/32 dst 10.1.1.200/32 2> /dev/null
  537. ip xfrm state delete src 172.16.1.100 dst 172.16.1.200 proto esp spi 0x1 2> /dev/null
  538. ip xfrm state delete src 172.16.1.200 dst 172.16.1.100 proto esp spi 0x2 2> /dev/null
  539. }
  540. cleanup_exit()
  541. {
  542. echo "CATCH SIGKILL or SIGINT, cleanup and exit"
  543. cleanup
  544. exit 0
  545. }
  546. check()
  547. {
  548. ip link help 2>&1 | grep -q "\s$1\s"
  549. if [ $? -ne 0 ];then
  550. echo "SKIP $1: iproute2 not support"
  551. cleanup
  552. return 1
  553. fi
  554. }
  555. enable_debug()
  556. {
  557. echo 'file ip_gre.c +p' > /sys/kernel/debug/dynamic_debug/control
  558. echo 'file ip6_gre.c +p' > /sys/kernel/debug/dynamic_debug/control
  559. echo 'file geneve.c +p' > /sys/kernel/debug/dynamic_debug/control
  560. echo 'file ipip.c +p' > /sys/kernel/debug/dynamic_debug/control
  561. }
  562. check_err()
  563. {
  564. if [ $ret -eq 0 ]; then
  565. ret=$1
  566. fi
  567. }
  568. bpf_tunnel_test()
  569. {
  570. local errors=0
  571. echo "Testing GRE tunnel..."
  572. test_gre
  573. errors=$(( $errors + $? ))
  574. echo "Testing IP6GRE tunnel..."
  575. test_ip6gre
  576. errors=$(( $errors + $? ))
  577. echo "Testing IP6GRETAP tunnel..."
  578. test_ip6gretap
  579. errors=$(( $errors + $? ))
  580. echo "Testing ERSPAN tunnel..."
  581. test_erspan v2
  582. errors=$(( $errors + $? ))
  583. echo "Testing IP6ERSPAN tunnel..."
  584. test_ip6erspan v2
  585. errors=$(( $errors + $? ))
  586. echo "Testing GENEVE tunnel..."
  587. test_geneve
  588. errors=$(( $errors + $? ))
  589. echo "Testing IP6GENEVE tunnel..."
  590. test_ip6geneve
  591. errors=$(( $errors + $? ))
  592. echo "Testing IPIP tunnel..."
  593. test_ipip
  594. errors=$(( $errors + $? ))
  595. echo "Testing IPIP6 tunnel..."
  596. test_ipip6
  597. errors=$(( $errors + $? ))
  598. echo "Testing IP6IP6 tunnel..."
  599. test_ip6ip6
  600. errors=$(( $errors + $? ))
  601. echo "Testing IPSec tunnel..."
  602. test_xfrm_tunnel
  603. errors=$(( $errors + $? ))
  604. return $errors
  605. }
  606. trap cleanup 0 3 6
  607. trap cleanup_exit 2 9
  608. cleanup
  609. bpf_tunnel_test
  610. if [ $? -ne 0 ]; then
  611. echo -e "$(basename $0): ${RED}FAIL${NC}"
  612. exit 1
  613. fi
  614. echo -e "$(basename $0): ${GREEN}PASS${NC}"
  615. exit 0