diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2014-05-26 14:17:35 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-05-30 19:27:39 -0400 |
commit | ce25b68b74593bbb676ec087b3a0c69f94df7de0 (patch) | |
tree | 197fe97f042aa6975409bcf0a3124c4e0fab1aaa /lib/test_bpf.c | |
parent | 108cc22a93e1843e728b9753442429c71f48f9e4 (diff) |
net: filter: use block statements in tcpdump tests
This patch converts raw opcodes for tcpdump tests into
BPF_STMT()/BPF_JUMP() combinations, which brings it into
conformity with the rest of the patches and it also makes
life easier to grasp what's going on in these particular
test cases when they ever fail. Also arrange payload from
the jump+holes test in a way as we have with other packet
payloads in the test suite.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'lib/test_bpf.c')
-rw-r--r-- | lib/test_bpf.c | 143 |
1 files changed, 75 insertions, 68 deletions
diff --git a/lib/test_bpf.c b/lib/test_bpf.c index 6be9119c60f1..3c4a1e3e1f50 100644 --- a/lib/test_bpf.c +++ b/lib/test_bpf.c | |||
@@ -560,30 +560,30 @@ static struct bpf_test tests[] = { | |||
560 | { | 560 | { |
561 | "tcpdump port 22", | 561 | "tcpdump port 22", |
562 | .u.insns = { | 562 | .u.insns = { |
563 | { 0x28, 0, 0, 0x0000000c }, | 563 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), |
564 | { 0x15, 0, 8, 0x000086dd }, | 564 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */ |
565 | { 0x30, 0, 0, 0x00000014 }, | 565 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20), |
566 | { 0x15, 2, 0, 0x00000084 }, | 566 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0), |
567 | { 0x15, 1, 0, 0x00000006 }, | 567 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0), |
568 | { 0x15, 0, 17, 0x00000011 }, | 568 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17), |
569 | { 0x28, 0, 0, 0x00000036 }, | 569 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54), |
570 | { 0x15, 14, 0, 0x00000016 }, | 570 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0), |
571 | { 0x28, 0, 0, 0x00000038 }, | 571 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56), |
572 | { 0x15, 12, 13, 0x00000016 }, | 572 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13), |
573 | { 0x15, 0, 12, 0x00000800 }, | 573 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */ |
574 | { 0x30, 0, 0, 0x00000017 }, | 574 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23), |
575 | { 0x15, 2, 0, 0x00000084 }, | 575 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0), |
576 | { 0x15, 1, 0, 0x00000006 }, | 576 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0), |
577 | { 0x15, 0, 8, 0x00000011 }, | 577 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8), |
578 | { 0x28, 0, 0, 0x00000014 }, | 578 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), |
579 | { 0x45, 6, 0, 0x00001fff }, | 579 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0), |
580 | { 0xb1, 0, 0, 0x0000000e }, | 580 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), |
581 | { 0x48, 0, 0, 0x0000000e }, | 581 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14), |
582 | { 0x15, 2, 0, 0x00000016 }, | 582 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0), |
583 | { 0x48, 0, 0, 0x00000010 }, | 583 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16), |
584 | { 0x15, 0, 1, 0x00000016 }, | 584 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1), |
585 | { 0x06, 0, 0, 0x0000ffff }, | 585 | BPF_STMT(BPF_RET | BPF_K, 0xffff), |
586 | { 0x06, 0, 0, 0x00000000 }, | 586 | BPF_STMT(BPF_RET | BPF_K, 0), |
587 | }, | 587 | }, |
588 | CLASSIC, | 588 | CLASSIC, |
589 | /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800) | 589 | /* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800) |
@@ -609,39 +609,39 @@ static struct bpf_test tests[] = { | |||
609 | * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and | 609 | * ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and |
610 | * (len > 115 or len < 30000000000)' -d | 610 | * (len > 115 or len < 30000000000)' -d |
611 | */ | 611 | */ |
612 | { 0x28, 0, 0, 0x0000000c }, | 612 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12), |
613 | { 0x15, 30, 0, 0x000086dd }, | 613 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0), |
614 | { 0x15, 0, 29, 0x00000800 }, | 614 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29), |
615 | { 0x30, 0, 0, 0x00000017 }, | 615 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23), |
616 | { 0x15, 0, 27, 0x00000006 }, | 616 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27), |
617 | { 0x28, 0, 0, 0x00000014 }, | 617 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20), |
618 | { 0x45, 25, 0, 0x00001fff }, | 618 | BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0), |
619 | { 0xb1, 0, 0, 0x0000000e }, | 619 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), |
620 | { 0x48, 0, 0, 0x0000000e }, | 620 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14), |
621 | { 0x15, 2, 0, 0x00000016 }, | 621 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0), |
622 | { 0x48, 0, 0, 0x00000010 }, | 622 | BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16), |
623 | { 0x15, 0, 20, 0x00000016 }, | 623 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20), |
624 | { 0x28, 0, 0, 0x00000010 }, | 624 | BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16), |
625 | { 0x02, 0, 0, 0x00000001 }, | 625 | BPF_STMT(BPF_ST, 1), |
626 | { 0x30, 0, 0, 0x0000000e }, | 626 | BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14), |
627 | { 0x54, 0, 0, 0x0000000f }, | 627 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf), |
628 | { 0x64, 0, 0, 0x00000002 }, | 628 | BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2), |
629 | { 0x07, 0, 0, 0x00000005 }, | 629 | BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */ |
630 | { 0x60, 0, 0, 0x00000001 }, | 630 | BPF_STMT(BPF_LD | BPF_MEM, 1), |
631 | { 0x1c, 0, 0, 0x00000000 }, | 631 | BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0), |
632 | { 0x02, 0, 0, 0x00000005 }, | 632 | BPF_STMT(BPF_ST, 5), |
633 | { 0xb1, 0, 0, 0x0000000e }, | 633 | BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14), |
634 | { 0x50, 0, 0, 0x0000001a }, | 634 | BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26), |
635 | { 0x54, 0, 0, 0x000000f0 }, | 635 | BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0), |
636 | { 0x74, 0, 0, 0x00000002 }, | 636 | BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2), |
637 | { 0x07, 0, 0, 0x00000009 }, | 637 | BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */ |
638 | { 0x60, 0, 0, 0x00000005 }, | 638 | BPF_STMT(BPF_LD | BPF_MEM, 5), |
639 | { 0x1d, 4, 0, 0x00000000 }, | 639 | BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0), |
640 | { 0x80, 0, 0, 0x00000000 }, | 640 | BPF_STMT(BPF_LD | BPF_LEN, 0), |
641 | { 0x25, 1, 0, 0x00000073 }, | 641 | BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0), |
642 | { 0x35, 1, 0, 0xfc23ac00 }, | 642 | BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0), |
643 | { 0x06, 0, 0, 0x0000ffff }, | 643 | BPF_STMT(BPF_RET | BPF_K, 0xffff), |
644 | { 0x06, 0, 0, 0x00000000 }, | 644 | BPF_STMT(BPF_RET | BPF_K, 0), |
645 | }, | 645 | }, |
646 | CLASSIC, | 646 | CLASSIC, |
647 | { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, | 647 | { 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6, |
@@ -1453,17 +1453,24 @@ static struct bpf_test tests[] = { | |||
1453 | BPF_STMT(BPF_RET | BPF_A, 0), | 1453 | BPF_STMT(BPF_RET | BPF_A, 0), |
1454 | }, | 1454 | }, |
1455 | CLASSIC, | 1455 | CLASSIC, |
1456 | { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8, 0x90, 0xe2, | 1456 | { 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8, |
1457 | 0xba, 0x0a, 0x56, 0xb4, 0x08, 0x00, 0x45, 0x00, | 1457 | 0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4, |
1458 | 0x00, 0x28, 0x00, 0x00, 0x20, 0x00, 0x40, 0x11, | 1458 | 0x08, 0x00, |
1459 | 0x00, 0x00, 0xc0, 0xa8, 0x33, 0x01, 0xc0, 0xa8, | 1459 | 0x45, 0x00, 0x00, 0x28, 0x00, 0x00, |
1460 | 0x33, 0x02, 0xbb, 0xb6, 0xa9, 0xfa, 0x00, 0x14, | 1460 | 0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */ |
1461 | 0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | 1461 | 0xc0, 0xa8, 0x33, 0x01, |
1462 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | 1462 | 0xc0, 0xa8, 0x33, 0x02, |
1463 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | 1463 | 0xbb, 0xb6, |
1464 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | 1464 | 0xa9, 0xfa, |
1465 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | 1465 | 0x00, 0x14, 0x00, 0x00, |
1466 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc }, | 1466 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, |
1467 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | ||
1468 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | ||
1469 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | ||
1470 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | ||
1471 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | ||
1472 | 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, | ||
1473 | 0xcc, 0xcc, 0xcc, 0xcc }, | ||
1467 | { { 88, 0x001b } } | 1474 | { { 88, 0x001b } } |
1468 | }, | 1475 | }, |
1469 | { | 1476 | { |