From: Zvi Effron <zeffron@riotgames.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Daniel Borkmann <daniel@iogearbox.net>,
Jesper Dangaard Brouer <hawk@kernel.org>,
Andrii Nakryiko <andrii.nakryiko@gmail.com>,
Maciej Fijalkowski <maciej.fijalkowski@intel.com>,
Martin KaFai Lau <kafai@fb.com>, Yonghong Song <yhs@fb.com>,
Zvi Effron <zeffron@riotgames.com>,
Cody Haas <chaas@riotgames.com>,
Lisa Watanabe <lwatanabe@riotgames.com>
Subject: [PATCH bpf-next v6 3/4] bpf: support specifying ingress via xdp_md context in BPF_PROG_TEST_RUN
Date: Thu, 17 Jun 2021 23:29:03 +0000 [thread overview]
Message-ID: <20210617232904.1899-4-zeffron@riotgames.com> (raw)
In-Reply-To: <20210617232904.1899-1-zeffron@riotgames.com>
Support specifying the ingress_ifindex and rx_queue_index of xdp_md
contexts for BPF_PROG_TEST_RUN.
The intended use case is to allow testing XDP programs that make decisions
based on the ingress interface or RX queue.
If ingress_ifindex is specified, look up the device by the provided index
in the current namespace and use its xdp_rxq for the xdp_buff. If the
rx_queue_index is out of range, or is non-zero when the ingress_ifindex is
0, return -EINVAL.
Co-developed-by: Cody Haas <chaas@riotgames.com>
Signed-off-by: Cody Haas <chaas@riotgames.com>
Co-developed-by: Lisa Watanabe <lwatanabe@riotgames.com>
Signed-off-by: Lisa Watanabe <lwatanabe@riotgames.com>
Signed-off-by: Zvi Effron <zeffron@riotgames.com>
---
net/bpf/test_run.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/net/bpf/test_run.c b/net/bpf/test_run.c
index 229c5deb813c..1ba15c741517 100644
--- a/net/bpf/test_run.c
+++ b/net/bpf/test_run.c
@@ -690,15 +690,35 @@ int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,
static int xdp_convert_md_to_buff(struct xdp_md *xdp_md, struct xdp_buff *xdp)
{
+ unsigned int ingress_ifindex, rx_queue_index;
+ struct netdev_rx_queue *rxqueue;
+ struct net_device *device;
+
if (!xdp_md)
return 0;
if (xdp_md->egress_ifindex != 0)
return -EINVAL;
- if (xdp_md->ingress_ifindex != 0 || xdp_md->rx_queue_index != 0)
+ ingress_ifindex = xdp_md->ingress_ifindex;
+ rx_queue_index = xdp_md->rx_queue_index;
+
+ if (!ingress_ifindex && rx_queue_index)
return -EINVAL;
+ if (ingress_ifindex) {
+ device = dev_get_by_index(current->nsproxy->net_ns,
+ ingress_ifindex);
+ if (!device)
+ return -EINVAL;
+
+ if (rx_queue_index >= device->real_num_rx_queues)
+ return -EINVAL;
+
+ rxqueue = __netif_get_rx_queue(device, rx_queue_index);
+ xdp->rxq = &rxqueue->xdp_rxq;
+ }
+
xdp->data = xdp->data_meta + xdp_md->data;
return 0;
--
2.31.1
next prev parent reply other threads:[~2021-06-17 23:29 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-17 23:29 [PATCH bpf-next v6 0/4] bpf: support input xdp_md context in BPF_PROG_TEST_RUN Zvi Effron
2021-06-17 23:29 ` [PATCH bpf-next v6 1/4] bpf: add function for XDP meta data length check Zvi Effron
2021-06-18 0:53 ` Yonghong Song
2021-06-17 23:29 ` [PATCH bpf-next v6 2/4] bpf: support input xdp_md context in BPF_PROG_TEST_RUN Zvi Effron
2021-06-18 0:57 ` Yonghong Song
2021-06-17 23:29 ` Zvi Effron [this message]
2021-06-18 0:58 ` [PATCH bpf-next v6 3/4] bpf: support specifying ingress via " Yonghong Song
2021-06-21 21:26 ` Daniel Borkmann
2021-06-21 22:46 ` Zvi Effron
2021-06-17 23:29 ` [PATCH bpf-next v6 4/4] selftests/bpf: Add test for " Zvi Effron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210617232904.1899-4-zeffron@riotgames.com \
--to=zeffron@riotgames.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=chaas@riotgames.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=hawk@kernel.org \
--cc=kafai@fb.com \
--cc=lwatanabe@riotgames.com \
--cc=maciej.fijalkowski@intel.com \
--cc=yhs@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).