| .. | .. |
|---|
| 2 | 2 | # SPDX-License-Identifier: GPL-2.0 |
|---|
| 3 | 3 | |
|---|
| 4 | 4 | ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \ |
|---|
| 5 | | - match_src_ip_test match_ip_flags_test" |
|---|
| 5 | + match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \ |
|---|
| 6 | + match_ip_tos_test match_indev_test match_ip_ttl_test" |
|---|
| 6 | 7 | NUM_NETIFS=2 |
|---|
| 7 | 8 | source tc_common.sh |
|---|
| 8 | 9 | source lib.sh |
|---|
| .. | .. |
|---|
| 48 | 49 | tc_check_packets "dev $h2 ingress" 101 1 |
|---|
| 49 | 50 | check_fail $? "Matched on a wrong filter" |
|---|
| 50 | 51 | |
|---|
| 51 | | - tc_check_packets "dev $h2 ingress" 102 1 |
|---|
| 52 | | - check_err $? "Did not match on correct filter" |
|---|
| 52 | + tc_check_packets "dev $h2 ingress" 102 0 |
|---|
| 53 | + check_fail $? "Did not match on correct filter" |
|---|
| 53 | 54 | |
|---|
| 54 | 55 | tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower |
|---|
| 55 | 56 | tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower |
|---|
| .. | .. |
|---|
| 74 | 75 | tc_check_packets "dev $h2 ingress" 101 1 |
|---|
| 75 | 76 | check_fail $? "Matched on a wrong filter" |
|---|
| 76 | 77 | |
|---|
| 77 | | - tc_check_packets "dev $h2 ingress" 102 1 |
|---|
| 78 | | - check_err $? "Did not match on correct filter" |
|---|
| 78 | + tc_check_packets "dev $h2 ingress" 102 0 |
|---|
| 79 | + check_fail $? "Did not match on correct filter" |
|---|
| 79 | 80 | |
|---|
| 80 | 81 | tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower |
|---|
| 81 | 82 | tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower |
|---|
| .. | .. |
|---|
| 219 | 220 | log_test "ip_flags match ($tcflags)" |
|---|
| 220 | 221 | } |
|---|
| 221 | 222 | |
|---|
| 223 | +match_pcp_test() |
|---|
| 224 | +{ |
|---|
| 225 | + RET=0 |
|---|
| 226 | + |
|---|
| 227 | + vlan_create $h2 85 v$h2 192.0.2.11/24 |
|---|
| 228 | + |
|---|
| 229 | + tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \ |
|---|
| 230 | + flower vlan_prio 6 $tcflags dst_mac $h2mac action drop |
|---|
| 231 | + tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \ |
|---|
| 232 | + flower vlan_prio 7 $tcflags dst_mac $h2mac action drop |
|---|
| 233 | + |
|---|
| 234 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 7:85 -t ip -q |
|---|
| 235 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q |
|---|
| 236 | + |
|---|
| 237 | + tc_check_packets "dev $h2 ingress" 101 0 |
|---|
| 238 | + check_err $? "Matched on specified PCP when should not" |
|---|
| 239 | + |
|---|
| 240 | + tc_check_packets "dev $h2 ingress" 102 1 |
|---|
| 241 | + check_err $? "Did not match on specified PCP" |
|---|
| 242 | + |
|---|
| 243 | + tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower |
|---|
| 244 | + tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower |
|---|
| 245 | + |
|---|
| 246 | + vlan_destroy $h2 85 |
|---|
| 247 | + |
|---|
| 248 | + log_test "PCP match ($tcflags)" |
|---|
| 249 | +} |
|---|
| 250 | + |
|---|
| 251 | +match_vlan_test() |
|---|
| 252 | +{ |
|---|
| 253 | + RET=0 |
|---|
| 254 | + |
|---|
| 255 | + vlan_create $h2 85 v$h2 192.0.2.11/24 |
|---|
| 256 | + vlan_create $h2 75 v$h2 192.0.2.10/24 |
|---|
| 257 | + |
|---|
| 258 | + tc filter add dev $h2 ingress protocol 802.1q pref 1 handle 101 \ |
|---|
| 259 | + flower vlan_id 75 $tcflags action drop |
|---|
| 260 | + tc filter add dev $h2 ingress protocol 802.1q pref 2 handle 102 \ |
|---|
| 261 | + flower vlan_id 85 $tcflags action drop |
|---|
| 262 | + |
|---|
| 263 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -B 192.0.2.11 -Q 0:85 -t ip -q |
|---|
| 264 | + |
|---|
| 265 | + tc_check_packets "dev $h2 ingress" 101 0 |
|---|
| 266 | + check_err $? "Matched on specified VLAN when should not" |
|---|
| 267 | + |
|---|
| 268 | + tc_check_packets "dev $h2 ingress" 102 1 |
|---|
| 269 | + check_err $? "Did not match on specified VLAN" |
|---|
| 270 | + |
|---|
| 271 | + tc filter del dev $h2 ingress protocol 802.1q pref 2 handle 102 flower |
|---|
| 272 | + tc filter del dev $h2 ingress protocol 802.1q pref 1 handle 101 flower |
|---|
| 273 | + |
|---|
| 274 | + vlan_destroy $h2 75 |
|---|
| 275 | + vlan_destroy $h2 85 |
|---|
| 276 | + |
|---|
| 277 | + log_test "VLAN match ($tcflags)" |
|---|
| 278 | +} |
|---|
| 279 | + |
|---|
| 280 | +match_ip_tos_test() |
|---|
| 281 | +{ |
|---|
| 282 | + RET=0 |
|---|
| 283 | + |
|---|
| 284 | + tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ |
|---|
| 285 | + $tcflags dst_ip 192.0.2.2 ip_tos 0x20 action drop |
|---|
| 286 | + tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ |
|---|
| 287 | + $tcflags dst_ip 192.0.2.2 ip_tos 0x18 action drop |
|---|
| 288 | + |
|---|
| 289 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ |
|---|
| 290 | + -t ip tos=18 -q |
|---|
| 291 | + |
|---|
| 292 | + tc_check_packets "dev $h2 ingress" 101 1 |
|---|
| 293 | + check_fail $? "Matched on a wrong filter (0x18)" |
|---|
| 294 | + |
|---|
| 295 | + tc_check_packets "dev $h2 ingress" 102 1 |
|---|
| 296 | + check_err $? "Did not match on correct filter (0x18)" |
|---|
| 297 | + |
|---|
| 298 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ |
|---|
| 299 | + -t ip tos=20 -q |
|---|
| 300 | + |
|---|
| 301 | + tc_check_packets "dev $h2 ingress" 102 2 |
|---|
| 302 | + check_fail $? "Matched on a wrong filter (0x20)" |
|---|
| 303 | + |
|---|
| 304 | + tc_check_packets "dev $h2 ingress" 101 1 |
|---|
| 305 | + check_err $? "Did not match on correct filter (0x20)" |
|---|
| 306 | + |
|---|
| 307 | + tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower |
|---|
| 308 | + tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower |
|---|
| 309 | + |
|---|
| 310 | + log_test "ip_tos match ($tcflags)" |
|---|
| 311 | +} |
|---|
| 312 | + |
|---|
| 313 | +match_ip_ttl_test() |
|---|
| 314 | +{ |
|---|
| 315 | + RET=0 |
|---|
| 316 | + |
|---|
| 317 | + tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ |
|---|
| 318 | + $tcflags dst_ip 192.0.2.2 ip_ttl 63 action drop |
|---|
| 319 | + tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ |
|---|
| 320 | + $tcflags dst_ip 192.0.2.2 action drop |
|---|
| 321 | + |
|---|
| 322 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ |
|---|
| 323 | + -t ip "ttl=63" -q |
|---|
| 324 | + |
|---|
| 325 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ |
|---|
| 326 | + -t ip "ttl=63,mf,frag=256" -q |
|---|
| 327 | + |
|---|
| 328 | + tc_check_packets "dev $h2 ingress" 102 1 |
|---|
| 329 | + check_fail $? "Matched on the wrong filter (no check on ttl)" |
|---|
| 330 | + |
|---|
| 331 | + tc_check_packets "dev $h2 ingress" 101 2 |
|---|
| 332 | + check_err $? "Did not match on correct filter (ttl=63)" |
|---|
| 333 | + |
|---|
| 334 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ |
|---|
| 335 | + -t ip "ttl=255" -q |
|---|
| 336 | + |
|---|
| 337 | + tc_check_packets "dev $h2 ingress" 101 3 |
|---|
| 338 | + check_fail $? "Matched on a wrong filter (ttl=63)" |
|---|
| 339 | + |
|---|
| 340 | + tc_check_packets "dev $h2 ingress" 102 1 |
|---|
| 341 | + check_err $? "Did not match on correct filter (no check on ttl)" |
|---|
| 342 | + |
|---|
| 343 | + tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower |
|---|
| 344 | + tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower |
|---|
| 345 | + |
|---|
| 346 | + log_test "ip_ttl match ($tcflags)" |
|---|
| 347 | +} |
|---|
| 348 | + |
|---|
| 349 | +match_indev_test() |
|---|
| 350 | +{ |
|---|
| 351 | + RET=0 |
|---|
| 352 | + |
|---|
| 353 | + tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ |
|---|
| 354 | + $tcflags indev $h1 dst_mac $h2mac action drop |
|---|
| 355 | + tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ |
|---|
| 356 | + $tcflags indev $h2 dst_mac $h2mac action drop |
|---|
| 357 | + |
|---|
| 358 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ |
|---|
| 359 | + -t ip -q |
|---|
| 360 | + |
|---|
| 361 | + tc_check_packets "dev $h2 ingress" 101 1 |
|---|
| 362 | + check_fail $? "Matched on a wrong filter" |
|---|
| 363 | + |
|---|
| 364 | + tc_check_packets "dev $h2 ingress" 102 1 |
|---|
| 365 | + check_err $? "Did not match on correct filter" |
|---|
| 366 | + |
|---|
| 367 | + tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower |
|---|
| 368 | + tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower |
|---|
| 369 | + |
|---|
| 370 | + log_test "indev match ($tcflags)" |
|---|
| 371 | +} |
|---|
| 372 | + |
|---|
| 222 | 373 | setup_prepare() |
|---|
| 223 | 374 | { |
|---|
| 224 | 375 | h1=${NETIFS[p1]} |
|---|