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>
This commit is contained in:
Родитель
108cc22a93
Коммит
ce25b68b74
143
lib/test_bpf.c
143
lib/test_bpf.c
|
@ -560,30 +560,30 @@ static struct bpf_test tests[] = {
|
||||||
{
|
{
|
||||||
"tcpdump port 22",
|
"tcpdump port 22",
|
||||||
.u.insns = {
|
.u.insns = {
|
||||||
{ 0x28, 0, 0, 0x0000000c },
|
BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
|
||||||
{ 0x15, 0, 8, 0x000086dd },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 0, 8), /* IPv6 */
|
||||||
{ 0x30, 0, 0, 0x00000014 },
|
BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 20),
|
||||||
{ 0x15, 2, 0, 0x00000084 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
|
||||||
{ 0x15, 1, 0, 0x00000006 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
|
||||||
{ 0x15, 0, 17, 0x00000011 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 17),
|
||||||
{ 0x28, 0, 0, 0x00000036 },
|
BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 54),
|
||||||
{ 0x15, 14, 0, 0x00000016 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 14, 0),
|
||||||
{ 0x28, 0, 0, 0x00000038 },
|
BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 56),
|
||||||
{ 0x15, 12, 13, 0x00000016 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 12, 13),
|
||||||
{ 0x15, 0, 12, 0x00000800 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x0800, 0, 12), /* IPv4 */
|
||||||
{ 0x30, 0, 0, 0x00000017 },
|
BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
|
||||||
{ 0x15, 2, 0, 0x00000084 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x84, 2, 0),
|
||||||
{ 0x15, 1, 0, 0x00000006 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 1, 0),
|
||||||
{ 0x15, 0, 8, 0x00000011 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x11, 0, 8),
|
||||||
{ 0x28, 0, 0, 0x00000014 },
|
BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
|
||||||
{ 0x45, 6, 0, 0x00001fff },
|
BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 6, 0),
|
||||||
{ 0xb1, 0, 0, 0x0000000e },
|
BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
|
||||||
{ 0x48, 0, 0, 0x0000000e },
|
BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
|
||||||
{ 0x15, 2, 0, 0x00000016 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
|
||||||
{ 0x48, 0, 0, 0x00000010 },
|
BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
|
||||||
{ 0x15, 0, 1, 0x00000016 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 1),
|
||||||
{ 0x06, 0, 0, 0x0000ffff },
|
BPF_STMT(BPF_RET | BPF_K, 0xffff),
|
||||||
{ 0x06, 0, 0, 0x00000000 },
|
BPF_STMT(BPF_RET | BPF_K, 0),
|
||||||
},
|
},
|
||||||
CLASSIC,
|
CLASSIC,
|
||||||
/* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
|
/* 3c:07:54:43:e5:76 > 10:bf:48:d6:43:d6, ethertype IPv4(0x0800)
|
||||||
|
@ -609,39 +609,39 @@ static struct bpf_test tests[] = {
|
||||||
* ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
|
* ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0) and
|
||||||
* (len > 115 or len < 30000000000)' -d
|
* (len > 115 or len < 30000000000)' -d
|
||||||
*/
|
*/
|
||||||
{ 0x28, 0, 0, 0x0000000c },
|
BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 12),
|
||||||
{ 0x15, 30, 0, 0x000086dd },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x86dd, 30, 0),
|
||||||
{ 0x15, 0, 29, 0x00000800 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x800, 0, 29),
|
||||||
{ 0x30, 0, 0, 0x00000017 },
|
BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 23),
|
||||||
{ 0x15, 0, 27, 0x00000006 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 0x6, 0, 27),
|
||||||
{ 0x28, 0, 0, 0x00000014 },
|
BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 20),
|
||||||
{ 0x45, 25, 0, 0x00001fff },
|
BPF_JUMP(BPF_JMP | BPF_JSET | BPF_K, 0x1fff, 25, 0),
|
||||||
{ 0xb1, 0, 0, 0x0000000e },
|
BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
|
||||||
{ 0x48, 0, 0, 0x0000000e },
|
BPF_STMT(BPF_LD | BPF_H | BPF_IND, 14),
|
||||||
{ 0x15, 2, 0, 0x00000016 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 2, 0),
|
||||||
{ 0x48, 0, 0, 0x00000010 },
|
BPF_STMT(BPF_LD | BPF_H | BPF_IND, 16),
|
||||||
{ 0x15, 0, 20, 0x00000016 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, 22, 0, 20),
|
||||||
{ 0x28, 0, 0, 0x00000010 },
|
BPF_STMT(BPF_LD | BPF_H | BPF_ABS, 16),
|
||||||
{ 0x02, 0, 0, 0x00000001 },
|
BPF_STMT(BPF_ST, 1),
|
||||||
{ 0x30, 0, 0, 0x0000000e },
|
BPF_STMT(BPF_LD | BPF_B | BPF_ABS, 14),
|
||||||
{ 0x54, 0, 0, 0x0000000f },
|
BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf),
|
||||||
{ 0x64, 0, 0, 0x00000002 },
|
BPF_STMT(BPF_ALU | BPF_LSH | BPF_K, 2),
|
||||||
{ 0x07, 0, 0, 0x00000005 },
|
BPF_STMT(BPF_MISC | BPF_TAX, 0x5), /* libpcap emits K on TAX */
|
||||||
{ 0x60, 0, 0, 0x00000001 },
|
BPF_STMT(BPF_LD | BPF_MEM, 1),
|
||||||
{ 0x1c, 0, 0, 0x00000000 },
|
BPF_STMT(BPF_ALU | BPF_SUB | BPF_X, 0),
|
||||||
{ 0x02, 0, 0, 0x00000005 },
|
BPF_STMT(BPF_ST, 5),
|
||||||
{ 0xb1, 0, 0, 0x0000000e },
|
BPF_STMT(BPF_LDX | BPF_B | BPF_MSH, 14),
|
||||||
{ 0x50, 0, 0, 0x0000001a },
|
BPF_STMT(BPF_LD | BPF_B | BPF_IND, 26),
|
||||||
{ 0x54, 0, 0, 0x000000f0 },
|
BPF_STMT(BPF_ALU | BPF_AND | BPF_K, 0xf0),
|
||||||
{ 0x74, 0, 0, 0x00000002 },
|
BPF_STMT(BPF_ALU | BPF_RSH | BPF_K, 2),
|
||||||
{ 0x07, 0, 0, 0x00000009 },
|
BPF_STMT(BPF_MISC | BPF_TAX, 0x9), /* libpcap emits K on TAX */
|
||||||
{ 0x60, 0, 0, 0x00000005 },
|
BPF_STMT(BPF_LD | BPF_MEM, 5),
|
||||||
{ 0x1d, 4, 0, 0x00000000 },
|
BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_X, 0, 4, 0),
|
||||||
{ 0x80, 0, 0, 0x00000000 },
|
BPF_STMT(BPF_LD | BPF_LEN, 0),
|
||||||
{ 0x25, 1, 0, 0x00000073 },
|
BPF_JUMP(BPF_JMP | BPF_JGT | BPF_K, 0x73, 1, 0),
|
||||||
{ 0x35, 1, 0, 0xfc23ac00 },
|
BPF_JUMP(BPF_JMP | BPF_JGE | BPF_K, 0xfc23ac00, 1, 0),
|
||||||
{ 0x06, 0, 0, 0x0000ffff },
|
BPF_STMT(BPF_RET | BPF_K, 0xffff),
|
||||||
{ 0x06, 0, 0, 0x00000000 },
|
BPF_STMT(BPF_RET | BPF_K, 0),
|
||||||
},
|
},
|
||||||
CLASSIC,
|
CLASSIC,
|
||||||
{ 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
|
{ 0x10, 0xbf, 0x48, 0xd6, 0x43, 0xd6,
|
||||||
|
@ -1453,17 +1453,24 @@ static struct bpf_test tests[] = {
|
||||||
BPF_STMT(BPF_RET | BPF_A, 0),
|
BPF_STMT(BPF_RET | BPF_A, 0),
|
||||||
},
|
},
|
||||||
CLASSIC,
|
CLASSIC,
|
||||||
{ 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8, 0x90, 0xe2,
|
{ 0x00, 0x1b, 0x21, 0x3c, 0x9d, 0xf8,
|
||||||
0xba, 0x0a, 0x56, 0xb4, 0x08, 0x00, 0x45, 0x00,
|
0x90, 0xe2, 0xba, 0x0a, 0x56, 0xb4,
|
||||||
0x00, 0x28, 0x00, 0x00, 0x20, 0x00, 0x40, 0x11,
|
0x08, 0x00,
|
||||||
0x00, 0x00, 0xc0, 0xa8, 0x33, 0x01, 0xc0, 0xa8,
|
0x45, 0x00, 0x00, 0x28, 0x00, 0x00,
|
||||||
0x33, 0x02, 0xbb, 0xb6, 0xa9, 0xfa, 0x00, 0x14,
|
0x20, 0x00, 0x40, 0x11, 0x00, 0x00, /* IP header */
|
||||||
0x00, 0x00, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
0xc0, 0xa8, 0x33, 0x01,
|
||||||
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
0xc0, 0xa8, 0x33, 0x02,
|
||||||
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
0xbb, 0xb6,
|
||||||
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
0xa9, 0xfa,
|
||||||
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
0x00, 0x14, 0x00, 0x00,
|
||||||
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc },
|
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc,
|
||||||
|
0xcc, 0xcc, 0xcc, 0xcc },
|
||||||
{ { 88, 0x001b } }
|
{ { 88, 0x001b } }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Загрузка…
Ссылка в новой задаче