tc_flower.sh 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
  4. match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \
  5. match_ip_tos_test match_indev_test match_ip_ttl_test
  6. match_mpls_label_test \
  7. match_mpls_tc_test match_mpls_bos_test match_mpls_ttl_test \
  8. match_mpls_lse_test"
  9. NUM_NETIFS=2
  10. source tc_common.sh
  11. source lib.sh
  12. tcflags="skip_hw"
  13. h1_create()
  14. {
  15. simple_if_init $h1 192.0.2.1/24 198.51.100.1/24
  16. }
  17. h1_destroy()
  18. {
  19. simple_if_fini $h1 192.0.2.1/24 198.51.100.1/24
  20. }
  21. h2_create()
  22. {
  23. simple_if_init $h2 192.0.2.2/24 198.51.100.2/24
  24. tc qdisc add dev $h2 clsact
  25. }
  26. h2_destroy()
  27. {
  28. tc qdisc del dev $h2 clsact
  29. simple_if_fini $h2 192.0.2.2/24 198.51.100.2/24
  30. }
  31. match_dst_mac_test()
  32. {
  33. local dummy_mac=de:ad:be:ef:aa:aa
  34. RET=0
  35. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  36. $tcflags dst_mac $dummy_mac action drop
  37. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  38. $tcflags dst_mac $h2mac action drop
  39. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  40. -t ip -q
  41. tc_check_packets "dev $h2 ingress" 101 1
  42. check_fail $? "Matched on a wrong filter"
  43. tc_check_packets "dev $h2 ingress" 102 0
  44. check_fail $? "Did not match on correct filter"
  45. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  46. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  47. log_test "dst_mac match ($tcflags)"
  48. }
  49. match_src_mac_test()
  50. {
  51. local dummy_mac=de:ad:be:ef:aa:aa
  52. RET=0
  53. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  54. $tcflags src_mac $dummy_mac action drop
  55. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  56. $tcflags src_mac $h1mac action drop
  57. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  58. -t ip -q
  59. tc_check_packets "dev $h2 ingress" 101 1
  60. check_fail $? "Matched on a wrong filter"
  61. tc_check_packets "dev $h2 ingress" 102 0
  62. check_fail $? "Did not match on correct filter"
  63. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  64. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  65. log_test "src_mac match ($tcflags)"
  66. }
  67. match_dst_ip_test()
  68. {
  69. RET=0
  70. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  71. $tcflags dst_ip 198.51.100.2 action drop
  72. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  73. $tcflags dst_ip 192.0.2.2 action drop
  74. tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
  75. $tcflags dst_ip 192.0.2.0/24 action drop
  76. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  77. -t ip -q
  78. tc_check_packets "dev $h2 ingress" 101 1
  79. check_fail $? "Matched on a wrong filter"
  80. tc_check_packets "dev $h2 ingress" 102 1
  81. check_err $? "Did not match on correct filter"
  82. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  83. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  84. -t ip -q
  85. tc_check_packets "dev $h2 ingress" 103 1
  86. check_err $? "Did not match on correct filter with mask"
  87. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  88. tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
  89. log_test "dst_ip match ($tcflags)"
  90. }
  91. match_src_ip_test()
  92. {
  93. RET=0
  94. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  95. $tcflags src_ip 198.51.100.1 action drop
  96. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  97. $tcflags src_ip 192.0.2.1 action drop
  98. tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
  99. $tcflags src_ip 192.0.2.0/24 action drop
  100. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  101. -t ip -q
  102. tc_check_packets "dev $h2 ingress" 101 1
  103. check_fail $? "Matched on a wrong filter"
  104. tc_check_packets "dev $h2 ingress" 102 1
  105. check_err $? "Did not match on correct filter"
  106. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  107. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  108. -t ip -q
  109. tc_check_packets "dev $h2 ingress" 103 1
  110. check_err $? "Did not match on correct filter with mask"
  111. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  112. tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
  113. log_test "src_ip match ($tcflags)"
  114. }
  115. match_ip_flags_test()
  116. {
  117. RET=0
  118. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  119. $tcflags ip_flags frag action continue
  120. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  121. $tcflags ip_flags firstfrag action continue
  122. tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
  123. $tcflags ip_flags nofirstfrag action continue
  124. tc filter add dev $h2 ingress protocol ip pref 4 handle 104 flower \
  125. $tcflags ip_flags nofrag action drop
  126. $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  127. -t ip "frag=0" -q
  128. tc_check_packets "dev $h2 ingress" 101 1
  129. check_fail $? "Matched on wrong frag filter (nofrag)"
  130. tc_check_packets "dev $h2 ingress" 102 1
  131. check_fail $? "Matched on wrong firstfrag filter (nofrag)"
  132. tc_check_packets "dev $h2 ingress" 103 1
  133. check_err $? "Did not match on nofirstfrag filter (nofrag) "
  134. tc_check_packets "dev $h2 ingress" 104 1
  135. check_err $? "Did not match on nofrag filter (nofrag)"
  136. $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  137. -t ip "frag=0,mf" -q
  138. tc_check_packets "dev $h2 ingress" 101 1
  139. check_err $? "Did not match on frag filter (1stfrag)"
  140. tc_check_packets "dev $h2 ingress" 102 1
  141. check_err $? "Did not match fistfrag filter (1stfrag)"
  142. tc_check_packets "dev $h2 ingress" 103 1
  143. check_err $? "Matched on wrong nofirstfrag filter (1stfrag)"
  144. tc_check_packets "dev $h2 ingress" 104 1
  145. check_err $? "Match on wrong nofrag filter (1stfrag)"
  146. $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  147. -t ip "frag=256,mf" -q
  148. $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  149. -t ip "frag=256" -q
  150. tc_check_packets "dev $h2 ingress" 101 3
  151. check_err $? "Did not match on frag filter (no1stfrag)"
  152. tc_check_packets "dev $h2 ingress" 102 1
  153. check_err $? "Matched on wrong firstfrag filter (no1stfrag)"
  154. tc_check_packets "dev $h2 ingress" 103 3
  155. check_err $? "Did not match on nofirstfrag filter (no1stfrag)"
  156. tc_check_packets "dev $h2 ingress" 104 1
  157. check_err $? "Matched on nofrag filter (no1stfrag)"
  158. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  159. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  160. tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
  161. tc filter del dev $h2 ingress protocol ip pref 4 handle 104 flower
  162. log_test "ip_flags match ($tcflags)"
  163. }
  164. match_pcp_test()
  165. {
  166. RET=0
  167. vlan_create $h2 85 v$h2 192.0.2.11/24
  168. tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \
  169. flower vlan_prio 6 $tcflags dst_mac $h2mac action drop
  170. tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \
  171. flower vlan_prio 7 $tcflags dst_mac $h2mac action drop
  172. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 7:85 -t ip -q
  173. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q
  174. tc_check_packets "dev $h2 ingress" 101 0
  175. check_err $? "Matched on specified PCP when should not"
  176. tc_check_packets "dev $h2 ingress" 102 1
  177. check_err $? "Did not match on specified PCP"
  178. tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower
  179. tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower
  180. vlan_destroy $h2 85
  181. log_test "PCP match ($tcflags)"
  182. }
  183. match_vlan_test()
  184. {
  185. RET=0
  186. vlan_create $h2 85 v$h2 192.0.2.11/24
  187. vlan_create $h2 75 v$h2 192.0.2.10/24
  188. tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \
  189. flower vlan_id 75 $tcflags action drop
  190. tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \
  191. flower vlan_id 85 $tcflags action drop
  192. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q
  193. tc_check_packets "dev $h2 ingress" 101 0
  194. check_err $? "Matched on specified VLAN when should not"
  195. tc_check_packets "dev $h2 ingress" 102 1
  196. check_err $? "Did not match on specified VLAN"
  197. tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower
  198. tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower
  199. vlan_destroy $h2 75
  200. vlan_destroy $h2 85
  201. log_test "VLAN match ($tcflags)"
  202. }
  203. match_ip_tos_test()
  204. {
  205. RET=0
  206. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  207. $tcflags dst_ip 192.0.2.2 ip_tos 0x20 action drop
  208. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  209. $tcflags dst_ip 192.0.2.2 ip_tos 0x18 action drop
  210. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  211. -t ip tos=18 -q
  212. tc_check_packets "dev $h2 ingress" 101 1
  213. check_fail $? "Matched on a wrong filter (0x18)"
  214. tc_check_packets "dev $h2 ingress" 102 1
  215. check_err $? "Did not match on correct filter (0x18)"
  216. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  217. -t ip tos=20 -q
  218. tc_check_packets "dev $h2 ingress" 102 2
  219. check_fail $? "Matched on a wrong filter (0x20)"
  220. tc_check_packets "dev $h2 ingress" 101 1
  221. check_err $? "Did not match on correct filter (0x20)"
  222. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  223. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  224. log_test "ip_tos match ($tcflags)"
  225. }
  226. match_ip_ttl_test()
  227. {
  228. RET=0
  229. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  230. $tcflags dst_ip 192.0.2.2 ip_ttl 63 action drop
  231. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  232. $tcflags dst_ip 192.0.2.2 action drop
  233. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  234. -t ip "ttl=63" -q
  235. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  236. -t ip "ttl=63,mf,frag=256" -q
  237. tc_check_packets "dev $h2 ingress" 102 1
  238. check_fail $? "Matched on the wrong filter (no check on ttl)"
  239. tc_check_packets "dev $h2 ingress" 101 2
  240. check_err $? "Did not match on correct filter (ttl=63)"
  241. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  242. -t ip "ttl=255" -q
  243. tc_check_packets "dev $h2 ingress" 101 3
  244. check_fail $? "Matched on a wrong filter (ttl=63)"
  245. tc_check_packets "dev $h2 ingress" 102 1
  246. check_err $? "Did not match on correct filter (no check on ttl)"
  247. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  248. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  249. log_test "ip_ttl match ($tcflags)"
  250. }
  251. match_indev_test()
  252. {
  253. RET=0
  254. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  255. $tcflags indev $h1 dst_mac $h2mac action drop
  256. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  257. $tcflags indev $h2 dst_mac $h2mac action drop
  258. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  259. -t ip -q
  260. tc_check_packets "dev $h2 ingress" 101 1
  261. check_fail $? "Matched on a wrong filter"
  262. tc_check_packets "dev $h2 ingress" 102 1
  263. check_err $? "Did not match on correct filter"
  264. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  265. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  266. log_test "indev match ($tcflags)"
  267. }
  268. # Unfortunately, mausezahn can't build MPLS headers when used in L2
  269. # mode, so we have this function to build Label Stack Entries.
  270. mpls_lse()
  271. {
  272. local label=$1
  273. local tc=$2
  274. local bos=$3
  275. local ttl=$4
  276. printf "%02x %02x %02x %02x" \
  277. $((label >> 12)) \
  278. $((label >> 4 & 0xff)) \
  279. $((((label & 0xf) << 4) + (tc << 1) + bos)) \
  280. $ttl
  281. }
  282. match_mpls_label_test()
  283. {
  284. local ethtype="88 47"; readonly ethtype
  285. local pkt
  286. RET=0
  287. check_tc_mpls_support $h2 || return 0
  288. tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
  289. flower $tcflags mpls_label 0 action drop
  290. tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
  291. flower $tcflags mpls_label 1048575 action drop
  292. pkt="$ethtype $(mpls_lse 1048575 0 1 255)"
  293. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  294. tc_check_packets "dev $h2 ingress" 101 1
  295. check_fail $? "Matched on a wrong filter (1048575)"
  296. tc_check_packets "dev $h2 ingress" 102 1
  297. check_err $? "Did not match on correct filter (1048575)"
  298. pkt="$ethtype $(mpls_lse 0 0 1 255)"
  299. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  300. tc_check_packets "dev $h2 ingress" 102 2
  301. check_fail $? "Matched on a wrong filter (0)"
  302. tc_check_packets "dev $h2 ingress" 101 1
  303. check_err $? "Did not match on correct filter (0)"
  304. tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
  305. tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
  306. log_test "mpls_label match ($tcflags)"
  307. }
  308. match_mpls_tc_test()
  309. {
  310. local ethtype="88 47"; readonly ethtype
  311. local pkt
  312. RET=0
  313. check_tc_mpls_support $h2 || return 0
  314. tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
  315. flower $tcflags mpls_tc 0 action drop
  316. tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
  317. flower $tcflags mpls_tc 7 action drop
  318. pkt="$ethtype $(mpls_lse 0 7 1 255)"
  319. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  320. tc_check_packets "dev $h2 ingress" 101 1
  321. check_fail $? "Matched on a wrong filter (7)"
  322. tc_check_packets "dev $h2 ingress" 102 1
  323. check_err $? "Did not match on correct filter (7)"
  324. pkt="$ethtype $(mpls_lse 0 0 1 255)"
  325. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  326. tc_check_packets "dev $h2 ingress" 102 2
  327. check_fail $? "Matched on a wrong filter (0)"
  328. tc_check_packets "dev $h2 ingress" 101 1
  329. check_err $? "Did not match on correct filter (0)"
  330. tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
  331. tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
  332. log_test "mpls_tc match ($tcflags)"
  333. }
  334. match_mpls_bos_test()
  335. {
  336. local ethtype="88 47"; readonly ethtype
  337. local pkt
  338. RET=0
  339. check_tc_mpls_support $h2 || return 0
  340. tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
  341. flower $tcflags mpls_bos 0 action drop
  342. tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
  343. flower $tcflags mpls_bos 1 action drop
  344. pkt="$ethtype $(mpls_lse 0 0 1 255)"
  345. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  346. tc_check_packets "dev $h2 ingress" 101 1
  347. check_fail $? "Matched on a wrong filter (1)"
  348. tc_check_packets "dev $h2 ingress" 102 1
  349. check_err $? "Did not match on correct filter (1)"
  350. # Need to add a second label to properly mark the Bottom of Stack
  351. pkt="$ethtype $(mpls_lse 0 0 0 255) $(mpls_lse 0 0 1 255)"
  352. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  353. tc_check_packets "dev $h2 ingress" 102 2
  354. check_fail $? "Matched on a wrong filter (0)"
  355. tc_check_packets "dev $h2 ingress" 101 1
  356. check_err $? "Did not match on correct filter (0)"
  357. tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
  358. tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
  359. log_test "mpls_bos match ($tcflags)"
  360. }
  361. match_mpls_ttl_test()
  362. {
  363. local ethtype="88 47"; readonly ethtype
  364. local pkt
  365. RET=0
  366. check_tc_mpls_support $h2 || return 0
  367. tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
  368. flower $tcflags mpls_ttl 0 action drop
  369. tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
  370. flower $tcflags mpls_ttl 255 action drop
  371. pkt="$ethtype $(mpls_lse 0 0 1 255)"
  372. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  373. tc_check_packets "dev $h2 ingress" 101 1
  374. check_fail $? "Matched on a wrong filter (255)"
  375. tc_check_packets "dev $h2 ingress" 102 1
  376. check_err $? "Did not match on correct filter (255)"
  377. pkt="$ethtype $(mpls_lse 0 0 1 0)"
  378. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  379. tc_check_packets "dev $h2 ingress" 102 2
  380. check_fail $? "Matched on a wrong filter (0)"
  381. tc_check_packets "dev $h2 ingress" 101 1
  382. check_err $? "Did not match on correct filter (0)"
  383. tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
  384. tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
  385. log_test "mpls_ttl match ($tcflags)"
  386. }
  387. match_mpls_lse_test()
  388. {
  389. local ethtype="88 47"; readonly ethtype
  390. local pkt
  391. RET=0
  392. check_tc_mpls_lse_stats $h2 || return 0
  393. # Match on first LSE (minimal values for each field)
  394. tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \
  395. flower $tcflags mpls lse depth 1 label 0 action continue
  396. tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \
  397. flower $tcflags mpls lse depth 1 tc 0 action continue
  398. tc filter add dev $h2 ingress protocol mpls_uc pref 3 handle 103 \
  399. flower $tcflags mpls lse depth 1 bos 0 action continue
  400. tc filter add dev $h2 ingress protocol mpls_uc pref 4 handle 104 \
  401. flower $tcflags mpls lse depth 1 ttl 0 action continue
  402. # Match on second LSE (maximal values for each field)
  403. tc filter add dev $h2 ingress protocol mpls_uc pref 5 handle 105 \
  404. flower $tcflags mpls lse depth 2 label 1048575 action continue
  405. tc filter add dev $h2 ingress protocol mpls_uc pref 6 handle 106 \
  406. flower $tcflags mpls lse depth 2 tc 7 action continue
  407. tc filter add dev $h2 ingress protocol mpls_uc pref 7 handle 107 \
  408. flower $tcflags mpls lse depth 2 bos 1 action continue
  409. tc filter add dev $h2 ingress protocol mpls_uc pref 8 handle 108 \
  410. flower $tcflags mpls lse depth 2 ttl 255 action continue
  411. # Match on LSE depth
  412. tc filter add dev $h2 ingress protocol mpls_uc pref 9 handle 109 \
  413. flower $tcflags mpls lse depth 1 action continue
  414. tc filter add dev $h2 ingress protocol mpls_uc pref 10 handle 110 \
  415. flower $tcflags mpls lse depth 2 action continue
  416. tc filter add dev $h2 ingress protocol mpls_uc pref 11 handle 111 \
  417. flower $tcflags mpls lse depth 3 action continue
  418. # Base packet, matched by all filters (except for stack depth 3)
  419. pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 1 255)"
  420. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  421. # Make a variant of the above packet, with a non-matching value
  422. # for each LSE field
  423. # Wrong label at depth 1
  424. pkt="$ethtype $(mpls_lse 1 0 0 0) $(mpls_lse 1048575 7 1 255)"
  425. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  426. # Wrong TC at depth 1
  427. pkt="$ethtype $(mpls_lse 0 1 0 0) $(mpls_lse 1048575 7 1 255)"
  428. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  429. # Wrong BOS at depth 1 (not adding a second LSE here since BOS is set
  430. # in the first label, so anything that'd follow wouldn't be considered)
  431. pkt="$ethtype $(mpls_lse 0 0 1 0)"
  432. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  433. # Wrong TTL at depth 1
  434. pkt="$ethtype $(mpls_lse 0 0 0 1) $(mpls_lse 1048575 7 1 255)"
  435. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  436. # Wrong label at depth 2
  437. pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048574 7 1 255)"
  438. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  439. # Wrong TC at depth 2
  440. pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 6 1 255)"
  441. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  442. # Wrong BOS at depth 2 (adding a third LSE here since BOS isn't set in
  443. # the second label)
  444. pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 0 255)"
  445. pkt="$pkt $(mpls_lse 0 0 1 255)"
  446. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  447. # Wrong TTL at depth 2
  448. pkt="$ethtype $(mpls_lse 0 0 0 0) $(mpls_lse 1048575 7 1 254)"
  449. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q
  450. # Filters working at depth 1 should match all packets but one
  451. tc_check_packets "dev $h2 ingress" 101 8
  452. check_err $? "Did not match on correct filter"
  453. tc_check_packets "dev $h2 ingress" 102 8
  454. check_err $? "Did not match on correct filter"
  455. tc_check_packets "dev $h2 ingress" 103 8
  456. check_err $? "Did not match on correct filter"
  457. tc_check_packets "dev $h2 ingress" 104 8
  458. check_err $? "Did not match on correct filter"
  459. # Filters working at depth 2 should match all packets but two (because
  460. # of the test packet where the label stack depth is just one)
  461. tc_check_packets "dev $h2 ingress" 105 7
  462. check_err $? "Did not match on correct filter"
  463. tc_check_packets "dev $h2 ingress" 106 7
  464. check_err $? "Did not match on correct filter"
  465. tc_check_packets "dev $h2 ingress" 107 7
  466. check_err $? "Did not match on correct filter"
  467. tc_check_packets "dev $h2 ingress" 108 7
  468. check_err $? "Did not match on correct filter"
  469. # Finally, verify the filters that only match on LSE depth
  470. tc_check_packets "dev $h2 ingress" 109 9
  471. check_err $? "Did not match on correct filter"
  472. tc_check_packets "dev $h2 ingress" 110 8
  473. check_err $? "Did not match on correct filter"
  474. tc_check_packets "dev $h2 ingress" 111 1
  475. check_err $? "Did not match on correct filter"
  476. tc filter del dev $h2 ingress protocol mpls_uc pref 11 handle 111 flower
  477. tc filter del dev $h2 ingress protocol mpls_uc pref 10 handle 110 flower
  478. tc filter del dev $h2 ingress protocol mpls_uc pref 9 handle 109 flower
  479. tc filter del dev $h2 ingress protocol mpls_uc pref 8 handle 108 flower
  480. tc filter del dev $h2 ingress protocol mpls_uc pref 7 handle 107 flower
  481. tc filter del dev $h2 ingress protocol mpls_uc pref 6 handle 106 flower
  482. tc filter del dev $h2 ingress protocol mpls_uc pref 5 handle 105 flower
  483. tc filter del dev $h2 ingress protocol mpls_uc pref 4 handle 104 flower
  484. tc filter del dev $h2 ingress protocol mpls_uc pref 3 handle 103 flower
  485. tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower
  486. tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower
  487. log_test "mpls lse match ($tcflags)"
  488. }
  489. setup_prepare()
  490. {
  491. h1=${NETIFS[p1]}
  492. h2=${NETIFS[p2]}
  493. h1mac=$(mac_get $h1)
  494. h2mac=$(mac_get $h2)
  495. vrf_prepare
  496. h1_create
  497. h2_create
  498. }
  499. cleanup()
  500. {
  501. pre_cleanup
  502. h2_destroy
  503. h1_destroy
  504. vrf_cleanup
  505. }
  506. trap cleanup EXIT
  507. setup_prepare
  508. setup_wait
  509. tests_run
  510. tc_offload_check
  511. if [[ $? -ne 0 ]]; then
  512. log_info "Could not test offloaded functionality"
  513. else
  514. tcflags="skip_sw"
  515. tests_run
  516. fi
  517. exit $EXIT_STATUS