[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200924032125.18619-24-jasowang@redhat.com>
Date: Thu, 24 Sep 2020 11:21:24 +0800
From: Jason Wang <jasowang@...hat.com>
To: mst@...hat.com, jasowang@...hat.com
Cc: lulu@...hat.com, kvm@...r.kernel.org,
virtualization@...ts.linux-foundation.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, rob.miller@...adcom.com,
lingshan.zhu@...el.com, eperezma@...hat.com, hanand@...inx.com,
mhabets@...arflare.com, eli@...lanox.com, amorenoz@...hat.com,
maxime.coquelin@...hat.com, stefanha@...hat.com,
sgarzare@...hat.com
Subject: [RFC PATCH 23/24] vdpa_sim: filter destination mac address
Add a simple unicast filter to filter out the dest MAC doesn't match
to the one stored in the config.
Signed-off-by: Jason Wang <jasowang@...hat.com>
---
drivers/vdpa/vdpa_sim/vdpa_sim.c | 49 ++++++++++++++++++++------------
1 file changed, 31 insertions(+), 18 deletions(-)
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c
index b21670e054ba..66d901fb4c57 100644
--- a/drivers/vdpa/vdpa_sim/vdpa_sim.c
+++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c
@@ -171,6 +171,22 @@ static void vdpasim_complete(struct vdpasim_virtqueue *vq, size_t len)
local_bh_enable();
}
+static bool receive_filter(struct vdpasim *vdpasim, size_t len)
+{
+ bool modern = vdpasim->features & (1ULL << VIRTIO_F_VERSION_1);
+ size_t hdr_len = modern ? sizeof(struct virtio_net_hdr_v1) :
+ sizeof(struct virtio_net_hdr);
+
+ if (len < ETH_ALEN + hdr_len)
+ return false;
+
+ if (!strncmp(vdpasim->buffer + hdr_len,
+ vdpasim->config.mac, ETH_ALEN))
+ return true;
+
+ return false;
+}
+
static void vdpasim_work(struct work_struct *work)
{
struct vdpasim *vdpasim = container_of(work, struct
@@ -178,7 +194,6 @@ static void vdpasim_work(struct work_struct *work)
struct vdpasim_virtqueue *txq = &vdpasim->vqs[1];
struct vdpasim_virtqueue *rxq = &vdpasim->vqs[0];
ssize_t read, write;
- size_t total_write;
int pkts = 0;
int err;
@@ -191,36 +206,34 @@ static void vdpasim_work(struct work_struct *work)
goto out;
while (true) {
- total_write = 0;
err = vringh_getdesc_iotlb(&txq->vring, &txq->riov, NULL,
&txq->head, GFP_ATOMIC);
if (err <= 0)
break;
+ read = vringh_iov_pull_iotlb(&txq->vring, &txq->riov,
+ vdpasim->buffer,
+ PAGE_SIZE);
+
+ if (!receive_filter(vdpasim, read)) {
+ vdpasim_complete(txq, 0);
+ continue;
+ }
+
err = vringh_getdesc_iotlb(&rxq->vring, NULL, &rxq->wiov,
&rxq->head, GFP_ATOMIC);
if (err <= 0) {
- vringh_complete_iotlb(&txq->vring, txq->head, 0);
+ vdpasim_complete(txq, 0);
break;
}
- while (true) {
- read = vringh_iov_pull_iotlb(&txq->vring, &txq->riov,
- vdpasim->buffer,
- PAGE_SIZE);
- if (read <= 0)
- break;
-
- write = vringh_iov_push_iotlb(&rxq->vring, &rxq->wiov,
- vdpasim->buffer, read);
- if (write <= 0)
- break;
-
- total_write += write;
- }
+ write = vringh_iov_push_iotlb(&rxq->vring, &rxq->wiov,
+ vdpasim->buffer, read);
+ if (write <= 0)
+ break;
vdpasim_complete(txq, 0);
- vdpasim_complete(rxq, total_write);
+ vdpasim_complete(rxq, write);
if (++pkts > 4) {
schedule_work(&vdpasim->work);
--
2.20.1
Powered by blists - more mailing lists