UPSTREAM: bpf: Allow to specify ifindex for skb in bpf_prog_test_run_skb

Now skb->dev is unconditionally set to the loopback device in current net
namespace. But if we want to test bpf program which contains code branch
based on ifindex condition (eg filters out localhost packets) it is useful
to allow specifying of ifindex from userspace. This patch adds such option
through ctx_in (__sk_buff) parameter.

Change-Id: Ia56479984ad24f3e0deb878c30dc42a6377bfb0b
Signed-off-by: Dmitry Yakunin <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
This commit is contained in:
Dmitry Yakunin 2020-08-03 12:05:45 +03:00 • committed by basamaryan
commit 64e25a5d35
No known key found for this signature in database
GPG key ID: 210D5384FB2A5885
2 changed files with 25 additions and 2 deletions

View file

@ -10,6 +10,7 @@ void test_skb_ctx(void)
.cb[3] = 4,
.cb[4] = 5,
.priority = 6,
.ifindex = 1,
.tstamp = 7,
.wire_len = 100,
.gso_segs = 8,
@ -90,6 +91,10 @@ void test_skb_ctx(void)
"ctx_out_priority",
"skb->priority == %d, expected %d\n",
skb.priority, 7);
CHECK_ATTR(skb.ifindex != 1,
"ctx_out_ifindex",
"skb->ifindex == %d, expected %d\n",
skb.ifindex, 1);
CHECK_ATTR(skb.tstamp != 8,
"ctx_out_tstamp",
"skb->tstamp == %lld, expected %d\n",