|
3 | 3 |
|
4 | 4 | ALL_TESTS="match_dst_mac_test match_src_mac_test match_dst_ip_test \
|
5 | 5 | match_src_ip_test match_ip_flags_test match_pcp_test match_vlan_test \
|
6 |
| - match_ip_tos_test match_indev_test" |
| 6 | + match_ip_tos_test match_indev_test match_mpls_label_test \ |
| 7 | + match_mpls_tc_test match_mpls_bos_test match_mpls_ttl_test" |
7 | 8 | NUM_NETIFS=2
|
8 | 9 | source tc_common.sh
|
9 | 10 | source lib.sh
|
@@ -334,6 +335,175 @@ match_indev_test()
|
334 | 335 | log_test "indev match ($tcflags)"
|
335 | 336 | }
|
336 | 337 |
|
| 338 | +# Unfortunately, mausezahn can't build MPLS headers when used in L2 |
| 339 | +# mode, so we have this function to build Label Stack Entries. |
| 340 | +mpls_lse() |
| 341 | +{ |
| 342 | + local label=$1 |
| 343 | + local tc=$2 |
| 344 | + local bos=$3 |
| 345 | + local ttl=$4 |
| 346 | + |
| 347 | + printf "%02x %02x %02x %02x" \ |
| 348 | + $((label >> 12)) \ |
| 349 | + $((label >> 4 & 0xff)) \ |
| 350 | + $((((label & 0xf) << 4) + (tc << 1) + bos)) \ |
| 351 | + $ttl |
| 352 | +} |
| 353 | + |
| 354 | +match_mpls_label_test() |
| 355 | +{ |
| 356 | + local ethtype="88 47"; readonly ethtype |
| 357 | + local pkt |
| 358 | + |
| 359 | + RET=0 |
| 360 | + |
| 361 | + check_tc_mpls_support $h2 || return 0 |
| 362 | + |
| 363 | + tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \ |
| 364 | + flower $tcflags mpls_label 0 action drop |
| 365 | + tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \ |
| 366 | + flower $tcflags mpls_label 1048575 action drop |
| 367 | + |
| 368 | + pkt="$ethtype $(mpls_lse 1048575 0 1 255)" |
| 369 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q |
| 370 | + |
| 371 | + tc_check_packets "dev $h2 ingress" 101 1 |
| 372 | + check_fail $? "Matched on a wrong filter (1048575)" |
| 373 | + |
| 374 | + tc_check_packets "dev $h2 ingress" 102 1 |
| 375 | + check_err $? "Did not match on correct filter (1048575)" |
| 376 | + |
| 377 | + pkt="$ethtype $(mpls_lse 0 0 1 255)" |
| 378 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q |
| 379 | + |
| 380 | + tc_check_packets "dev $h2 ingress" 102 2 |
| 381 | + check_fail $? "Matched on a wrong filter (0)" |
| 382 | + |
| 383 | + tc_check_packets "dev $h2 ingress" 101 1 |
| 384 | + check_err $? "Did not match on correct filter (0)" |
| 385 | + |
| 386 | + tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower |
| 387 | + tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower |
| 388 | + |
| 389 | + log_test "mpls_label match ($tcflags)" |
| 390 | +} |
| 391 | + |
| 392 | +match_mpls_tc_test() |
| 393 | +{ |
| 394 | + local ethtype="88 47"; readonly ethtype |
| 395 | + local pkt |
| 396 | + |
| 397 | + RET=0 |
| 398 | + |
| 399 | + check_tc_mpls_support $h2 || return 0 |
| 400 | + |
| 401 | + tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \ |
| 402 | + flower $tcflags mpls_tc 0 action drop |
| 403 | + tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \ |
| 404 | + flower $tcflags mpls_tc 7 action drop |
| 405 | + |
| 406 | + pkt="$ethtype $(mpls_lse 0 7 1 255)" |
| 407 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q |
| 408 | + |
| 409 | + tc_check_packets "dev $h2 ingress" 101 1 |
| 410 | + check_fail $? "Matched on a wrong filter (7)" |
| 411 | + |
| 412 | + tc_check_packets "dev $h2 ingress" 102 1 |
| 413 | + check_err $? "Did not match on correct filter (7)" |
| 414 | + |
| 415 | + pkt="$ethtype $(mpls_lse 0 0 1 255)" |
| 416 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q |
| 417 | + |
| 418 | + tc_check_packets "dev $h2 ingress" 102 2 |
| 419 | + check_fail $? "Matched on a wrong filter (0)" |
| 420 | + |
| 421 | + tc_check_packets "dev $h2 ingress" 101 1 |
| 422 | + check_err $? "Did not match on correct filter (0)" |
| 423 | + |
| 424 | + tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower |
| 425 | + tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower |
| 426 | + |
| 427 | + log_test "mpls_tc match ($tcflags)" |
| 428 | +} |
| 429 | + |
| 430 | +match_mpls_bos_test() |
| 431 | +{ |
| 432 | + local ethtype="88 47"; readonly ethtype |
| 433 | + local pkt |
| 434 | + |
| 435 | + RET=0 |
| 436 | + |
| 437 | + check_tc_mpls_support $h2 || return 0 |
| 438 | + |
| 439 | + tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \ |
| 440 | + flower $tcflags mpls_bos 0 action drop |
| 441 | + tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \ |
| 442 | + flower $tcflags mpls_bos 1 action drop |
| 443 | + |
| 444 | + pkt="$ethtype $(mpls_lse 0 0 1 255)" |
| 445 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q |
| 446 | + |
| 447 | + tc_check_packets "dev $h2 ingress" 101 1 |
| 448 | + check_fail $? "Matched on a wrong filter (1)" |
| 449 | + |
| 450 | + tc_check_packets "dev $h2 ingress" 102 1 |
| 451 | + check_err $? "Did not match on correct filter (1)" |
| 452 | + |
| 453 | + # Need to add a second label to properly mark the Bottom of Stack |
| 454 | + pkt="$ethtype $(mpls_lse 0 0 0 255) $(mpls_lse 0 0 1 255)" |
| 455 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q |
| 456 | + |
| 457 | + tc_check_packets "dev $h2 ingress" 102 2 |
| 458 | + check_fail $? "Matched on a wrong filter (0)" |
| 459 | + |
| 460 | + tc_check_packets "dev $h2 ingress" 101 1 |
| 461 | + check_err $? "Did not match on correct filter (0)" |
| 462 | + |
| 463 | + tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower |
| 464 | + tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower |
| 465 | + |
| 466 | + log_test "mpls_bos match ($tcflags)" |
| 467 | +} |
| 468 | + |
| 469 | +match_mpls_ttl_test() |
| 470 | +{ |
| 471 | + local ethtype="88 47"; readonly ethtype |
| 472 | + local pkt |
| 473 | + |
| 474 | + RET=0 |
| 475 | + |
| 476 | + check_tc_mpls_support $h2 || return 0 |
| 477 | + |
| 478 | + tc filter add dev $h2 ingress protocol mpls_uc pref 1 handle 101 \ |
| 479 | + flower $tcflags mpls_ttl 0 action drop |
| 480 | + tc filter add dev $h2 ingress protocol mpls_uc pref 2 handle 102 \ |
| 481 | + flower $tcflags mpls_ttl 255 action drop |
| 482 | + |
| 483 | + pkt="$ethtype $(mpls_lse 0 0 1 255)" |
| 484 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q |
| 485 | + |
| 486 | + tc_check_packets "dev $h2 ingress" 101 1 |
| 487 | + check_fail $? "Matched on a wrong filter (255)" |
| 488 | + |
| 489 | + tc_check_packets "dev $h2 ingress" 102 1 |
| 490 | + check_err $? "Did not match on correct filter (255)" |
| 491 | + |
| 492 | + pkt="$ethtype $(mpls_lse 0 0 1 0)" |
| 493 | + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac "$pkt" -q |
| 494 | + |
| 495 | + tc_check_packets "dev $h2 ingress" 102 2 |
| 496 | + check_fail $? "Matched on a wrong filter (0)" |
| 497 | + |
| 498 | + tc_check_packets "dev $h2 ingress" 101 1 |
| 499 | + check_err $? "Did not match on correct filter (0)" |
| 500 | + |
| 501 | + tc filter del dev $h2 ingress protocol mpls_uc pref 2 handle 102 flower |
| 502 | + tc filter del dev $h2 ingress protocol mpls_uc pref 1 handle 101 flower |
| 503 | + |
| 504 | + log_test "mpls_ttl match ($tcflags)" |
| 505 | +} |
| 506 | + |
337 | 507 | setup_prepare()
|
338 | 508 | {
|
339 | 509 | h1=${NETIFS[p1]}
|
|
0 commit comments