selftests: bpf: add selftest for __sk_buff context in BPF_PROG_TEST_RUN
Simple test that sets cb to {1,2,3,4,5} and priority to 6, runs bpf
program that fails if cb is not what we expect and increments cb[i] and
priority. When the test finishes, we check that cb is now {2,3,4,5,6}
and priority is 7.
We also test the sanity checks:
* ctx_in is provided, but ctx_size_in is zero (same for
ctx_out/ctx_size_out)
* unexpected non-zero fields in __sk_buff return EINVAL
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-04-10 02:49:11 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
|
|
|
|
#include <linux/bpf.h>
|
2020-01-20 21:06:45 +08:00
|
|
|
#include <bpf/bpf_helpers.h>
|
selftests: bpf: add selftest for __sk_buff context in BPF_PROG_TEST_RUN
Simple test that sets cb to {1,2,3,4,5} and priority to 6, runs bpf
program that fails if cb is not what we expect and increments cb[i] and
priority. When the test finishes, we check that cb is now {2,3,4,5,6}
and priority is 7.
We also test the sanity checks:
* ctx_in is provided, but ctx_size_in is zero (same for
ctx_out/ctx_size_out)
* unexpected non-zero fields in __sk_buff return EINVAL
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-04-10 02:49:11 +08:00
|
|
|
|
|
|
|
int _version SEC("version") = 1;
|
|
|
|
char _license[] SEC("license") = "GPL";
|
|
|
|
|
|
|
|
SEC("skb_ctx")
|
|
|
|
int process(struct __sk_buff *skb)
|
|
|
|
{
|
|
|
|
#pragma clang loop unroll(full)
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
if (skb->cb[i] != i + 1)
|
|
|
|
return 1;
|
|
|
|
skb->cb[i]++;
|
|
|
|
}
|
|
|
|
skb->priority++;
|
2019-10-16 02:31:25 +08:00
|
|
|
skb->tstamp++;
|
2019-12-19 04:57:47 +08:00
|
|
|
skb->mark++;
|
selftests: bpf: add selftest for __sk_buff context in BPF_PROG_TEST_RUN
Simple test that sets cb to {1,2,3,4,5} and priority to 6, runs bpf
program that fails if cb is not what we expect and increments cb[i] and
priority. When the test finishes, we check that cb is now {2,3,4,5,6}
and priority is 7.
We also test the sanity checks:
* ctx_in is provided, but ctx_size_in is zero (same for
ctx_out/ctx_size_out)
* unexpected non-zero fields in __sk_buff return EINVAL
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-04-10 02:49:11 +08:00
|
|
|
|
2019-12-14 06:30:28 +08:00
|
|
|
if (skb->wire_len != 100)
|
|
|
|
return 1;
|
|
|
|
if (skb->gso_segs != 8)
|
|
|
|
return 1;
|
2020-03-04 04:05:03 +08:00
|
|
|
if (skb->gso_size != 10)
|
|
|
|
return 1;
|
2019-12-14 06:30:28 +08:00
|
|
|
|
selftests: bpf: add selftest for __sk_buff context in BPF_PROG_TEST_RUN
Simple test that sets cb to {1,2,3,4,5} and priority to 6, runs bpf
program that fails if cb is not what we expect and increments cb[i] and
priority. When the test finishes, we check that cb is now {2,3,4,5,6}
and priority is 7.
We also test the sanity checks:
* ctx_in is provided, but ctx_size_in is zero (same for
ctx_out/ctx_size_out)
* unexpected non-zero fields in __sk_buff return EINVAL
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2019-04-10 02:49:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|