tc_flower.sh 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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"
  5. NUM_NETIFS=2
  6. source tc_common.sh
  7. source lib.sh
  8. tcflags="skip_hw"
  9. h1_create()
  10. {
  11. simple_if_init $h1 192.0.2.1/24 198.51.100.1/24
  12. }
  13. h1_destroy()
  14. {
  15. simple_if_fini $h1 192.0.2.1/24 198.51.100.1/24
  16. }
  17. h2_create()
  18. {
  19. simple_if_init $h2 192.0.2.2/24 198.51.100.2/24
  20. tc qdisc add dev $h2 clsact
  21. }
  22. h2_destroy()
  23. {
  24. tc qdisc del dev $h2 clsact
  25. simple_if_fini $h2 192.0.2.2/24 198.51.100.2/24
  26. }
  27. match_dst_mac_test()
  28. {
  29. local dummy_mac=de:ad:be:ef:aa:aa
  30. RET=0
  31. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  32. $tcflags dst_mac $dummy_mac action drop
  33. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  34. $tcflags dst_mac $h2mac action drop
  35. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  36. -t ip -q
  37. tc_check_packets "dev $h2 ingress" 101 1
  38. check_fail $? "Matched on a wrong filter"
  39. tc_check_packets "dev $h2 ingress" 102 1
  40. check_err $? "Did not match on correct filter"
  41. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  42. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  43. log_test "dst_mac match ($tcflags)"
  44. }
  45. match_src_mac_test()
  46. {
  47. local dummy_mac=de:ad:be:ef:aa:aa
  48. RET=0
  49. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  50. $tcflags src_mac $dummy_mac action drop
  51. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  52. $tcflags src_mac $h1mac action drop
  53. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  54. -t ip -q
  55. tc_check_packets "dev $h2 ingress" 101 1
  56. check_fail $? "Matched on a wrong filter"
  57. tc_check_packets "dev $h2 ingress" 102 1
  58. check_err $? "Did not match on correct filter"
  59. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  60. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  61. log_test "src_mac match ($tcflags)"
  62. }
  63. match_dst_ip_test()
  64. {
  65. RET=0
  66. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  67. $tcflags dst_ip 198.51.100.2 action drop
  68. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  69. $tcflags dst_ip 192.0.2.2 action drop
  70. tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
  71. $tcflags dst_ip 192.0.2.0/24 action drop
  72. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  73. -t ip -q
  74. tc_check_packets "dev $h2 ingress" 101 1
  75. check_fail $? "Matched on a wrong filter"
  76. tc_check_packets "dev $h2 ingress" 102 1
  77. check_err $? "Did not match on correct filter"
  78. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  79. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  80. -t ip -q
  81. tc_check_packets "dev $h2 ingress" 103 1
  82. check_err $? "Did not match on correct filter with mask"
  83. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  84. tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
  85. log_test "dst_ip match ($tcflags)"
  86. }
  87. match_src_ip_test()
  88. {
  89. RET=0
  90. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  91. $tcflags src_ip 198.51.100.1 action drop
  92. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  93. $tcflags src_ip 192.0.2.1 action drop
  94. tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
  95. $tcflags src_ip 192.0.2.0/24 action drop
  96. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  97. -t ip -q
  98. tc_check_packets "dev $h2 ingress" 101 1
  99. check_fail $? "Matched on a wrong filter"
  100. tc_check_packets "dev $h2 ingress" 102 1
  101. check_err $? "Did not match on correct filter"
  102. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  103. $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  104. -t ip -q
  105. tc_check_packets "dev $h2 ingress" 103 1
  106. check_err $? "Did not match on correct filter with mask"
  107. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  108. tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
  109. log_test "src_ip match ($tcflags)"
  110. }
  111. match_ip_flags_test()
  112. {
  113. RET=0
  114. tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
  115. $tcflags ip_flags frag action continue
  116. tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \
  117. $tcflags ip_flags firstfrag action continue
  118. tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
  119. $tcflags ip_flags nofirstfrag action continue
  120. tc filter add dev $h2 ingress protocol ip pref 4 handle 104 flower \
  121. $tcflags ip_flags nofrag action drop
  122. $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  123. -t ip "frag=0" -q
  124. tc_check_packets "dev $h2 ingress" 101 1
  125. check_fail $? "Matched on wrong frag filter (nofrag)"
  126. tc_check_packets "dev $h2 ingress" 102 1
  127. check_fail $? "Matched on wrong firstfrag filter (nofrag)"
  128. tc_check_packets "dev $h2 ingress" 103 1
  129. check_err $? "Did not match on nofirstfrag filter (nofrag) "
  130. tc_check_packets "dev $h2 ingress" 104 1
  131. check_err $? "Did not match on nofrag filter (nofrag)"
  132. $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  133. -t ip "frag=0,mf" -q
  134. tc_check_packets "dev $h2 ingress" 101 1
  135. check_err $? "Did not match on frag filter (1stfrag)"
  136. tc_check_packets "dev $h2 ingress" 102 1
  137. check_err $? "Did not match fistfrag filter (1stfrag)"
  138. tc_check_packets "dev $h2 ingress" 103 1
  139. check_err $? "Matched on wrong nofirstfrag filter (1stfrag)"
  140. tc_check_packets "dev $h2 ingress" 104 1
  141. check_err $? "Match on wrong nofrag filter (1stfrag)"
  142. $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  143. -t ip "frag=256,mf" -q
  144. $MZ $h1 -c 1 -p 1000 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
  145. -t ip "frag=256" -q
  146. tc_check_packets "dev $h2 ingress" 101 3
  147. check_err $? "Did not match on frag filter (no1stfrag)"
  148. tc_check_packets "dev $h2 ingress" 102 1
  149. check_err $? "Matched on wrong firstfrag filter (no1stfrag)"
  150. tc_check_packets "dev $h2 ingress" 103 3
  151. check_err $? "Did not match on nofirstfrag filter (no1stfrag)"
  152. tc_check_packets "dev $h2 ingress" 104 1
  153. check_err $? "Matched on nofrag filter (no1stfrag)"
  154. tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
  155. tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower
  156. tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower
  157. tc filter del dev $h2 ingress protocol ip pref 4 handle 104 flower
  158. log_test "ip_flags match ($tcflags)"
  159. }
  160. setup_prepare()
  161. {
  162. h1=${NETIFS[p1]}
  163. h2=${NETIFS[p2]}
  164. h1mac=$(mac_get $h1)
  165. h2mac=$(mac_get $h2)
  166. vrf_prepare
  167. h1_create
  168. h2_create
  169. }
  170. cleanup()
  171. {
  172. pre_cleanup
  173. h2_destroy
  174. h1_destroy
  175. vrf_cleanup
  176. }
  177. trap cleanup EXIT
  178. setup_prepare
  179. setup_wait
  180. tests_run
  181. tc_offload_check
  182. if [[ $? -ne 0 ]]; then
  183. log_info "Could not test offloaded functionality"
  184. else
  185. tcflags="skip_sw"
  186. tests_run
  187. fi
  188. exit $EXIT_STATUS