summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/bpf/prog_tests/skb_ctx.c
diff options
context:
space:
mode:
authorNeil Spring <ntspring@fb.com>2021-08-30 20:33:56 -0700
committerAndrii Nakryiko <andrii@kernel.org>2021-09-07 16:55:32 -0700
commitb238290b965f23ac5f8aeb64cd731aef18aa796c (patch)
treeb3b69bb8f8be36d9453cc1bedba161e3c68ead80 /tools/testing/selftests/bpf/prog_tests/skb_ctx.c
parent27151f177827d478508e756c7657273261aaf8a9 (diff)
bpf: Permit ingress_ifindex in bpf_prog_test_run_xattr
bpf_prog_test_run_xattr takes a struct __sk_buff, but did not permit that __skbuff to include an nonzero ingress_ifindex. This patch updates to allow ingress_ifindex, convert the __sk_buff field to sk_buff (skb_iif) and back, and tests that the value is present from on BPF program side. The test sets an unlikely distinct value for ingress_ifindex (11) from ifindex (1), which is in line with the rest of the synthetic field tests. Adding this support allows testing BPF that operates differently on incoming and outgoing skbs by discriminating on this field. Signed-off-by: Neil Spring <ntspring@fb.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20210831033356.1459316-1-ntspring@fb.com
Diffstat (limited to 'tools/testing/selftests/bpf/prog_tests/skb_ctx.c')
-rw-r--r--tools/testing/selftests/bpf/prog_tests/skb_ctx.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/testing/selftests/bpf/prog_tests/skb_ctx.c b/tools/testing/selftests/bpf/prog_tests/skb_ctx.c
index fafeddaad6a9..2bf8c687348b 100644
--- a/tools/testing/selftests/bpf/prog_tests/skb_ctx.c
+++ b/tools/testing/selftests/bpf/prog_tests/skb_ctx.c
@@ -11,6 +11,7 @@ void test_skb_ctx(void)
.cb[3] = 4,
.cb[4] = 5,
.priority = 6,
+ .ingress_ifindex = 11,
.ifindex = 1,
.tstamp = 7,
.wire_len = 100,
@@ -97,6 +98,10 @@ void test_skb_ctx(void)
"ctx_out_ifindex",
"skb->ifindex == %d, expected %d\n",
skb.ifindex, 1);
+ CHECK_ATTR(skb.ingress_ifindex != 11,
+ "ctx_out_ingress_ifindex",
+ "skb->ingress_ifindex == %d, expected %d\n",
+ skb.ingress_ifindex, 11);
CHECK_ATTR(skb.tstamp != 8,
"ctx_out_tstamp",
"skb->tstamp == %lld, expected %d\n",