rtnetlink.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. #!/bin/sh
  2. #
  3. # This test is for checking rtnetlink callpaths, and get as much coverage as possible.
  4. #
  5. # set -e
  6. devdummy="test-dummy0"
  7. ret=0
  8. # set global exit status, but never reset nonzero one.
  9. check_err()
  10. {
  11. if [ $ret -eq 0 ]; then
  12. ret=$1
  13. fi
  14. }
  15. # same but inverted -- used when command must fail for test to pass
  16. check_fail()
  17. {
  18. if [ $1 -eq 0 ]; then
  19. ret=1
  20. fi
  21. }
  22. kci_add_dummy()
  23. {
  24. ip link add name "$devdummy" type dummy
  25. check_err $?
  26. ip link set "$devdummy" up
  27. check_err $?
  28. }
  29. kci_del_dummy()
  30. {
  31. ip link del dev "$devdummy"
  32. check_err $?
  33. }
  34. kci_test_netconf()
  35. {
  36. dev="$1"
  37. r=$ret
  38. ip netconf show dev "$dev" > /dev/null
  39. check_err $?
  40. for f in 4 6; do
  41. ip -$f netconf show dev "$dev" > /dev/null
  42. check_err $?
  43. done
  44. if [ $ret -ne 0 ] ;then
  45. echo "FAIL: ip netconf show $dev"
  46. test $r -eq 0 && ret=0
  47. return 1
  48. fi
  49. }
  50. # add a bridge with vlans on top
  51. kci_test_bridge()
  52. {
  53. devbr="test-br0"
  54. vlandev="testbr-vlan1"
  55. ret=0
  56. ip link add name "$devbr" type bridge
  57. check_err $?
  58. ip link set dev "$devdummy" master "$devbr"
  59. check_err $?
  60. ip link set "$devbr" up
  61. check_err $?
  62. ip link add link "$devbr" name "$vlandev" type vlan id 1
  63. check_err $?
  64. ip addr add dev "$vlandev" 10.200.7.23/30
  65. check_err $?
  66. ip -6 addr add dev "$vlandev" dead:42::1234/64
  67. check_err $?
  68. ip -d link > /dev/null
  69. check_err $?
  70. ip r s t all > /dev/null
  71. check_err $?
  72. for name in "$devbr" "$vlandev" "$devdummy" ; do
  73. kci_test_netconf "$name"
  74. done
  75. ip -6 addr del dev "$vlandev" dead:42::1234/64
  76. check_err $?
  77. ip link del dev "$vlandev"
  78. check_err $?
  79. ip link del dev "$devbr"
  80. check_err $?
  81. if [ $ret -ne 0 ];then
  82. echo "FAIL: bridge setup"
  83. return 1
  84. fi
  85. echo "PASS: bridge setup"
  86. }
  87. kci_test_gre()
  88. {
  89. gredev=neta
  90. rem=10.42.42.1
  91. loc=10.0.0.1
  92. ret=0
  93. ip tunnel add $gredev mode gre remote $rem local $loc ttl 1
  94. check_err $?
  95. ip link set $gredev up
  96. check_err $?
  97. ip addr add 10.23.7.10 dev $gredev
  98. check_err $?
  99. ip route add 10.23.8.0/30 dev $gredev
  100. check_err $?
  101. ip addr add dev "$devdummy" 10.23.7.11/24
  102. check_err $?
  103. ip link > /dev/null
  104. check_err $?
  105. ip addr > /dev/null
  106. check_err $?
  107. kci_test_netconf "$gredev"
  108. ip addr del dev "$devdummy" 10.23.7.11/24
  109. check_err $?
  110. ip link del $gredev
  111. check_err $?
  112. if [ $ret -ne 0 ];then
  113. echo "FAIL: gre tunnel endpoint"
  114. return 1
  115. fi
  116. echo "PASS: gre tunnel endpoint"
  117. }
  118. # tc uses rtnetlink too, for full tc testing
  119. # please see tools/testing/selftests/tc-testing.
  120. kci_test_tc()
  121. {
  122. dev=lo
  123. ret=0
  124. tc qdisc add dev "$dev" root handle 1: htb
  125. check_err $?
  126. tc class add dev "$dev" parent 1: classid 1:10 htb rate 1mbit
  127. check_err $?
  128. tc filter add dev "$dev" parent 1:0 prio 5 handle ffe: protocol ip u32 divisor 256
  129. check_err $?
  130. tc filter add dev "$dev" parent 1:0 prio 5 handle ffd: protocol ip u32 divisor 256
  131. check_err $?
  132. tc filter add dev "$dev" parent 1:0 prio 5 handle ffc: protocol ip u32 divisor 256
  133. check_err $?
  134. tc filter add dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32 ht ffe:2: match ip src 10.0.0.3 flowid 1:10
  135. check_err $?
  136. tc filter add dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:2 u32 ht ffe:2: match ip src 10.0.0.2 flowid 1:10
  137. check_err $?
  138. tc filter show dev "$dev" parent 1:0 > /dev/null
  139. check_err $?
  140. tc filter del dev "$dev" protocol ip parent 1: prio 5 handle ffe:2:3 u32
  141. check_err $?
  142. tc filter show dev "$dev" parent 1:0 > /dev/null
  143. check_err $?
  144. tc qdisc del dev "$dev" root handle 1: htb
  145. check_err $?
  146. if [ $ret -ne 0 ];then
  147. echo "FAIL: tc htb hierarchy"
  148. return 1
  149. fi
  150. echo "PASS: tc htb hierarchy"
  151. }
  152. kci_test_polrouting()
  153. {
  154. ret=0
  155. ip rule add fwmark 1 lookup 100
  156. check_err $?
  157. ip route add local 0.0.0.0/0 dev lo table 100
  158. check_err $?
  159. ip r s t all > /dev/null
  160. check_err $?
  161. ip rule del fwmark 1 lookup 100
  162. check_err $?
  163. ip route del local 0.0.0.0/0 dev lo table 100
  164. check_err $?
  165. if [ $ret -ne 0 ];then
  166. echo "FAIL: policy route test"
  167. return 1
  168. fi
  169. echo "PASS: policy routing"
  170. }
  171. kci_test_route_get()
  172. {
  173. ret=0
  174. ip route get 127.0.0.1 > /dev/null
  175. check_err $?
  176. ip route get 127.0.0.1 dev "$devdummy" > /dev/null
  177. check_err $?
  178. ip route get ::1 > /dev/null
  179. check_err $?
  180. ip route get fe80::1 dev "$devdummy" > /dev/null
  181. check_err $?
  182. ip route get 127.0.0.1 from 127.0.0.1 oif lo tos 0x1 mark 0x1 > /dev/null
  183. check_err $?
  184. ip route get ::1 from ::1 iif lo oif lo tos 0x1 mark 0x1 > /dev/null
  185. check_err $?
  186. ip addr add dev "$devdummy" 10.23.7.11/24
  187. check_err $?
  188. ip route get 10.23.7.11 from 10.23.7.12 iif "$devdummy" > /dev/null
  189. check_err $?
  190. ip addr del dev "$devdummy" 10.23.7.11/24
  191. check_err $?
  192. if [ $ret -ne 0 ];then
  193. echo "FAIL: route get"
  194. return 1
  195. fi
  196. echo "PASS: route get"
  197. }
  198. kci_test_addrlabel()
  199. {
  200. ret=0
  201. ip addrlabel add prefix dead::/64 dev lo label 1
  202. check_err $?
  203. ip addrlabel list |grep -q "prefix dead::/64 dev lo label 1"
  204. check_err $?
  205. ip addrlabel del prefix dead::/64 dev lo label 1 2> /dev/null
  206. check_err $?
  207. ip addrlabel add prefix dead::/64 label 1 2> /dev/null
  208. check_err $?
  209. ip addrlabel del prefix dead::/64 label 1 2> /dev/null
  210. check_err $?
  211. # concurrent add/delete
  212. for i in $(seq 1 1000); do
  213. ip addrlabel add prefix 1c3::/64 label 12345 2>/dev/null
  214. done &
  215. for i in $(seq 1 1000); do
  216. ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
  217. done
  218. wait
  219. ip addrlabel del prefix 1c3::/64 label 12345 2>/dev/null
  220. if [ $ret -ne 0 ];then
  221. echo "FAIL: ipv6 addrlabel"
  222. return 1
  223. fi
  224. echo "PASS: ipv6 addrlabel"
  225. }
  226. kci_test_ifalias()
  227. {
  228. ret=0
  229. namewant=$(uuidgen)
  230. syspathname="/sys/class/net/$devdummy/ifalias"
  231. ip link set dev "$devdummy" alias "$namewant"
  232. check_err $?
  233. if [ $ret -ne 0 ]; then
  234. echo "FAIL: cannot set interface alias of $devdummy to $namewant"
  235. return 1
  236. fi
  237. ip link show "$devdummy" | grep -q "alias $namewant"
  238. check_err $?
  239. if [ -r "$syspathname" ] ; then
  240. read namehave < "$syspathname"
  241. if [ "$namewant" != "$namehave" ]; then
  242. echo "FAIL: did set ifalias $namewant but got $namehave"
  243. return 1
  244. fi
  245. namewant=$(uuidgen)
  246. echo "$namewant" > "$syspathname"
  247. ip link show "$devdummy" | grep -q "alias $namewant"
  248. check_err $?
  249. # sysfs interface allows to delete alias again
  250. echo "" > "$syspathname"
  251. ip link show "$devdummy" | grep -q "alias $namewant"
  252. check_fail $?
  253. for i in $(seq 1 100); do
  254. uuidgen > "$syspathname" &
  255. done
  256. wait
  257. # re-add the alias -- kernel should free mem when dummy dev is removed
  258. ip link set dev "$devdummy" alias "$namewant"
  259. check_err $?
  260. fi
  261. if [ $ret -ne 0 ]; then
  262. echo "FAIL: set interface alias $devdummy to $namewant"
  263. return 1
  264. fi
  265. echo "PASS: set ifalias $namewant for $devdummy"
  266. }
  267. kci_test_vrf()
  268. {
  269. vrfname="test-vrf"
  270. ret=0
  271. ip link show type vrf 2>/dev/null
  272. if [ $? -ne 0 ]; then
  273. echo "SKIP: vrf: iproute2 too old"
  274. return 0
  275. fi
  276. ip link add "$vrfname" type vrf table 10
  277. check_err $?
  278. if [ $ret -ne 0 ];then
  279. echo "FAIL: can't add vrf interface, skipping test"
  280. return 0
  281. fi
  282. ip -br link show type vrf | grep -q "$vrfname"
  283. check_err $?
  284. if [ $ret -ne 0 ];then
  285. echo "FAIL: created vrf device not found"
  286. return 1
  287. fi
  288. ip link set dev "$vrfname" up
  289. check_err $?
  290. ip link set dev "$devdummy" master "$vrfname"
  291. check_err $?
  292. ip link del dev "$vrfname"
  293. check_err $?
  294. if [ $ret -ne 0 ];then
  295. echo "FAIL: vrf"
  296. return 1
  297. fi
  298. echo "PASS: vrf"
  299. }
  300. kci_test_encap_vxlan()
  301. {
  302. ret=0
  303. vxlan="test-vxlan0"
  304. vlan="test-vlan0"
  305. testns="$1"
  306. ip netns exec "$testns" ip link add "$vxlan" type vxlan id 42 group 239.1.1.1 \
  307. dev "$devdummy" dstport 4789 2>/dev/null
  308. if [ $? -ne 0 ]; then
  309. echo "FAIL: can't add vxlan interface, skipping test"
  310. return 0
  311. fi
  312. check_err $?
  313. ip netns exec "$testns" ip addr add 10.2.11.49/24 dev "$vxlan"
  314. check_err $?
  315. ip netns exec "$testns" ip link set up dev "$vxlan"
  316. check_err $?
  317. ip netns exec "$testns" ip link add link "$vxlan" name "$vlan" type vlan id 1
  318. check_err $?
  319. ip netns exec "$testns" ip link del "$vxlan"
  320. check_err $?
  321. if [ $ret -ne 0 ]; then
  322. echo "FAIL: vxlan"
  323. return 1
  324. fi
  325. echo "PASS: vxlan"
  326. }
  327. kci_test_encap_fou()
  328. {
  329. ret=0
  330. name="test-fou"
  331. testns="$1"
  332. ip fou help 2>&1 |grep -q 'Usage: ip fou'
  333. if [ $? -ne 0 ];then
  334. echo "SKIP: fou: iproute2 too old"
  335. return 1
  336. fi
  337. ip netns exec "$testns" ip fou add port 7777 ipproto 47 2>/dev/null
  338. if [ $? -ne 0 ];then
  339. echo "FAIL: can't add fou port 7777, skipping test"
  340. return 1
  341. fi
  342. ip netns exec "$testns" ip fou add port 8888 ipproto 4
  343. check_err $?
  344. ip netns exec "$testns" ip fou del port 9999 2>/dev/null
  345. check_fail $?
  346. ip netns exec "$testns" ip fou del port 7777
  347. check_err $?
  348. if [ $ret -ne 0 ]; then
  349. echo "FAIL: fou"
  350. return 1
  351. fi
  352. echo "PASS: fou"
  353. }
  354. # test various encap methods, use netns to avoid unwanted interference
  355. kci_test_encap()
  356. {
  357. testns="testns"
  358. ret=0
  359. ip netns add "$testns"
  360. if [ $? -ne 0 ]; then
  361. echo "SKIP encap tests: cannot add net namespace $testns"
  362. return 1
  363. fi
  364. ip netns exec "$testns" ip link set lo up
  365. check_err $?
  366. ip netns exec "$testns" ip link add name "$devdummy" type dummy
  367. check_err $?
  368. ip netns exec "$testns" ip link set "$devdummy" up
  369. check_err $?
  370. kci_test_encap_vxlan "$testns"
  371. kci_test_encap_fou "$testns"
  372. ip netns del "$testns"
  373. }
  374. kci_test_macsec()
  375. {
  376. msname="test_macsec0"
  377. ret=0
  378. ip macsec help 2>&1 | grep -q "^Usage: ip macsec"
  379. if [ $? -ne 0 ]; then
  380. echo "SKIP: macsec: iproute2 too old"
  381. return 0
  382. fi
  383. ip link add link "$devdummy" "$msname" type macsec port 42 encrypt on
  384. check_err $?
  385. if [ $ret -ne 0 ];then
  386. echo "FAIL: can't add macsec interface, skipping test"
  387. return 1
  388. fi
  389. ip macsec add "$msname" tx sa 0 pn 1024 on key 01 12345678901234567890123456789012
  390. check_err $?
  391. ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef"
  392. check_err $?
  393. ip macsec add "$msname" rx port 1234 address "1c:ed:de:ad:be:ef" sa 0 pn 1 on key 00 0123456789abcdef0123456789abcdef
  394. check_err $?
  395. ip macsec show > /dev/null
  396. check_err $?
  397. ip link del dev "$msname"
  398. check_err $?
  399. if [ $ret -ne 0 ];then
  400. echo "FAIL: macsec"
  401. return 1
  402. fi
  403. echo "PASS: macsec"
  404. }
  405. #-------------------------------------------------------------------
  406. # Example commands
  407. # ip x s add proto esp src 14.0.0.52 dst 14.0.0.70 \
  408. # spi 0x07 mode transport reqid 0x07 replay-window 32 \
  409. # aead 'rfc4106(gcm(aes))' 1234567890123456dcba 128 \
  410. # sel src 14.0.0.52/24 dst 14.0.0.70/24
  411. # ip x p add dir out src 14.0.0.52/24 dst 14.0.0.70/24 \
  412. # tmpl proto esp src 14.0.0.52 dst 14.0.0.70 \
  413. # spi 0x07 mode transport reqid 0x07
  414. #
  415. # Subcommands not tested
  416. # ip x s update
  417. # ip x s allocspi
  418. # ip x s deleteall
  419. # ip x p update
  420. # ip x p deleteall
  421. # ip x p set
  422. #-------------------------------------------------------------------
  423. kci_test_ipsec()
  424. {
  425. srcip="14.0.0.52"
  426. dstip="14.0.0.70"
  427. algo="aead rfc4106(gcm(aes)) 0x3132333435363738393031323334353664636261 128"
  428. # flush to be sure there's nothing configured
  429. ip x s flush ; ip x p flush
  430. check_err $?
  431. # start the monitor in the background
  432. tmpfile=`mktemp ipsectestXXX`
  433. ip x m > $tmpfile &
  434. mpid=$!
  435. sleep 0.2
  436. ipsecid="proto esp src $srcip dst $dstip spi 0x07"
  437. ip x s add $ipsecid \
  438. mode transport reqid 0x07 replay-window 32 \
  439. $algo sel src $srcip/24 dst $dstip/24
  440. check_err $?
  441. lines=`ip x s list | grep $srcip | grep $dstip | wc -l`
  442. test $lines -eq 2
  443. check_err $?
  444. ip x s count | grep -q "SAD count 1"
  445. check_err $?
  446. lines=`ip x s get $ipsecid | grep $srcip | grep $dstip | wc -l`
  447. test $lines -eq 2
  448. check_err $?
  449. ip x s delete $ipsecid
  450. check_err $?
  451. lines=`ip x s list | wc -l`
  452. test $lines -eq 0
  453. check_err $?
  454. ipsecsel="dir out src $srcip/24 dst $dstip/24"
  455. ip x p add $ipsecsel \
  456. tmpl proto esp src $srcip dst $dstip \
  457. spi 0x07 mode transport reqid 0x07
  458. check_err $?
  459. lines=`ip x p list | grep $srcip | grep $dstip | wc -l`
  460. test $lines -eq 2
  461. check_err $?
  462. ip x p count | grep -q "SPD IN 0 OUT 1 FWD 0"
  463. check_err $?
  464. lines=`ip x p get $ipsecsel | grep $srcip | grep $dstip | wc -l`
  465. test $lines -eq 2
  466. check_err $?
  467. ip x p delete $ipsecsel
  468. check_err $?
  469. lines=`ip x p list | wc -l`
  470. test $lines -eq 0
  471. check_err $?
  472. # check the monitor results
  473. kill $mpid
  474. lines=`wc -l $tmpfile | cut "-d " -f1`
  475. test $lines -eq 20
  476. check_err $?
  477. rm -rf $tmpfile
  478. # clean up any leftovers
  479. ip x s flush
  480. check_err $?
  481. ip x p flush
  482. check_err $?
  483. if [ $ret -ne 0 ]; then
  484. echo "FAIL: ipsec"
  485. return 1
  486. fi
  487. echo "PASS: ipsec"
  488. }
  489. kci_test_gretap()
  490. {
  491. testns="testns"
  492. DEV_NS=gretap00
  493. ret=0
  494. ip netns add "$testns"
  495. if [ $? -ne 0 ]; then
  496. echo "SKIP gretap tests: cannot add net namespace $testns"
  497. return 1
  498. fi
  499. ip link help gretap 2>&1 | grep -q "^Usage:"
  500. if [ $? -ne 0 ];then
  501. echo "SKIP: gretap: iproute2 too old"
  502. ip netns del "$testns"
  503. return 1
  504. fi
  505. # test native tunnel
  506. ip netns exec "$testns" ip link add dev "$DEV_NS" type gretap seq \
  507. key 102 local 172.16.1.100 remote 172.16.1.200
  508. check_err $?
  509. ip netns exec "$testns" ip addr add dev "$DEV_NS" 10.1.1.100/24
  510. check_err $?
  511. ip netns exec "$testns" ip link set dev $DEV_NS up
  512. check_err $?
  513. ip netns exec "$testns" ip link del "$DEV_NS"
  514. check_err $?
  515. # test external mode
  516. ip netns exec "$testns" ip link add dev "$DEV_NS" type gretap external
  517. check_err $?
  518. ip netns exec "$testns" ip link del "$DEV_NS"
  519. check_err $?
  520. if [ $ret -ne 0 ]; then
  521. echo "FAIL: gretap"
  522. ip netns del "$testns"
  523. return 1
  524. fi
  525. echo "PASS: gretap"
  526. ip netns del "$testns"
  527. }
  528. kci_test_ip6gretap()
  529. {
  530. testns="testns"
  531. DEV_NS=ip6gretap00
  532. ret=0
  533. ip netns add "$testns"
  534. if [ $? -ne 0 ]; then
  535. echo "SKIP ip6gretap tests: cannot add net namespace $testns"
  536. return 1
  537. fi
  538. ip link help ip6gretap 2>&1 | grep -q "^Usage:"
  539. if [ $? -ne 0 ];then
  540. echo "SKIP: ip6gretap: iproute2 too old"
  541. ip netns del "$testns"
  542. return 1
  543. fi
  544. # test native tunnel
  545. ip netns exec "$testns" ip link add dev "$DEV_NS" type ip6gretap seq \
  546. key 102 local fc00:100::1 remote fc00:100::2
  547. check_err $?
  548. ip netns exec "$testns" ip addr add dev "$DEV_NS" fc00:200::1/96
  549. check_err $?
  550. ip netns exec "$testns" ip link set dev $DEV_NS up
  551. check_err $?
  552. ip netns exec "$testns" ip link del "$DEV_NS"
  553. check_err $?
  554. # test external mode
  555. ip netns exec "$testns" ip link add dev "$DEV_NS" type ip6gretap external
  556. check_err $?
  557. ip netns exec "$testns" ip link del "$DEV_NS"
  558. check_err $?
  559. if [ $ret -ne 0 ]; then
  560. echo "FAIL: ip6gretap"
  561. ip netns del "$testns"
  562. return 1
  563. fi
  564. echo "PASS: ip6gretap"
  565. ip netns del "$testns"
  566. }
  567. kci_test_erspan()
  568. {
  569. testns="testns"
  570. DEV_NS=erspan00
  571. ret=0
  572. ip link help erspan 2>&1 | grep -q "^Usage:"
  573. if [ $? -ne 0 ];then
  574. echo "SKIP: erspan: iproute2 too old"
  575. return 1
  576. fi
  577. ip netns add "$testns"
  578. if [ $? -ne 0 ]; then
  579. echo "SKIP erspan tests: cannot add net namespace $testns"
  580. return 1
  581. fi
  582. # test native tunnel erspan v1
  583. ip netns exec "$testns" ip link add dev "$DEV_NS" type erspan seq \
  584. key 102 local 172.16.1.100 remote 172.16.1.200 \
  585. erspan_ver 1 erspan 488
  586. check_err $?
  587. ip netns exec "$testns" ip addr add dev "$DEV_NS" 10.1.1.100/24
  588. check_err $?
  589. ip netns exec "$testns" ip link set dev $DEV_NS up
  590. check_err $?
  591. ip netns exec "$testns" ip link del "$DEV_NS"
  592. check_err $?
  593. # test native tunnel erspan v2
  594. ip netns exec "$testns" ip link add dev "$DEV_NS" type erspan seq \
  595. key 102 local 172.16.1.100 remote 172.16.1.200 \
  596. erspan_ver 2 erspan_dir ingress erspan_hwid 7
  597. check_err $?
  598. ip netns exec "$testns" ip addr add dev "$DEV_NS" 10.1.1.100/24
  599. check_err $?
  600. ip netns exec "$testns" ip link set dev $DEV_NS up
  601. check_err $?
  602. ip netns exec "$testns" ip link del "$DEV_NS"
  603. check_err $?
  604. # test external mode
  605. ip netns exec "$testns" ip link add dev "$DEV_NS" type erspan external
  606. check_err $?
  607. ip netns exec "$testns" ip link del "$DEV_NS"
  608. check_err $?
  609. if [ $ret -ne 0 ]; then
  610. echo "FAIL: erspan"
  611. ip netns del "$testns"
  612. return 1
  613. fi
  614. echo "PASS: erspan"
  615. ip netns del "$testns"
  616. }
  617. kci_test_ip6erspan()
  618. {
  619. testns="testns"
  620. DEV_NS=ip6erspan00
  621. ret=0
  622. ip link help ip6erspan 2>&1 | grep -q "^Usage:"
  623. if [ $? -ne 0 ];then
  624. echo "SKIP: ip6erspan: iproute2 too old"
  625. return 1
  626. fi
  627. ip netns add "$testns"
  628. if [ $? -ne 0 ]; then
  629. echo "SKIP ip6erspan tests: cannot add net namespace $testns"
  630. return 1
  631. fi
  632. # test native tunnel ip6erspan v1
  633. ip netns exec "$testns" ip link add dev "$DEV_NS" type ip6erspan seq \
  634. key 102 local fc00:100::1 remote fc00:100::2 \
  635. erspan_ver 1 erspan 488
  636. check_err $?
  637. ip netns exec "$testns" ip addr add dev "$DEV_NS" 10.1.1.100/24
  638. check_err $?
  639. ip netns exec "$testns" ip link set dev $DEV_NS up
  640. check_err $?
  641. ip netns exec "$testns" ip link del "$DEV_NS"
  642. check_err $?
  643. # test native tunnel ip6erspan v2
  644. ip netns exec "$testns" ip link add dev "$DEV_NS" type ip6erspan seq \
  645. key 102 local fc00:100::1 remote fc00:100::2 \
  646. erspan_ver 2 erspan_dir ingress erspan_hwid 7
  647. check_err $?
  648. ip netns exec "$testns" ip addr add dev "$DEV_NS" 10.1.1.100/24
  649. check_err $?
  650. ip netns exec "$testns" ip link set dev $DEV_NS up
  651. check_err $?
  652. ip netns exec "$testns" ip link del "$DEV_NS"
  653. check_err $?
  654. # test external mode
  655. ip netns exec "$testns" ip link add dev "$DEV_NS" \
  656. type ip6erspan external
  657. check_err $?
  658. ip netns exec "$testns" ip link del "$DEV_NS"
  659. check_err $?
  660. if [ $ret -ne 0 ]; then
  661. echo "FAIL: ip6erspan"
  662. ip netns del "$testns"
  663. return 1
  664. fi
  665. echo "PASS: ip6erspan"
  666. ip netns del "$testns"
  667. }
  668. kci_test_rtnl()
  669. {
  670. kci_add_dummy
  671. if [ $ret -ne 0 ];then
  672. echo "FAIL: cannot add dummy interface"
  673. return 1
  674. fi
  675. kci_test_polrouting
  676. kci_test_route_get
  677. kci_test_tc
  678. kci_test_gre
  679. kci_test_gretap
  680. kci_test_ip6gretap
  681. kci_test_erspan
  682. kci_test_ip6erspan
  683. kci_test_bridge
  684. kci_test_addrlabel
  685. kci_test_ifalias
  686. kci_test_vrf
  687. kci_test_encap
  688. kci_test_macsec
  689. kci_test_ipsec
  690. kci_del_dummy
  691. }
  692. #check for needed privileges
  693. if [ "$(id -u)" -ne 0 ];then
  694. echo "SKIP: Need root privileges"
  695. exit 0
  696. fi
  697. for x in ip tc;do
  698. $x -Version 2>/dev/null >/dev/null
  699. if [ $? -ne 0 ];then
  700. echo "SKIP: Could not run test without the $x tool"
  701. exit 0
  702. fi
  703. done
  704. kci_test_rtnl
  705. exit $ret