|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 14/15] plat/driver: Support tap_netdev_xmit
Transmit a network packet from the tap device.
Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
plat/drivers/tap/tap.c | 13 ++++++++++++-
plat/linuxu/include/linuxu/tap.h | 1 +
plat/linuxu/tap_io.c | 20 ++++++++++++++++++++
3 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c
index 69a042a..1765a0a 100644
--- a/plat/drivers/tap/tap.c
+++ b/plat/drivers/tap/tap.c
@@ -275,7 +275,6 @@ static int tap_netdev_recv(struct uk_netdev *dev,
uk_pr_err(DRIVER_NAME": Failed(%d) to read the packet\n", rc);
goto err_exit;
}
- uk_pr_debug("setting the buf %p\n", *pkt);
*pkt = _pkt;
@@ -294,10 +293,22 @@ 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_debug(DRIVER_NAME": Send packet of size %d\n", rc);
+ rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE;
+ } else if (rc == -EWOULDBLOCK || rc == -EAGAIN) {
+ uk_pr_debug(DRIVER_NAME": The send queue is full\n");
+ rc = 0;
+ }
+
return rc;
}
diff --git a/plat/linuxu/include/linuxu/tap.h b/plat/linuxu/include/linuxu/tap.h
index fd1c773..5c10123 100644
--- a/plat/linuxu/include/linuxu/tap.h
+++ b/plat/linuxu/include/linuxu/tap.h
@@ -154,5 +154,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);
__ssz tap_read(int fd, void *buf, size_t count);
+__ssz tap_write(int fd, const void *buf, size_t count);
#endif /* LINUXU_TAP_H */
diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c
index c29dfe7..44c6135 100644
--- a/plat/linuxu/tap_io.c
+++ b/plat/linuxu/tap_io.c
@@ -118,6 +118,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;
+ int written = 0;
+
+ while (count > 0) {
+ rc = sys_write(fd, buf, 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 written;
+}
+
int tap_close(int fd)
{
return sys_close(fd);
--
2.7.4
_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |