|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [UNIKRAFT PATCH v2 13/15] plat/tap: Support tap_netdev_recv
Implement receive on the tap device.
Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
plat/drivers/include/tap/tap.h | 1 +
plat/drivers/tap/tap.c | 47 +++++++++++++++++++++++++++++++++++++++++-
plat/linuxu/tap_io.c | 13 ++++++++++++
3 files changed, 60 insertions(+), 1 deletion(-)
diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index 686b666..797a62e 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -47,5 +47,6 @@ int tap_close(int fd);
int tap_dev_configure(int fd, __u32 feature_flags, void *arg);
int tap_netif_configure(int fd, __u32 request, void *arg);
int tap_netif_create(void);
+__ssz tap_read(int fd, void *buf, size_t count);
#endif /* __PLAT_DRV_TAP_H */
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 3027aeb..998b9e8 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -255,12 +255,57 @@ static int tap_netdev_recv(struct uk_netdev *dev,
struct uk_netdev_rx_queue *queue,
struct uk_netbuf **pkt)
{
- int rc = -EINVAL;
+ int rc = 0;
+ struct tap_net_dev *tdev __maybe_unused;
+ struct uk_netbuf *_pkt = NULL;
UK_ASSERT(dev);
UK_ASSERT(queue && pkt);
+ tdev = to_tapnetdev(dev);
+
+ if (!queue->alloc_rxpkts)
+ return -EINVAL;
+
+
+ /**
+ * Allocate the packet in which the packet will be received.
+ */
+ rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt, 1);
+ if (rc == 0) {
+ uk_pr_err(DRIVER_NAME": Failed to allocate the memory\n");
+ rc = -ENOMEM;
+ _pkt = NULL;
+ goto err_exit;
+ }
+ uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d) %p(%d)\n",
+ tdev->name, queue->fd, _pkt->data, _pkt->len);
+ rc = tap_read(queue->fd, _pkt->data, _pkt->len);
+
+ if (rc > 0) {
+ uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc);
+ /* Setting the length of the packet */
+ _pkt->len = rc;
+ rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE;
+ } else if (rc == 0 || rc == -EWOULDBLOCK || rc == -EAGAIN) {
+ rc = 0;
+ goto err_exit;
+ } else {
+ uk_pr_err(DRIVER_NAME": Failed(%d) to read the packet\n", rc);
+ goto err_exit;
+ }
+ uk_pr_debug("uk_netdev buf ptr: %p\n", _pkt);
+
+ *pkt = _pkt;
+
+exit:
return rc;
+
+err_exit:
+ if (_pkt)
+ uk_netbuf_free(_pkt);
+ *pkt = NULL;
+ goto exit;
}
static int tap_netdev_xmit(struct uk_netdev *dev,
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 8ac3709..01c9bff 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -110,6 +110,19 @@ int tap_netif_create(void)
return sys_socket(AF_INET, SOCK_DGRAM, 0);
}
+ssize_t tap_read(int fd, void *buf, size_t count)
+{
+ ssize_t rc = -EINTR;
+
+ while (rc == -EINTR)
+ rc = sys_read(fd, buf, count);
+
+ if (rc < 0)
+ uk_pr_err("Failed(%ld) to read from the tap device\n", rc);
+
+ return rc;
+}
+
int tap_close(int fd)
{
return sys_close(fd);
--
2.7.4
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |