[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT/LIBLWIP PATCH v3 15/16] plat/tap: Support tap_netdev_xmit



Implement packet send on a tap device.

Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
 plat/drivers/include/tap/tap.h |  1 +
 plat/drivers/tap/tap.c         | 15 +++++++++++++--
 plat/linuxu/tap_io.c           | 20 ++++++++++++++++++++
 3 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h
index f3e1b3eb..8bd1d888 100644
--- a/plat/drivers/include/tap/tap.h
+++ b/plat/drivers/include/tap/tap.h
@@ -46,5 +46,6 @@ 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);
+__ssz tap_write(int fd, const 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 03948150..f0257f8f 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -273,7 +273,6 @@ static int tap_netdev_recv(struct uk_netdev *dev,
        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;
                rc = UK_NETDEV_STATUS_UNDERRUN | UK_NETDEV_STATUS_MORE;
                return rc;
@@ -281,7 +280,6 @@ static int tap_netdev_recv(struct uk_netdev *dev,
        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 */
@@ -313,10 +311,23 @@ static int tap_netdev_xmit(struct uk_netdev *dev,
                           struct uk_netbuf *pkt)
 {
        int rc = -EINVAL;
+       struct tap_net_dev *tdev __unused;
 
        UK_ASSERT(dev);
        UK_ASSERT(queue && pkt);
 
+       tdev = to_tapnetdev(dev);
+
+       rc = tap_write(queue->fd, pkt->data, pkt->len);
+       if (rc > 0) {
+               uk_pr_info(DRIVER_NAME": Send packet of size %d\n", rc);
+               uk_netbuf_free(pkt);
+               rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE;
+       } else if (rc == -EWOULDBLOCK || rc == -EAGAIN) {
+               uk_pr_info(DRIVER_NAME": The send queue is full\n");
+               rc = UK_NETDEV_STATUS_UNDERRUN;
+       }
+
        return rc;
 }
 
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index 1072c60f..edef18ed 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -122,6 +122,26 @@ ssize_t tap_read(int fd, void *buf, size_t count)
        return rc;
 }
 
+ssize_t tap_write(int fd, const void *buf, size_t count)
+{
+       ssize_t rc = -EINTR;
+       size_t written = 0;
+
+       while (count > 0) {
+               rc = sys_write(fd, buf + written, count);
+               if (rc == -EINTR)
+                       continue;
+               else if (rc < 0) {
+                       uk_pr_err("Failed(%ld) to write to the tap device\n",
+                                 rc);
+                       return rc;
+               }
+               count -= rc;
+               written += rc;
+       }
+       return (ssize_t)written;
+}
+
 int tap_close(int fd)
 {
        return sys_close(fd);
-- 
2.20.1




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.