Commit 440ea4ae authored by Davide Caratti's avatar Davide Caratti Committed by David S. Miller

tc-testing: add selftests for 'bpf' action

Test d959: Add cBPF action with valid bytecode
Test f84a: Add cBPF action with invalid bytecode
Test e939: Add eBPF action with valid object-file
Test 282d: Add eBPF action with invalid object-file
Test d819: Replace cBPF bytecode and action control
Test 6ae3: Delete cBPF action
Test 3e0d: List cBPF actions
Test 55ce: Flush BPF actions
Test ccc3: Add cBPF action with duplicate index
Test 89c7: Add cBPF action with invalid index
Test 7ab9: Add cBPF action with cookie

Changes since v1:
 - use index=2^32-1 in test ccc3, add tests 7a89, 89c7 (thanks Roman Mashak)
 - added test 282d
Signed-off-by: default avatarDavide Caratti <dcaratti@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 82792a07
[
{
"id": "d959",
"name": "Add cBPF action with valid bytecode",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC action flush action bpf",
0,
1,
255
]
],
"cmdUnderTest": "$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' index 100",
"expExitCode": "0",
"verifyCmd": "$TC action get action bpf index 100",
"matchPattern": "action order [0-9]*: bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' default-action pipe.*index 100 ref",
"matchCount": "1",
"teardown": [
"$TC action flush action bpf"
]
},
{
"id": "f84a",
"name": "Add cBPF action with invalid bytecode",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC actions flush action bpf",
0,
1,
255
]
],
"cmdUnderTest": "$TC action add action bpf bytecode '4,40 0 0 12,31 0 1 2048,6 0 0 262144,6 0 0 0' index 100",
"expExitCode": "255",
"verifyCmd": "$TC action get action bpf index 100",
"matchPattern": "action order [0-9]*: bpf bytecode '4,40 0 0 12,31 0 1 2048,6 0 0 262144,6 0 0 0' default-action pipe.*index 100 ref",
"matchCount": "0",
"teardown": [
"$TC actions flush action bpf"
]
},
{
"id": "e939",
"name": "Add eBPF action with valid object-file",
"category": [
"actions",
"bpf"
],
"setup": [
"printf '#include <linux/bpf.h>\nchar l[] __attribute__((section(\"license\"),used))=\"GPL\"; __attribute__((section(\"action\"),used)) int m(struct __sk_buff *s) { return 2; }' | clang -O2 -x c -c - -target bpf -o _b.o",
[
"$TC action flush action bpf",
0,
1,
255
]
],
"cmdUnderTest": "$TC action add action bpf object-file _b.o index 667",
"expExitCode": "0",
"verifyCmd": "$TC action get action bpf index 667",
"matchPattern": "action order [0-9]*: bpf _b.o:\\[action\\] id [0-9]* tag 3b185187f1855c4c default-action pipe.*index 667 ref",
"matchCount": "1",
"teardown": [
"$TC action flush action bpf",
"rm -f _b.o"
]
},
{
"id": "282d",
"name": "Add eBPF action with invalid object-file",
"category": [
"actions",
"bpf"
],
"setup": [
"printf '#include <linux/bpf.h>\nchar l[] __attribute__((section(\"license\"),used))=\"GPL\"; __attribute__((section(\"action\"),used)) int m(struct __sk_buff *s) { s->data = 0x0; return 2; }' | clang -O2 -x c -c - -target bpf -o _c.o",
[
"$TC action flush action bpf",
0,
1,
255
]
],
"cmdUnderTest": "$TC action add action bpf object-file _c.o index 667",
"expExitCode": "255",
"verifyCmd": "$TC action get action bpf index 667",
"matchPattern": "action order [0-9]*: bpf _b.o:\\[action\\] id [0-9].*index 667 ref",
"matchCount": "0",
"teardown": [
"$TC action flush action bpf",
"rm -f _c.o"
]
},
{
"id": "d819",
"name": "Replace cBPF bytecode and action control",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC actions flush action bpf",
0,
1,
255
],
[
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' index 555",
0,
1,
255
]
],
"cmdUnderTest": "$TC action replace action bpf bytecode '4,40 0 0 12,21 0 1 2054,6 0 0 262144,6 0 0 0' drop index 555",
"expExitCode": "0",
"verifyCmd": "$TC action get action bpf index 555",
"matchPattern": "action order [0-9]*: bpf bytecode '4,40 0 0 12,21 0 1 2054,6 0 0 262144,6 0 0 0' default-action drop.*index 555 ref",
"matchCount": "1",
"teardown": [
"$TC action flush action bpf"
]
},
{
"id": "6ae3",
"name": "Delete cBPF action ",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC actions flush action bpf",
0,
1,
255
],
[
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' index 444",
0,
1,
255
]
],
"cmdUnderTest": "$TC action delete action bpf index 444",
"expExitCode": "0",
"verifyCmd": "$TC action get action bpf index 444",
"matchPattern": "action order [0-9]*: bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' default-action pipe.*index 444 ref",
"matchCount": "0",
"teardown": [
"$TC action flush action bpf"
]
},
{
"id": "3e0d",
"name": "List cBPF actions",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC action flush action bpf",
0,
1,
255
],
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' ok index 101",
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2054,6 0 0 262144,6 0 0 0' drop index 102",
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 33024,6 0 0 262144,6 0 0 0' continue index 103"
],
"cmdUnderTest": "$TC action list action bpf",
"expExitCode": "0",
"verifyCmd": "$TC action list action bpf",
"matchPattern": "action order [0-9]*: bpf bytecode",
"matchCount": "3",
"teardown": [
"$TC actions flush action bpf"
]
},
{
"id": "55ce",
"name": "Flush BPF actions",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC actions flush action bpf",
0,
1,
255
],
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' ok index 101",
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2054,6 0 0 262144,6 0 0 0' drop index 102",
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 33024,6 0 0 262144,6 0 0 0' continue index 103"
],
"cmdUnderTest": "$TC action flush action bpf",
"expExitCode": "0",
"verifyCmd": "$TC action list action bpf",
"matchPattern": "action order [0-9]*: bpf bytecode",
"matchCount": "0",
"teardown": [
"$TC actions flush action bpf"
]
},
{
"id": "ccc3",
"name": "Add cBPF action with duplicate index",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC actions flush action bpf",
0,
1,
255
],
"$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' index 4294967295"
],
"cmdUnderTest": "$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2054,6 0 0 262144,6 0 0 0' index 4294967295",
"expExitCode": "255",
"verifyCmd": "$TC action get action bpf index 4294967295",
"matchPattern": "action order [0-9]*: bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' default-action pipe.*index 4294967295",
"matchCount": "1",
"teardown": [
"$TC action flush action bpf"
]
},
{
"id": "89c7",
"name": "Add cBPF action with invalid index",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC actions flush action bpf",
0,
1,
255
]
],
"cmdUnderTest": "$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2054,6 0 0 262144,6 0 0 0' index 4294967296 cookie 12345",
"expExitCode": "255",
"verifyCmd": "$TC action ls action bpf",
"matchPattern": "action order [0-9]*: bpf bytecode '4,40 0 0 12,21 0 1 2048,6 0 0 262144,6 0 0 0' default-action pipe.*cookie 12345",
"matchCount": "0",
"teardown": [
"$TC action flush action bpf"
]
},
{
"id": "7ab9",
"name": "Add cBPF action with cookie",
"category": [
"actions",
"bpf"
],
"setup": [
[
"$TC actions flush action bpf",
0,
1,
255
]
],
"cmdUnderTest": "$TC action add action bpf bytecode '4,40 0 0 12,21 0 1 2054,6 0 0 262144,6 0 0 0' cookie d0d0d0d0d0d0d0d0",
"expExitCode": "0",
"verifyCmd": "$TC action list action bpf",
"matchPattern": "action order [0-9]*: bpf.*cookie d0d0d0d0d0d0d0",
"matchCount": "1",
"teardown": [
"$TC action flush action bpf"
]
}
]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment